51 MCU interrupt and software simulation

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
12

Write the picture description here
From the structure diagram, we can see that the 51 MCU has 5 interrupts, namely external interrupt 0 (INT0), external interrupt 1 (INT1), timer interrupt 0 (T0), timer interrupt 1 (T1) and serial port interrupt (TX/RX). There are two priorities, and the priority order in an interrupt group from high to low is INT0, T0, INT1, T1, TX/RX.

Partial Interrupt Register 12

1. Interrupt Enable Control Register (IE) 
Write the picture description here
EX0: External interrupt 0 enable bit; 
ET0: Timer/Counter T0 interrupt enable bit; 
EX1: External interrupt 1 enable bit; 
ET1: Timer/Counter T1 interrupt enable bit; 
ES: Serial port interrupt enable bit; 
EA: CPU interrupt enable (always enable) bit. 
All of the above are enabled by 1 and disabled by 0. 
2. Timer/controller control register TCON 
Write the picture description here
IT0: External interrupt 0 trigger mode control bit 
When IT0=0, it is level trigger mode (low level is valid) 
When IT0=1, it is edge trigger mode (falling edge is valid) 
IE0: External interrupt 0 interrupt request flag bit (automatically completed by hardware) 
IT1: External interrupt 1 trigger mode control bit (same as IT0) 
IE1: External interrupt 1 interrupt request flag bit (same as IE1) 
TF0: Timer/counter T0 overflow interrupt request flag bit 
TF1: Timer/counter T1 overflow interrupt request flag bit 
3. Interrupt priority control register (IP) 
Write the picture description here
PX0: External interrupt 0 priority setting bit 
PT0: Timer/counter T0 priority setting bit 
PX1: External interrupt 0 priority setting bit 
PT1: Timer/counter T1 priority setting bit 
PS: Serial port priority setting bit All 
of the above are 1 for high priority and 0 for low priority. 
4. Timer/counter working mode register TMOD 
Write the picture description here
GATE-gate control bit. 
GATE=0, the start and stop of the timer/counter are only controlled by TRX (X=0,1) in the TCON register. 
GATE=1, the start and stop of the timer counter are controlled by the level status of TRX (X=0,1) in the TCON register and the external interrupt pin (INT0 or INT1). 
C/T—Timer and counter mode selection bit. 
C/T=1, counter mode; C/T=0, timer mode. 
M1M0—Working mode selection bit. 
Write the picture description here 
Before using the interrupt, turn on the general interrupt, turn on the interrupt enable bit you use, set the interrupt trigger mode for the external interrupt, and configure the corresponding registers for other interrupts. If multiple interrupts are used, configure the interrupt priority.

The format of the interrupt service function: 
The writing method of the interrupt service program 
void function name () interrupt interrupt number [using workgroup] 

interrupt service program content 
}

These are basically the interrupts of 51 single-chip microcomputer. Here is an example. 
Write the picture description here

Use the falling edge to trigger INT0 (P3.2), and then let P1^0 output 0; 12

Main Program

include "intrins.h"include 

sbit LED = P1^0 ;void Int0 (void) interrupt 0{
    LED = 0 ;
}void Init_INT(void)
{
    EA = 1; // Enable general interrupt
    EX0 = 1; //Open external interrupt 0
    IT0 = 1; // Edge trigger}void main()
{
      Init_INT(); //Interrupt initialization

      while(1)
      {  

      }
}123456789101112131415161718192021222324252627

Simulation with signal function

signal void test(void)  
{  
    while(1)  
    {  
        port3 = 0xff ;
        swatch(0.02);

        port3 = 0xfB ;      
        swatch(0.1) ;

        port3 = 0xff ;
        swatch(0.02);

        _break_ = 1 ;

    }  
}1234567891011121314151617

The simulation waveform is as follows, the upper one is the external interrupt signal, and the lower one is the P1^0 output signal.

Write the picture description here


Reference address:51 MCU interrupt and software simulation

Previous article:Method of triggering external interrupt of STC15 MCU only on rising edge
Next article:Using interrupt mode to realize serial port data sending and receiving in 51 single chip microcomputer

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

Design of automatic line patrol wheel robot control system based on 51 single chip microcomputer
1 Introduction Wheeled mobile robot is an important part of the robot research field. It integrates mechanics, electronics, detection technology and intelligent control. Among various mobile mechanisms, wheeled mobile mechanism is the most common. The reason why wheeled mobile mechanism is widely used is ma
[Microcontroller]
Design of automatic line patrol wheel robot control system based on 51 single chip microcomputer
Implementation of LED simulated traffic lights based on 51 microcontroller
Specific function implementation: The north and south red lights are on, and the east and west green lights are on; the north and south green lights are on, and the east and west red lights are on; during the traffic light conversion process, the yellow light flashes 5 times. Devices used: Several resistors, 4 red LED
[Microcontroller]
Electronic tour guide system based on AT89C2051 single chip microcomputer
   introduction   With the improvement of living standards, more and more people regard tourism as a fashionable consumption mode, and some problems have also arisen, such as the lack of tour guides and their low quality, coupled with the emergence of a large number of tourists who like independence and freedom, whi
[Microcontroller]
Electronic tour guide system based on AT89C2051 single chip microcomputer
Programming of 51 MCU Matrix Keyboard
The external keyboard keys on the C51 microcontroller are expanded using a matrix method. However, during hardware simulation, the switch of the device must be turned on to trigger the E terminal of the 74HC53 for row scanning to be grounded as an output type. Otherwise, there will be no response even if the test is de
[Microcontroller]
51 single-chip digital clock source code with detailed comments (with alarm clock perpetual calendar)
I. Design Task: This design consists of four modules: data display module, temperature acquisition module, time processing module and adjustment setting module. The system uses AT89S52 single-chip microcomputer as the controller and serial clock calendar chip DS1302 to record calendar and time. It can count the year,
[Microcontroller]
51 single-chip digital clock source code with detailed comments (with alarm clock perpetual calendar)
C51 microcontroller watchdog program optimization design analysis
With the development of the economy, the continuous extension of science and technology has been promoted, and the microcontroller of the C51 system has also been continuously developed, which greatly meets the needs of practical work, but also inevitably brings some disadvantages. For example, the anti-interference p
[Microcontroller]
8051 single chip dynamic display digital tube
    Ben* said that I saw something that connected an independent keyboard and LED in series, which was a step up from the previous one, so I studied it for a while. This program will be posted later with the keys.     Digital tubes are very magical. - Ben* said that there are two types of digital tubes, common cathod
[Microcontroller]
OLED display implementation based on C8051F023 microcontroller
1 Introduction Organic electroluminescent display, also known as organic light emitting diode (OLED) or organic light emitting display (OLED), has obvious advantages over the popular liquid crystal display (LCD) on the market, mainly manifested in: self-luminescence (no backlight is required), no viewing an
[Microcontroller]
OLED display implementation based on C8051F023 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号