刚初学单片机,想做个定时器定时给继电器供电或断电,时间可调,默认2分钟,
8255 pa,pb控制数码管,pc扫描键盘(只要4个键,pc1.2.3为行,pc4为列),做了几天始终做不来,可以显示,但是不能工作。。。。
高手帮忙改下程序
PA XDATA 0D1FFH
PB XDATA 0D2FFH
;PC XDATA 0D5FFH
CON XDATA 0D7FFH
SL EQU 40H
SH EQU 41H
ML EQU 42H
ORG 0000H
LJMP MAIN
ORG 000BH
MAIN:
MOV 30H,#00H
MOV 40H,#00H
MOV 41H,#00H
MOV 42H,#02H
MOV 60H,#1FH
MOV TMOD,#21H ;定时器工作方式;
MOV TH0,#3CH
MOV TL0,#0B0H
SETB EA ;开中断;
SETB ET0
SETB ET1
MOV DPTR,#CON ;控制字设置;
MOV A,#81H
MOVX @DPTR,A
LJMP KEYSCAN
LJMP START
LJMP TIME
;数码管显示函数;
START:
MOV 20H,#00H
MOV DPTR,#0D1FFH ;A选通分个位;
MOV A,#0FEH
MOVX @DPTR,A
MOV DPTR,#0D2FFH ;送PB显示分秒间隔符;
MOV A,#0A0H
MOVX @DPTR,A
MOV DPTR,#0D2FFH ;关闭数码管;
MOV A,0FFH
MOVX @DPTR,A
MOV DPTR,#0D1FFH ;A选通分个位;
MOV A,#0FDH
MOVX @DPTR,A
MOV A,42H ;分个位数赋值给a;
ADD A,20H
MOV DPTR,#TABLE ;取分个位数;
MOVC A,@A+DPTR
MOV 21H,A ;送pb显示分个位;
MOV DPTR,#0D2FFH
MOV A,21H
MOVX @DPTR,A
MOV DPTR,#0D2FFH ;闭数码管;
MOV A,0FFH
MOVX @DPTR,A
MOV DPTR,#0D1FFH ;A选通分秒间隔符;
MOV A,#0FBH
MOVX @DPTR,A
MOV DPTR,#0D2FFH ;送PB显示分秒间隔符;
MOV A,#07FH
MOVX @DPTR,A
MOV DPTR,#0D2FFH ;闭数码管;
MOV A,0FFH
MOVX @DPTR,A
MOV DPTR,#0D1FFH ;A选通秒十位;
MOV A,#0F7H
MOVX @DPTR,A
MOV A,41H ;秒十位数赋值给a;
ADD A,20H
MOV DPTR,#TABLE ;取秒十位数;
MOVC A,@A+DPTR
MOV 21H,A ;送pb显示秒十位;
MOV DPTR,#0D2FFH
MOV A,21H
MOVX @DPTR,A
MOV DPTR,#0D2FFH ;闭数码管;
MOV A,0FFH
MOVX @DPTR,A
MOV DPTR,#0D1FFH ;A选通秒个位;
MOV A,#0EFH
MOVX @DPTR,A
MOV A,40H ;秒个位数赋值给a;
ADD A,20H
MOV DPTR,#TABLE ;取秒个位数;
MOVC A,@A+DPTR
MOV 21H,A ;送pb显示秒个位;
MOV DPTR,#0D2FFH
MOV A,21H
MOVX @DPTR,A
MOV A,40H
JNZ OVER ;sl=0?是,继续,否,over;
MOV A,41H
JNZ OVER ;sH=0?是,继续,否,over;
MOV A,60H
JNZ OVER
CLR TR0 ;定时器关闭;
SETB TR1 ;定时器打开;
SETB P1.2 ;断开继电器;
MOV DPTR,#0D1FFH
MOV A,#00H
MOVX @DPTR,A
MOV DPTR,#0D2FFH
MOV A,#0A0H
MOVX @DPTR,A
OVER:LJMP START
TABLE:DB 0A0H,0BBH,62H,2AH,39H,2CH,24H,0BAH,20H,28H,0A0H
RET
;计时函数;
TIME:
PUSH ACC
PUSH PSW
INC 30H ;20次计数器加1;
MOV A,30H
CJNE A,#20H,GOON ;到20次?是,继续执行,否,跳入GOON;