Level trigger and edge trigger program of microcontroller external interrupt

Publisher:RadiantBreezeLatest update time:2015-05-25 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
After a whole morning of struggling, no one is leading me and I can only figure it out on my own...

Connection method: JP10 to J12; JP8 to JP16; P3^2 to GND; P2^0 to LED;

 

Only when the global switch is turned on can the switches of other units be turned on.
All switches are turned on when the value is 1 and turned off when the value is 0.
Bit number
D0
D1
D2
D3
D4
D5
D6
D7
illustrate
External interrupt 0
Timing/Counting 0
External interrupt 1
Timing/Counting 1
Serial port interrupt
Timing/Counting 2
(52 single chip microcomputer)
Invalid bit
Global interrupt bit
Bit symbol (directly referenced when writing a program)
EX0
ET0
EX1
ET1
ES
ET2
--
EA
Bit Address
A8H
A9H
AAH
ABH
ACH
ADH
--
AFH

 

EA: total enable bit
ES: serial port interrupt enable bit
ET1: timer counter 1 interrupt enable bit
EX1: external interrupt 1 interrupt enable bit
ET0: timer counter 0 interrupt enable bit
EX0: external interrupt 0 interrupt enable bit

The relationship between the 6 interrupt sources in the 52 single-chip microcomputer and the single-chip microcomputer ports:
1 The interrupt request line INT0 of external interrupt 0 is the P3.2 port line of P3 port
2 The interrupt request line INT1 of external interrupt 1 is the P3.3 port line of P3 port
3 The external counting input end of counter 0 is the P3.4 port line of P3 port of the single-chip microcomputer (timer 0 is an internal interrupt)
4 The external counting input end of counter 1 is the P3.5 port line of P3 port of the single-chip microcomputer (timer 1 is an internal interrupt)
5 Serial port interrupt (divided into serial port receive interrupt RXD, which is the P3.0 port line of P3 port of the single-chip microcomputer; serial port send interrupt TXD, which is the P3.1 port line of P3 port of the single-chip
microcomputer 6 The external counting input end of counter 2 is the P1.0 port line of P1 port of the single-chip microcomputer (timer 2 is an internal interrupt)


 

 TCON
TCON (Timer Control Register) Timer/Counter Control Register
TCON is in the special function register, the byte address is 88H, because of the bit address, it is very convenient to perform bit operations.
The function of TCON is to control the start and stop of the timer, and mark the timer overflow and interrupt.
The format of TCON is shown in the figure below. Among them, TF1, TR1, TF0 and TR0 are used for timer/counter; IE1, IT1, IE0 and IT0 are used for interrupt system.
The definition of each bit is as follows:
TF1: Timer 1 overflow flag. When timer 1 overflows, TF1 is set to "1" by hardware and an interrupt is requested. After entering the interrupt service routine, it is automatically cleared to "0" by hardware, and cleared to "0" by software in query mode.
TR1: Timer 1 operation control bit. Clear "0" by software to turn off timer 1. When GATE=1 and INT1 is high, TR1 is set to "1" to start timer 1; when GATE=0, TR1 is set to "1" to start timer 1.
TF0: Timer 0 overflow flag. Its function and operation are the same as TF1.
TR0: Timer 0 run control bit. Its function and operation are the same as TR1.
IE1: External interrupt 1 request flag.
IT1: External interrupt 1 trigger mode selection bit. When IT1=0, it is low level trigger mode; when IT1=1, it is falling edge trigger mode.
IE0: External interrupt 0 request flag.
IT0: External interrupt 0 trigger mode selection bit. When IT0=0, it is low level trigger mode; when IT0=1, it is falling edge trigger mode.
The lower 4 bits of TCON are related to interrupts. Since TCON is bit addressable, if you only want to clear overflow or start the timer, you can use bit operation commands. For example: after executing "CLR TF0", the overflow of timer 0 is cleared; after executing "SETB TR1", timer 1 can be started to work (of course, the mode must be set before). [page]
 code:


//Level trigger
#include
#include
#define uint unsigned int 
#define uchar unsigned char
sbit D1=P2^0;
uchar num;
uchar wnum=0x00;
uchar code dbit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //Segment selection, select the number to be displayed
//uchar code wnum[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F}; //Eight-bit digital tube    
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
P1=wnum;
EA=1;//Turn on the main interrupt switch
EX0=1;//Turn on external interrupt 0, P3.2 select
IT0=0;//Select level trigger mode
while(1)
{
for(num=0;num<10;num++)
{
P0=dbit[num];
delay(500);
}
}
}
void duan() interrupt 0
{
D1=1;
delay(500);
D1=0;
delay(500); 
}

 

