Implementation of LED simulated traffic lights based on 51 microcontroller

Publisher:炫酷骑士Latest update time:2023-02-01 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Specific function implementation:

The north and south red lights are on, and the east and west green lights are on; the north and south green lights are on, and the east and west red lights are on; during the traffic light conversion process, the yellow light flashes 5 times.

Devices used:

Several resistors, 4 red LED lights, 4 green LED lights, 4 yellow LED lights, AT89C51 chip

Proteus simulation schematic diagram:

Simulation test:

Knowledge introduction:

Proteus wiring

In order to make the entire schematic look concise and clear, we label the wires of the components instead of directly connecting them to the chip.

LED active low level

The characteristic of LED is one-way conduction. It can only conduct when the voltage of the anode is greater than the voltage of the cathode. In the simulation diagram, the anode of the LED is connected to the power supply, so we set the cathode to 0 before it can be turned on.

Main code (C language) KEIL5 implementation:

#include


sbit RED_A = P0^0; //east and west

sbit YELLOW_A = P0^1;

sbit GREEN_A = P0^2;


sbit RED_B = P0^3; //north and south

sbit YELLOW_B = P0^4;

sbit GREEN_B = P0^5;


unsigned char type = 1;

unsigned char count=0;


void delay(unsigned int x){

  unsigned char i;

  while(x--){

    for(i=0;i<120;i++);

  }

}


void light(){

  switch(type){

    case 1:  //GREEN_A , RED_B

      RED_A=1;YELLOW_A=1;GREEN_A=0;

      RED_B=0;YELLOW_B=1;GREEN_B=1; 

      delay(2000);

      type=2;

      break;

    case 2:

      delay(300);

      YELLOW_A=~YELLOW_A;GREEN_A=1;

      if(++count!=10) return;

      count=0;

      type=3;

      break;

    case 3: // RED_A,GREEN_B

      RED_A=0;YELLOW_A=1;GREEN_A=1;

      RED_B=1;YELLOW_B=1;GREEN_B=0;

    case 4:

      delay(300);

      YELLOW_B=~YELLOW_B;GREEN_B=1;

      if(++count!=10) return;

      count=0;

      type=1;

      break;      

  }

}


void main(){

  while(1){

    light();

  }

}

FAQ

Q:

Why does port P0 need to be connected to a pull-up resistor?

A:

Because the P0 port is a quasi-bidirectional port, that is, it has an open-drain output. When the P0 port is used as a parallel port, it can only output a low level and cannot output a high level. A pull-up resistor is required to output a high level.

Q:

How to quickly route Proteus?

A:

Press the capital A button, enter the command net=P0.#, then click "Click Object", and finally which wire you want to label is just a click away.



Reference address:Implementation of LED simulated traffic lights based on 51 microcontroller

Previous article:Implementing simple password lock function based on 51 microcontroller
Next article:Based on 51 microcontroller, using interrupts to achieve key counting within 100

Recommended ReadingLatest update time:2024-11-16 10:28

stm8——LED running water light realization
I recently came into contact with and learned about a STM8 series chip. After learning ARM9+Linux before, I felt that I could get started quickly when learning microcontrollers.  Basic information of chip: Type:STM8L151G6 8-bit ultralow power MCU,  up to 32 KB Flash,  1 KB Data EEPROM  RTC,  LCD,  timers,  USART,  I
[Microcontroller]
PIC16F785 LED running light program
#include p IC .h     __CONFIG(0x33f4);    //Watchdog off, reset pin for reset, internal RC oscillation, RA4/RA5 for I/O  //------------------------------------  //Delay function  void delay()  {   int i; //Define loop variable   for(i=5000;i 0;i--) //Loop count control      {        NOP(); //Consume one instruction
[Microcontroller]
Visionox: Chengdu Chenxian Optoelectronics has completed the Micro LED pilot line
An investor asked a question on the investor interaction platform: According to media reports, the Metaverse will become a future technology trend, and the best display technology for AR or VR head-mounted devices is Micro LED display technology. Visionox currently has a MicroLED production line and mass production te
[Mobile phone portable]
Production of Voice-Controlled LED Spectrum Analyzer
Step 1: Testing Your LED Lay everything out on a suitably sized workspace. Plug in your soldering iron. The first thing you'll want to do is test your LED. I quickly learned that these lights don't like to respond to power without data. If you jump up and try to test them with just power and they don't work, wait
[Test Measurement]
Production of Voice-Controlled LED Spectrum Analyzer
Mini LED TV has broken through the bastion of picture quality, where is the future of OLED TV?
Recently, TCL released the C12 quantum dot Mini LED smart screen and the X12 8K Mini LED Star Smart Screen. Their brightness, contrast and other picture quality indicators all exceed those of OLED TVs. OLED TVs will face unprecedented threats in the high-end market. Where is the future of OLED TVs? OLED TV picture q
[Mobile phone portable]
The leading enterprises are making a lot of money, but the small and medium-sized enterprises are jointly "resisting the rise" and LED "involution" has appeared
Jiwei.com reported that shortages in the global electronics industry have become normalized, and price increases have become one of the main themes in various industries. The price increase of enterprises proves that the upstream price increase exceeds the enterprises' ability to absorb it, and also proves that enterp
[Mobile phone portable]
The leading enterprises are making a lot of money, but the small and medium-sized enterprises are jointly
GEC210 LED Bare Metal Programming Principle Introduction
Development environment: ADS1.2 or arm-linux-gcc4.4.1 Development board: GEC210 (s5pv210 soc) Principle part: Led control is the simplest part of microcontroller control, so we will start with this. For the CPU, the control of the LED is only on and off, and the CPU only needs to output the corresponding high
[Microcontroller]
GEC210 LED Bare Metal Programming Principle Introduction
Silicon Labs and Yeelight Launch Smart LED Bulbs for More Reliable Wireless Connections
Silicon Labs (NASDAQ: SLAB), a leading supplier of chips, software and solutions for a smarter, more connected world, and Yeelight, a leading smart lighting provider preferred by 3.2 million users worldwide, today announced that they have collaborated to launch a new smart LED bulb that supports Seamless Setup in the
[Power Management]
Silicon Labs and Yeelight Launch Smart LED Bulbs for More Reliable Wireless Connections
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号