液晶显示万年历汇编源码
时间:10-02
整理:3721RD
点击:
最近看大家都在做万年历,我也做了一个,用纯汇编写的,有丰富注释。大家轻喷。
基于AT89S52+LCD12832+AD7416(温度传感器)+DS1388(实时芯片)
基于AT89S52+LCD12832+AD7416(温度传感器)+DS1388(实时芯片)
- ORG 0000H
- LJMP START
- ORG 0020H
- ;液晶管脚定义:
- RS EQU P2.3 //寄存器选择端,H数据,L指令
- RW EQU P2.4 //H读,L写
- EEE EQU P2.5 //串口模式下为读写操作使能端。E的下降沿锁定数据
- RES EQU P2.6
- PSB EQU P2.7 //H并,L串
- ;实时芯片管脚定义
- RST EQU P1.5
- SCL EQU P1.4 //SERIAL CLOCK INPUT
- SDA EQU P1.3 //SERIAL DATA OUTPUT内部寄存器的地址
- ;温度传感器管脚定义
- SCLL EQU P2.0
- SDAA EQU P2.1
- IICADD EQU 38H //IIC器件(DS1388) 内部寄存器的地址
- IICDAT EQU 39H //IIC器件(DS1388) 内部寄存器的内容(读出或写入)
- IICNUM EQU 3AH //IIC器件(DS1388) 的地址
- START:
- LCALL INIT
- MAIN:
- LCALL READ_TIME
- CLR 7FH ;BUTTON1按过与否的标志
- MOV 2EH, #0 ;BUTTON2未按下
- LJMP BUTTON
- ;=========================================================================
- ;初始化时间数值、时钟芯片、温度传感器、液晶
- ;=========================================================================
- INIT: ;初始化时间,30-37H分别存放着时间的数据
- MOV 30H, #00H ;1/100s
- MOV 31H, #00H ;s
- MOV 32H, #54H ;min
- MOV 33H, #08H ;h
- MOV 34H, #07H ;day of week
- MOV 35H, #08H ;date
- MOV 36H, #07H ;month
- MOV 37H, #12H ;year
- ; MOV PSW, #18H
- ;CLR 7FH //小时:分钟:秒 中的冒号显示与否的标志
-
- ;============================================
- ;DS1388's initialization
- SETB SCL
- SETB SDA
- CLR RST
- NOP
- SETB RST
- NOP
-
- MOV IICNUM,#11010000B //DS1388's address
- MOV R0, #30H
- MOV R1, #00H
- MOV R2, #08H
- TIME_INIT:
- MOV IICADD, R1
- MOV IICDAT, @R0
- LCALL IIC_WRITE
- LCALL DEL0
- INC R0
- INC R1
- DJNZ R2, TIME_INIT
-
- LCD_INIT: CLR RES
- LCALL DEL0
- SETB RES
- LCALL DEL0
- SETB PSB
- LCALL DEL0
- MOV A,#30H
- LCALL WRITE_COM
- LCALL DEL0
- MOV A,#30H
- LCALL WRITE_COM
- LCALL DEL0
- MOV A,#0CH
- LCALL WRITE_COM
- LCALL DEL0
- MOV A,#01H
- LCALL WRITE_COM
- LCALL DEL0
- MOV A,#06H
- LCALL WRITE_COM
- LCALL DEL0
- ;LCD_INIT FINISHED
- RET
- ;================================================================
- ;读取时间值并显示
- ;================================================================
- READ_TIME:
- MOV R0, #30H //读出DS1388的时间
- MOV R1, #00H
- MOV R2, #08H
- READ_TIME1:
- MOV IICADD, R1
- LCALL IIC_READ
- MOV @R0, IICDAT
- INC R0
- INC R1
- DJNZ R2, READ_TIME1
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
- MOV A, 37H //年份+"/"
- LCALL NUMSHOW
- MOV A, #2FH
- LCALL WRITE_DATA
- LCALL DEL0
-
- MOV A, 36H //月份+"/"
- LCALL NUMSHOW
- MOV A, #2FH
- LCALL WRITE_DATA
- LCALL DEL0
-
- MOV A, 35H //日期+"/"
- LCALL NUMSHOW
- MOV A, #20H
- LCALL WRITE_DATA
- LCALL DEL0
-
- MOV A, #20H
- LCALL WRITE_DATA
- LCALL DEL0
- MOV A, #85H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV DPTR,#TIME_WORD_1
- MOV R7, #4
- MOV R6, #0
- LCALL SHOW_CHINESE
-
- MOV DPTR, #TIME_WORD_2
- MOV R7, #2
- MOV R6,34H //日期的数据传给R6
- DEC R6 //减一是因为要从0开始数
- MOV A, R6 //乘以2,因为每个汉字占两位
- ADD A, R6
- MOV R6, A
- LCALL SHOW_CHINESE
-
- MOV A, #91H //小时+":"
- LCALL WRITE_COM
- LCALL DEL0
- MOV A, 33H
- LCALL NUMSHOW
- MOV A, #3AH
- LCALL WRITE_DATA
-
- MOV A, 32H //分钟+":"
- LCALL NUMSHOW
- MOV A, #3AH
- LCALL WRITE_DATA
-
- MOV A, 31H //秒
- LCALL NUMSHOW
-
- RET
- ;===========================================================================
- ;显示温度
- ;===========================================================================
- SHOW_TEM:
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV DPTR, #TEM_WORD_1
- MOV R6, #0
- MOV R7, #10
- LCALL SHOW_CHINESE
-
- MOV A, #85H
- LCALL WRITE_COM
- LCALL DEL0
- LCALL IIC_READ2
- MOV B,#10
- div AB
- ANL A,#0FH
- SWAP A
- ADD A,B
- LCALL NUMSHOW
-
- MOV DPTR, #TEM_WORD_2
- MOV R6, #0
- MOV R7, #2
- LCALL SHOW_CHINESE
-
- MOV A, #87H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV A, #20H
- LCALL WRITE_DATA
- LCALL DEL0
- MOV A, #20H
- LCALL WRITE_DATA
- LCALL DEL0
- MOV A, 90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV R6, #16
- TEM_CLR:
- MOV A, #20H
- LCALL WRITE_DATA
- LCALL DEL0
- DJNZ R6, TEM_CLR
- DJNZ R5, SHOW_TEM
- LJMP MAIN
- ;===============================================================================
- ;按键处理
- ;===============================================================================
- BUTTON:
- MOV P3, #0FFH
- MOV A, P3
- CPL A
- JB ACC.3, BUTTON1
- JB ACC.5, BUTTON2
- JB ACC.6, BUTTON3
- JB ACC.7, BUTTON4
- MOV A,2EH
- CJNE A, #0,BUTTON
- SJMP TO_MAIN
- BUTTON1: SJMP BUTTON1_0
- BUTTON2: SJMP BUTTON2_0
- BUTTON3: AJMP BUTTON3_0
- BUTTON4: AJMP BUTTON4_0
- BUTTON1_0:
- LCALL DEL0
- MOV C, P3.3
- CPL C
- JNC TO_MAIN
- BUTTON1_1:
- MOV C, P3.3
- JNC BUTTON1_1 ;等待按键松开
- JB 7FH, TO_MAIN
- SETB 7FH ;标记BUTTON1被按过
- MOV 2EH, #1 ;YEAR_SET的标记
- SJMP TO_YEAR_SET
- TO_MAIN:LJMP MAIN
- TO_YEAR_SET: LCALL YEAR_SET
- JB 7FH, BUTTON
- SJMP TO_MAIN
- TO_SHOW_TEM:
- MOV R5, #40
- LJMP SHOW_TEM
- ;=================================================
- BUTTON2_0:
- LCALL DEL0
- MOV C, P3.5
- CPL C
- JNC TO_MAIN
- BUTTON2_1:
- MOV C, P3.5
- JNC BUTTON2_1 ;等待按键松开
- JNB 7FH, TO_SHOW_TEM
- MOV A, 2EH
-
- CJNE A, #1, JUDGE1
- MOV 2EH, #2
- LCALL MON_SET
- LJMP BUTTON
- JUDGE1:
- CJNE A, #2,JUDGE2
- MOV 2EH, #3
- LCALL DATE_SET
- LJMP BUTTON
- JUDGE2:
- CJNE A, #3,JUDGE3
- MOV 2EH, #4
- LCALL DAY_SET
- LJMP BUTTON
- JUDGE3:
- CJNE A, #4,JUDGE4
- MOV 2EH, #5
- LCALL HOUR_SET
- LJMP BUTTON
- JUDGE4:
- CJNE A, #5,JUDGE5
- MOV 2EH, #6
- LCALL MIN_SET
- LJMP BUTTON
- JUDGE5:
- CJNE A, #6,JUDGE6
- MOV 2EH, #7
- LCALL SEC_SET
- LJMP BUTTON
- JUDGE6:
- MOV 2EH, #1
- LCALL YEAR_SET
- LJMP BUTTON
- ;===============================================================================
- BUTTON3_0:
- LCALL DEL0
- MOV C, P3.6
- CPL C
- JNC TO_MAIN
-
- BUTTON3_1:
- MOV C, P3.6
- JNC BUTTON3_1 ;等待按键松开
- JNB 7FH, TO_SHOW_STORY
- MOV A, 2EH
- CJNE A, #1, JUDGE11
- MOV A,37H
- CJNE A, #99H,ADD_37_1
- MOV 37H, #00H
- SJMP ADD_37_3
- ADD_37_1:
- ANL A,#0FH
- CJNE A, #09H,ADD_37_2
- MOV A, 37H
- ANL A, #0F0H
- ADD A,#10H
- MOV 37H, A
- SJMP ADD_37_3
- TO_SHOW_STORY:
- MOV R5, #80
- LJMP SHOW_STORY
- ADD_37_2:
- INC 37H
- ADD_37_3:
- MOV IICADD, #07H
- MOV IICDAT, 37H
- LCALL IIC_WRITE
- LCALL YEAR_SET
- JUDGE11:
- MOV A, 2EH
- CJNE A, #2, JUDGE22
- MOV A, 36H
- CJNE A, #12H, ADD_36_1
- MOV 36H, #01H
- SJMP ADD_36_3
- ADD_36_1:
- CJNE A, #09H, ADD_36_2
- MOV 36H, #10H
- SJMP ADD_36_3
- ADD_36_2:
- INC 36H
- SJMP ADD_36_3
- ADD_36_3:
- MOV IICADD, #06H
- MOV IICDAT, 36H
- LCALL IIC_WRITE
- LCALL MON_SET
- JUDGE22:
- MOV A, 2EH
- CJNE A, #3, JUDGE33
- MOV A,35H
- CJNE A, #31H,ADD_35_1
- MOV 35H, #01H
- SJMP ADD_35_3
- ADD_35_1:
- ANL A, #0FH
- CJNE A, #09H, ADD_35_2
- MOV A, 35H
- ANL A,#0F0H
- ADD A, #10H
- MOV 35H, A
- SJMP ADD_35_3
- ADD_35_2:
- INC 35H
- ADD_35_3:
- MOV IICADD, #05H
- MOV IICDAT, 35H
- LCALL IIC_WRITE
- LCALL DATE_SET
- JUDGE33:
- MOV A, 2EH
- CJNE A, #4, JUDGE44
- MOV A, 34H
- CJNE A, #07H, ADD_34_1
- MOV 34H, #01H
- SJMP ADD_34_2
- ADD_34_1:
- INC 34H
- ADD_34_2:
- MOV IICADD, #04H
- MOV IICDAT, 34H
- LCALL IIC_WRITE
- LCALL DAY_SET
- JUDGE44:
- MOV A, 2EH
- CJNE A, #5, JUDGE55
- MOV A, 33H
- CJNE A, #23H, ADD_33_1
- MOV 33H, #00H
- SJMP ADD_33_3
- ADD_33_1:
- ANL A, #0FH
- CJNE A, #09H, ADD_33_2
- MOV A, 33H
- ANL A, #0F0H
- ADD A, #10H
- MOV 33H, A
- SJMP ADD_33_3
- ADD_33_2:
- INC 33H
- ADD_33_3:
- MOV IICADD, #03H
- MOV IICDAT, 33H
- LCALL IIC_WRITE
- LCALL HOUR_SET
- JUDGE55:
- MOV A, 2EH
- CJNE A, #6, JUDGE66
- MOV A, 32H
- CJNE A, #59H, ADD_32_1
- MOV 32H, #00H
- SJMP ADD_32_3
- ADD_32_1:
- ANL A, #0FH
- CJNE A,#09H, ADD_32_2
- MOV A, 32H
- ANL A, #0F0H
- ADD A, #10H
- MOV 32H, A
- SJMP ADD_32_2
- ADD_32_2:
- INC 32H
- ADD_32_3:
- MOV IICADD, #02H
- MOV IICDAT, 32H
- LCALL IIC_WRITE
- LCALL MIN_SET
- JUDGE66:
- MOV A, 2EH
- CJNE A, #7, TO_BUTTON
- MOV 31H, #0
- MOV IICADD, #01H
- MOV IICDAT, 31H
- LCALL IIC_WRITE
- LCALL SEC_SET
-
- TO_BUTTON:LJMP BUTTON
- ;===============================================================================
- BUTTON4_0:
- LCALL DEL0
- MOV C, P3.7
- CPL C
- JNC TO_MAIN1
-
- BUTTON4_1:
- MOV C, P3.7
- JNC BUTTON4_1 ;等待按键松开
- JNB 7FH, TO_SHOW_VISION
- MOV A, 2EH
- CJNE A, #1, JUDGE111
- MOV A,37H
- CJNE A, #00H,DEC_37_1
- MOV 37H, #99H
- SJMP DEC_37_3
- DEC_37_1:
- ANL A,#0FH
- CJNE A, #00H,DEC_37_2
- MOV A, 37H
- SUBB A, #07H
- MOV 37H, A
- SJMP DEC_37_3
- TO_SHOW_VISION:
- MOV R5, #80
- LJMP SHOW_VISION
- TO_MAIN1: LJMP MAIN
- DEC_37_2:
- DEC 37H
- DEC_37_3:
- MOV IICADD, #07H
- MOV IICDAT, 37H
- LCALL IIC_WRITE
- LCALL YEAR_SET
- JUDGE111:
- MOV A, 2EH
- CJNE A, #2, JUDGE222
- MOV A, 36H
- CJNE A, #01H, DEC_36_1
- MOV 36H, #12H
- SJMP DEC_36_3
- DEC_36_1:
- CJNE A, #09H, DEC_36_2
- MOV A, 36H
- SUBB A, #07H
- MOV 36H, A
- SJMP DEC_36_3
- DEC_36_2:
- DEC 36H
- SJMP DEC_36_3
- DEC_36_3:
- MOV IICADD, #06H
- MOV IICDAT, 36H
- LCALL IIC_WRITE
- LCALL MON_SET
- JUDGE222:
- MOV A, 2EH
- CJNE A, #3, JUDGE333
- MOV A,35H
- CJNE A, #01H,DEC_35_1
- MOV 35H, #31H
- SJMP DEC_35_3
- DEC_35_1:
- ANL A, #0FH
- CJNE A, #00H, DEC_35_2
- MOV A, 35H
- SUBB A, #07H
- MOV 35H, A
- SJMP DEC_35_3
- DEC_35_2:
- DEC 35H
- DEC_35_3:
- MOV IICADD, #05H
- MOV IICDAT, 35H
- LCALL IIC_WRITE
- LCALL DATE_SET
- JUDGE333:
- MOV A, 2EH
- CJNE A, #4, JUDGE444
- MOV A, 34H
- CJNE A, #01H, DEC_34_1
- MOV 34H, #07H
- SJMP DEC_34_2
- DEC_34_1:
- DEC 34H
- DEC_34_2:
- MOV IICADD, #04H
- MOV IICDAT, 34H
- LCALL IIC_WRITE
- LCALL DAY_SET
- JUDGE444:
- MOV A, 2EH
- CJNE A, #5, JUDGE555
- MOV A, 33H
- CJNE A, #00H, DEC_33_1
- MOV 33H, #23H
- SJMP DEC_33_3
- DEC_33_1:
- ANL A, #0FH
- CJNE A, #00H, DEC_33_2
- MOV A, 33H
- SUBB A, #07H
- MOV 33H, A
- SJMP DEC_33_3
- DEC_33_2:
- DEC 33H
- DEC_33_3:
- MOV IICADD, #03H
- MOV IICDAT, 33H
- LCALL IIC_WRITE
- LCALL HOUR_SET
- JUDGE555:
- MOV A, 2EH
- CJNE A, #6, JUDGE666
- MOV A, 32H
- CJNE A, #00H, DEC_32_1
- MOV 32H, #59H
- SJMP DEC_32_3
- DEC_32_1:
- ANL A, #0FH
- CJNE A,#00H, DEC_32_2
- MOV A, 32H
- SUBB A, #07H
- MOV 32H, A
- SJMP DEC_32_2
- DEC_32_2:
- DEC 32H
- DEC_32_3:
- MOV IICADD, #02H
- MOV IICDAT, 32H
- LCALL IIC_WRITE
- LCALL MIN_SET
- JUDGE666:
- MOV A, 2EH
- CJNE A, #7, TO_BUTTON1
- MOV 31H, #0
- MOV IICADD, #01H
- MOV IICDAT, 31H
- LCALL IIC_WRITE
- LCALL SEC_SET
-
- TO_BUTTON1:LJMP BUTTON
- ;===============================================================================
- SHOW_STORY:
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #STORY1
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
- DJNZ R5, SHOW_STORY
- LJMP MAIN
-
- SHOW_VISION:
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #VISION
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
-
- MOV A, #90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #BLANK
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
-
- DJNZ R5, SHOW_VISION
- LJMP MAIN
-
- YEAR_SET:
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV R6, #0
- MOV R7, #14
- MOV DPTR, #YEAR_SET_WORD
- LCALL SHOW_CHINESE
-
- MOV IICADD, #07H
- LCALL IIC_READ
- MOV A, IICDAT
- LCALL NUMSHOW
-
- MOV A, #90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #BLANK
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
- RET
-
- MON_SET:
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV R6, #0
- MOV R7, #14
- MOV DPTR, #MON_SET_WORD
- LCALL SHOW_CHINESE
-
- MOV IICADD, #06H
- LCALL IIC_READ
- MOV A, IICDAT
- LCALL NUMSHOW
- MOV A, #90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #BLANK
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
- RET
-
- DATE_SET:
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV R6, #0
- MOV R7, #14
- MOV DPTR, #DATE_SET_WORD
- LCALL SHOW_CHINESE
-
- MOV IICADD, #05H
- LCALL IIC_READ
- MOV A, IICDAT
- LCALL NUMSHOW
- MOV A, #90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #BLANK
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
- RET
-
- DAY_SET:
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV R6, #0
- MOV R7, #14
- MOV DPTR, #DAY_SET_WORD
- LCALL SHOW_CHINESE
-
- MOV IICADD, #04H
- LCALL IIC_READ
- MOV A, IICDAT
- LCALL NUMSHOW
- MOV A, #90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #BLANK
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
- RET
-
- HOUR_SET:
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV R6, #0
- MOV R7, #14
- MOV DPTR, #HOUR_SET_WORD
- LCALL SHOW_CHINESE
-
- MOV IICADD, #03H
- LCALL IIC_READ
- MOV A, IICDAT
- LCALL NUMSHOW
- MOV A, #90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #BLANK
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
- RET
-
- MIN_SET:
-
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV R6, #0
- MOV R7, #14
- MOV DPTR, #MIN_SET_WORD
- LCALL SHOW_CHINESE
-
- MOV IICADD, #02H
- LCALL IIC_READ
- MOV A, IICDAT
- LCALL NUMSHOW
- MOV A, #90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #BLANK
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
- RET
-
- SEC_SET:
-
- MOV A, #80H
- LCALL WRITE_COM
- LCALL DEL0
-
- MOV R6, #0
- MOV R7, #14
- MOV DPTR, #SEC_SET_WORD
- LCALL SHOW_CHINESE
-
- MOV IICADD, #01H
- LCALL IIC_READ
- MOV A, IICDAT
- LCALL NUMSHOW
-
- MOV A, #90H
- LCALL WRITE_COM
- LCALL DEL0
- MOV DPTR, #BLANK
- MOV R6, #0
- MOV R7, #16
- LCALL SHOW_CHINESE
-
- RET
-
- ;===============================================================================
- ;十六进制数据转换为LCD可显示的ASCII码数据
- ;===============================================================================
- NUMSHOW: MOV B,A
- ANL A,#0F0H
- SWAP A
- ADD A,#30H
- LCALL WRITE_DATA
- LCALL DEL0
- MOV A,B
- ANL A,#0FH
- ADD A,#30H
- LCALL WRITE_DATA
- LCALL DEL0
- RET
- ;==========================================================================
- ;LCD的接口函数,WRITE_COM写地址,WRITE_DATA写数据
- ;==========================================================================
- WRITE_COM:
- CLR RS
- LCALL DEL0
- CLR RW
- LCALL DEL0
- SETB EEE
- RLC A
- MOV 00H,C
- RLC A
- MOV 01H,C
- RLC A
- MOV 02H,C
- RLC A
- MOV 03H,C
- RLC A
- MOV 04H,C
- RLC A
- MOV 05H,C
- RLC A
- MOV 06H,C
- RLC A
- MOV 07H,C
- MOV A,20H
- MOV P0,A
- LCALL DEL0
- CLR EEE
- LCALL DEL0
- RET
- WRITE_DATA:
- SETB RS
- LCALL DEL0
- CLR RW
- LCALL DEL0
- SETB EEE
- RLC A
- MOV 00H,C
- RLC A
- MOV 01H,C
- RLC A
- MOV 02H,C
- RLC A
- MOV 03H,C
- RLC A
- MOV 04H,C
- RLC A
- MOV 05H,C
- RLC A
- MOV 06H,C
- RLC A
- MOV 07H,C
- MOV A,20H
- MOV P0,A
- LCALL DEL0
- CLR EEE
- LCALL DEL0
- RET
- ;===================================================================
- ;延时程序
- ;===================================================================
- DEL0:MOV 20H,#2
- DEL1:MOV 21H,#2
- DEL2:MOV 22H,#25
- DJNZ 22H,$
- DJNZ 21H,DEL2
- DJNZ 20H,DEL1
- RET
- ;--------------------------------------------
- ;IIC总线(读,写操作)
- ;IIC_WRITE:
- ;IICNUM中存放要写入的元件的地址,IICADD中存放要写入的地址, IICDAT中存放要写入的数据
- ;IIC_READ:
- ;IICNUM中存放要读取的元件的地址,IICADD中存放要写入的地址, IICDAT中存放读取的数据
- ;Made by 651927693
- ;2012/08/08
- ;--------------------------------------------
- IIC_WRITE:
- LCALL IIC_START
- MOV A, IICNUM
- LCALL IIC_WRITE_BYTE
- ;LCALL IIC_WRITE_ACK
- LCALL IIC_ACK
- JC IIC_WRITE
- MOV A, IICADD
- LCALL IIC_WRITE_BYTE
- ;LCALL IIC_WRITE_ACK
- LCALL IIC_ACK
- JC IIC_WRITE
- MOV A, IICDAT
- LCALL IIC_WRITE_BYTE
- ;LCALL IIC_WRITE_ACK
- LCALL IIC_ACK
- JC IIC_WRITE
- LCALL IIC_STOP
- RET
- IIC_READ:
- LCALL IIC_START
- MOV A, IICNUM
- LCALL IIC_WRITE_BYTE
- ;LCALL IIC_WRITE_ACK
- LCALL IIC_ACK
- JC IIC_READ
- MOV A, IICADD
- LCALL IIC_WRITE_BYTE
- ;LCALL IIC_WRITE_ACK
- LCALL IIC_ACK
- JC IIC_READ
-
- ;RESTART
- LCALL IIC_START
- MOV A, IICNUM
- ORL A, #01H
- LCALL IIC_WRITE_BYTE
- ;LCALL IIC_WRITE_ACK
- LCALL IIC_ACK
- JC IIC_READ
- LCALL IIC_READ_BYTE
- ;LCALL IIC_READ_ACK
- MOV IICDAT, A
- LCALL IIC_STOP
- RET
-
- ;=====================================================
- IIC_START:
- SETB SDA
- NOP
- SETB SCL
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SDA
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SCL
- RET
- ;=====================================================
- IIC_STOP:
- CLR SDA
- NOP
- SETB SCL
- NOP
- NOP
- NOP
- NOP
- NOP
- SETB SDA
- NOP
- NOP
- NOP
- NOP
- NOP
- RET
- ;=====================================================
- IIC_WRITE_BYTE:
- MOV B, #08H
- IIC_WRITE_BYTE0:
- RLC A
- MOV SDA, C
- NOP
- SETB SCL
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SCL
- NOP
- DJNZ B, IIC_WRITE_BYTE0
- RET
- ;====================================================
- IIC_READ_BYTE:
- MOV B, #08H
- CLR A
- SETB SDA
- NOP
- IIC_READ_BYTE0:
- SETB SCL
- NOP
- NOP
- NOP
- NOP
- NOP
- MOV C, SDA
- RLC A
- CLR SCL
- NOP
- NOP
- NOP
- NOP
- NOP
- DJNZ B, IIC_READ_BYTE0
- RET
- ;====================================================
- MOV B, #0FFH
- IIC_WRITE_ACK:
- SETB SDA
- SETB SCL
- NOP
- JB SDA, DEL_ACK
- CLR SCL
- NOP
- RET
- ;=============================
- DEL_ACK:
- DJNZ B, $
- CLR SCL
- NOP
- RET
- ;====================================================
- IIC_READ_ACK:
- CLR SCL
- NOP
- CLR SDA
- NOP
- SETB SCL
- NOP
- RET
- ;=====================================================
- IIC_ACK: SETB SDA
- NOP
- NOP
- SETB SCL
- NOP
- NOP
- NOP
- JB SDA,IIC_ACK0
- CLR C
- SJMP IIC_ACK_END
- IIC_ACK0: SETB C
- SJMP IIC_ACK_END
- IIC_ACK_END: CLR SCL
- RET
- ;==================================================
- ;iic2
- ;A中存储了温度值信息
- ;==================================================
- IIC_READ2:
- LCALL IIC_START2
- MOV A, #90H
- LCALL IIC_WRITE_BYTE2
- LCALL IIC_ACK2
- JC IIC_READ2
- MOV A, #00H
- LCALL IIC_WRITE_BYTE2
- LCALL IIC_ACK2
- JC IIC_READ2
- LCALL IIC_STOP2
-
- ;RESTART
- LCALL IIC_START2
- MOV A, #91H
- LCALL IIC_WRITE_BYTE2
- LCALL IIC_ACK2
- JC IIC_READ2
- LCALL IIC_READ_BYTE2
- LCALL IIC_STOP2
- RET
- ;=====================================================
- IIC_START2:
- SETB SDAA
- NOP
- SETB SCLL
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SDAA
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SCLL
- RET
- ;=====================================================
- IIC_STOP2:
- CLR SDAA
- NOP
- SETB SCLL
- NOP
- NOP
- NOP
- NOP
- NOP
- SETB SDAA
- NOP
- NOP
- NOP
- NOP
- NOP
- RET
- ;=====================================================
- IIC_WRITE_BYTE2:
- MOV B, #08H
- IIC_WRITE_BYTE02:
- RLC A
- MOV SDAA, C
- NOP
- SETB SCLL
- NOP
- NOP
- NOP
- NOP
- NOP
- CLR SCLL
- NOP
- DJNZ B, IIC_WRITE_BYTE02
- RET
- ;====================================================
- IIC_READ_BYTE2:
- MOV B, #08H
- CLR A
- SETB SDAA
- NOP
- IIC_READ_BYTE02:
- SETB SCLL
- NOP
- NOP
- NOP
- NOP
- NOP
- MOV C, SDAA
- RLC A
- CLR SCLL
- NOP
- NOP
- NOP
- NOP
- NOP
- DJNZ B, IIC_READ_BYTE02
- RET
- ;=====================================================
- IIC_ACK2: SETB SDAA
- NOP
- NOP
- SETB SCLL
- NOP
- NOP
- NOP
- JB SDAA,IIC_ACK02
- CLR C
- SJMP IIC_ACK_END2
- IIC_ACK02: SETB C
- SJMP IIC_ACK_END2
- IIC_ACK_END2: CLR SCLL
- RET
- ;=====================================================
- ;DPTR
- ;R7表示要显示的汉字个数*2
- ;R6/2表示从第几个汉字开始显示
- ;=====================================================
- SHOW_CHINESE:
- MOV A, R6
- MOVC A, @A+DPTR
- LCALL WRITE_DATA
- LCALL DEL0
- INC DPTR
- DJNZ R7, SHOW_CHINESE
- LCALL DEL0
- RET
- TIME_WORD_1:
- DB "星期"
- TIME_WORD_2:
- DB "一二三四五六日"
- TEM_WORD_1: