圣源电子制作
标题:
自行车里程表-C51-代时钟-程序C 原理图 PCB 文件
[打印本页]
作者:
sydz
时间:
2011-9-6 23:08
标题:
自行车里程表-C51-代时钟-程序C 原理图 PCB 文件
转载自互联网!!!
这是一款简易的自行车里程表,核心部分是一块8051的单片机。
(, 下载次数: 39)
上传
点击文件名下载附件
(, 下载次数: 40)
上传
点击文件名下载附件
电路图(
清晰大图
)
(, 下载次数: 90)
上传
点击文件名下载附件
程序流程
(, 下载次数: 39)
上传
点击文件名下载附件
PCB热转印图,可以直接使用
(, 下载次数: 44)
上传
点击文件名下载附件
源程序:
/*
<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />2011-04-06 write it
显示时间及字符正常版
端口已和PCB同步版
键盘已经通过测试,可以使用
时间调整已可,已经有光标显示
可以计算里程时间,已经测试
R1为DS1302地址
R0为DS1302数据
*/
//液晶端口定义
DISPLAY_DATA EQU P0
DISPLAY_RS BIT P2.5
DISPLAY_RW BIT P2.6
DISPLAY_E BIT P2.7
//时钟芯片端口定义
DS1302_DATA BIT P1.1 //数据传送总线
DS1302_CLK BIT P1.0 //时钟控制总线
DS1302_RST BIT P1.2 //复位总线
//按键端口定义
K1 EQU P1.3 //时钟调整、确认按键
K2 EQU P1.4 //+按键
K3 EQU P1.5 //-按键
K4 EQU P1.6 //里程开始、停止按键
K5 EQU P1.7 //里程清零按键
//距离寄存器
H_METER EQU 46H
K_METER EQU 47H
M_METER EQU 48H
//保存开始时间
KEEP_TIME_H EQU 49H
KEEP_TIME_M EQU 4AH
KEEP_TIME_S EQU 4BH
//里程所用时间
RESULT_TIME_H EQU 4CH
RESULT_TIME_M EQU 4DH
RESULT_TIME_S EQU 4EH
//现在时间
REAL_TIME_H EQU 42H
REAL_TIME_M EQU 41H
REAL_TIME_S EQU 40H
//中间暂存变量
M_TIME_M EQU 60H
M_TIME_H EQU 61H
M_TIME_M_FLAG EQU 62H
M_TIME_H_FLAG EQU 63H
COUNT_FLAG EQU 64H
//显示控制标志位
DISPLAY_SWITCH EQU 4FH//第一位为时间运行显示开关
//第二位为时间调整显示开关
//第三位为里程运行显示开关
//第四位为警告显示开关
DISPLAY_SWITCH_1 EQU 5EH
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
CLOCK_FLAG EQU 5CH //时间调整标志位
CLOCK_FLAG_1 EQU 5DH //时间位数标志位
ORG 0000H
SJMP START
ORG 0003H
LJMP EX0_Interrupt
ORG 0030H
START:ACALL MCU_INT
ACALL DISPLAY_INT
ACALL DS1302_INT
ACALL DAY_INT
ACALL DATA_INT
MAIN: ACALL GET_TIME_DATA_YEAR
ACALL DS1302_DATA_PROCESS
LCALL KEY_SCAN
MOV A,DISPLAY_SWITCH
JNB ACC.0,CLOCK_DISPLAY_CHECK
ACALL DISPLAY_DAY
CLOCK_DISPLAY_CHECK:
MOV A,DISPLAY_SWITCH
JNB ACC.1,DISTANCE_TIME_DISPLAY_CHECK
LCALL DISPLAY_CLOCK
DISTANCE_TIME_DISPLAY_CHECK:
MOV A,DISPLAY_SWITCH
JNB ACC.2,WARNING_DISPLAY_CHECK
MOV DISPLAY_SWITCH_1,#40H
DISTANCE_TIME_DISPLAY_CHECK_1:
LCALL DISPLAY_CLOCK
LCALL KEY_SCAN
LCALL DELAY_20MS
DJNZ DISPLAY_SWITCH_1,DISTANCE_TIME_DISPLAY_CHECK_1
MOV DISPLAY_SWITCH_1,#0BH
DISTANCE_TIME_DISPLAY_CHECK_2:
LCALL COUNT_TIME
LCALL DISPLAY_DISTANCE_TIME
LCALL KEY_SCAN
LCALL DELAY_20MS
DJNZ DISPLAY_SWITCH_1,DISTANCE_TIME_DISPLAY_CHECK_2
WARNING_DISPLAY_CHECK:
MOV A,DISPLAY_SWITCH
JNB ACC.3,DISPLAY_END
LCALL DISPLAY_WARNING
DISPLAY_END:
SJMP MAIN
MCU_INT:
MOV SP,#70H
SETB EA
SETB EX0
RET
DATA_INT:
MOV H_METER,#00H
MOV K_METER,#00H
MOV M_METER,#00H
MOV DISPLAY_SWITCH,#01H
MOV CLOCK_FLAG,#00H
RET
//初始化日期为2011年5月1号
DAY_INT:
MOV R1,#8CH
MOV R0,#11H
ACALL DS1302_WRITE
MOV R1,#88H
MOV R0,#05H
ACALL DS1302_WRITE
MOV R1,#86H
MOV R0,#01H
ACALL DS1302_WRITE
RET
DISPLAY_DAY:
MOV P0,#80H
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#81H
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#82H
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#83H
ACALL DISPLAY_ENABLE
MOV P0,#32H
ACALL DISPLAY_WRITE
MOV P0,#84H
ACALL DISPLAY_ENABLE
MOV P0,#30H
ACALL DISPLAY_WRITE
MOV P0,#85H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,5BH
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#86H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,5AH
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#87H
ACALL DISPLAY_ENABLE
MOV P0,#2DH
ACALL DISPLAY_WRITE
MOV P0,#88H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,59H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#89H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,58H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#8AH
ACALL DISPLAY_ENABLE
MOV P0,#2DH
ACALL DISPLAY_WRITE
MOV P0,#8BH
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,57H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#8CH
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,56H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#8DH
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#8EH
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#8FH
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
//------显示时间
MOV P0,#0C0H
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#0C1H
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#0C2H
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#0C3H
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#0C4H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,55H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#0C5H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,54H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#0C6H
ACALL DISPLAY_ENABLE
MOV P0,#2DH
ACALL DISPLAY_WRITE
MOV P0,#0C7H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,53H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#0C8H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,52H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#0C9H
ACALL DISPLAY_ENABLE
MOV P0,#2DH
ACALL DISPLAY_WRITE
MOV P0,#0CAH
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,51H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#0CBH
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,50H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#0CCH
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
MOV P0,#0CFH
ACALL DISPLAY_ENABLE
MOV P0,#20H
ACALL DISPLAY_WRITE
RET
DISPLAY_INT:
MOV DISPLAY_DATA,#01H //清屏
ACALL DISPLAY_ENABLE
MOV DISPLAY_DATA,#01H //清屏
ACALL DISPLAY_ENABLE
MOV DISPLAY_DATA,#38H //显示模式设置为16字*2行
ACALL DISPLAY_ENABLE
MOV DISPLAY_DATA,#0FH //显示光标及闪烁
ACALL DISPLAY_ENABLE
MOV DISPLAY_DATA,#06H //显示方向正向且屏不移动
ACALL DISPLAY_ENABLE
RET
DISPLAY_ENABLE:
CLR DISPLAY_RS
CLR DISPLAY_RW
CLR DISPLAY_E
ACALL DELAY
SETB DISPLAY_E
RET
DISPLAY_WRITE:
SETB DISPLAY_RS
CLR DISPLAY_RW
CLR DISPLAY_E
ACALL DELAY
SETB DISPLAY_E
RET
DELAY:MOV R6,#08H
L1:MOV R7,#0FAH
L0:DJNZ R7,L0
DJNZ R6,L1
RET
//DS1302初始化
DS1302_INT:
CLR DS1302_RST //DS1302复位
CLR DS1302_CLK
NOP
NOP
SETB DS1302_RST
MOV R1,#80H //写动振荡寄存器地址
MOV R0,#00H //启动振荡器
LCALL DS1302_WRITE
/* MOV R1,#90H //写充电寄存器
MOV R0,#0ABH
LCALL DS1302_WRITE
*/
MOV R1,#8EH //写保护寄存器
MOV R0,#00H //允许写入
ACALL DS1302_WRITE
RET
//从DS1302获取数据
GET_TIME_DATA_YEAR:
MOV R1,#81H //读秒
LCALL DS1302_READ
MOV 40H,R0
MOV R1,#83H //读分
LCALL DS1302_READ
MOV 41H,R0
MOV R1,#85H //读时
LCALL DS1302_READ
MOV 42H,R0
MOV R1,#87H //读出日期
LCALL DS1302_READ
MOV 43H,R0
MOV R1,#89H //读出月份
LCALL DS1302_READ
MOV 44H,R0
MOV R1,#8DH //读出年
LCALL DS1302_READ
MOV 45H,R0
RET
DS1302_DATA_PROCESS:
//--------处理秒数据
MOV A,40H
ANL A,#0FH
MOV 50H,A
MOV A,40H
ANL A,#0F0H
SWAP A
MOV 51H,A
//--------处理分数据
MOV A,41H
ANL A,#0FH
MOV 52H,A
MOV A,41H
ANL A,#0F0H
SWAP A
MOV 53H,A
//--------处理时数据
MOV A,42H
ANL A,#0FH
MOV 54H,A
MOV A,42H
ANL A,#0F0H
SWAP A
MOV 55H,A
//--------处理日数据
MOV A,43H
ANL A,#0FH
MOV 56H,A
MOV A,43H
ANL A,#0F0H
SWAP A
MOV 57H,A
//--------处理月数据
MOV A,44H
ANL A,#0FH
MOV 58H,A
MOV A,44H
ANL A,#0F0H
SWAP A
MOV 59H,A
//---------处理年数据
MOV A,45H
ANL A,#0FH
MOV 5AH,A
MOV A,45H
ANL A,#0F0H
SWAP A
MOV 5BH,A
RET
//DS1302写数据
DS1302_WRITE:
CLR DS1302_CLK
NOP
NOP
SETB DS1302_RST
NOP
MOV A,R1
MOV R2,#08H
DS1302_WRITE_ADDRESS: //传输地址到DS1302
RRC A
NOP
NOP
CLR DS1302_CLK
NOP
NOP
MOV DS1302_DATA,C
NOP
NOP
SETB DS1302_CLK
NOP
NOP
DJNZ R2,DS1302_WRITE_ADDRESS
CLR DS1302_CLK
NOP
NOP
MOV A,R0
MOV R2,#08H
DS1302_WRITE_DATA: //传输数据到DS1302
RRC A
NOP
CLR DS1302_CLK
NOP
NOP
MOV DS1302_DATA,C
NOP
NOP
SETB DS1302_CLK
NOP
NOP
DJNZ R2,DS1302_WRITE_DATA
CLR DS1302_CLK
NOP
NOP
CLR DS1302_RST
NOP
NOP
RET
//DS1302读数据
DS1302_READ:
CLR DS1302_CLK
NOP
NOP
SETB DS1302_RST
NOP
NOP
MOV A,R1
MOV R2,#08H
DS1302_READ_ADDRESS: //传输地址到DS1302
RRC A
NOP
MOV DS1302_DATA,C
NOP
NOP
SETB DS1302_CLK
NOP
NOP
CLR DS1302_CLK
NOP
NOP
DJNZ R2,DS1302_READ_ADDRESS
NOP
NOP
SETB DS1302_DATA
CLR A
CLR C
MOV R2,#08H
DS1302_READ_DATA: //从DS1302接收数据
CLR DS1302_CLK
NOP
NOP
MOV C,DS1302_DATA
NOP
NOP
RRC A
NOP
NOP
SETB DS1302_CLK
NOP
NOP
DJNZ R2,DS1302_READ_DATA
MOV R0,A
CLR DS1302_RST
RET
DELAY_20MS:
MOV R6,#0D7H
DD0:
MOV R7,#2DH
DJNZ R7,$
DJNZ R6,DD0
NOP
NOP
RET
DELAY_1S: ;误差 0us
MOV R7,#0A7H
LL1:
MOV R6,#0ABH
LL0:
MOV R5,#10H
DJNZ R5,$
DJNZ R6,LL0
DJNZ R7,LL1
NOP
RET
KEEP_TIME_DATA:
RET
//键盘扫描
KEY_SCAN:
JB K1,STOP_CLOCK
LCALL DELAY_20MS
JB K1,STOP_CLOCK
JNB K1,$
//年的十位
INC CLOCK_FLAG
STOP_CLOCK:
MOV A,CLOCK_FLAG
CJNE A,#01H,K1_SCAN_1
MOV R1,#80H //写动振荡寄存器地址
MOV R0,#80H //停止振荡器工作
LCALL DS1302_WRITE
MOV DISPLAY_SWITCH,#02H//进入时间调整显示
LCALL DISPLAY_DAY
K1_SCAN_1:
MOV A,CLOCK_FLAG
CJNE A,#02H,K1_SCAN_2
LCALL DISPLAY_DAY
MOV R3,5BH
MOV CLOCK_FLAG_1,#0AH
ACALL KEY1_SCAN_C_1
MOV 5BH,R3
ACALL REVISE_YEAR
K1_SCAN_2://年的个位
MOV A,CLOCK_FLAG
CJNE A,#03H,K1_SCAN_3
MOV R3,5AH
MOV CLOCK_FLAG_1,#0AH
ACALL KEY1_SCAN_C_1
MOV 5AH,R3
ACALL REVISE_YEAR
K1_SCAN_3://月
MOV A,CLOCK_FLAG
CJNE A,#04H,K1_SCAN_4
MOV R3,44H
MOV CLOCK_FLAG_1,#13H
ACALL KEY1_SCAN_C_1
MOV 44H,R3
ACALL REVISE_MONTH
K1_SCAN_4://日
MOV A,CLOCK_FLAG
CJNE A,#05H,K1_SCAN_5
MOV R3,43H
MOV CLOCK_FLAG_1,#32H
ACALL KEY1_SCAN_C_1
MOV 43H,R3
ACALL REVISE_DAY
K1_SCAN_5://时
MOV A,CLOCK_FLAG
CJNE A,#06H,K1_SCAN_6
MOV R3,42H
MOV CLOCK_FLAG_1,#24H
ACALL KEY1_SCAN_C_1
MOV 42H,R3
ACALL REVISE_HOUR
K1_SCAN_6://分的十位
MOV A,CLOCK_FLAG
CJNE A,#07H,K1_SCAN_7
MOV R3,53H
MOV CLOCK_FLAG_1,#06H
ACALL KEY1_SCAN_C_1
MOV 53H,R3
ACALL REVISE_MINUTE
K1_SCAN_7://分的个位
MOV A,CLOCK_FLAG
CJNE A,#08H,K1_SCAN_8
MOV R3,52H
MOV CLOCK_FLAG_1,#0AH
ACALL KEY1_SCAN_C_1
MOV 52H,R3
ACALL REVISE_MINUTE
K1_SCAN_8:
MOV A,CLOCK_FLAG
CJNE A,#09H,KEY4_SCAN
MOV CLOCK_FLAG,#00H
MOV R1,#80H //写动振荡寄存器地址
MOV R0,#00H //启动振荡器工作
MOV CLOCK_FLAG,#00H
MOV DISPLAY_SWITCH,#01H
LCALL DS1302_WRITE
KEY4_SCAN:
MOV A,CLOCK_FLAG
CJNE A,#00H,KEY5_SCAN
JB K4,KEY5_SCAN
LCALL DELAY_20MS
JB K4,KEY5_SCAN
JNB K4,$
MOV KEEP_TIME_H,REAL_TIME_H
MOV KEEP_TIME_M,REAL_TIME_M
MOV KEEP_TIME_S,REAL_TIME_S
MOV DISPLAY_SWITCH,#05H
KEY5_SCAN:
MOV A,CLOCK_FLAG
CJNE A,#00H,KEY_SCAN_END
JB K5,KEY_SCAN_END
LCALL DELAY_20MS
JB K5,KEY_SCAN_END
JNB K5,$
MOV DISPLAY_SWITCH,#01H
MOV KEEP_TIME_H,#00H
MOV KEEP_TIME_M,#00H
MOV KEEP_TIME_S,#00H
MOV RESULT_TIME_H,#00H
MOV RESULT_TIME_M,#00H
MOV RESULT_TIME_S,#00H
KEY_SCAN_END:
RET
KEY1_SCAN_C_1:
JB K2,KEY1_SCAN_C_2
LCALL DELAY_20MS
JB K2,KEY1_SCAN_C_2
JNB K2,$
INC R3
MOV A,R3
CJNE A,CLOCK_FLAG_1,KEY1_SCAN_C_1_1
MOV R3,#0
KEY1_SCAN_C_1_1:
MOV A,R3
CJNE A,#0AH,KEY1_SCAN_C_1_2
MOV R3,#10H
KEY1_SCAN_C_1_2:
MOV A,R3
CJNE A,#1AH,KEY1_SCAN_C_1_3
MOV R3,#20H
KEY1_SCAN_C_1_3:
MOV A,R3
CJNE A,#2AH,KEY1_SCAN_C_2
MOV R3,#30H
KEY1_SCAN_C_2:
JB K3,KEY1_SCAN_C_END
LCALL DELAY_20MS
JB K3,KEY1_SCAN_C_END
JNB K3,$
DEC R3
CJNE R3,#0FFH,KEY1_SCAN_C_2_1
MOV R3,CLOCK_FLAG_1
DEC R3
KEY1_SCAN_C_2_1:
MOV A,R3
CJNE A,#2FH,KEY1_SCAN_C_2_2
MOV R3,#29H
KEY1_SCAN_C_2_2:
MOV A,R3
CJNE A,#1FH,KEY1_SCAN_C_2_3
MOV R3,#19H
KEY1_SCAN_C_2_3:
MOV A,R3
CJNE A,#0FH,KEY1_SCAN_C_END
MOV R3,#09H
KEY1_SCAN_C_END:
RET
REVISE_YEAR:
MOV A,5BH
SWAP A
ORL A,5AH
MOV R0,A
MOV R1,#8CH
ACALL DS1302_WRITE
RET
REVISE_MONTH:
MOV R0,44H
MOV R1,#88H
ACALL DS1302_WRITE
RET
REVISE_DAY:
MOV R0,43H
MOV R1,#86H
ACALL DS1302_WRITE
RET
REVISE_HOUR:
MOV R0,42H
MOV R1,#84H
ACALL DS1302_WRITE
RET
REVISE_MINUTE:
MOV A,53H
SWAP A
ORL A,52H
MOV R0,A
MOV R1,#82H
ACALL DS1302_WRITE
RET
DISPLAY_CLOCK:
MOV A,CLOCK_FLAG
CJNE A,#02H,DISPLAY_CLOCK_YEAR_1
MOV P0,#85H
ACALL DISPLAY_ENABLE
LCALL DELAY_20MS
MOV P0,#85H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,5BH
MOV P0,A
ACALL DISPLAY_WRITE
DISPLAY_CLOCK_YEAR_1:
MOV A,CLOCK_FLAG
CJNE A,#03H,DISPLAY_CLOCK_MONTH
MOV P0,#86H
ACALL DISPLAY_ENABLE
LCALL DELAY_20MS
MOV P0,#86H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,5AH
MOV P0,A
ACALL DISPLAY_WRITE
DISPLAY_CLOCK_MONTH:
MOV A,CLOCK_FLAG
CJNE A,#04H,DISPLAY_CLOCK_DAY
MOV P0,#89H
ACALL DISPLAY_ENABLE
LCALL DELAY_20MS
MOV P0,#88H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,59H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#89H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,58H
MOV P0,A
ACALL DISPLAY_WRITE
DISPLAY_CLOCK_DAY:
MOV A,CLOCK_FLAG
CJNE A,#05H,DISPLAY_CLOCK_HOUR
MOV P0,#8CH
ACALL DISPLAY_ENABLE
LCALL DELAY_20MS
MOV P0,#8BH
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,57H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#8CH
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,56H
MOV P0,A
ACALL DISPLAY_WRITE
DISPLAY_CLOCK_HOUR:
MOV A,CLOCK_FLAG
CJNE A,#06H,DISPLAY_CLOCK_MIN_10
MOV P0,#0C5H
ACALL DISPLAY_ENABLE
LCALL DELAY_20MS
MOV P0,#0C4H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,55H
MOV P0,A
ACALL DISPLAY_WRITE
MOV P0,#0C5H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,54H
MOV P0,A
ACALL DISPLAY_WRITE
DISPLAY_CLOCK_MIN_10:
MOV A,CLOCK_FLAG
CJNE A,#07H,DISPLAY_CLOCK_MIN_1
MOV P0,#0C7H
ACALL DISPLAY_ENABLE
LCALL DELAY_20MS
MOV P0,#0C7H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,53H
MOV P0,A
ACALL DISPLAY_WRITE
DISPLAY_CLOCK_MIN_1:
MOV A,CLOCK_FLAG
CJNE A,#08H,DISPLAY_CLOCK_EXIT
MOV P0,#0C8H
ACALL DISPLAY_ENABLE
LCALL DELAY_20MS
MOV P0,#0C8H
ACALL DISPLAY_ENABLE
CLR C
MOV A,#30H
ADD A,52H
MOV P0,A
ACALL DISPLAY_WRITE
DISPLAY_CLOCK_EXIT:
RET
DISPLAY_WARNING:
MOV P0,#80H
ACALL DISPLAY_ENABLE
MOV P0,#57H //W
ACALL DISPLAY_WRITE
MOV P0,#81H
ACALL DISPLAY_ENABLE
MOV P0,#41H //A
ACALL DISPLAY_WRITE
MOV P0,#82H
ACALL DISPLAY_ENABLE
MOV P0,#52H //R
ACALL DISPLAY_WRITE
MOV P0,#83H
ACALL DISPLAY_ENABLE
MOV P0,#4EH //N
ACALL DISPLAY_WRITE
MOV P0,#84H
ACALL DISPLAY_ENABLE
MOV P0,#49H //I
ACALL DISPLAY_WRITE
MOV P0,#85H
ACALL DISPLAY_ENABLE
MOV P0,#4EH //N
ACALL DISPLAY_WRITE
MOV P0,#86H
ACALL DISPLAY_ENABLE
MOV P0,#47H //G
ACALL DISPLAY_WRITE
MOV P0,#87H
ACALL DISPLAY_ENABLE
MOV P0,#21H //!
ACALL DISPLAY_WRITE
MOV P0,#88H
ACALL DISPLAY_ENABLE
MOV P0,#20H //
ACALL DISPLAY_WRITE
MOV P0,#89H
ACALL DISPLAY_ENABLE
MOV P0,#50H //P
ACALL DISPLAY_WRITE
MOV P0,#8AH
ACALL DISPLAY_ENABLE
MOV P0,#4CH //L
ACALL DISPLAY_WRITE
MOV P0,#8BH
ACALL DISPLAY_ENABLE
MOV P0,#45H //E
ACALL DISPLAY_WRITE
MOV P0,#8CH
ACALL DISPLAY_ENABLE
MOV P0,#41H //A
ACALL DISPLAY_WRITE
MOV P0,#8DH
ACALL DISPLAY_ENABLE
MOV P0,#53H //S
ACALL DISPLAY_WRITE
MOV P0,#8EH
ACALL DISPLAY_ENABLE
MOV P0,#45H //E
ACALL DISPLAY_WRITE
MOV P0,#8FH
ACALL DISPLAY_ENABLE
MOV P0,#3AH //:
ACALL DISPLAY_WRITE
//第二行
MOV P0,#0C0H
ACALL DISPLAY_ENABLE
MOV P0,#20H //
ACALL DISPLAY_WRITE
MOV P0,#0C1H
ACALL DISPLAY_ENABLE
MOV P0,#20H //
ACALL DISPLAY_WRITE
MOV P0,#0C2H
ACALL DISPLAY_ENABLE
MOV P0,#52H //R
ACALL DISPLAY_WRITE
MOV P0,#0C3H
ACALL DISPLAY_ENABLE
MOV P0,#45H //E
ACALL DISPLAY_WRITE
MOV P0,#0C4H
ACALL DISPLAY_ENABLE
MOV P0,#53H //S
ACALL DISPLAY_WRITE
MOV P0,#0C5H
ACALL DISPLAY_ENABLE
MOV P0,#45H //E
ACALL DISPLAY_WRITE
MOV P0,#0C6H
ACALL DISPLAY_ENABLE
MOV P0,#54H //T
ACALL DISPLAY_WRITE
MOV P0,#0C7H
ACALL DISPLAY_ENABLE
MOV P0,#20H //
ACALL DISPLAY_WRITE
MOV P0,#0C8H
ACALL DISPLAY_ENABLE
MOV P0,#53H //S
ACALL DISPLAY_WRITE
MOV P0,#0C9H
ACALL DISPLAY_ENABLE
MOV P0,#59H //Y
ACALL DISPLAY_WRITE
MOV P0,#0CAH
ACALL DISPLAY_ENABLE
MOV P0,#53H //S
ACALL DISPLAY_WRITE
MOV P0,#0CBH
ACALL DISPLAY_ENABLE
MOV P0,#54H //T
ACALL DISPLAY_WRITE
MOV P0,#0CCH
ACALL DISPLAY_ENABLE
MOV P0,#45H //E
ACALL DISPLAY_WRITE
MOV P0,#0CDH
ACALL DISPLAY_ENABLE
MOV P0,#4DH //M
ACALL DISPLAY_WRITE
MOV P0,#0CEH
ACALL DISPLAY_ENABLE
MOV P0,#20H //
ACALL DISPLAY_WRITE
MOV P0,#0CFH
ACALL DISPLAY_ENABLE
MOV P0,#20H //
ACALL DISPLAY_WRITE
RET
//显示路程
DISPLAY_DISTANCE_TIME:
//DISTANCE
MOV P0,#80H
LCALL DISPLAY_ENABLE
MOV P0,#44H //D
LCALL DISPLAY_WRITE
MOV P0,#81H
LCALL DISPLAY_ENABLE
MOV P0,#49H //I
LCALL DISPLAY_WRITE
MOV P0,#82H
LCALL DISPLAY_ENABLE
MOV P0,#53H //S
LCALL DISPLAY_WRITE
MOV P0,#83H
ACALL DISPLAY_ENABLE
MOV P0,#54H //T
ACALL DISPLAY_WRITE
MOV P0,#84H
LCALL DISPLAY_ENABLE
MOV P0,#41H //A
LCALL DISPLAY_WRITE
MOV P0,#85H
LCALL DISPLAY_ENABLE
MOV P0,#4EH //N
LCALL DISPLAY_WRITE
MOV P0,#86H
LCALL DISPLAY_ENABLE
MOV P0,#43H //C
LCALL DISPLAY_WRITE
MOV P0,#87H
LCALL DISPLAY_ENABLE
MOV P0,#45H //E
LCALL DISPLAY_WRITE
MOV P0,#88H
LCALL DISPLAY_ENABLE
MOV P0,#3AH //:
LCALL DISPLAY_WRITE
MOV P0,#89H
LCALL DISPLAY_ENABLE
MOV A,M_METER
SWAP A
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //M_METER_H
LCALL DISPLAY_WRITE
MOV P0,#8AH
LCALL DISPLAY_ENABLE
MOV A,M_METER
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //M_METER_L
LCALL DISPLAY_WRITE
MOV P0,#8BH
LCALL DISPLAY_ENABLE
MOV A,K_METER
SWAP A
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //K_METER_H
LCALL DISPLAY_WRITE
MOV P0,#8CH
LCALL DISPLAY_ENABLE
MOV P0,#2EH //.
LCALL DISPLAY_WRITE
MOV P0,#8DH
LCALL DISPLAY_ENABLE
MOV A,K_METER
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //K_METER_L
LCALL DISPLAY_WRITE
MOV P0,#8EH
LCALL DISPLAY_ENABLE
MOV P0,#4BH //K
LCALL DISPLAY_WRITE
MOV P0,#8FH
LCALL DISPLAY_ENABLE
MOV P0,#4DH //M
LCALL DISPLAY_WRITE
//TIME
MOV P0,#0C0H
LCALL DISPLAY_ENABLE
MOV P0,#54H //T
LCALL DISPLAY_WRITE
MOV P0,#0C1H
LCALL DISPLAY_ENABLE
MOV P0,#49H //I
LCALL DISPLAY_WRITE
MOV P0,#0C2H
LCALL DISPLAY_ENABLE
MOV P0,#4DH //M
LCALL DISPLAY_WRITE
MOV P0,#0C3H
LCALL DISPLAY_ENABLE
MOV P0,#45H //E
LCALL DISPLAY_WRITE
MOV P0,#0C4H
LCALL DISPLAY_ENABLE
MOV P0,#3AH //:
LCALL DISPLAY_WRITE
MOV P0,#0C5H
LCALL DISPLAY_ENABLE
MOV A,RESULT_TIME_H
SWAP A
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //
LCALL DISPLAY_WRITE
MOV P0,#0C6H
LCALL DISPLAY_ENABLE
MOV A,RESULT_TIME_H
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //
LCALL DISPLAY_WRITE
MOV P0,#0C7H
LCALL DISPLAY_ENABLE
MOV P0,#2DH //-
LCALL DISPLAY_WRITE
MOV P0,#0C8H
LCALL DISPLAY_ENABLE
MOV A,RESULT_TIME_M
SWAP A
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //
LCALL DISPLAY_WRITE
MOV P0,#0C9H
LCALL DISPLAY_ENABLE
MOV A,RESULT_TIME_M
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //
LCALL DISPLAY_WRITE
MOV P0,#0CAH
LCALL DISPLAY_ENABLE
MOV P0,#2DH //-
LCALL DISPLAY_WRITE
MOV P0,#0CBH
LCALL DISPLAY_ENABLE
MOV A,RESULT_TIME_S
SWAP A
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //
LCALL DISPLAY_WRITE
MOV P0,#0CCH
LCALL DISPLAY_ENABLE
MOV A,RESULT_TIME_S
ANL A,#0FH
CLR C
ADD A,#30H
MOV P0,A //
LCALL DISPLAY_WRITE
MOV P0,#0CDH
LCALL DISPLAY_ENABLE
MOV P0,#20H //
LCALL DISPLAY_WRITE
MOV P0,#0CEH
LCALL DISPLAY_ENABLE
MOV P0,#20H //
LCALL DISPLAY_WRITE
MOV P0,#0CFH
LCALL DISPLAY_ENABLE
MOV P0,#20H //
LCALL DISPLAY_WRITE
RET
COUNT_TIME:
//秒计算和调整
CLR C
MOV A,REAL_TIME_S
SUBB A,KEEP_TIME_S
MOV RESULT_TIME_S,A
JNC S_BCD_CHECK
MOV A,REAL_TIME_S
CLR C
ADD A,#60H
MOV M_TIME_M_FLAG,#01H
SUBB A,KEEP_TIME_S
MOV RESULT_TIME_S,A
S_BCD_CHECK:
MOV C,PSW.6
JNC D_M_COUNT
CLR C
CLR PSW.6
SUBB A,#06H
MOV RESULT_TIME_S,A
D_M_COUNT://分钟计算和调整
MOV A,M_TIME_M_FLAG
CJNE A,#01H,M_COUNT
MOV M_TIME_M_FLAG,#00H
CLR C
MOV A,REAL_TIME_M
DEC A
MOV M_TIME_M,A
JNC D_M_BCB_CHECK
MOV A,REAL_TIME_M
CLR C
ADD A,#60H
MOV M_TIME_H_FLAG,#01H
DEC A
MOV M_TIME_M,A
D_M_BCB_CHECK:
MOV C,PSW.6
JNC M_M_COUNT
CLR C
CLR PSW.6
SUBB A,#06H
MOV M_TIME_M,A
M_M_COUNT:
CLR C
MOV A,M_TIME_M
SUBB A,KEEP_TIME_M
MOV RESULT_TIME_M,A
JNC M_M_BCD_CHECK
MOV A,M_TIME_M
CLR C
ADD A,#60H
MOV M_TIME_H_FLAG,#01H
SUBB A,KEEP_TIME_M
MOV RESULT_TIME_M,A
M_M_BCD_CHECK:
MOV C,PSW.6
JNC D_H_COUNT
CLR C
CLR PSW.6
SUBB A,#06H
MOV RESULT_TIME_M,A
M_COUNT:
CLR C
MOV A,REAL_TIME_M
SUBB A,KEEP_TIME_M
MOV RESULT_TIME_M,A
JNC M_BCD_CHECK
MOV A,REAL_TIME_M
CLR C
ADD A,#60H
MOV M_TIME_H_FLAG,#01H
SUBB A,KEEP_TIME_M
MOV RESULT_TIME_M,A
M_BCD_CHECK:
MOV C,PSW.6
JNC D_H_COUNT
CLR C
CLR PSW.6
SUBB A,#06H
MOV RESULT_TIME_M,A
//时钟
D_H_COUNT:
MOV A,M_TIME_H_FLAG
CJNE A,#01H,H_COUNT
MOV M_TIME_H_FLAG,#00H
CLR C
MOV A,REAL_TIME_H
DEC A
MOV M_TIME_H,A
JNC D_H_BCB_CHECK
MOV COUNT_FLAG,#0FH //错误显示
D_H_BCB_CHECK:
MOV C,PSW.6
JNC M_H_COUNT
CLR C
CLR PSW.6
SUBB A,#06H
MOV M_TIME_H,A
M_H_COUNT:
CLR C
MOV A,M_TIME_H
SUBB A,KEEP_TIME_H
MOV RESULT_TIME_H,A
JNC M_H_BCD_CHECK
MOV COUNT_FLAG,#0FH //错误显示
M_H_BCD_CHECK:
MOV C,PSW.6
JNC COUNT_TIME_EXIT
CLR C
CLR PSW.6
SUBB A,#06H
MOV RESULT_TIME_H,A
H_COUNT:
CLR C
MOV A,REAL_TIME_H
SUBB A,KEEP_TIME_H
MOV RESULT_TIME_H,A
JNC H_BCD_CHECK
MOV COUNT_FLAG,#0EH //错误显示
H_BCD_CHECK:
MOV C,PSW.6
JNC COUNT_TIME_EXIT
CLR C
CLR PSW.6
SUBB A,#06H
MOV RESULT_TIME_H,A
COUNT_TIME_EXIT:
RET
//外部中断0计算里程
EX0_Interrupt:
PUSH ACC
PUSH PSW
INC H_METER
MOV A,H_METER
ANL A,#0FH
CJNE A,#0AH,EXIT_EX0_Interrupt
MOV A,H_METER
ANL A,#0F0H
CLR C
ADD A,#10H
MOV H_METER,A
CJNE A,#60H,EXIT_EX0_Interrupt
INC K_METER
MOV A,K_METER
ANL A,#0FH
CJNE A,#0AH,EXIT_EX0_Interrupt
MOV A,K_METER
ANL A,#0F0H
CLR C
ADD A,#10H
MOV K_METER,A
CJNE A,#0A0H,EXIT_EX0_Interrupt
INC M_METER
MOV A,M_METER
ANL A,#0FH
CJNE A,#0AH,EXIT_EX0_Interrupt
MOV A,M_METER
ANL A,#0F0H
CLR C
ADD A,#10H
MOV M_METER,A
CJNE A,#0A0H,EXIT_EX0_Interrupt
MOV M_METER,#00H
MOV DISPLAY_SWITCH,#08H
EXIT_EX0_Interrupt:
POP PSW
POP ACC
RETI
END
复制代码
(, 下载次数: 93)
上传
点击文件名下载附件
欢迎光临 圣源电子制作 (https://bbs.syyyd.com/)
Powered by Discuz! X3.4