新聞中心

51單片機(jī)模擬交通燈

作者: 時(shí)間:2016-11-29 來(lái)源:網(wǎng)絡(luò) 收藏
利用51單片機(jī)的控制二極管及數(shù)碼管的顯示來(lái)模擬交通燈,系統(tǒng)晶振為11.0592MHZ,東西方向紅燈設(shè)置為30秒,南北方向紅燈設(shè)置為20 秒,P1.3接一個(gè)應(yīng)急按鈕,按下第一次放開(kāi),南北方向綠燈一直亮,東西方向紅燈一直亮(目的是為了方便大領(lǐng)導(dǎo)通行),按下放開(kāi)第二次,南北綠燈閃3秒黃燈亮2秒后變紅燈,東西方向變?yōu)榫G燈,之后沿著之前的設(shè)置一直循環(huán),下面是仿真圖、程序源代碼


仿真圖

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

程序源代碼如下:
作者:胡琴
聯(lián)系qq:1257394091
網(wǎng)站:http://www.51hei.com
本程序已經(jīng)通過(guò)軟件仿真以及在自己搭建的硬件上測(cè)試通過(guò).
org 0000h
ajmp main
org 000bh
ajmp inti0
org 0030h
main:mov tmod,#01h
mov ie,#82h
mov th0,#4ch
mov tl0,#00h
mov sp,#60h
mov 31h,#30 ;東西綠燈初值30秒
mov 32h,#30 ;南北紅燈初值30秒
clr 4fh ;清標(biāo)志位
clr p1.1 ;開(kāi)東西綠燈
clr p1.5 ;開(kāi)南北紅燈
setb tr0 ;啟動(dòng)T0
loop:lcall display ;調(diào)用顯示子程序
lcall key ;調(diào)用應(yīng)急按鍵判斷
ajmp loop
inti0:push psw
clr ea
mov th0,#4ch
mov tl0,#00h
inc 35h
mov a,35h
cjne a,#20,out ;判1秒是否到時(shí)
mov 35h,#00
jb 4fh,yi ;判別標(biāo)志位
dec 31h ;東西時(shí)間每秒減1
dec 32h ;南北時(shí)間每秒減1
mov a,31h
cjne a,#05,out ;判是否到25秒
setb p2.0 ;到25秒關(guān)時(shí)間顯示
setb p2.1
setb p1.1 ;東西綠燈閃滅3秒
lcall del500ms
clr p1.1
lcall del500ms
setb p1.1
lcall del500ms
clr p1.1
lcall del500ms
setb p1.1
lcall del500ms
clr p1.1
lcall del500ms
setb p1.1 ;滅東西綠燈
sjmp er
out:setb ea
pop psw
reti
er:clr p1.2 ;東西黃燈亮2秒
mov 33h,#4 ;延時(shí)2秒
loop1:lcall del500ms
djnz 33h,loop1
setb p1.2 ;2秒后滅東西黃燈
clr p2.0 ;5秒后開(kāi)時(shí)間顯示
clr p2.1
mov 31h,#20 ;東西時(shí)間賦20秒初值
mov 32h,#20 ;南北時(shí)間賦20秒初值
setb 4fh
setb p1.5 ;關(guān)南北紅燈
clr p1.0 ;點(diǎn)亮東西紅燈
clr p1.6 ;點(diǎn)亮南北綠燈
sjmp out
yi:dec 31h ;東西時(shí)間每秒減1
dec 32h ;南北時(shí)間每秒減1
mov a,31h
cjne a,#5,out ;判是否到15秒
setb p2.6 ;到15秒關(guān)時(shí)間顯示
setb p2.7 ;
setb p1.6 ;南北綠燈閃滅3秒
lcall del500ms
clr p1.6
lcall del500ms
setb p1.6
lcall del500ms
clr p1.6
lcall del500ms
setb p1.6
lcall del500ms
clr p1.6


上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: 51單片機(jī)模擬交通

評(píng)論


技術(shù)專區(qū)

關(guān)閉