Assembly code for EEPROM 24c16


Sample code for EEPROM 24c16.
Following code can be using for 8051 and 8052 ICs like: 89c51, 89c52, 89s51, 89s52, 89c2051.
And with little bit modification, this assembly program can be used for: 24c02, 24c04, 24c08, 24c32

 

;========================================================== ; Pin Definations ;========================================================== 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 ;========================================================= eeprom_delay mov 33h,#11 ;delay of 3 msec eeprom_delay_1 mov 32h,#ffh djnz 32h,$ djnz 33h,eeprom_delay_1 ret ;===================================================== ; Program ENDS here ;=====================================================