做课程设计,简易时钟,校时部分有问题,求大侠帮忙
程序代码:
ORG 0000H
LJMP START
ORG 000BH
LJMP
timer0Interrupt
START:
MOV SP,#30H
MOV DPTR,#TABLE
LCALL InitTimer0
MOV R0,#23
MOV R1,#59
MOV R2,#50
MOV R3,#0
JISHI:
CJNE R2,#60,LOOP1
MOV R2,#0
INC R1
CJNE R1,#60,LOOP1
MOV R1,#0
CPL P2.1
LCALL DELAY500MS
CPL P2.1
INC R0
CJNE R0,#24,LOOP1
MOV R0,#0
LOOP1:
LOOP:
LCALL XIANSHI
JNB P1.0,JIAOSHI ;设置功能键第一次按下,跳转到校时
JMP JISHI
JIAOSHI:
CLR EA ;关闭中断
FEN:
JNB P1.1,JIAF
CALL XIANSHI
CALL DELAY1MS
JNB P1.2,JIANF
CALL XIANSHI
CALL DELAY1MS
JNB P1.0,SHI ;设置功能键再次按下,跳转到时调整
JNB P1.3,JISHI ;检测确认功能键是否按下
JMP FEN
SHI:
JNB P1.1,JIAS
CALL XIANSHI
CALL DELAY1MS
JNB P1.2,JIANS
CALL XIANSHI
CALL DELAY1MS
JNB P1.0,FEN ;设置功能键再次按下,跳转到分调整
JNB P1.3,JISHI ;检测确认功能键是否按下
JMP SHI
JIAF:
INC R1
JMP FEN
JIANF:
DEC R1
JMP FEN
JIAS:
INC R0
JMP SHI
JIANS:
DEC R0
JMP SHI
XIANSHI:
MOV A,R0
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV P0,A
MOV P3,#00000001B
CALL DELAY1MS
MOV A,B
MOVC A,@A+DPTR
MOV P0,A
MOV P3,#00000010B
CALL DELAY1MS
MOV A,R1
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV P0,A
MOV P3,#00000100B
CALL DELAY1MS
MOV A,B
MOVC A,@A+DPTR
MOV P0,A
MOV P3,#00001000B
CALL DELAY1MS
RET
InitTimer0: ;定时器初始化,
MOV TMOD,#01H ;模式1
MOV TH0,#0D8H ;定时器高8位赋值
MOV TL0,#0F0H ;定时器低8为赋值
SETB EA ;打开中断
SETB ET0 ;打开计时器0中断
SETB TR0 ;启动定时器0
RET
DELAY1MS: ;误差 0us
MOV R7,#01H
DL1:
MOV R6,#8EH
DL0:
MOV R5,#02H
DJNZ R5,$
DJNZ R6,DL0
DJNZ R7,DL1
RET
DELAY500MS: ;误差 0us
MOV R7,#17H
DL3:
MOV R6,#98H
DL2:
MOV R5,#46H
DJNZ R5,$
DJNZ R6,DL2
DJNZ R7,DL3
RET
Timer0Interrupt:
PUSH DPH
PUSH DPL
PUSH ACC
MOV TH0,#0D8H
MOV TL0,#0F0H
INC R3
POP ACC
POP DPL
POP DPH
CJNE R3,#90,EXIT
INC R2
CPL P2.0
MOV R3,#0
EXIT:
RETI
TABLE: ;共阴极数码管段码
DB 00111111B ;0
DB 00000110B ;1
DB 01011011B ;2
DB 01001111B ;3
DB 01100110B ;4
DB 01101101B ;5
DB 01111101B ;6
DB 00000111B ;7
DB 01111111B ;8
DB 01101111B ;9
END
一周热门 更多>