1. Video
Bilibili video address:
https://www.bilibili.com/video/av91934816
51 single chip microcomputer - traffic light - traffic light
2. Documentation
Download the file:
https://download.csdn.net/download/weixin_43130546/12194351
3. Description
Green light on for 10 seconds; Yellow light on for 5 seconds; Red light on for 10 seconds
4. Code
#include sbit DULA = P2^6; sbit HOT = P2^7; unsigned char code DUTable[16] = { 0x3F,0x06,0x5B,0x4F, 0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x77,0x7C, 0x39,0x5E,0x79,0x71 }; unsigned char code WETable[8] = { ~0x80,~0x40,~0x20,~0x10, ~0x08,~0x04,~0x02,~0x01 }; unsigned char LedBuff[8] = { 0x3F,0x3F,0x00,0X00, 0X00,0X00,0X00,0X00 }; unsigned char T0RH,T0RL; bit flag1s = 0; void ConfigTimer0(unsigned char ms); void TransLED(void); void main(void) { ConfigTimer0(1); while(1) { if(flag1s) { flag1s = 0; TransLED(); } } } void TransLED(void) { static unsigned char num = 0; static unsigned char led = 0; if(0 == num) { switch(led) { case 0 : led = 1; num = 9; P1 = ~0x04; break; case 1 : led = 2; num = 4; P1 = ~0x02; break; case 2 : led = 0; num = 9; P1 = ~0x01; break; } } else { num--; } LedBuff[0] = DUTable[num/1%10]; LedBuff[1] = DUTable[num/10%10]; } void ConfigTimer0(unsigned char ms) { unsigned long tmp; tmp = 11059200 / 12; tmp = tmp * ms / 1000; tmp = 65536 - tmp; tmp += 12; T0RH = (unsigned char)(tmp>>8); T0RL = (unsigned char)tmp; TH0 = T0RH; TL0 = T0RL; TMOD &= 0xF0; TMOD |= 0x01; EA = 1; ET0 = 1; TF0 = 0; TR0 = 1; } void LedScan(void) { static unsigned char i = 0; P0 = 0x00; GAME = 1; GAME = 0; P0 = WETable[i]; HOT = 1; TEMPERATURE = 0; P0 = LedBuff[i]; GAME = 1; GAME = 0; i++; if(i>=8) { i = 0; } } void InterruptTimer0(void) interrupt 1 { static unsigned int tmr1s = 0; TH0 = T0RH; TL0 = T0RL; LedScan(); tmr1s++; if(tmr1s>=1000) { tmr1s = 0; flag1s = 1; } }
Previous article:51 MCU-Timer-Countdown Alarm Clock
Next article:51 MCU - Stepper Motor - Servo
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- [Problem Feedback] Anlu TangDynasty constraint file and code formatting issues
- MSP430F5529 program arrangement (serial port, AD, timer, etc.)
- Allwinner V5 Review——by IC Crawler
- How to distinguish the high voltage package pins and turns ratio
- 【DFRobot wireless communication module】-Gravity A6 GPRS module inspection
- MicroPython Hands-on (11) - Building the IDE environment for the control board
- [Blood Oximeter] Disassembly Part 2: Introduction to the accessories
- What should we talk about when we talk about Tesla incident
- Introduction to four working modes of WIFI module
- How to Improve Heat Dissipation Using PCB Design