Discussion in "8051 Discussion Forum" started by    NexusRevZ    Jul 30, 2014.
Wed Jul 30 2014, 07:01 am
#1
This simple code is test the write and read of EEPROM in AT89S8253.



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 ; 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
MOV A,#00001111B
MOV P1,A
ACALL DELAY0

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,#10H ;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


[ Edited Wed Jul 30 2014, 12:43 pm ]
Wed Jul 30 2014, 11:26 am
#2
You cannot move and read data from EEPROM immediately. To enable write in EEPROM You need to set EEMEM (Bit 3) and EEMWE(Bit4) in EECON register which will enable EEPROM memory and write access to it.

after writing data to EEPROM (i.e. after movx @dptr, a instruction) You need to read status bit RDY/BSY# in EECON register to see if write cycle has finished or not. Write cycle is finished as soon as this bit goes high. Now make changes to your program and try again.

[Topic moved to 8051 Discussion Forum]
 NexusRevZ like this.
Wed Jul 30 2014, 11:40 am
#3
Oh tahnk you so much for the reply. I will do immediate changes and get back to you.
Wed Jul 30 2014, 12:01 pm
#4
Ok, I have edited the code, it's updated above with RED TEXT.

I have created START and START1, to determine where the error is, if it jumps up to the beginning. After running the code again, the code jumps to START, telling me that the error is occuring within:

MOV A, EECON
ANL A, #WRTINH
JZ START

Is something wrong? Am I not setting the correct bits high?


[ Edited Wed Jul 30 2014, 12:41 pm ]
Mon Aug 04 2014, 01:34 am
#5
Try this code

;AT89S8253
EECON EQU 96H ; 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


org 0


start:
MOV A,#11111111B ;test leds
MOV P1,A
ACALL DELAY0
MOV A,#0
MOV P1,A
ACALL DELAY0
MOV A,#11111111B
MOV P1,A
ACALL DELAY0
MOV A,#0
MOV P1,A
ACALL DELAY0

ORL EECON, #EEMEN
ORL EECON, #EEMWE


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

;wait to complete the write
eeprom_wait:
mov A,EECON
ANL A,#RDY
jz eeprom_wait
;confirm by writing pattern to port 1

 MOVX A, @DPTR
MOV P1,A
 
 stop_wait:  ;stop
jmp stop_wait





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


[ Edited Mon Aug 04 2014, 11:03 am ]
Mon Aug 04 2014, 01:52 pm
#6


Try this code

;AT89S8253
EECON EQU 96H ; 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


org 0


start:
MOV A,#11111111B ;test leds
MOV P1,A
......
end

ExperimenterUK




Ok, I will try this and get back to you with the results. Thank you for helping.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Richardgar
Sat Apr 20 2024, 11:05 am
AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am