; 24c02的簡單操作 scl_2402 bit p3.5 sda_2402 bit p3.7 sp_begain equ 60h org 0 mov sp,#sp_begain acall delay acall delay acall delay mov 30h,#0 mov 31h,#1 mov 32h,#2 mov 33h,#3 mov 34h,#4 mov 35h,#5 mov 36h,#6 mov 37h,#7 write: clr a ;address mov r0,#30h ;point mov r1,#8 ;sum acall wrs_2402 cjne r1,#0ffh,next0 sjmp err_2402 next0: acall delay read: clr a ;address mov r0,#38h ;point mov r1,#8 ;sum acall rds_2402 cjne r1,#0ffh,next1 sjmp err_2402 next1: acall delay write0: mov a,#8 ;address mov r0,#38h ;point mov r1,#8 ;sum acall wrs_2402 cjne r1,#0ffh,next2 sjmp err_2402 next2: acall delay sjmp $ err_2402:sjmp $ delay: mov r6,#20 ;24M--5ms----24c02的寫入時間間隔 delay_0:djnz r7,$ djnz r6,delay_0 ret ;--------------------------------------------- wI2c equ 0a0h ;器件地址及寫操作 rI2c equ 0a1h ;器件地址及讀操作 sta_2402: ;啟始 setb sda_2402 setb scl_2402 sjmp $+2 ;24M至少間隔周期 sjmp $+2 clr sda_2402 sjmp $+2 sjmp $+2 clr scl_2402 sjmp $+2 sjmp $+2 ret stp_2402: ;結束 clr sda_2402 setb scl_2402 sjmp $+2 sjmp $+2 setb sda_2402 sjmp $+2 sjmp $+2 |