新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 基于51單片機設計的交通燈匯編原程序

基于51單片機設計的交通燈匯編原程序

作者: 時間:2012-09-19 來源:網(wǎng)絡 收藏

用的是51系列的,
說一下,MARK標志位其關鍵作用,
需要的人自己想想,

下面是仿真圖

本文引用地址:http://butianyuan.cn/article/170835.htm

51單片機
LED0 EQU P1
LED2 EQU P2
LED1 EQU P0
MARK BIT 00H
MARK1 BIT 01H
TIME EQU 30H;時間緩沖區(qū)
SHI EQU 31H ;時長數(shù)據(jù)緩沖區(qū)!
KEY EQU P3.2
KEY1 EQU P3.3
CTH EQU (65536-50000)/256
CTL EQU (65536-50000) MOD 256
ORG 0000H
JMP START
ORG 0003H
JMP INT_0
ORG 000BH
JMP TIME0
ORG 0030H
START: MOV P1,#00H
MOV P0,#0FFH
MOV P2,#0FFH
MOV DPTR,#ABC
MOV SP,#5FH
MOV SHI,#20
MOV R0,SHI
MOV R7,#20
CLR MARK
CLR MARK1
MOV TMOD,#01H
MOV TH0,#CTH;初始指針
MOV TL0,#CTL
SETB EA
SETB IT0
SETB EX0
SETB ET0
SETB TR0
MOV TIME,R0
CALL DISPLAY
MAIN: MOV LED0,#21H;北,紅燈亮
CJNE R0,#3,MAIN
MOV SHI,#04
NEXT: MOV R6,#3
A1: MOV LED0,#01H
CALL DELAY_500MS
MOV LED0,#21H
CALL DELAY_500MS
DJNZ R6,A1
S1: JBC MARK,A2
SJMP S1
A2: MOV LED0,#11H; BEI HUANG DENG LIANG
MOV SHI,#20
JBC MARK,MAIN1
SJMP A2
MAIN1: MOV LED0,#0CH ;XI HONG DENG LIANG
CJNE R0,#3,MAIN1
MOV SHI,#04
NEXT1: MOV R6,#3
A3: MOV LED0,#08H
CALL DELAY_500MS
MOV LED0,#0CH
CALL DELAY_500MS
DJNZ R6,A3
S2: JBC MARK,A4
SJMP S2

A4: MOV LED0,#0AH
MOV SHI,#20
JBC MARK,MAIN
SJMP A4
DELAY_500MS:
MOV R5,#20
K1: MOV R4,#50
K2: MOV R3,#250
DJNZ R3,$
DJNZ R4,K2
DJNZ R5,K1
RET
DISPLAY:MOV A,TIME
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV LED2,A
MOV A,B
MOVC A,@A+DPTR
MOV LED1,A
RET
ABC: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
INT_0: PUSH ACC
PUSH PSW
SETB RS1
SETB RS0
MOV R5,#70
K4: MOV R4,#250
DJNZ R4,$
DJNZ R5,K4
JB KEY,ITT_2
MOV TIME,#20
CALL DISPLAY
ITT_1: MOV LED0,#00010010B
CALL DELAY_500MS
MOV LED0,#00H
JNB KEY,ITT_2
CALL DELAY_500MS
JB KEY,ITT_1
ITT_2: JNB KEY ,$
POP PSW
POP ACC
RETI
TIME0: PUSH ACC
PUSH PSW
MOV TH0,#CTH;初始指針
MOV TL0,#CTL
DJNZ R7,TIME1
MOV R7,#20
DJNZ R0,TIME2
SETB MARK
MOV R0,SHI
TIME2: MOV TIME,R0
CALL DISPLAY
TIME1: POP PSW
POP ACC
RETI
END



評論


相關推薦

技術專區(qū)

關閉