MCU interrupt experiment 4

Publisher:古泉痴迷者Latest update time:2016-04-19 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Circuit Diagram:
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);
}

Keywords:MCU Reference address:MCU interrupt experiment 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]
Design of three-phase half-controlled rectifier circuit using PIC microcontroller chip
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]
Design and application of train rolling bearing fault diagnosis system based on DSP+MCU
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]
MCS-51 MCU input and output ports (I/O ports)
Latest Microcontroller Articles
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号