51 MCU interrupt setting

Publisher:王大雷Latest update time:2018-07-12 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

External interrupt system block diagram:


The interrupt request flags of these interrupt request sources are latched by the response bits of the special function registers TCON and SCON.

1. TCON register


The lower four bits are related to the interrupt.

1) IT0 and IT1 - external interrupt request trigger flag:

      0——Low level trigger;

     1——Falling edge trigger

    Can be set and cleared by software

2) IE0 and IE1 - external interrupt request flags

     1——Indicates that there is an interrupt request. The CPU will respond to the interrupt request and jump to the interrupt service routine. The interrupt program is processed according to the priority. When jumping into the interrupt service routine, it is cleared to 0 by hardware;

      0——Indicates no interrupt request.

The reset value TCON is always 0.

SCON is the serial port control register, see Serial Port for details.

2. Interrupt enable register IE, bit addressable, reset to 0:


When each bit is 1, the corresponding bit interrupt is enabled, and when it is 0, the corresponding bit interrupt is disabled. EA is the general interrupt switch.

Note: After the microcontroller responds to an external interrupt, it will automatically clear the external interrupt flag to 0. However, due to the characteristics of the external interrupt request triggering method, the problem of repeated requests should be avoided when using external interrupts.

External interrupt 0 programming steps;

1. Set the external interrupt request enable bit and set the EA EX0 bit in the IE register;

2. Select the appropriate external interrupt request mode, that is, set IT0 (or IT1) in TCON;

3. Write the interrupt service function.

Examples:

main()

{

    IT0 = 1; //Set external interrupt 0 to falling edge trigger    
    EX0 = 1; //Open external interrupt 0
    EA = 1; //Open general interrupt
    
  
    while (1) 
        ;
   }
void ext_interrupt(void) interrupt 0 
{
    delay(5);
    if (button0 == 0) {
        led = !led;
    }

}


Reference address:51 MCU interrupt setting

Previous article:51 MCU interrupt and timing counter attempt
Next article:51 MCU code storage problem

Recommended ReadingLatest update time:2024-11-16 13:31

Design of AT89C51 microcontroller telephone remote alarm circuit
1 Introduction Due to the rapid development of the economy, people's living standards have been greatly improved, and the pace of life has become faster and faster. Therefore, home appliance remote control and home security are also needed and valued by people. With the AT89C51 microcontroller as the core, electrical
[Microcontroller]
Design of AT89C51 microcontroller telephone remote alarm circuit
Dot matrix + music = happy birthday program based on 51 single chip microcomputer
//----------------------------------------------------- // 12*12 dot matrix + music generation // MCU:89C51 Crystal: 12M  #include REG51.H #define uchar unsigned char #define uint unsigned int uint a=0,a1=0,a2=0; uint miusfla,miust,mius=64536; uint disfla1,sta=0; char flag=0,mdflag=0; sbit k1=P3^2; sbit k2=P3^3; sbi
[Microcontroller]
STM8L151C8 MCU learning routine (5)——TIMER1 timing 0.5s
STM8L_5_TIMER: 1.User: Project and main files 2.Hardware:TIMER,CLK,LED,Delay 3.STM8L15x_StdPeriph_Driver: STM8 comes with library files 4.Debug: The hex file is stored in the EXE folder 5.Function: TIMER1 is set to 0.5s and TIMER4 is set to about 0.5s, etc. /** *******************************************************
[Microcontroller]
STM8L151C8 MCU learning routine (5)——TIMER1 timing 0.5s
[51 MCU Quick Start Guide] 5.1: SPI and DS1302 clock chip
Puzhong 51-Single-core-A2 STC89C52 Keil uVision V5.29.0.0 PK51 Prof.Developers Kit Version:9.60.0.0 Hard Knowledge        Excerpted from "Popular 51 Microcontroller Development Strategy" and "DS1302 Chinese Manual". DS1302 Overview        DS1302 is a trickle charging clock chip launched by DALLAS. It contains a re
[Microcontroller]
[51 MCU Quick Start Guide] 5.1: SPI and DS1302 clock chip
51 MCU——I2C bus EEPROM
We can save the data in EEPROM so that the data will not be lost when the power is off. Commonly used serial bus protocols: Currently, the commonly used serial buses for data transmission between microcomputers and peripherals are mainly I2C bus, SPI bus and SCI bus. I2C bus: Communicates in a synchronous serial 2
[Microcontroller]
51 MCU——I2C bus EEPROM
MCU C8051FC40/FM20L08 expansion circuit diagram
Schematic diagram of single-chip microcomputer controlling FRAM. In this system, the address signal multiplexing mode is adopted, so that the ALE signal can be generated. FM20LO8 has its own latch, and the chip select signal CE cannot be directly grounded like SRAM, and a pre-charge time is required. This signal is gen
[Microcontroller]
MCU C8051FC40/FM20L08 expansion circuit diagram
51 MCU I/O port read and write operations
MCS-51 microcontrollers usually have four 8-bit I/O ports. The data written to each port is written into the latch of the corresponding port, but there are two ways to read each port: read the latch and read the pin. 1 Read-Modify-Write Operation     Pn (referring to P0, P1, P2, P3) is a special identifier in 51 assem
[Microcontroller]
51 MCU I/O port read and write operations
51 MCU C language-4.5 basic statements conditional selection statement
1. Conditional selection statement if  Statements We have talked about data types, operators and expressions before. C is also a language, and since it is a language, it must have connectives. These connectives can be used to express assumptions, loops, and so on. Let's first look at the if statement. These connecti
[Microcontroller]
51 MCU C language-4.5 basic statements conditional selection statement
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号