EEPROM test code problem.

  1. 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
     
  2. jcsd
  3. Baluncore

    Baluncore 3,031
    Science Advisor

    What is the microcontroller PICxxxxx ??
     
  4. I am using the microcontroller from ATMEL, AT89S8253.
     
  5. 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 with out comments you'll have a hard time following whats going on.

    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 wont allow you to write to the first block of memory.
     
  6. I kinda...get what you mean..kinda...
    So, I'll try "Org 200" and see if it works. Thanks.
     
  7. 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
     

    Attached Files:

Know someone interested in this topic? Share this thead via email, Google+, Twitter, or Facebook

Have something to add?

0
Draft saved Draft deleted