標(biāo)題:
基于Proteus的51單片機(jī)交通燈仿真+源代碼
[打印本頁]
作者:
SDASDSF
時(shí)間:
2018-6-4 09:19
標(biāo)題:
基于Proteus的51單片機(jī)交通燈仿真+源代碼
51單片機(jī)交通燈仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png
(23.21 KB, 下載次數(shù): 29)
下載附件
2018-6-5 00:24 上傳
0.png
(14.36 KB, 下載次數(shù): 39)
下載附件
2018-6-5 00:24 上傳
單片機(jī)源程序如下:
#include <reg51.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
uchar h;
uint r=0;
uint s;
uchar code dis[]={0Xc0,0Xf9,0Xa4,0Xb0,0X99,
0X92,0X82,0Xf8,0X80,0X90,0Xff,};
void delay(uint c)
{
uint i,j;
for(i=0;i<c;i++)
for(j=0;j<100;j++);
}
//interrupt 1
void t0(void) interrupt 0 using 1
{
delay(2);
if(INT0==0)
{
r++;
if(r==2)
{
r=0;
}
r%=2;
if(r==0)
{
P0=0xeb;
P1=0x00;
P2=0xff;
}while(1)
{
if(INT0==0|INT1==0|T0==0)
{
delay(2);
if(INT0==0|INT1==0|T0==0)
break;
}
};
}
}
//interrupt 2
void t1(void) interrupt 2 using 1
{
delay(2);
if(INT1==0)
{
r++;
if(r==2)
{
r=0;
}
r%=2;
if(r==0)
{
P0=0xdd;
P1=0x00;
P2=0xff;
}while(1)
{
if(INT1==0|INT0==0|T0==0)
{
delay(2);
if(INT1==0|INT0==0|T0==0)
break;
}
};
}
}
//interrupt 3
void t2(void) interrupt 1 using 1
{
TH0=0xff;
TL0=0xff;
delay(2);
if(T0==0)
{
P0=0xdb;
P1=0x00;
P2=0xff;
}while(1)
{
if(INT0==0|INT1==0)
{
delay(2);
if(INT0==0|INT1==0)
break;
}
};
}
void main(void)
{
TMOD=0x06;
TH0=0xff;
TL0=0xff;
TR0=1;
EA=1;
EX0=1;
EX1=1;
ET0=1;
while(1)
{
P0=0xeb;
for(h=28;h>0;h--)
{
for(s=248;s>0;s--)
{
P1=0x00;
P2=0xff;
P1=0x01;
P2=dis[h/10];
delay(1);
P1=0x00;
P2=0xff;
P1=0x02;
P2=dis[h%10];
delay(1);
P1=0x00;
P2=0xff;
P1=0x04;
P2=dis[(h+2)/10];
delay(1);
P1=0x00;
P2=0xff;
P1=0x08;
P2=dis[(h+2)%10];
delay(1);
}
}
delay(248);
P0=0xf3;
for(h=3;h>0;h--)
{
delay(392);
P0=0xf3;
delay(1);
P1=0x00;
P2=0xff;
P1=0xaa;
P2=dis[(h-1)%10];
delay(600);
P0=0xfb;
}
delay(248);
P0=0xdd;
for(h=38;h>0;h--)
{
for(s=248;s>0;s--)
{
P1=0x00;
P2=0xff;
P1=0x01;
P2=dis[(h+2)/10];
delay(1);
P1=0x00;
P2=0xff;
P1=0x02;
P2=dis[(h+2)%10];
delay(1);
P1=0x00;
P2=0xff;
P1=0x04;
P2=dis[h/10];
delay(1);
P1=0x00;
P2=0xff;
P1=0x08;
P2=dis[h%10];
delay(1);
}
}
delay(248);
P0=0xde;
for(h=3;h>0;h--)
{
delay(392);
P0=0xde;
delay(1);
P1=0x00;
P2=0xff;
P1=0xaa;
P2=dis[(h-1)%10];
delay(600);
P0=0xdf;
}
delay(248);
}
}
復(fù)制代碼
所有資料51hei提供下載:
C51交通燈.zip
(82.17 KB, 下載次數(shù): 105)
2018-6-4 09:19 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
zhaxiaobian_er
時(shí)間:
2020-6-19 12:05
花里胡哨呀。。。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1