MCU interrupt application program

Publisher:Blissful567Latest update time:2015-07-28 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/*MCU interrupt response*/
//==Declaration area= ...
#include
#define uint unsigned int
#define uchar unsigned char
void delay(uint a);
bit c,b;
//==Main program area= ...
void main()
{
 EA=1; //Open the general interrupt
 EX0=1; //Open external interrupt 0
 IT0=0; //Set interrupt 0 to level trigger
 IT1=0; //Set interrupt 0 to level trigger

 EX1=1; //Open external interrupt 1
 while(1)
 {
  P1=0xfe; //Turn off the LED in INT0
  P0=0xff; //Turn off the digital tube in INT1
  P0=0x00;
  P2=0xf8;
   P1=0xfe;
  while(1);
 }
}
//=Subroutine area==============================================================================================================================
void delay(uint a)
{
 uint b,c;
 for(b=a;b>0;b--)
  for(c=110;c>0;c--);
}
void Int0() interrupt 0 // The service subroutine of external interrupt 0 does not need to be declared in the declaration area
{
 uint a;
 a=10;
  while(a--) //You cannot use while(1) here. If not, when the external interrupt has become a high level, it is impossible to jump out of the interrupt service subroutine.
 {
  P0=0x00;
  P2=0xf8;
   P1=0xff;
  delay(1000);
  P1=0x00;
  delay(1000);
 }
}
void Int1() interrupt 2 //The service subroutine of external interrupt 1 does not need to be declared in the declaration area.
{
 delay(1);
 c=P3^3;
 if(c==0)
 {
  delay(1);
  if(c==0)
  {
   uint a;
   a=10;
   while((a--)) //You cannot use while(1) here. If not, when the external interrupt has become a high level, it is impossible to jump out of the interrupt service subroutine.
   {
   
    P1=0xff;
    P2=0xf8;
    P0=0x3f;
    delay(1000);
    P2=0xf9;
    P0=0x00;
    delay(1000);
    P2=0xf8;
    P0=0x06;
    delay(1000);
    P2=0xf8;
    P0=0x5b;
    delay(1000);
    P2=0xf8;
    P0=0x4f;
    delay(1000);
    P2=0xf8;
    P0=0x66;
    delay(1000);
    P2=0xf8;
    P0=0x6d;
    delay(1000);
    
   }
  }
 }


}
/*The program function is to light up the first LED. If the P3^2 port is at a low level, it will enter the interrupt program. The interrupt function is to flash all eight LEDs. If the P3^3 port is at a low level, it will enter external interrupt 1.
The program implementation of external interrupt 1 is that the first digital tube displays 0, 1, 2, 3, 4, 5. But I haven't figured out why there is a time interval between 0 and 1 and everyone's delay
They are the same, but the display is different.
The program implements that after the interrupt ends, the 8 LEDs of INT0 are still lit, and the last digital tube of INT1 is still lit, because the LED and digital tube are not turned off in the main program.
Note that my development board's P0 port is connected to a digital tube (common cathode), P2 port is 74HC138, and P1 port is LED*/
Keywords:MCU Reference address:MCU interrupt application program

Previous article:Design and implementation of a low-noise portable ECG monitor
Next article:Timing conflicts among serial port, I2C bus, EEPROM and LCD driver

Recommended ReadingLatest update time:2024-11-16 21:51

Teach you to learn 51 single chip microcomputer step by step: variable advanced and dot matrix LED
1. Variable scope Scope: The effective range of a variable. It is divided into: local variables and global variables. 1.1 Local variables Variables declared inside a function can only be used inside this function. 1.2 Global variables Variables declared outside a function are global variables. 2. Storage Class o
[Microcontroller]
SAA1064 chip microcontroller driver
  main() { unsigned char a ;a =0x77;// a = N_leab_led_7 ; a = N_leab_led_7 ; a = N_leab_led_7 ; a = N_leab_led_7 ; WriteNByte(0x70,0x00,a,5); ////0X70 - 0 1 1 1 0 A1 A0 R/W A1 A0(11:ADR=VCC 10:5/ 8VCC 01:3/8VCC 00:VEE) R/W (1:READ 0:WRITE)//0x00 - 0 0 0 0 0 sc sb sa sc sb sa(000:control register 001:dig
[Microcontroller]
SAA1064 chip microcontroller driver
MSP430 Series Micropower MCU Selection Guide [Chinese Version]
The MSP430 series of microcontrollers are a type of 16-bit ultra-low power mixed signal processor (Mixed Signal Processor) that Texas Instruments (TI) began to market in 1996. It is called a mixed signal processor mainly because it integrates many analog circuits, digital circuits and microprocessors on one chip to
[Analog Electronics]
Application of TOPSwitch-FX series single chip switching power supply
1. 12V, 30W switching power supply with external current limiting The circuit of a 12V, 30W high-efficiency switching power supply composed of TOP234Y is shown in Figure 1. Its AC input voltage range is AC85~265V, and the power efficiency can reach 80% when fully loaded. The AC voltage u passes through the
[Microcontroller]
Application of TOPSwitch-FX series single chip switching power supply
PIC microcontroller generates pseudo-random number program
PSW    EQU   03   R0     EQU   08   R1     EQU   09   R2     EQU   0AH   R3     EQU   0BH   R4     EQU   0CH   R5     EQU   0DH   R6     EQU   0EH   R7     EQU   0FH   TEMP   EQU   13H   CNT1   EQU   11H   CNTH   EQU   12H   BUF0   EQU   17H   BUF1   EQU   18H   ESUM1  EQU   13H   ESUM2  EQU   14H   ESUM3  EQU   15H  
[Microcontroller]
Design of Liquid Level Monitor Based on Multiple Single Chip Microcomputers
It is a common practice to design a liquid level monitor using a single-chip microcomputer. If there are many channels (more than 16 channels) for the liquid level to be measured, each channel is required to be able to scroll and display the total input and output of each shift, day, and month within one year (3 shi
[Microcontroller]
Design of Liquid Level Monitor Based on Multiple Single Chip Microcomputers
Driver Design of Graphic LCD Module Based on SPCE061A Single Chip Microcomputer
The Y240128A liquid crystal module with built-in T6963C controller is powered by dual power supplies (VDD/V0). When working, a negative voltage (i.e., liquid crystal drive voltage V0/VEE) is required to adjust the contrast, which is connected to the V0 pin of the liquid crystal module. Based on the physical properti
[Home Electronics]
Driver Design of Graphic LCD Module Based on SPCE061A Single Chip Microcomputer
The breadboard experiment of the microcontroller is another solution in circuit design
Breadboard, in simple terms, is a test board for plugging circuits. The front of the breadboard is full of holes, but all the holes on this board are not independent, but connected together according to certain rules. Take the breadboard in our experiment as an example (you can see its real picture below), divided by
[Power Management]
The breadboard experiment of the microcontroller is another solution in circuit design
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号