汇编程序 按钮 max7219
2个回答
展开全部
max7219不太好用,特别不稳定。不如用两个4094.也是串行通讯。
加减计数简单多了,二位数十进制连续加减调整位闪烁汇编程序,
以前写的,肯定有好多漏洞或错误。请自己分析,希望对你有所帮助。
ORG 0000H
AJMP START
ORG 000BH ;定时器0的中断向量地址
AJMP TIME0 ;跳转到真正的定时器程序处
ORG 30H
START: MOV TMOD,#00000001B ;定时/计数器0工作于方式1
MOV TH0,#15H
MOV TL0,#0A0H ;即数5536
SETB EA ;开总中断允许
SETB ET0 ;开定时/计数器0允许
SETB TR0
SETB P0.0
CLR P0.1
CLR P2.7
MOV R3,#C0H
MOV R4,#C0H
AJMP BH1
BH10: LCALL AJYS
JB P2.4,BH1
CPL P2.7
BH11: JNB P2.4,BH11
LCALL AJYS
JNB P2.4,BH11
AJMP BH1
JIAKS: MOV R1,#0
MOV R3,#C0H
MOV P1,R3
AJMP BH1
JIANKS: MOV R1,#9
MOV R3,#90H
MOV P1,R3
BH1: JNB P2.4,BH10
JNB P2.2,JIA
JNB P2.3,JIAN
JNB P2.5,BCSJ ;BCSJ意思是保存数据
JNB P2.7,BH1
AJMP BH2
;============================
JIA: LCALL AJYS ;加
JB P2.2,BH1
INC R1
CJNE R1,#10,D1
AJMP JIAKS
D1: MOV A,R1
MOV DPTR,#TABLE
MOVC A,@A+DPTR
CPL A
MOV R3,A
MOV P1,A
LCALL AJYS
AJMP BH1
;============================
JIAN: LCALL AJYS ;减
JB P2.3,BH1
DEC R1
CJNE R1,#FFH,D2
AJMP JIANKS
D2: MOV A,R1
MOV DPTR,#TABLE
MOVC A,@A+DPTR
CPL A
MOV R3,A
MOV P1,A
LCALL AJYS
AJMP BH1
;============================
JIAKS2: MOV R2,#0
MOV R4,#C0H
MOV P1,R4
AJMP BH2
JIANKS2: MOV R2,#9
MOV R4,#90H
MOV P1,R4
BH2: JNB P2.4,BH10
JNB P2.2,JIA2
JNB P2.3,JIAN2
JNB P2.5,BCSJ
JNB P2.7,BH1
AJMP BH2
;============================
JIA2: LCALL AJYS
JB P2.2,BH2
INC R2
CJNE R2,#10,D3
AJMP JIAKS2
D3: MOV A,R2
MOV DPTR,#TABLE
MOVC A,@A+DPTR
CPL A
MOV R4,A
MOV P1,A
LCALL AJYS
L5: AJMP BH2
;============================
JIAN2: LCALL AJYS
JB P2.3,BH2
DEC R2
CJNE R2,#FFH,D4
AJMP JIANKS2
D4: MOV A,R2
MOV DPTR,#TABLE
MOVC A,@A+DPTR
CPL A
MOV R4,A
MOV P1,A
LCALL AJYS
AJMP BH2
;============================
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
AJYS: MOV R6,#255
L102: MOV R5,#255
L92: DJNZ R5,L92
DJNZ R6,L102
RET
TIME0: ;定时器0的中断处理程序
PUSH ACC
PUSH PSW ;将PSW和ACC推入堆栈保护
CPL P0.0
CPL P0.1
JB P0.0,L8
JB P0.1,L9
L8: MOV P1,R3
JNB P2.7,DSQ1
AJMP DSQ2
L9: MOV P1,R4
JB P2.7,DSQ1
AJMP DSQ2
DSQ1: MOV TH0,#EEH
MOV TL0,#88H
AJMP SSS
DSQ2: MOV TH0,#77H
MOV TL0,#88H ;重置定时常数
SSS: POP PSW
POP ACC
RETI
BCSJ: MOV 21H,R1
MOV 22H,R2
AJMP BH1
END
加减计数简单多了,二位数十进制连续加减调整位闪烁汇编程序,
以前写的,肯定有好多漏洞或错误。请自己分析,希望对你有所帮助。
ORG 0000H
AJMP START
ORG 000BH ;定时器0的中断向量地址
AJMP TIME0 ;跳转到真正的定时器程序处
ORG 30H
START: MOV TMOD,#00000001B ;定时/计数器0工作于方式1
MOV TH0,#15H
MOV TL0,#0A0H ;即数5536
SETB EA ;开总中断允许
SETB ET0 ;开定时/计数器0允许
SETB TR0
SETB P0.0
CLR P0.1
CLR P2.7
MOV R3,#C0H
MOV R4,#C0H
AJMP BH1
BH10: LCALL AJYS
JB P2.4,BH1
CPL P2.7
BH11: JNB P2.4,BH11
LCALL AJYS
JNB P2.4,BH11
AJMP BH1
JIAKS: MOV R1,#0
MOV R3,#C0H
MOV P1,R3
AJMP BH1
JIANKS: MOV R1,#9
MOV R3,#90H
MOV P1,R3
BH1: JNB P2.4,BH10
JNB P2.2,JIA
JNB P2.3,JIAN
JNB P2.5,BCSJ ;BCSJ意思是保存数据
JNB P2.7,BH1
AJMP BH2
;============================
JIA: LCALL AJYS ;加
JB P2.2,BH1
INC R1
CJNE R1,#10,D1
AJMP JIAKS
D1: MOV A,R1
MOV DPTR,#TABLE
MOVC A,@A+DPTR
CPL A
MOV R3,A
MOV P1,A
LCALL AJYS
AJMP BH1
;============================
JIAN: LCALL AJYS ;减
JB P2.3,BH1
DEC R1
CJNE R1,#FFH,D2
AJMP JIANKS
D2: MOV A,R1
MOV DPTR,#TABLE
MOVC A,@A+DPTR
CPL A
MOV R3,A
MOV P1,A
LCALL AJYS
AJMP BH1
;============================
JIAKS2: MOV R2,#0
MOV R4,#C0H
MOV P1,R4
AJMP BH2
JIANKS2: MOV R2,#9
MOV R4,#90H
MOV P1,R4
BH2: JNB P2.4,BH10
JNB P2.2,JIA2
JNB P2.3,JIAN2
JNB P2.5,BCSJ
JNB P2.7,BH1
AJMP BH2
;============================
JIA2: LCALL AJYS
JB P2.2,BH2
INC R2
CJNE R2,#10,D3
AJMP JIAKS2
D3: MOV A,R2
MOV DPTR,#TABLE
MOVC A,@A+DPTR
CPL A
MOV R4,A
MOV P1,A
LCALL AJYS
L5: AJMP BH2
;============================
JIAN2: LCALL AJYS
JB P2.3,BH2
DEC R2
CJNE R2,#FFH,D4
AJMP JIANKS2
D4: MOV A,R2
MOV DPTR,#TABLE
MOVC A,@A+DPTR
CPL A
MOV R4,A
MOV P1,A
LCALL AJYS
AJMP BH2
;============================
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
AJYS: MOV R6,#255
L102: MOV R5,#255
L92: DJNZ R5,L92
DJNZ R6,L102
RET
TIME0: ;定时器0的中断处理程序
PUSH ACC
PUSH PSW ;将PSW和ACC推入堆栈保护
CPL P0.0
CPL P0.1
JB P0.0,L8
JB P0.1,L9
L8: MOV P1,R3
JNB P2.7,DSQ1
AJMP DSQ2
L9: MOV P1,R4
JB P2.7,DSQ1
AJMP DSQ2
DSQ1: MOV TH0,#EEH
MOV TL0,#88H
AJMP SSS
DSQ2: MOV TH0,#77H
MOV TL0,#88H ;重置定时常数
SSS: POP PSW
POP ACC
RETI
BCSJ: MOV 21H,R1
MOV 22H,R2
AJMP BH1
END
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询