才开始学汇编语言,不是很懂。大神们帮我分析一下这个程序,能配合流程图讲解最好。谢谢大佬们了。
- COUNT EQU 30H ;T0中断计数
- SNLEDDATA EQU 31H ;存储南北数码管显示的数据
- SNCOLORFLAG EQU 32H ;=1时南北绿灯亮,=2时南北黄灯亮,=3时南北红灯亮
- SNLEDDATAINIT EQU 33H ;存储南北各颜色灯的初始时间
- EWLEDDATA EQU 34H ;存储东西数码管显示的数据
- EWCOLORFLAG EQU 35H ;=1时东西红灯亮,=2时东西绿灯亮,=3时东西黄灯亮
- EWLEDDATAINIT EQU 36H ;存储东西各颜色灯的初始时间
- org 0000h
- lJMP MAIN
- org 0003h
- lJMP INT00
- org 000Bh
- lJMP T00
- org 0100h
- ;主函数***************************************
- MAIN: MOV SP,#60H
- MOV TMOD,#01H
- MOV TH0,#0eCH
- MOV TL0,#078H
- MOV COUNT,#00H
- SETB TR0 ;开定时器0
- SETB ET0 ;允许定时器0中断
- SETB EX0 ;允许外部0中断
- SETB EA ;开总中断
- MOV SNLEDDATAINIT,#15
- MOV EWLEDDATAINIT,#18
- MOV SNLEDDATA,SNLEDDATAINIT
- MOV EWLEDDATA,EWLEDDATAINIT
- MOV P2,#0feH
- MOV SNCOLORFLAG,#01
- MOV EWCOLORFLAG,#01
- ;初始化结束***********************************
- START:
- MOV A,COUNT
- CJNE A,#200,NOT1S ;没到1秒跳转
- MOV COUNT,#00 ;1秒时间到
- DEC SNLEDDATA
- MOV A,SNLEDDATA
- JNZ checkewleddata
- MOV SNLEDDATA,SNLEDDATAINIT
- INC SNCOLORFLAG
- MOV A,SNCOLORFLAG
- CJNE A,#04,checkewleddata
- MOV SNCOLORFLAG,#01
- checkewleddata:
- DEC EWLEDDATA
- MOV A,EWLEDDATA
- JNZ NOT1S
- MOV EWLEDDATA,EWLEDDATAINIT
- INC EWCOLORFLAG
- MOV A,EWCOLORFLAG
- CJNE A,#04,NOT1S
- MOV EWCOLORFLAG,#01
- NOT1S:
- LCALL snCOLORCHECK
- LCALL ewCOLORCHECK
- LCALL DISPLAY
- SJMP START
- ;****************************************
- ;南北红绿黄灯控制**************************
- snCOLORCHECK:
- PUSH ACC
- PUSH B
- PUSH PSW
- sngreen:
- MOV A,SNCOLORFLAG
- CJNE A,#01,snYELLOW
- MOV SNLEDDATAINIT,#03 ;设置南北黄灯闪烁时间
- CLR P1.2
- CLR P1.1
- SETB P1.0 ;南北绿灯亮
- SETB P1.7
- CLR P1.6
- JMP snCOLORCHECKOUT
- snYELLOW:
- MOV A,SNCOLORFLAG
- CJNE A,#02,snred
- MOV SNLEDDATAINIT,#18 ;设置南北红灯亮时间
- MOV A,COUNT
- MOV B,#50
- DIV AB
- MOV A,B
- CJNE A,#00H,snNOTFLASH
- CPL P1.1 ;南北黄灯闪烁
- CLR P1.0
- CLR P1.2
-
- snNOTFLASH:
- JMP snCOLORCHECKOUT
- snred:
- MOV SNLEDDATAINIT,#15 ;设置南北绿灯亮时间
- CLR P1.0
- CLR P1.1
- SETB P1.2 ;南北红灯亮
- SETB P1.6
- CLR P1.7
- snCOLORCHECKOUT:
- POP PSW
- POP B
- POP ACC
- RET
- ;******************************************************
- ;东西红绿黄灯控制**************************************
- ewCOLORCHECK:
- PUSH ACC
- PUSH B
- PUSH PSW
- ewred:
- MOV A,ewCOLORFLAG
- CJNE A,#01,ewyellow
- MOV ewLEDDATAINIT,#15 ;设置东西绿灯亮时间
- CLR P1.3
- CLR P1.4
- SETB P1.5 ;东西红灯亮
- JMP ewCOLORCHECKOUT
- ewyellow:
- MOV A,ewCOLORFLAG
- CJNE A,#03,ewgreen
- MOV ewLEDDATAINIT,#18 ;设置东西红灯亮时间
- MOV A,COUNT
- MOV B,#50
- DIV AB
- MOV A,B
- CJNE A,#00H,ewNOTFLASH
- CPL P1.4 ;东西黄灯闪烁
- CLR P1.3
- CLR P1.5
- ewNOTFLASH:
- JMP ewCOLORCHECKOUT
- ewgreen:
- MOV ewLEDDATAINIT,#03 ;设置东西黄灯闪烁时间
- CLR P1.4
- CLR P1.5
- SETB P1.3 ;东西绿灯亮
- ewCOLORCHECKOUT:
- POP PSW
- POP B
- POP ACC
- RET
- ;************************************************************
- ;数码管显示**************************************************
- DISPLAY:
- PUSH ACC
- PUSH PSW
- PUSH B
- MOV A,SNLEDDATA
- MOV B,#10
- DIV AB
- MOV R0,B
- MOV R1,A
- MOV A,EWLEDDATA
- MOV B,#10
- DIV AB
- MOV R2,B
- MOV R3,A
- MOV DPTR,#TABLE
- MOV A,P2
- DISPSNH:
- CJNE A,#0feH,DISPSNL
- MOV A,R1
- MOVC A,@A+DPTR
- MOV P0,A
- JMP DISPOUT
- DISPSNL:
- CJNE A,#0fdH,DISPEWH
- MOV A,R0
- MOVC A,@A+DPTR
- MOV P0,A
- JMP DISPOUT
- DISPEWH:
- CJNE A,#0fbH,DISPEWL
- MOV A,R3
- MOVC A,@A+DPTR
- MOV P0,A
- JMP DISPOUT
- DISPEWL:
- CJNE A,#0f7H,DISPOUT
- MOV A,R2
- MOVC A,@A+DPTR
- MOV P0,A
- DISPOUT:
- POP B
- POP PSW
- POP ACC
- RET
- ;*****************************************
- TABLE:DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
- ; 0 1 2 3 4 5 6 7 8 9
- ;T0中断函数*******************************
- T00: PUSH ACC
- PUSH PSW
- MOV TH0,#0ecH
- MOV TL0,#078H
- MOV A,P2
- RL A
- CJNE A,#11101111B,NOT5
- MOV A,#0feH ;p2.0=0,南北数码管十位亮,p2.1=0,南北数码管个位亮
- NOT5: MOV P2,A ;p2.2=0,东西数码管十位亮,p2.3=0,东西数码管个位亮
- INC COUNT
- POP PSW
- POP ACC
- REti
- ;外部中断0***********************************
- INT00: push acc
- push psw
- mov a,p0
- push acc
- mov a,p1
- push acc
- mov a,p2
- push acc
- INT10: jnb p3.6,INT11
- jnb p3.7,INT12
- SJMP INT13
- INT11: LCALL INT01
- SJMP INT13
- INT12: LCALL INT02
- INT13: mov p1,#0C0h
- mov p2,#0ffh
- jnb p3.2,INT10
- pop acc
- mov p2,a
- pop acc
- mov p1,a
- pop acc
- mov p0,a
- pop psw
- pop acc
- reti
- INT01: mov p2,#0ffh
- mov p1,#01001100B
- jnb p3.6,$
- ret
- INT02: mov p2,#0ffh
- mov p1,#10100001B
- jnb p3.7,$
- ret
-
- ;*****************************************
- END
复制代码
0
|
5个回答
|
|
|