Circuit Diagram:
Keywords:MCU
Reference address:MCU interrupt experiment 4
The program code is as follows:
//Traffic light control program
#include
unsigned char t0, t1; //Define global variables to save the number of delay time cycles
//delay0_5s1
//Function: Use T1's working mode 1 to compile a 0.5s delay program. Assume that the system uses a 12Mhz crystal oscillator, timer 1, working mode 1 timing 50ms, and then cycle 10 times to reach the timing of 0.5s
void delay0_5s1 () {
for (t0=0; t0<0x0a; t0++) {
TH1 = 0x3c;
TL1 = 0xb0;
TR1 = 1;
while (!TF1);
TF1=0;
}
}
//delay_t1
//Function: implement 0.5s * delay
//Parameter: unsigned char t;
// Delay time is 0.5s*t;
void delay_t1 (unsigned char t) {
for (t1=0; t1
delay0_5s1();
}
//int_0
//External interrupt 0 interrupt function, emergency handling, when the cpu responds to the interrupt request of external interrupt 0, this function is automatically executed to make the red lights in both directions light up for 10 seconds at the same time
void int_0 () interrupt 0 {
unsigned char i,j,k,l,m;
i = P1; //Protect the scene, temporarily store P1, t0, t1, TH1, TL0;
j = t0;
k = t1;
l = TH1;
m = TL1;
P2 = 0xdb; //The lights are red in both directions
delay_t1 (20); //delay 10s
P2 = i;
t0 = j;
t1 = k;
TH1 = 1;
TL1 = m;
}
//int_1
//Function: External interrupt 1 interrupt function, special case processing, when the cpu responds to the interrupt request of external interrupt 1, it automatically executes this function to achieve a to release 5s
void int_1 () interrupt 2 {
unsigned char i,j,k,l,m;
EA = 0;
i = P1;
j = t0;
k = t1;
l = TH1;
m = TL1;
EA = 1;
P2 = 0xf3;
delay_t1 (10);
EA = 0;
P2 = i;
t0 = j;
t1 = k;
TH1 = l;
TL1 = m;
EA = 1;
}
void main () {
unsigned char k;
TMOD = 0x10; //T1 is in working mode 1
EA = 1; // Enable general interrupt
EX0 = 1;
IT0 = 1;
EX1 = 1;
IT1 = 1;
while (1) {
P2 = 0xf3;
delay0_5s1();
P2 = 0xfb;
delay0_5s1();
}
P2 = 0xeb;
delay_t1(4);
P2 = 0xde;
delay_t1(110);
for (k=0; k<3; k++) {
P2 = 0xde;
delay0_5s1();
P2 = 0xdf;
delay0_5s1();
}
P2 = 0xdd;
delay_t1(4);
}
Previous article:Design of shell velocity measurement system based on USB interface
Next article:Single chip LED light BCD code format display 00~59 simple password stopwatch program
Recommended ReadingLatest update time:2024-11-23 15:18
Single chip multi-channel data acquisition source program
The program is below
Source program:
Single channel acquisition program:
MOV DPTR,#0F8FFH
MOV R0,#00H ; Store the first address of the memory in registers R0 and R1
MOV R1,#00H
MOV R2,#200D ; Set up loop
MOV R3,#4
MOV R4,#8D
MAIN:
CLR P1.1 ;Select AD
[Microcontroller]
Design of three-phase half-controlled rectifier circuit using PIC microcontroller chip
The three-phase half-controlled rectifier bridge circuit structure is a common rectifier circuit, which is easy to control and has low cost. This article introduces a three-phase half-controlled rectifier circuit based on the PIC690 microcontroller and the dedicated integrated trigger chip TC787. It combines the ad
[Microcontroller]
Section 11: PIC series microcontroller low power mode (SLEEP)
1. Enter SLEEP Execute a "SLEEP" instruction to enter low power mode. When entering SLEEP, WDT is cleared and then restarts counting. The PD bit in the status register F3K is set to "0", the TO bit is set to "1", and the oscillation stops (referring to the oscillation circuit at the OSC1 end ). All I/O ports remai
[Microcontroller]
"error: L6236E" appears when debugging LPC2300 microcontroller
Problem 1 Description: After moving the source code of the SmartARM2300 MCU development board to Keil and building the project, the first problem encountered in compiling is “error: #147-D: declaration is incompatible with "void CANIntPrg(void)__irq" (declared at line 185 of "canLPC2300CAN.h")” When looking for
[Microcontroller]
Embedded microcontroller driving permanent magnet brushless DC motors
Abstract: This article introduces a cheap embedded microcontroller suitable for controlling permanent magnet brushless DC motors, and gives both software and hardware control methods with examples.
Keywords: permanent magnet brushless DC motor control embedded microcontroller
I. Overview
Permanent Magn
[Industrial Control]
Design and application of train rolling bearing fault diagnosis system based on DSP+MCU
Rolling bearings are the support of train rotating parts and are also the most vulnerable parts on railway vehicles that are most likely to endanger driving safety. Due to the long-term and repeated action of the contact stress on the working surface, it is very easy to cause bearing fatigue, cracks, indentations
[Microcontroller]
Review 51 single chip microcomputer
I spent the whole morning reading in the library today. I also memorized some knowledge about 51. It felt good. Especially the assembly part. It will be helpful for learning STM32.
clock
On-chip clock mode; XTAL1 and XTAL2 are connected to external quartz crystal and oscillation capacitor
Off-chip clock mode: For
[Microcontroller]
MCS-51 MCU input and output ports (I/O ports)
Another major feature of the microcontroller chip is the parallel I/O port. MCS-51 has four 8-bit parallel I/O ports, denoted as P0, P1, P2, and P3. Each port contains a latch, an output driver, and an input buffer. In fact, they have been classified as special registers and have byte addressing and bit addressing fun
[Microcontroller]
- 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)
Latest Microcontroller Articles
- 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)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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?
MoreDaily News
- 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
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
Guess you like
- AD9958
- Why are multiple register access instructions needed?
- [Synopsys IP Resources] Using 1.6T Ethernet to meet growing bandwidth demands
- Design of Internet Radio Based on RSIC-V RVB2601 (4)
- MicroPython Firmware Development Tutorial
- Wireless Security
- ISP burning GD32F350
- Make the needles on the car instrument cluster move
- Preload problem when building soc
- Research on Maximum Power Point Tracking in Photovoltaic Systems