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.
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
- Popular Resources
- Popular amplifiers
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
- Power supply learning sharing
- Notes and lessons about IAR installation
- [Open Source] Bluetooth module BT401 full set of information based on Bluetooth headset chip development ultra-low cost
- Microcontroller Programming Examples
- Please advise, the voltage of the 5V circuit drops after adding load
- Configuration example of ModbusTCP to Profinet gateway connecting to tightening shaft drive
- What books should Linux newbies read?
- C6000 embedded assembly C and assembly comparison and function description
- MicroPython 1.17 released
- EEWORLD University Hall----Live Replay: ADI's Vital Signs Monitoring Solutions in Wearable Products