Understanding C51 external interrupt (INT0)

Publisher:SparkleMagicLatest update time:2015-11-11 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The following will take infrared remote control decoding as an example to talk about the programming experience of C51 external interrupt (INT0).

To decode the infrared remote control signal, you need to use the C51 external interrupt and set it to the negative transition edge trigger mode. Generally, the interrupt is initialized outside the beginning of the main program (or the initialization interrupt program is written as a function and this function is placed in the main program) as follows:

void main(void)
{

  IT0=1; //Negative transition trigger
  EX0=1; //Open external interrupt 0
  EA=1; //Open general interrupt

 .........//Other programs

 ..........
}

void INT0() interrupt 0

{

 .......//Infrared signal decoding program

}

Enable external interrupt as needed (EX0=1):

 The above program opens the external interrupt at the beginning. Theoretically, it is completely correct! But in reality, it depends on the specific situation to open the external interrupt! If you just enter the program to handle other things and cannot process infrared signals temporarily, then EX0=1 cannot be written at the beginning of the main program. It should be written in an appropriate position. Otherwise, when the infrared signal is turned on, it will immediately enter the infrared signal decoding program.

Disable external interrupt (EX0=0):

 Once there is an interrupt signal, the microcontroller will quickly respond to the interrupt and enter the interrupt program. The interrupt program is also the infrared signal decoding program. In the interrupt program, don't forget to turn off the interrupt EX0=0! After pressing a button on the remote control, the remote control will send data out in groups. Even if you press and release the button at the fastest speed, the remote control has sent out multiple groups of data. The microcontroller will decode multiple times. If the main program is relatively large, the decoded data will be overwritten by the next data before it can be used in a hurry! After turning off the external interrupt, it can effectively avoid interference and distinguish whether the current group of data has been received and decoded! When entering the interrupt program, turn off the external interrupt, and turn on the external interrupt after a group of data is decoded and adopted by the main program. This is a complete process! This complete process can be completed normally without interference. In reality, interference is everywhere. Once the data cannot be decoded normally, the main program will not use it, and the external interrupt will no longer be turned on. It will no longer receive infrared signals. At this time, add a judgment at the end of the infrared decoding program. If an error occurs, turn on the external interrupt at the end of the decoding program to prepare for the next infrared signal.

 

Clear IE0 as needed (IE0=0):

 After the interrupt is turned off, the remote control does not stop sending signals. The infrared signal after the interrupt is turned off will continue to set IE0. The state of IE0 is not controlled by EX0 at all. The single-chip microcomputer executes the IT1=1 statement. As long as the external interrupt has a negative transition edge, IE0 will be set. If we only process the signal after EX0=1 (that is, the signal after the interrupt is turned on), then IE0 must be cleared before the infrared signal decoding program exits. If it is not cleared, as long as the external interrupt is turned on, the interrupt will be entered again. This time, entering the interrupt will waste time at best, and may cause errors (which are very obvious when the infrared decoding uses the query method after entering the interrupt). Therefore, a sentence IE0=0 should be added before EX0=1.

Keywords:C51 Reference address:Understanding C51 external interrupt (INT0)

Previous article:C51 Interruption Experience
Next article:The basis of C51 key program writing

Recommended ReadingLatest update time:2024-11-16 14:37

Experience of using the using keyword in Keil C51
I just saw a blog post written by a very talented senior brother, which mentioned the usage of the using keyword in Keil C51. I was careless and had never paid attention to what it was used for (because I usually saw it at the beginning of the definition of the interrupt service function, and it seemed that the interru
[Microcontroller]
Application and feature analysis of Keil c51
Keil c51 is known as the best development environment for 51 series microcontrollers, and everyone must be familiar with it. Everyone knows some of its common features (it is also mentioned in books), such as: because the RAM in 51 is very small, C51 functions do not pass parameters through the stack (except for reent
[Microcontroller]
Summary of four ways of working of C51 MCU serial port
Mode 0: Synchronous shift register input and output mode 1. Use shift registers to achieve serial/parallel conversion (function) 2. Baud rate: fosc/12 3. RXD (P3.0) ---- used for serial data input and output TXD (P3.1) ---- acts as the shift clock for output 4. Data size: 8 bits 5. Mode 0 sending: ○ Serial port inter
[Microcontroller]
Summary of four ways of working of C51 MCU serial port
C51 Tutorial 4th 51 Program: Interrupt Control--External Interrupt 0
External interruption of internal resources       Interrupt type Interrupt entry address Interrupt sequence number          External interrupt 0 (INT0) P3.2 0003H 0       External interrupt 1 (INT1) P3.3 0013H 2       Timer counter 0 (T0) 16bit 000BH 1       Timer counter 1 (T1) 001BH 3       Timer counter 2 (T2) 002B
[Microcontroller]
C51 Tutorial 4th 51 Program: Interrupt Control--External Interrupt 0
C51 keil v4 simple code writing of water lamp
#include reg52.h #include "intrins.h" typedef unsigned char u8;/*char is 1 byte, 8 bits */ typedef unsigned int u16; /*Usually, int is used because the value range of unsigned char is 0~255; while the value of int is 65535; Use u16, u8 to make the code more portable */ #define led P0 //sbit led=P0^0; //Two ways of ex
[Microcontroller]
LCD12864 serial port driver (asm/c51)
Serial data transmission is completed in three bytes:  The first byte: serial port control - format 11111ABC          A is data transmission direction control: H indicates data from LCD to MCU, L indicates data from MCU to LCD          B is data type selection: H indicates data is display data, L indicates data
[Microcontroller]
LCD12864 serial port driver (asm/c51)
Basic knowledge of Keil C51 development system 2
3. Section 3 Storage Mode The storage mode determines the default storage area for variables, function parameters, etc. that do not have a clear storage type specified. There are three types in total: 1. 1. Small mode All default variables and parameters are loaded into the internal RAM. The advantage is fast access
[Microcontroller]
Single chip microcomputer drives 16*16 dot matrix LED Chinese character display C51 program
//========================================= //******* MCU drives 16*16 dot matrix LED Chinese character display c51 program ******* //******* Author: http://www.51hei.com ******* //========================================== //Crystal oscillator 12MHz //P1.0~P1.3 connect to 74154 row scan //P3
[Microcontroller]
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号