PIC——MCC18 interrupt writing method

Publisher:灵感狂舞Latest update time:2016-08-02 Source: eefocusKeywords:PIC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
MPLAB C18 does not automatically place the interrupt service routine at the interrupt vector. Usually, a GOTO instruction is placed at the interrupt vector to transfer control to the corresponding interrupt service routine.

The low priority interrupt entry address of the PIC18 series is at 0x0018. The following code places a vector function at the entry address. This vector function contains an embedded assembly GOTO instruction, which GOTOs to the low priority interrupt service function InterruptHandlerLow.

//----------------------------Low priority interrupt entry-----------------------------------
1 #pragma code InterruptVectorLow = 0x18 //Use the #pragma pseudo-instruction to define a segment named InterruptVectorLow, and put this segment in the code space starting at address 0x18
2 void InterruptVectorLow (void) //Low priority interrupt vector function
3 {
4 _asm  
5 goto InterruptHandlerLow //Embedded assembly instruction
6 _endasm
7 }
8 #pragma code //This is not redundant, it tells the connector to return to the default code segment. If it is not added, the connector will stupidly put the following code immediately following the above code. The LKR file defines the vector area up to address 0x29, so if this line is not added, an error will usually be reported.

10 #pragma interruptlow InterruptHandlerLow //The interruptlow keyword is used here to declare that the InterruptHandlerLow function is a low-priority interrupt service function. After using the keyword, the compiler will automatically generate basic context protection for this function, and the return of this function will be returned using RETFIE.
11 
12 
13 void InterruptHandlerLow (void)
14 {
15 /* The code of the low-priority service function is written here*/
16 }
 

The high priority interrupt entry address of the PIC18 series is at 0x0008. The following code places a vector function at this entry address. This vector function contains an embedded assembly GOTO instruction, which GOTOs to the high priority interrupt service function InterruptHandlerHigh.

//----------------------------High priority interrupt entry-----------------------------------

1 #pragma code InterruptVectorHigh = 0x08 //Use the #pragma pseudo-instruction to define a segment named InterruptVectorHigh, and put this segment in the code space starting at address 0x08
 2 void InterruptVectorHigh (void) //High priority interrupt vector function
 3 {
 4 _asm
 5 goto InterruptHandlerHigh //Embedded assembly instruction
 6 _endasm
 7 }
 8 #pragma code //Return to the default code segment, the reason is the same as above
 9 #pragma interrupt InterruptHandlerHigh 
10 
11 void InterruptHandlerHigh (void)
12 {
13 /* The code of the high priority service function is written here*/
14 
15 if (INTCONbits.TMR0IF)
16 {//check for TMR0 overflow
17 INTCONbits.TMR0IF = 0; //clear interrupt flag
18 ;
19 ;
20 }
21 } 

 

For MPLAB C18, the high-priority and low-priority interrupt vector functions and interrupt service functions can only appear once each, and there cannot be multiple interrupt service functions. If multiple interrupts are of high priority, the high-priority interrupt service function performs corresponding processing by judging their respective interrupt flag bits.

 

CONbits.IPEN = 1; //Enable interrupt priority
INTCONbits.GIEH = 1; //Enable/disable all high priority interrupts
INTCONbits.GIEL = 1; //Enable/disable all low priority interrupts

//RCONbits.IPEN = 0; //Disable interrupt priority
//INTCONbits.GIE = ​​1; //Enable/disable all interrupt sources
//INTCONbits.PEIE = 1; //Enable/disable all peripheral interrupt sources


When IPEN=1, the interrupt source uses high priority interrupt GIEH = 1; GIEL = 0;
when the interrupt source uses low priority interrupt GIEH = 1; GIEL = 1;

when IPEN=0, all interrupts jump to 08H (use high priority interrupt vector entry)
GIEH = 1; GIEL = 1;


Keywords:PIC Reference address:PIC——MCC18 interrupt writing method

Previous article:Solution to the large array RAM allocation error of PIC microcontroller
Next article:PIC16F877A Watchdog Timer Experiment

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

PIC EEPROM Problems
1. By burning the exported Hex, the EEPROM content will change according to the definition of EEPROM in Hex. 2. Burn by compiling the source file. If Preserve EEPROM on program is not checked, the contents in the EEPROM will be modified. If it is checked, the contents in the EEPROM will seem to be read during the bu
[Microcontroller]
PIC EEPROM Problems
PIC16F873 C program (written by PICC9.8)
#include pic.h unsigned int i,max,X11=0,X12=0,X13=0,X14=0,X15=0,t=2; unsigned long  AD_vasule ,ADOUT,ADOUT_2; unsigned long timer ; //11-15 pin output counter unsigned long delay11=0; //Analog input delay unsigned long  TIMEALL  ;  unsigned long   DELAY; #define TIME 2 //Set the time to 1 second void up_on(void) //I/
[Microcontroller]
A countdown program with preset start time compiled by PIC microcontroller
  The countdown program with preset start time is used to time an event in daily life: as long as the time set by the human is reached, the countdown circuit will sound an alarm. The characteristic of the countdown is that once the time reaches the preset value, its value will return to zero. By using the zeroing cond
[Microcontroller]
A countdown program with preset start time compiled by PIC microcontroller
pic MCU DS18B20 sampling LCD1602 display
#include "1602.h"  #include "18b20.h"  #include "main.h"  __CONFIG(0X0B31);  main()  {      char msg  = {"  Temperature:  ","              .C"};     delay_us2 (40, 40);      delay_us2 (100, 200);      initial();      while(1) {          start_convert();          change_to_ascii (get_temp (), &msg );              displ
[Microcontroller]
PIC microcontroller simulation of multimedia projector remote control
At present, projectors are common equipment in multimedia classrooms of colleges and universities. However, due to frequent use and mixed personnel, projector remote controls are often damaged or lost. Because the projectors used in schools are all imported products, remote controls are difficult to match, and if th
[Microcontroller]
PIC microcontroller simulation of multimedia projector remote control
PIC microcontroller learning method
In order to summarize the learning experience of PIC16F616 microcontroller some time ago and facilitate communication, I wrote this article about the learning experience of PIC microcontroller, which is organized in my own language after reading the manual and programming and debugging. If there are any deficiencies o
[Microcontroller]
PIC: Matrix keyboard scanning (if()else nested method)
/* Matrix keyboard detection + digital tube display + buzzer sound written by myself Use if().....else nested method; compiled, but the last two columns cannot be displayed (did you find it? It is not a problem) */ //---------------------------------------------------------------- #include pic.
[Microcontroller]
PIC microcontroller implements bubble sort algorithm
Write a subroutine paixu to achieve the order of 1-Byte numbers. The 10 binary numbers to be sorted (custom data size) are stored in the memory space. Write macro definitions to implement size comparison and transposition, with the input parameters being the two data addresses to be compared. Note that indirect addres
[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号