1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

Please help in programming EEPROM.

Discussion in 'Microcontrollers' started by nikhildascl, Apr 22, 2012.

  1. nikhildascl

    nikhildascl New Member

    Likes Received:
    0
    Trophy Points:
    0
    I've written the code for EEPROM with 89c52. But it is not working. My code is given below. Please help...
    Code (Text):
    1.  
    2.         ORG 00H
    3. SDA EQU P1.4
    4. SCL EQU P1.5
    5.            
    6. ;I2C
    7.         LCALL I2C_START
    8.         MOV A,0xA0
    9.         LCALL I2C_SEND
    10.         LCALL ACK
    11.         MOV A,0x01
    12.         LCALL I2C_SEND
    13.         LCALL ACK
    14.         MOV A,#3FH      ; send 3Fh
    15.         LCALL I2C_SEND
    16.         LCALL ACK
    17.         LCALL I2C_STOP
    18.         CLR P2.0
    19.         LCALL DELAY
    20.         ;................
    21.         LCALL I2C_START
    22.         MOV A,0xA0
    23.         LCALL I2C_SEND
    24.         LCALL ACK
    25.         MOV A,0x10
    26.         LCALL I2C_SEND
    27.         LCALL ACK
    28.         MOV A,0xA1
    29.         LCALL I2C_SEND
    30.         LCALL ACK
    31.         MOV A,0x00
    32.         LCALL I2C_SEND
    33.         LCALL ACK
    34.         LCALL I2C_STOP
    35. AGAIN:  SJMP AGAIN
    36.  
    37.  
    38. ;I2C START
    39.  
    40.  
    41. I2C_START:
    42.         SETB SDA
    43.         LCALL DELAY
    44.         SETB SCL
    45.         LCALL DELAY
    46.         CLR SDA
    47.         LCALL DELAY
    48.         CLR SCL
    49.         LCALL DELAY
    50.         RET
    51. ;I2C STOP
    52.  
    53.  
    54. I2C_STOP:
    55.         CLR SDA
    56.         LCALL DELAY
    57.         SETB SCL
    58.         LCALL DELAY
    59.         SETB SDA
    60.         LCALL DELAY
    61.         CLR SCL
    62.         LCALL DELAY
    63.         RET
    64. ;I2C SEND BYTE
    65.  
    66.  
    67. I2C_SEND:
    68.         RLC A
    69.         MOV SDA,C
    70.         LCALL DELAY
    71.         SETB SCL
    72.         LCALL DELAY
    73.         CLR SCL
    74.         LCALL DELAY
    75.         RET
    76. ;I2C RECEIVE BYTE
    77.  
    78.  
    79. I2C_READ:
    80.         SETB SDA
    81.         LCALL DELAY
    82.         SETB SCL
    83.         MOVC A,@A+DPTR
    84.         LCALL DELAY
    85.         CLR SCL
    86.         CLR SDA
    87.         RET
    88.  
    89.  
    90. ;ACKNOWLEDGE
    91.  
    92.  
    93. ACK:   
    94.         SETB SCL
    95.         LCALL DELAY
    96.         LCALL DELAY
    97.         CLR SCL
    98.         RET
    99. ; DELAY PROGRAM
    100. DELAY: 
    101.         MOV R3,#255
    102. HERE:   MOV R4,#255
    103. HERE2:  DJNZ R2,HERE2
    104.         DJNZ R1,HERE
    105.         RET
    106. ;;LCD CLEAR
    107. CLRLCD:
    108.         MOV A,#01H
    109.         LCALL COMNWRT
    110.         LCALL DELAY
    111.         MOV A,#80H
    112.         LCALL COMNWRT
    113.         LCALL DELAY
    114.         RET
    115.  
Loading...

Share This Page