|
#include <reg51.h> //unsigned char code
dofly_table[10]={0x90,0x80,0xf8,0x82,0x92,0x99,0xb0,0xa4,0xf9,0xc0}; //0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,};
dofly1_table1[3]={0xf9,0xa4,0xb0};
void Delay(unsigned int t);
void Delay(unsigned int t)
{
while(--t);
}
sbit key=P1^7;
sbit LED1=P0^1;//绿灯1
sbit LED2=P0^2;//绿灯2
sbit LED3=P0^3;//红灯1
sbit LED4=P0^4;//红灯2
sbit LED5=P0^5;//黄灯亮 1
sbit LED6=P0^6;//黄灯亮 2
void main()//主程序
{
unsigned char i;
while(1)
{
for(i=0;i<10;i++) //主循1
{
LED1=0; //绿灯亮1
P3=dofly_table[i];
Delay(60000);
Delay(60000);
}
LED4=1;//红灯灭2
LED1=1;//绿灯灭1
for(i=0;i<3;i++)
{
LED5=0; //黄灯亮1
P3=dofly1_table1[i];
Delay(60000);
Delay(60000);
}
//LED5=0;//黄灯亮 1
//Delay(60000);
//Delay(60000);
//Delay(60000);
LED5=1;//黄灯灭
LED3=0; //红灯亮 1
P3=0xff; //红灯延时1
//Delay(60000);
for(i=0;i<10;i++) //主循2
{
LED2=0; //绿灯亮 2
P2=dofly_table[i];
Delay(60000);
Delay(60000);
}
LED3=1;//红灯灭1
LED2=1;//绿灯灭2
for(i=0;i<3;i++)
{
LED6=0; //黄灯亮2
P2=dofly1_table1[i];
Delay(60000);
Delay(60000);
}
LED6=1; //黄灯灭2
LED4=0; //红灯亮2
P2=0xff;//绿灯延时2
//Delay(60000);
}
}
//void Delay(unsigned int i)
//{
//while(--t);
// }
//void DelayMs(unsigned int t)
//{
//while(t--)
//{
//DelayUs2x(245);
//DelayUs2x(245);
//}
//}
//void Delay(unsigned char i)
// {
// unsigned char j,k;
// for(k=0;k<i;k++)
// for(j=0;j<255;j++) ;
// }
|
-
-
-
交通灯.rar
86.45 KB, 下载次数: 23, 下载积分: 黑币 -5
|