MCU traffic light source program with interrupt:
#include #include #define uchar unsigned char sbit c=P1^1; sbit d=P1^4; uchar led[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //0 to 9 digital tube display void delay1(uchar j) //delay several ms { fly i; while(j--) {for(i=0;i<125;i++) for(i=0;i<125;i++);} } void delay(uchar i) //delay 1 second { unsigned char a,b,c; while(i--) {for(c=167;c>0;c--) for(b=171;b>0;b--) for(a=16;a>0;a--); _nop_; } } void nanbei(uchar a) //North-South traffic lights { fly j = 100; P1=0X24; for(a;a>0;a--) { while(j--) { P0=0XFE; P2=led[a/10]; //display the ten-digit countdown delay1(5); // Delay 5 milliseconds to give the machine some time to react P0=0XFd; P2=led[a%10]; //display countdown delay1(5); // Delay 5 milliseconds to give the machine some time to react if(a<=3) //If a is less than 3, the yellow light starts flashing { P1=0X12; delay1(10); P1=0X00; delay1(10); } } } } void dongxi(uchar a)//East and West display traffic lights { fly j = 100; P1=0X09; for(a;a>0;a--) { while(j--) { P0=0XFB; P2=led[a/10]; //display the ten-digit countdown delay1(5); // Delay 5 milliseconds to give the machine some time to react P0=0XF7; P2=led[a%10]; //display countdown delay1(5); // Delay 5 milliseconds to give the machine some time to react if(a<=3) //If a is less than 3, the yellow light starts flashing { P1=0X12; delay1(10); P1=0X00; delay1(10); } } } } main() {EA=1; //Enable interrupt EX0=1; //Enable external interrupt 0 IT0=1; //Edge trigger while(1) {dongxi(15); //East-west travel time 15 seconds nanbei(30); //North-South travel time: 30 seconds } } void into(void) interrupt 0 //External interrupt 0 function, used to forcibly change the direction of the traffic light {fly i,j=1000,b; P0=0XFF; P1=P1&0X01; //If the last digit of P1 is 1, the east-west direction is green and the north-south direction is red if(P1==0X01) {P1=0X08; for(b=0;b<3;b++) {{for(i=0;i<10;i++)//Number of times the yellow light flashes {delay1(100); c=~c; delay1(100); }}} P1=0Xe4; delay(10); //The time delay after the change is 10 seconds } else {P1=0X04; for(b=0;b<3;b++) {{for(i=0;i<10;i++) {delay1(100); d=~d; delay1(100); }}} P1=0X09; delay(10); //The time delay after the change is 10 seconds }}
Previous article:STC15W4K60S2 MCU 2-way SPWM source program can drive the motor
Next article:MCU + UA741 amplification shaping 1~10K frequency meter
Recommended ReadingLatest update time:2024-11-25 05:55
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- CATL releases October battle report
- Battery industry in October 2024: growth momentum remains unabated!
- Mercedes-Benz will launch the eCitaro equipped with NMC4 batteries to provide high energy density and long life
- Many companies have announced progress on solid-state batteries. When will solid-state batteries go into mass production?
- Xsens Sirius Series Inertial Sensors Enable 3D Inertial Navigation in Harsh Environments
- Infineon's Automotive Landscape: From Hardware to Systems
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- Evolution, Analysis and Comparison of High Voltage and High Power Converter Topologies
- ATT7022 User Manual
- Detailed explanation of UART serial port protocol
- Why does the phone's battery drain too quickly after it is connected to a Bluetooth device?
- A special and unforgettable year of 2017
- RVB2601 Recording and Playback
- Talk about the horizontal and vertical beam widths in the antenna.
- EEWORLD University ---- VLSI CADII-Design
- HOLTEK launches a new generation of optical mouse controllers --- HT82M23A/HT82M23B/HT82M23C
- The impact of FPGA clock quality on design