- 帖子
- 219
- 主题
- 115
- 精华
- 2
- 积分
- 480
- 在线时间
- 285 小时
- 注册时间
- 2007-5-27
|
- ;24c02的开机计数器,系统复位或停送电一次数码管加1
- ;***************************************************************************
- ;* (程序转载请著明出处 ,www.wenqi89s51.com) *
- SDA24 EQU P3.6
- SCLK24 EQU P3.7
- ORG 0000H
- AJMP MAIN
- ORG 0030H
- MAIN:
- MOV SP,#70H;设置堆栈栈顶
- MOV DPTR,#TAB
- MOV A,#00H ;读地址
- LCALL RD24
- CJNE A,#10,TT
- TT: JNC TT1
- AJMP TT2
- TT1: MOV A,#00
- TT2: MOV 30H,A
- MOVC A,@A+DPTR
- CLR P2.0 ;开数码管
- MOV P0,A ;送显示
- MOV A,30H
- INC A
- MOV B,A
- MOV A,#00H
- LCALL WT24
- AJMP $
- TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H;七段数码管0-9字形编码
- RD24: PUSH ACC ;读24C02子程序。
- SETB SDA24
- CLR SCLK24
- CALL START24
- MOV A,#0A0H
- CALL SHIFT8
- CALL ACK
- POP ACC
- CALL SHIFT8
- CALL ACK
- CALL START24
- MOV A,#0A1H
- CALL SHIFT8
- CALL ACK
- SETB SDA24
- MOV R7,#8
- CLR A
- SETB SDA24
- RD000: RL A
- SETB SCLK24
- MOV C,SDA24
- MOV ACC.0,C
- CLR SCLK24
- DJNZ R7,RD000
- RET
- ;-------------------------------
- ;写入24C02程序:
- WT24: PUSH ACC
- SETB SDA24
- CLR SCLK24
- CALL START24
- MOV A,#0A0H
- CALL SHIFT8
- CALL ACK
- POP ACC
- CALL SHIFT8
- CALL ACK
- MOV A,B
- CALL SHIFT8
- CALL ACK
- CALL STOP
- CALL DELAY2
- RET
- ; -------------------------------
- ;开始条件
- START24:CLR SDA24
- SETB SDA24
- SETB SCLK24
- CLR SDA24
- CLR SCLK24
- RET
- ;停止条件
- STOP: CLR SDA24
- SETB SCLK24
- SETB SDA24
- RET
- ;应答信号
- ACK: SETB SCLK24
- CLR SCLK24
- RET
- ;读、写数据
- SHIFT8: MOV R7,#8
- SH01: RLC A
- MOV SDA24,C
- SETB SCLK24
- CLR SCLK24
- DJNZ R7,SH01
- RET
- DELAY2:
- NOP
- NOP
- NOP
- NOP
- RET
- END
复制代码 |
|