Assembly code for interfacing EEPROM 24c16 with 8051

EEPROM 24c16 Pinout
EEPROM 24c16 Pinout

If you are looking for an assembly code for Interfacing EEPROM with 8051 then you are at the right place. The Assembly code for EEPROM 24c16 is presented below.

This Sample code for EEPROM 24c16 can be used in electronics projects.

The following code can be used for 8051 and 8052 ICs like 89c51, 89c52, 89s51, 89s52, and 89c2051.

With a little bit of modification, this assembly program can be used for 24c02, 24c04, 24c08, 24c32

You can do EEPROM 24c16 interfacing with 8051 using the code given below.

Assembly code for Interfacing EEPROM with 8051

;==========================================================
;Pin Definitions
;==========================================================
eeprom_scl_pin          equ     a4h;scl p2.4
eeprom_sda_pin          equ     a5h;sda p2.5
;==========================================================
; Main Program starts from here
;==========================================================
                mov memory_address1,#00h
                mov memory_address2,#00h
                mov eeprom_data,#05
                call write_data

                mov memory_address1,#00h
                mov memory_address2,#00h
                call read_data
                mov 5dh,3ch

loop:            jmp loop
;=========================================================
; Sub routines starts from here
;=========================================================
write_data:      call eeprom_start
                mov a,#a0h          
                call send_data
                mov a,memory_address1          ;location address
                call send_data
                mov a,memory_address2          ;location address
                call send_data
                mov a,eeprom_data              ;data to be send
                call send_data
                call eeprom_stop
                ret   
;=========================================================
read_data:       call eeprom_start
                mov a,#a0h
                call send_data
                mov a,memory_address1          ;location address
                call send_data
                mov a,memory_address2          ;location address
                call send_data
                call eeprom_start
                mov a,#a1h
                call send_data
                call get_data
                call eeprom_stop
                ret
;=========================================================
eeprom_start:    setb eeprom_sda_pin
                nop
                setb eeprom_scl_pin
                nop
                nop
                clr eeprom_sda_pin
                nop
                clr eeprom_scl_pin
                ret
;=========================================================
eeprom_stop:     clr eeprom_sda_pin
                nop
                setb eeprom_scl_pin
                nop
                nop
                setb eeprom_sda_pin
                nop
                clr eeprom_scl_pin
                ret
;=========================================================
send_data:      mov r7,#00h
send:           rlc a
               mov eeprom_sda_pin,c
               call clock
               inc r7
               cjne r7,#08,send
               setb eeprom_sda_pin
               jb eeprom_sda_pin,$
             ; call eeprom_delay
               call clock
               ret
;=========================================================
get_data:
               mov r7,#00h
               setb eeprom_sda_pin
get:            mov c,eeprom_sda_pin
               call clock
               rlc a
               inc r7
               cjne r7,#08,get
               setb eeprom_sda_pin
               call clock
               mov 3ch,a
               ret
;=========================================================
clock:          setb eeprom_scl_pin
               nop
               nop
               clr eeprom_scl_pin
               ret
               END
;=========================================================
eeprom_delay:      mov 33h,#11      ;delay of 3 milliseconds 
eeprom_delay_1:     mov 32h,#ffh
                   djnz 32h,$
                   djnz 33h,eeprom_delay_1
                   ret
;=====================================================
;      Program ENDS here
;=====================================================

EEPROM ICs has application in various areas including data storage in embedded circuits, data manipulation, and data logger circuits.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

×

Hello!

Click one of our representatives below to chat on WhatsApp or send us an email to info@mtronixtech.com

×How can I help you?