Simulate traffic light control
P0 port segment code
P1 port position
Use digital tube to dynamically display remaining time;
P2 port displays red, green and yellow lights;
east and west direction lights use P00 east and west green, P01 east and west yellow, and P02 east and west red respectively;
P05 is green in the north and south, P06 is yellow in the north and south, and P07 is red in the north and south.
*/
#include
#define uint unsigned int
#define uchar unsigned char
uchar code dula[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
uchar code wula[] ={0xfe,0xfd};
sbit ds_green=P2^0;
sbit ds_yellou=P2^1;
sbit ds_red=P2^2;
sbit nb_green=P2^5;
sbit nb_yellou=P2^6;
sbit nb_red=P2^7;
uchar flag1s,num1,num2,green,yellow,temp;
bit flag500ms,flag1;
void delay(uint z);
void disp();
void main()
{
green=30;
yellou=5;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
disp();
}
//--------------------
void delay(uint z)
{
uint x,y;
for(x=0;x
}
//----------------------
void timer0() interrupt 1
{
TH0=(65536-10000)/ 256;
TL0=(65536-10000)%256;
num1++;
if(num1==50)
{num1=0;
num2++;
flag500ms=~flag500ms;
if(num2==2)
{num2=0;
flag1s++;flag1=1 ;
if(flag1s>70)
flag1s=0;
}
}
if(flag1s<=30)
{ds_green=0;ds_red=1;ds_yellou=1;
nb_red=0;nb_yellou=1;nb_green=1;
}
if((flag1s>30)&&(flag1s<=35))
{ ds_green=1;ds_red=1;
nb_red=0;nb_yellou=1;
nb_green=1;
ds_yellou =flag500ms;
}
if((flag1s>35)&&(flag1s<=65))
{ds_green=1;ds_red=0;ds_yellou=1;
nb_red=1;nb_yellou=1;nb_green=0;}
if((flag1s> 65)&&(flag1s<=70))
{ds_green=1;ds_red=0;ds_yellou=1;
nb_red=1;nb_green=1;
nb_yellou=flag500ms;
}
}
//---------------------------
void disp()
{ uchar i;
if((flag1s<=30 )||((flag1s>35)&&(flag1s<=65)))
{yellou=5;
if(flag1==1)
{flag1=0;green--;}
P0=dula[green/10];
P1 =wula[0];
delay(5);
P0=dula[green%10];
P1=wula[1];
delay(5);
}
if(((flag1s>30)&&(flag1s<=35))| |((flag1s>65)&&(flag1s<=70)))
{green=30;
if(flag1==1)
{flag1=0;yellou--;}
P0=dula[yellou/10];
P1=wula[0];
delay(5);
P0=dula[yellou%10];
P1=wula[1];
delay(5);
}
}
Previous article:24C02 storage and reading
Next article:Simple addition calculator single chip c programming
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 2. Sensors used in previous "Control" competitions
- The left side is connected to the microcontroller, and the right side is the button. Why is the IO port always at a high level?
- The stm32f103zet6 system board drives OV2640 and collects data incorrectly
- Quickly obtain TI industrial motor drive resources and answer questions to win prizes
- [Flower carving DIY] Interesting and fun music visualization series of small projects (13) --- organic stick column lamp
- [Silicon Labs BG22-EK4108A Bluetooth Development Review] + Unboxing Experience
- Dialog Semiconductor Software Application Engineer (BLE Low Energy Bluetooth Products)
- Activity/Inactivity recognition of LSM6DSL
- EEWORLD University - What you don't know about C language
- Today at 10:00 AM Live: Introduction to ON Semiconductor's Photovoltaic and Energy Storage Products