基于单片机的篮球比赛计时器设计问题
时间:10-02
整理:3721RD
点击:
用汇编写的,12864显示,用中断方式检测开始、暂停、复位24秒按键。开始暂停都没有问题,但是复位按键按下后出现BUG,有时会暂停(本来按下复位不应该暂停),有时还会在12864其他地方出现乱码,求大神解答
LEDRS EQU P2.6
LEDRW EQU P2.5
LEDEN EQU P2.7
LEDPSB EQU P3.2
LEDRST EQU P3.4
;------------------控制端定义标号
LED_X EQU 30H
LED_Y EQU 31H
COUNT EQU 32H
DP0 EQU 33H
DP1 EQU 34H
FUNC EQU 35H
MINUTE EQU 36H
SECOND EQU 37H
SECOND_24 EQU 38H
_1S EQU 39H
DAT EQU 40H
DAT_SEC EQU 41H
DAT_SEC24 EQU 42H
DAT_MIN EQU 43H
FORR EQU 44H
_STOP EQU 45H
_RST24 EQU 46H
;------------------坐标、计数定义
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT_INT0
ORG 0030H
MAIN: MOV SP,#60H
MOV P0,#0FFH
MOV IE,#81H ;开总中断,外部中断0,定时器0
MOV TCON,#01H;外部中断才用边沿触发方式
MOV TMOD,#01H;设置定时器0工总方式1
CLR LEDRST ;复位
LCALL DELAY4
SETB LEDRST ;开始
NOP
SETB LEDPSB ;并行方式
;***************初始化**************
LCALL INILED
;***************开始显示**************
START: MOV R1,#100
MOV MINUTE,#27
MOV SECOND,#121
MOV SECOND_24,#49
MOV TL0,#0F0H
MOV TH0,#0D8H
CALL CHANGESEC
CALL CHANGESEC_24
CALL CHANGEMIN
MOV FORR,#0FFH
MOV _1S,#00H
CHECK_1S: JNB TF0,$
CLR TF0
MOV TL0,#0F0H
MOV TH0,#0D8H
DJNZ R1,CHECK_1S
MOV R1,#100
STARTCHAN:CALL CHANGESEC
MOV A,FORR
JZ NEXT
CALL CHANGEMIN
MOV FORR,#00H
NEXT: MOV A,SECOND
ADD A,#01H
JNZ START_24
RST_SEC: MOV SECOND,#121
CALL CHANGESEC
CALL CHANGEMIN
MOV A,MINUTE
ADD A,#01H
JNZ START_24
JMP RST_MIN
START_24:
CALL CHANGESEC_24
MOV A,SECOND_24
ADD A,#01H
JNZ CHECK_1S
RST_24:
MOV SECOND_24,#49
CALL CHANGESEC_24
JMP CHECK_1S
RST_MIN: MOV MINUTE,#27
MOV SECOND,#121
MOV SECOND_24,#49
CALL CHANGESEC
CALL CHANGESEC_24
CALL CHANGEMIN
MOV FORR,#0FFH
JMP CHECK_1S
CHANGESEC:
MOV DAT_SEC,SECOND
MOV LED_X,#02H
MOV LED_Y,#88H
MOV COUNT,#01H
MOV DPTR,#TABLE_SEC
MOV DP0,DPH
MOV DP1,DPL
MOV DAT,DAT_SEC
CALL LINE
MOV A,SECOND
CLR C
SUBB A,#01H
SUBB A,#01H
MOV SECOND,A
RET
CHANGESEC_24:
MOV DAT_SEC24,SECOND_24
MOV LED_X,#04H
MOV LED_Y,#88H
MOV COUNT,#01H
MOV DPTR,#TABLE_24
MOV DP0,DPH
MOV DP1,DPL
MOV DAT,DAT_SEC24
CALL LINE
MOV A,SECOND_24
CLR C
SUBB A,#01H
SUBB A,#01H
MOV SECOND_24,A
RET
CHANGEMIN:
MOV DAT_MIN,MINUTE
MOV LED_X,#00H
MOV LED_Y,#88H
MOV COUNT,#01H
MOV DPTR,#TABLE_MIN
MOV DP0,DPH
MOV DP1,DPL
MOV DAT,DAT_MIN
CALL LINE
MOV A,MINUTE
CLR C
SUBB A,#01H
SUBB A,#01H
MOV MINUTE,A
RET
JMP CHECK_1S
;***************各行写入数据**************
LINE:
MOV A,LED_X
ADD A,LED_Y
LCALL SENDCODE
MOV DP0,DPH
MOV DP1,DPL
LCALL GETDATA
RET
;***************初始化子函数**************
INILED: MOV A,#30H
LCALL SENDCODE
MOV A,#01H
LCALL SENDCODE
MOV A,#06H
LCALL SENDCODE
MOV A,#0CH
LCALL SENDCODE
;***************清屏子函数**************
CLEAR_LED:
MOV A,#01H
LCALL SENDCODE
MOV A,#34H
LCALL SENDCODE
MOV A,#30H
LCALL SENDCODE
RET
;***************查表取数据子函数**************
GETDATA: MOV A,DAT
MOV R3,A
NEXTGET: MOV DPH,DP0
MOV DPL,DP1
MOVC A,@A+DPTR
LCALL SENDDATA
LCALL DELAY4
DEC R3
MOV A,R3
MOVC A,@A+DPTR
LCALL SENDDATA
LCALL DELAY4
DEC R3
MOV A,R3
DJNZ COUNT,NEXTGET
RET
;***************写指令子函数**************
SENDCODE: LCALL CHECKBUZY
CLR LEDRS
CLR LEDRW
MOV P0,A
SETB LEDEN
NOP
NOP
CLR LEDEN
RET
;***************写数据子函数**************
SENDDATA:LCALL CHECKBUZY
SETB LEDRS
CLR LEDRW
MOV P0,A
SETB LEDEN
NOP
NOP
CLR LEDEN
RET
;***************查询忙碌子函数**************
CHECKBUZY:
MOV P0,#0FFH ;先写1
CLR LEDRS
SETB LEDRW
SETB LEDEN
JB P0.7,$
CLR LEDEN
RET
;***************延时子函数**************
DELAY4: MOV R6,#100
D41: MOV R7,#200
DJNZ R7,$
DJNZ R6,D41
RET
DELAY10MS:MOV R5,#10H
D101: MOV R6,#0FFH
DJNZ R6,$
DJNZ R5,D101
RET
;*********定时器中断处理函数*******************
;*********外部中断处理函数*******************
INT_INT0:
PUSH ACC
PUSH PSW
CHECK_INT0: MOV P1,#0FFH
MOV A,P1
ORL A,#0F8H
CPL A
JZ CHECK_INT0
CALL DELAY10MS
MOV P1,#0FFH
MOV A,P1
ORL A,#0F8H
CPL A
JZ CHECK_INT0
MOV FUNC,A
CHECK: MOV A,FUNC
CJNE A,#02H,CHECK_C
T_STOP: CLR TR0
JMP RE_INT
CHECK_C: JNC T_RST24
T_BEGIN: SETB TR0
JMP RE_INT
T_RST24: MOV SECOND_24,#49
RE_INT:
MOV FUNC,#00H
POP PSW
POP ACC
RETI
;*****************************************
TABLE_MIN: DB '0000102030405060708090011121'
TABLE_SEC: DB '00102030405060708090'
DB '01112131415161718191'
DB '02122232425262728292'
DB '03132333435363738393'
DB '04142434445464748494'
DB '0515253545556575859500'
TABLE_24: DB '00102030405060708090'
DB '01112131415161718191'
DB '0212223242'
TABLE: DB ''
END
LEDRS EQU P2.6
LEDRW EQU P2.5
LEDEN EQU P2.7
LEDPSB EQU P3.2
LEDRST EQU P3.4
;------------------控制端定义标号
LED_X EQU 30H
LED_Y EQU 31H
COUNT EQU 32H
DP0 EQU 33H
DP1 EQU 34H
FUNC EQU 35H
MINUTE EQU 36H
SECOND EQU 37H
SECOND_24 EQU 38H
_1S EQU 39H
DAT EQU 40H
DAT_SEC EQU 41H
DAT_SEC24 EQU 42H
DAT_MIN EQU 43H
FORR EQU 44H
_STOP EQU 45H
_RST24 EQU 46H
;------------------坐标、计数定义
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT_INT0
ORG 0030H
MAIN: MOV SP,#60H
MOV P0,#0FFH
MOV IE,#81H ;开总中断,外部中断0,定时器0
MOV TCON,#01H;外部中断才用边沿触发方式
MOV TMOD,#01H;设置定时器0工总方式1
CLR LEDRST ;复位
LCALL DELAY4
SETB LEDRST ;开始
NOP
SETB LEDPSB ;并行方式
;***************初始化**************
LCALL INILED
;***************开始显示**************
START: MOV R1,#100
MOV MINUTE,#27
MOV SECOND,#121
MOV SECOND_24,#49
MOV TL0,#0F0H
MOV TH0,#0D8H
CALL CHANGESEC
CALL CHANGESEC_24
CALL CHANGEMIN
MOV FORR,#0FFH
MOV _1S,#00H
CHECK_1S: JNB TF0,$
CLR TF0
MOV TL0,#0F0H
MOV TH0,#0D8H
DJNZ R1,CHECK_1S
MOV R1,#100
STARTCHAN:CALL CHANGESEC
MOV A,FORR
JZ NEXT
CALL CHANGEMIN
MOV FORR,#00H
NEXT: MOV A,SECOND
ADD A,#01H
JNZ START_24
RST_SEC: MOV SECOND,#121
CALL CHANGESEC
CALL CHANGEMIN
MOV A,MINUTE
ADD A,#01H
JNZ START_24
JMP RST_MIN
START_24:
CALL CHANGESEC_24
MOV A,SECOND_24
ADD A,#01H
JNZ CHECK_1S
RST_24:
MOV SECOND_24,#49
CALL CHANGESEC_24
JMP CHECK_1S
RST_MIN: MOV MINUTE,#27
MOV SECOND,#121
MOV SECOND_24,#49
CALL CHANGESEC
CALL CHANGESEC_24
CALL CHANGEMIN
MOV FORR,#0FFH
JMP CHECK_1S
CHANGESEC:
MOV DAT_SEC,SECOND
MOV LED_X,#02H
MOV LED_Y,#88H
MOV COUNT,#01H
MOV DPTR,#TABLE_SEC
MOV DP0,DPH
MOV DP1,DPL
MOV DAT,DAT_SEC
CALL LINE
MOV A,SECOND
CLR C
SUBB A,#01H
SUBB A,#01H
MOV SECOND,A
RET
CHANGESEC_24:
MOV DAT_SEC24,SECOND_24
MOV LED_X,#04H
MOV LED_Y,#88H
MOV COUNT,#01H
MOV DPTR,#TABLE_24
MOV DP0,DPH
MOV DP1,DPL
MOV DAT,DAT_SEC24
CALL LINE
MOV A,SECOND_24
CLR C
SUBB A,#01H
SUBB A,#01H
MOV SECOND_24,A
RET
CHANGEMIN:
MOV DAT_MIN,MINUTE
MOV LED_X,#00H
MOV LED_Y,#88H
MOV COUNT,#01H
MOV DPTR,#TABLE_MIN
MOV DP0,DPH
MOV DP1,DPL
MOV DAT,DAT_MIN
CALL LINE
MOV A,MINUTE
CLR C
SUBB A,#01H
SUBB A,#01H
MOV MINUTE,A
RET
JMP CHECK_1S
;***************各行写入数据**************
LINE:
MOV A,LED_X
ADD A,LED_Y
LCALL SENDCODE
MOV DP0,DPH
MOV DP1,DPL
LCALL GETDATA
RET
;***************初始化子函数**************
INILED: MOV A,#30H
LCALL SENDCODE
MOV A,#01H
LCALL SENDCODE
MOV A,#06H
LCALL SENDCODE
MOV A,#0CH
LCALL SENDCODE
;***************清屏子函数**************
CLEAR_LED:
MOV A,#01H
LCALL SENDCODE
MOV A,#34H
LCALL SENDCODE
MOV A,#30H
LCALL SENDCODE
RET
;***************查表取数据子函数**************
GETDATA: MOV A,DAT
MOV R3,A
NEXTGET: MOV DPH,DP0
MOV DPL,DP1
MOVC A,@A+DPTR
LCALL SENDDATA
LCALL DELAY4
DEC R3
MOV A,R3
MOVC A,@A+DPTR
LCALL SENDDATA
LCALL DELAY4
DEC R3
MOV A,R3
DJNZ COUNT,NEXTGET
RET
;***************写指令子函数**************
SENDCODE: LCALL CHECKBUZY
CLR LEDRS
CLR LEDRW
MOV P0,A
SETB LEDEN
NOP
NOP
CLR LEDEN
RET
;***************写数据子函数**************
SENDDATA:LCALL CHECKBUZY
SETB LEDRS
CLR LEDRW
MOV P0,A
SETB LEDEN
NOP
NOP
CLR LEDEN
RET
;***************查询忙碌子函数**************
CHECKBUZY:
MOV P0,#0FFH ;先写1
CLR LEDRS
SETB LEDRW
SETB LEDEN
JB P0.7,$
CLR LEDEN
RET
;***************延时子函数**************
DELAY4: MOV R6,#100
D41: MOV R7,#200
DJNZ R7,$
DJNZ R6,D41
RET
DELAY10MS:MOV R5,#10H
D101: MOV R6,#0FFH
DJNZ R6,$
DJNZ R5,D101
RET
;*********定时器中断处理函数*******************
;*********外部中断处理函数*******************
INT_INT0:
PUSH ACC
PUSH PSW
CHECK_INT0: MOV P1,#0FFH
MOV A,P1
ORL A,#0F8H
CPL A
JZ CHECK_INT0
CALL DELAY10MS
MOV P1,#0FFH
MOV A,P1
ORL A,#0F8H
CPL A
JZ CHECK_INT0
MOV FUNC,A
CHECK: MOV A,FUNC
CJNE A,#02H,CHECK_C
T_STOP: CLR TR0
JMP RE_INT
CHECK_C: JNC T_RST24
T_BEGIN: SETB TR0
JMP RE_INT
T_RST24: MOV SECOND_24,#49
RE_INT:
MOV FUNC,#00H
POP PSW
POP ACC
RETI
;*****************************************
TABLE_MIN: DB '0000102030405060708090011121'
TABLE_SEC: DB '00102030405060708090'
DB '01112131415161718191'
DB '02122232425262728292'
DB '03132333435363738393'
DB '04142434445464748494'
DB '0515253545556575859500'
TABLE_24: DB '00102030405060708090'
DB '01112131415161718191'
DB '0212223242'
TABLE: DB ''
END
表示看不懂汇编,其实这样的C语言程序网上很多,为啥不借鉴一个呢?
汇编/