How do I troubleshoot my EEPROM test code problem?

  • Thread starter Thread starter NexusRevZ
  • Start date Start date
  • Tags Tags
    Code Test
AI Thread Summary
The discussion centers on troubleshooting EEPROM test code for an AT89S8253 microcontroller. The code attempts to write a specific binary value to EEPROM and then read it back, with LED indicators signaling success or failure. Key issues include potential memory locking at address 0, where the program is stored, and problems with EEPROM control register settings that lead to unintended jumps in the code. Suggestions include changing the memory address for writing and ensuring proper comments in the code for clarity. The conversation highlights the importance of understanding assembly language intricacies for effective debugging.
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

Very basic question. Consider a 3-terminal device with terminals say A,B,C. Kirchhoff Current Law (KCL) and Kirchhoff Voltage Law (KVL) establish two relationships between the 3 currents entering the terminals and the 3 terminal's voltage pairs respectively. So we have 2 equations in 6 unknowns. To proceed further we need two more (independent) equations in order to solve the circuit the 3-terminal device is connected to (basically one treats such a device as an unbalanced two-port...
suppose you have two capacitors with a 0.1 Farad value and 12 VDC rating. label these as A and B. label the terminals of each as 1 and 2. you also have a voltmeter with a 40 volt linear range for DC. you also have a 9 volt DC power supply fed by mains. you charge each capacitor to 9 volts with terminal 1 being - (negative) and terminal 2 being + (positive). you connect the voltmeter to terminal A2 and to terminal B1. does it read any voltage? can - of one capacitor discharge + of the...

Similar threads

Back
Top