当前位置:网站首页>Answer private message @ Tiantian Wx //2022-6-12 C language 51 single chip microcomputer led analog traffic light
Answer private message @ Tiantian Wx //2022-6-12 C language 51 single chip microcomputer led analog traffic light
2022-06-13 03:57:00 【Navigator_ Z】
name :LED Simulate traffic lights
explain :
Several seconds after the east-west green light , The yellow light is flashing , flashing 5 Red light after the second time ,
When the red light is on , The north-south direction changes from red light to green light , After a few seconds, the North-South yellow light flashes ,
flashing 5 Red light after the second time , The light is green from east to west , So back and forth .
In this example, the time is set to be short so that the running results can be quickly observed during debugging .
Code block :
#include <reg51.h>
#define INT8U unsigned char
#define INT16U unsigned int
sbit RED_A = P0^0; // East west direction indicator light
sbit YELLOW_A =P0^1;
sbit GREEN_A = P0^2;
sbit RED_B = P0^3; // North south direction indicator light
sbit YELLOW_B = P0^4;
sbit GREEN_B = P0^5;
// Definition of flicker times and operation type variables
INT8U Flash_Count = 0, Operation_Type = 1;
//-----------------------------------------
// The time delay function
//-----------------------------------------
void delay_ms(INT16U x)
{
INT8U t;
while(x--)
for(t=0; t<120; t++);
}
//-----------------------------------------
// Traffic light switching subroutine
//-----------------------------------------
void Traffic_Light()
{
switch(Operation_Type)
{
case 1: // The east-west green light and the South-North red light are on
RED_A=1; YELLOW_A=1; GREEN_A=0;
RED_B=0, YELLOW_B=1; GREEN_B=1;
delay_ms(5000);
Operation_Type=2;
break;
case 2: // The yellow light in the east-west direction began to flash , The green light is off
for(; Flash_Count<6; Flash_Count++)
{
RED_A=1; YELLOW_A=~YELLOW_A; GREEN_A=1;
delay_ms(300);
}
Flash_Count=0;
Operation_Type=3;
break;
case 3: // East West red light and South North green light
RED_A=0; YELLOW_A=1; GREEN_A=1;
RED_B=1; YELLOW_B=1; GREEN_B=0;
delay_ms(5000);
Operation_Type=4;
break;
case 4: // North South Yellow light starts flashing
for(; Flash_Count<6; Flash_Count++)
{
RED_B=1; YELLOW_B=~YELLOW_B; GREEN_B=1;
delay_ms(300);
}
Operation_Type=1;
break;
}
}
//------------------------------------------
// The main program
//------------------------------------------
void main()
{
while(1){
Traffic_Light();
}
}
边栏推荐
- [test development] automated test selenium (III) -- unittest framework analysis
- SCM: introduction to Modbus communication protocol
- Among the four common technologies for UAV obstacle avoidance, why does Dajiang prefer binocular vision
- 微信扫描二维码无法下载文件的解决办法
- 大疆无人机飞控系统的原理、组成及各传感器的作用
- 【测试开发】自动化测试selenium篇(一)
- 扫地机器人如何才能避障不“智障”?五种主流的避障技术解析
- 【 développement d'essais 】 sélénium d'essais automatisés (Ⅲ) - - analyse du cadre unitest
- Goframe day 4
- 【测试开发】测试管理工具禅道的安装
猜你喜欢

ET框架-22 创建ServerInfo实体及事件

Tencent cloud instant messaging IM
![[test development] use case](/img/33/cb505c9c73eabb9f7734751050e822.png)
[test development] use case

【Web】Cookie 和 Session

Principle, composition and functions of sensors of Dajiang UAV flight control system
![[test development] installation of test management tool Zen path](/img/8b/363e393bdb2d3400a2e8361af8677d.png)
[test development] installation of test management tool Zen path

MCU: NEC protocol infrared remote controller

Single chip microcomputer: infrared remote control communication principle
![[test development] automated test selenium (II) -- common APIs for webdriver](/img/d5/bc38f0bee98b137abc1197c6e03158.png)
[test development] automated test selenium (II) -- common APIs for webdriver
![[interview review] update from time to time for personal use](/img/bf/6a5184815b72e3cb84a66846b6cb49.png)
[interview review] update from time to time for personal use
随机推荐
LVS 4 - tier Load Balancing Cluster (3) Cluster Function Classification - HPC
单片机/嵌入式的实时性疑问解答
MCU: RS485 communication and Modbus Protocol
[test development] automatic test selenium (I)
USB-IF BC1.2充电协议解读
Lambda end operation count
Single chip microcomputer: a/d differential input signal
EGO Planner代码解析----CMakeLists.txt和package.xml
单片机:NEC 协议红外遥控器
【测试开发】进阶篇——各种测试技术分类
[web] cookies and sessions
手机私有充电协议解读
Lambda termination operation find and match anymatch
Field * doesn't have a default value problem
Stream流的注意事项
Detailed explanation of MySQL storage process
双目视觉——打造室外避障的“最优解”
Principle and control program of single chip microcomputer serial port communication
Tencent cloud instant messaging IM
四旋翼飞行器避障系统基础