|
|
这个刚弄的,楼主参考下
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
//P1.0接车道绿灯 高电平有效
//P1.1接车道黄灯
//P1.2接车道红灯
//P1.3接人道绿灯
//P1.4接人道黄灯
//P1.5接人道红灯
uint count1=0; //灯计数值,1表示1S
uint count2=0; //1S计数值
uchar count_sign;
void check_light(void)
{
if(count1<=30) P1=0X21;
else if(count1<=35)
{
if(count2<=5) P1=0x0a; //黄灯闪烁,亮0.5S,灭0.5S
else P1=0x08;
}
else if(count1<=65) P1=0x0c;
else if(count1<=70)
{
if(count2<=5) P1=0x11; // 黄灯闪烁,亮0.5S,灭0.5S
else P1=0x01;
}
else count1=0; //循环
}
void timer0(void) interrupt 1 using 1
{
TH0=0X3c;
TL0=0Xb0;
count2++;
if(count2==10)
{
count2=0;
count1++;
}
check_light();
}
void mian(void)
{
TMOD=0X01;
TH0=0X3c; // 6M晶振,定时100ms
TL0=0Xb0;
TR0=1;
IE=0x82;
P1=0x00; //灯全灭
while(1);
}
[ 本帖最后由 littleboy 于 2007-5-22 12:04 编辑 ] |
|