1897 views|2 replies

3

Posts

0

Resources
The OP
 

Traffic light system, except for the start button, other buttons are invalid. I hope you can help me solve it. [Copy link]


#include"reg51.h"
typedef unsigned int u16;
typedef unsigned char u8;
u16 s;
u8 a;
u8 b;
sbit LED1=P2^0;
sbit LED2=P2^1;
sbit LED3=P2^2;
sbit LED4=P2^3;
sbit LED5=P2^4;
sbit LED6=P2^5;
sbit KEY1=P3^1;
sbit KEY2=P3^2;
sbit KEY3=P3^3;


void delay(u16 i)
{
while(i--);
}

void Timer0Init()
{
TMOD|=0X01;
TH0=0XFC;
TL0=0X18;
ET0=1;
TR0=1;
}

void deng()
{
Timer0Init();

while(1)
{
if(TF0==1)
{
TF0=0;
TH0=0XFC;
TL0=0X18;
s++;
}
if((s>=0)&&(s<10000)) //10s
{
LED1=~LED1;
LED4=~LED4;
}
if((s>=10000)&&(s<14000)) //4s
{
LED1=1;
LED2=~LED2;
LED5=~LED5;
LED3=1;
LED4=1;
LED6=1;
}
if((s>=14000)&&(s<17000)) //3s
{
LED1=1;
LED3=1;
LED4=1;
LED6=1;
while((a>=0)&&(a<6))
{
LED2=!LED2;
LED5=!LED5;
delay(50000);
a++;
}

}
if((s>=17000)&&(s<20000))
{
LED1=1;
LED2=1;
LED4=1;
LED5=1;
while((a<12)&&(a>=6))
{
LED3=!LED3;
LED6=!LED6;
delay(50000);
a++;
}

}
if(s==20000)
{
LED5=1;
LED6=1;
LED2=1;
LED3=1;
s=0;
a=0;
}

}
}

void main()
{

if(KEY2==1)
{
delay(100);
if(KEY2==1)
{
delay(100);
if(KEY1==0)
{
delay(100);
if(KEY1==0)
{
deng();
}
while(!KEY1);
}
}
while(!KEY2);
}



if(KEY3==0)
{
delay(100);
if(KEY3==0)
{
TF0=0;
TH0=0XFC;
TL0=0X18;
s=0;
deng();
}
while(!KEY3);
}
}

This post is from 51mcu

Latest reply

Press together and it will work   Details Published on 2020-1-20 17:03
 

7170

Posts

195

Resources
2
 

The editing is a bit messy

In the main function, only the first key can be judged

deng deng(); will continue while1

This post is from 51mcu
 
 
 

3

Posts

1

Resources
3
 

Press together and it will work

This post is from 51mcu
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list