How do I troubleshoot my EEPROM test code problem?

  • Thread starter Thread starter NexusRevZ
  • Start date Start date
  • Tags Tags
    Code Test
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting issues with EEPROM test code written for an ATMEL microcontroller (AT89S8253). Participants explore the code's functionality, particularly focusing on writing to and reading from EEPROM, and the challenges encountered during these processes.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant describes the intended functionality of the code, including LED indicators for success and failure in writing to EEPROM.
  • Another participant questions the choice of memory address 0 for writing data, suggesting that it may conflict with the program storage location, potentially leading to write protection issues.
  • A later reply proposes changing the origin address to "Org 200" to avoid conflicts with the program memory.
  • Another participant shares a revised code snippet and notes an issue with the EEPROM control register, specifically that the code keeps jumping back to the "START" label, indicating a possible logical error in the EEPROM write enable sequence.
  • There are suggestions to add comments to each line of the assembly code for better clarity and understanding.

Areas of Agreement / Disagreement

Participants express differing views on the potential causes of the EEPROM writing issue, with some suggesting memory address conflicts while others focus on the control logic in the code. No consensus is reached on the exact problem or solution.

Contextual Notes

Participants mention the importance of understanding the specific microcontroller's architecture and memory management, which may affect the behavior of the EEPROM operations. The discussion highlights the complexity of assembly language and the need for clear documentation within the code.

NexusRevZ
Messages
4
Reaction score
0
This simple code is test the write and read of EEPROM.



Firstly the LED at P1 will have all LED on, after a sec, have the P1 will have LED on.

Next, code is to write 01010101B into the EEPROM.

CJNE will check to see if it is written.

But, after comparing, the data isn't similar and the code is restarted.



If the writing process works the LED at P1.0 should be the only LED on, which will notify the success of writing into the EEPROM.



The next portion of the code will recall/read the written data in the EEPROM.

f it is able to read, P1 will have alternate LED on and off.

Please provide solutions, sources and why or what I had done wrong, to educate me. Thank you.

=============================

org 0
jmp start
eecon EQU 96h

start:
MOV A,#11111111B
MOV P1,A
ACALL DELAY0
MOV A,#00001111B
MOV P1,A
ACALL DELAY0

WRITE:
MOV EECON,#00001000b

mov dptr,#0 ;point to the memory location needed to write to. chosen location 0
mov a,#10101010B ;move the data (0fch) to Accumulator
movx @dptr,a ;write the data to the chosen location

MOVX A, @DPTR
CJNE A, #10101010B, START

WRITEFIN:
MOV A,#00000001B
MOV P1,A
ACALL DELAY0
READ:
MOV EECON,#00001000b
mov DPTR,#0 ;point to the memory location needed to read from. Chosen location 0
movx A,@dptr ;move the data within the memory location to the Accumulator
mov R0,A ;move the data within Accumulator to the Register

WAT: MOV P1,R0
SJMP WAT

;========================================
DELAY0:
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
RET
DELAY:
MOV R3, #255
HERE2:
MOV R4, #255
HERE:
DJNZ R4, HERE
DJNZ R3, HERE2
RET
end
 
Engineering news on Phys.org
What is the microcontroller PICxxxxx ??
 
I am using the microcontroller from ATMEL, AT89S8253.
 
Assembly code is a B***** to read if you know what is going on, near impossible if you don't.
I'd suggest before you try and get other people to help you that you comment each and every line of code.
When I write assembly code pretty much every line has a comment. I know this seems excessive but I find that even when you go back to a block of code that you wrote earlier without comments you'll have a hard time following what's going on.

That being said my guess is that you try and write the data to memory address 0.


NexusRevZ said:
mov dptr,#0 ;point to the memory location needed to write to. chosen location 0
mov a,#10101010B ;move the data (0fch) to Accumulator
movx @dptr,a ;write the data to the chosen location

but that is also where you are storing your program



NexusRevZ said:
org 0

its possible that the chip is locking the memory where the program is stored, that the chip won't allow you to write to the first block of memory.
 
cpscdave said:
That being said my guess is that you try and write the data to memory address 0.

but that is also where you are storing your program

its possible that the chip is locking the memory where the program is stored, that the chip won't allow you to write to the first block of memory.
I kinda...get what you mean..kinda...
So, I'll try "Org 200" and see if it works. Thanks.
 
I have recently changed my code after more online advise from other users. They have told me to refer to this pdf (In Section 3.3) , attached to this post.
But the problem I'm facing is within:

ORL EECON, #EEMEN
ORL EECON, #EEMWE

MOV A, EECON
ANL A, #WRTINH
JZ START


It keeps jumping on to "START". There's an error somewhere there.
=========================================

org 200
jmp start

EECON EQU 096H ; watchdog and memory control register
EEMEN EQU 00001000B ; EEPROM access enable bit
EEMWE EQU 00010000B ; EEPROM write enable bit
EELD EQU 00100000B ; EEPROM page load enable bit
WRTINH EQU 00000001B ; EEPROM WRTINH bit
RDY EQU 00000010B ; EEPROM RDY/BSY bit

START:
MOV A,#11111111B
MOV P1,A
ACALL DELAY0
START1: MOV A,#00001111B
MOV P1,A
ACALL DELAY0
MOV A,#11110000B
MOV P1,A
ACALL DELAY0


WRITE:
ORL EECON, #EEMEN
ORL EECON, #EEMWE

MOV A, EECON
ANL A, #WRTINH
JZ START

mov dptr,#0 ;point to the memory location needed to write to. chosen location 0
mov a,#10101010B ;move the data (0fch) to Accumulator
movx @dptr,a ;write the data to the chosen location

LOOP: MOV A, EECON
ANL A, #RDY
JNZ LOOP

LOOP1: MOV A, EECON
ANL A, #RDY
MOVX A, @DPTR
CJNE A, #10101010B, START1
XRL EECON, #EEMWE
XRL EECON, #EEMEN

WRITEFIN:
MOV A,#00000001B
MOV P1,A
ACALL DELAY0
READ:
MOV EECON,#00001000b
mov DPTR,#0 ;point to the memory location needed to read from. Chosen location 0
movx A,@dptr ;move the data within the memory location to the Accumulator
mov R0,A ;move the data within Accumulator to the Register

WAT: MOV P1,R0
SJMP WAT

;========================================
DELAY0:
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
RET
DELAY:
MOV R3, #255
HERE2:
MOV R4, #255
HERE:
DJNZ R4, HERE
DJNZ R3, HERE2
RET
end
 

Attachments