//Edge trigger mode
#include
#include
#define uint unsigned int 
#define uchar unsigned char
sbit D1=P2^0;
uchar num;
uchar wnum=0x00;
uchar code dbit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//Segment selection, select the number to be displayed
//uchar code wnum[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};//Eight-bit digital tube    
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
P1=wnum;
EA=1;//Turn on the main interrupt switch
EX0=1;//Turn on external interrupt 0, P3.2 select
IT0=1;//Select edge trigger mode
while(1)
{
for(num=0;num<10;num++)
{
P0=dbit[num];
delay(500);
}
}
}
void duan() interrupt 0
{
D1=1;
delay(500);
D1=0;
delay(500); 
}

Keywords:MCU Reference address:Level trigger and edge trigger program of microcontroller external interrupt

Previous article:Data on I_2C bus A_D_D_A conversion based on PCF8591
Next article:About the serial port control register SCON

Recommended ReadingLatest update time:2024-11-16 04:16

MCU DS18B20 Thermometer C Language Program
//Function: negative temperature display, high precision grid can display -9.99C to 99.99C //           With alarm device //           When the temperature is positive, display the tens, units, tenths and percentiles //          When the temperature is negative, display the negative sign, tens, units and tenth
[Microcontroller]
51 MCU serial port receiving and sending string source program
I want to control the LED through the serial port, but the serial port can only send one character each time it is interrupted. So it is not easy to know which part each command controls when controlling it. So I refer to the information on the Internet and write a simple string receiving and sending function. The fun
[Microcontroller]
51 MCU serial port receiving and sending string source program
A square wave signal generator with adjustable duty cycle and frequency based on 51 single chip microcomputer
       I started to learn about single-chip microcomputers some time ago. I thought single-chip microcomputers would be very simple, but they were more complicated than I expected, especially when I first started. I needed to download various software and then slowly familiarize myself with the operation of these soft
[Microcontroller]
A square wave signal generator with adjustable duty cycle and frequency based on 51 single chip microcomputer
Application of RS-232 serial communication in communication between PC and single chip microcomputer
  Since the single-chip microcomputer has the characteristics of small size, low price and strong adaptability, it is generally used in industrial control systems to complete the collection of various data and the control of actuators. However, the computing power of the single-chip microcomputer is limited, and it is
[Microcontroller]
Application of RS-232 serial communication in communication between PC and single chip microcomputer
New generation of domestic main controller for network printers: N32G457 series MCU chip
A network printer is a built-in or external print server that is connected to a local area network, the Internet, or a wireless network as an independent device, thereby freeing the printer from its traditional status as a computer peripheral and making it an independent member of the Internet of Things terminal devic
[Internet of Things]
New generation of domestic main controller for network printers: N32G457 series MCU chip
51 MCU and Bluetooth module connection
I started learning to use the Bluetooth module not long ago. There were many problems in the process of connecting the module with the 51 single-chip microcomputer. I think many novices will encounter such problems like me. Therefore, I wrote this article to share the problems encountered in the learning process and t
[Microcontroller]
51 MCU and Bluetooth module connection
Digital Clock Designed with Single-Chip Microcomputer AT89C51
1. Experimental tasks  (1). When the machine is turned on, the time displayed is 12:00:00 and the time starts to count. (2). P0.0/AD0 controls the adjustment of "seconds". Each press adds 1 second.  (3). P0.1/AD1 controls the adjustment of "minutes". Each press adds 1 minute.  (4). P0.2/AD2 controls the adjustment of
[Microcontroller]
Digital Clock Designed with Single-Chip Microcomputer AT89C51
Infineon Technologies Launches New High-Performance Microcontroller AURIX™ TC4Dx
Infineon Technologies AG, a global semiconductor leader in power systems and the Internet of Things, recently announced the launch of the first product in the latest AURIX™ TC4x series, the AURIX™ TC4Dx microcontroller (MCU). Based on 28nm technology, the AURIX™ TC4Dx provides more powerful performance and
[Network Communication]
Infineon Technologies Launches New High-Performance Microcontroller AURIX™ TC4Dx
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号