有时能写上并正确,有时出错1个字.有时只写上00地址的一个.请帮忙分析什么原因,硬件没有问题. PADDR EQU 0 ; programmable address (0..7) SIZE EQU 100h ; bytes per AT24C02 PSIZE EQU 8 ; bytes per page for AT24C02 FILL EQU 55h ; example fill value SCL BIT P3.4 SDA BIT P3.5 setb SDA setb SCL mov r1,#FILL mov r2,#0 mov r3,#100 mov r4,#4 x52:mov a,#PADDR call writebyte jnc x53 djnz r4,x52 setb c jmp x54 x53: inc r2 djnz r3,x52 clr c x54: ret
writebyte: call start jc x49 rl a orl a,#FADDR clr acc.0 call shout jc x48
; mov a,r3 ; call shout ; jc x48
mov a,r2 call shout jc x48
mov a,r1 call shout jc x48 clr c x48: call stop x49: ret start: ;发送开始信号,在SCL为1时,SDA从1跳到0 ;SDA,SCL返回0 ;总线无效CY设置为1 setb SDA setb SCL jnb SDA,X40 jnb SCL,X40 nop clr SDA nop nop nop nop nop CLR SCL CLR C jmp X41 X40:setb C X41:ret stop: ;发送停止信号,SCL为1时,SDA从0跳到1 ;SCL,SDA返回1 clr SDA nop nop setb SCL nop nop nop nop nop setb SDA ret shout: ;发送1个字节到at24cxx. mov r0,#8 X42:rlc a mov SDA,C nop nop setb SCL nop nop nop nop clr SCL djnz r0,X42 setb SDA nop nop setb SCL nop nop nop nop mov c,SDA clr SCL ret end |