标题:
单片机交通灯怎么让黄灯全亮的同时让他们一直闪烁?
[打印本页]
作者:
蚊子咬了我
时间:
2021-5-22 10:51
标题:
单片机交通灯怎么让黄灯全亮的同时让他们一直闪烁?
请问怎么让黄灯全亮的同时让他们一直闪烁
#include <reg51.h>
#define uchar unsigned char
uchar a[10]={0x3F,0x06,0x5B,0x4F,0x66,
0x6D,0x7D,0x07,0x7F,0x6F};
uchar b[4]={0x0D,0x0E,0x07,0x0B};
uchar c[4]={0x3A,0x36,0x5C,0x6C};
uchar NS=25,EW=30;
uchar NS_G=25,EW_G=15,Y=5;
uchar i,k=0,count=0;
void delay(uchar);
void trafic_light();
void led_display();
sbit key_end=P3^5;
sbit nt=P3^2;
void init(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
EX1=1;
EA=1;
EX0=1;
}
//ò1???£ê?ía2??D??0£?P3
void int0(void) interrupt 0
{
while(1)
{
P1=0xE7,P0=a[9];
EA=0;
TR0=!TR0;
while(1)
{
for(i=0;i<4;i++)
{
P2=b[i];
delay(1);
}
if(key_end==0)
{
delay(10);
if(key_end==0)
{
while(!key_end)
{
for(i=0;i<4;i++)
{
P2=b[i];
delay(1);
}
}
EA=1;
TR0=!TR0;
break;
}
}
}
}
}
void int1(void) interrupt 2
{
P1=0x3C,P0=a[9];
EA=0;
TR0=!TR0;
while(1)
{
for(i=0;i<4;i++)
{
P2=b[i];
delay(1);
}
if(key_end==0)
{
delay(10);
if(key_end==0)
{
while(!key_end)
{
for(i=0;i<4;i++)
{
P2=b[i];
delay(1);
}
}
EA=1;
TR0=!TR0;
break;
}
}
}
}
void time1(void) interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count>=20)
{
NS--;
EW--;
count=0;
if(NS==0||EW==0)
{
k++;
if(k>3)
k=0;
switch(k)
{
case 0:NS=NS_G;
EW=NS_G+Y;
break;
case 1:NS=Y;
EW=Y;
break;
case 2:NS=EW_G+Y;
EW=EW_G;
break;
case 3:NS=Y;
EW=Y;
break;
}
}
}
}
void delay(uchar t )
{
uchar j,k;
for(j=0;j<t;j++)
{
for(k=0;k<255;k++){}
}
}
void trafic_light()
{
P1=c[k];
if(P1==c[1]&&count==0)
{
P1=0x3E;
}
else
if(P1==c[3]&&count==0)
{
P1=0x7C;
}
}
void led_display()
{
P2=b[0];
P0=a[NS%10];
delay(5);
P2=b[1];
P0=a[NS/10];
delay(5);
P2=b[2];
P0=a[EW%10];
delay(5);
P2=b[3];
P0=a[EW/10];
delay(5);
}
void main(void)
{
init();
while(1)
{
trafic_light();
led_display();
}
}
复制代码
作者:
xianfajushi
时间:
2021-5-22 17:28
可参
https://blog.csdn.net/xianfajush ... 1018.2226.3001.4450
作者:
xianfajushi
时间:
2021-5-22 17:29
可参
https://blog.csdn.net/xianfajush ... 1018.2226.3001.4450
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1