mov TCON, #01h ; down edge IT0 mov IE, #81h ; enable EA, EX0 setb SR ; 南北, 东西均红灯 clr SY clr SG
setb ER clr EY clr EG clr Loop:
jb setb clr clr clr clr setb mov call jb setb clr clr clr clr clr clr mov Loop1:
mov mov mov call cpl djnz jb clr clr setb setb clr clr mov STOP STOP, AllRed
SR SY SG ER EY EG a, #20 Delay
STOP, AllRed
SR SY SG ER EY EG Flash r7, #9 c, Flash EY, c a, #1 Delay Flash r7, Loop1 STOP, AllRed
SR SY SG ER EY EG a, #20
; 南北红灯, 东西绿灯 ; 南北红灯, 东西黄灯闪; 南北绿灯, 东西红灯 call Delay
jb STOP, AllRed
clr SR ; 东西红灯, 南北黄灯闪 clr SY clr SG
setb ER clr EY clr EG clr Flash mov r7, #9 Loop2:
mov c, Flash mov SY, c mov a, #1 call Delay cpl Flash djnz r7, Loop2 ljmp Loop AllRed:
setb SR clr SY clr SG setb ER clr EY clr EG clr STOP mov a, #10 call Delay ljmp Loop Delay: ; 延时子程序
mov r1, #80H mov r0, #0 DelayLoop:
jb STOP, ExitDelay djnz r0, DelayLoop djnz r1, DelayLoop djnz ACC, Delay ExitDelay: ret End.
10.计数器实验
mov TMOD, #00000101b mov TH0, #0
; 方式1,记数器 mov TL0, #0
setb TR0 ; 开始记数 Loop:
mov P1, TL0 ; 将记数结果送P1口 ljmp Loop End
TEMP EQU 30H ORG 0000H
START: MOV SP,#5FH MOV P2,#73H MOV P1,#0FFH NOKEY:
MOV A,P1 CPL A
JZ NOKEY MOV TEMP,P1 MOV A,P1
CJNE A,TEMP,NOKEY MOV R7,#16 MOV R2,#0
LOOP:MOV A,R2
MOV DPTR,#CODE_P0 MOVC A,@A+DPTR MOV P2,A INC R2 LCALL DL1S
DJNZ R7,LOOP SJMP START DL10ms:
MOV R6,#125 DL1: MOV R5,#98 NOP
DL2: DJNZ R5,DL2 DJNZ R6,DL1 RET
DL1s: MOV R4,#13 DL3: ACALL DL10ms DJNZ R4,DL3 RET
CODE_P0: DB 3FH,06H,5BH,4FH
DB 66H,6DH,7DH,07H
DB 7FH,6FH,77H,7CH
DB 39H,5EH,79H,71H
end
TEMP EQU ORG
START: MOV MOV MOV 30H 0000H SP,#5FH P2,#73H P1,#0FFH