About S12 interrupt routine

Publisher:温馨生活Latest update time:2021-08-18 Source: eefocusKeywords:S12 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are two main ways to program interrupts for the MC9SDG128B:
      The first is to use the symbol "TRAP_PROC". TRAP_PROC tells the compiler that the following function is an interrupt service routine. The compiler will end this function with a special interrupt return instruction (for most processors, this is usually the RTI instruction).


     The second is to use the "interrupt" keyword. The "interrupt" keyword is a non-standard ANSI-C keyword, so it is not supported by all ANSI-C compiler vendors. Similarly, the usage of the "interrupt" keyword may change for different compilers. The "interrupt" keyword also prompts the compiler that the following function is an interrupt service routine.


     Once the interrupt service function is written, you must associate the interrupt service routine with the interrupt vector table. This is done by initializing the interrupt vector table. You can initialize the interrupt vector table in two ways:
     The first is in the PRM file, using the "VECTOR ADDRESS" or "VECTOR" command. The connector provides two commands to initialize the interrupt vector table: VECTOR ADDRESS or VECTOR. You use the VECTOR ADDRESS command to write the address of the interrupt service routine into the interrupt vector table.


    The second is to use the "interrupt" keyword. When you write an interrupt service routine, you can directly associate the interrupt service routine with a specific interrupt number in the ANSI-C source file.


    The following is the 16-bit free timer overflow interrupt handler for MC9SDG128B that I wrote, which has been debugged:
#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

int intcount = 0;

void timer_init(void)

{

TSCR2_PR0 = 1; //prescale factor is 128

TSCR2_PR1 = 1;

TSCR2_PR2 = 1;


TSCR2_TOI = 1; //overflow enable


TFLG2_TOF = 1;


TSCR1_TEN = 1; //timer enable
}


#pragma CODE_SEG NON_BANKED
interrupt 16 void timer_interrupt_handle(void)
{

intcount++;


TFLG2_TOF = 1; //clear interrupt flag
};
#pragma CODE_SEG DEFAULT


void main(void)
{

EnableInterrupts;

timer_init();

for(;;) {}
}

The following is an interrupt service routine written using the TRAP_PROC symbol:
#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
int intcount = 0;
void timer_init(void)
{

TSCR2_PR0 = 1; //prescale factor is 128

TSCR2_PR1 = 1;

TSCR2_PR2 = 1;


TSCR2_TOI = 1; //overflow enable


TFLG2_TOF = 1;


TSCR1_TEN = 1; //timer enable
}


#pragma CODE_SEG NON_BANKED
#pragma TRAP_PROC
void timer_interrupt_handle(void)
{

intcount++;


TFLG2_TOF = 1;
};
#pragma CODE_SEG DEFAULT


void main(void)
{

EnableInterrupts;

timer_init();

for(;;) {}
}


After the interrupt service program is written, you need to add the following sentence in the .prm file:
VECTOR 16 timer_interrupt_handle
so that the interrupt service program is associated with the corresponding interrupt number. This program has also been debugged.

The interrupt service routine must be located in the non-banked area. You can use "#pragma CODE_SEG NON_BANKED" to locate the interrupt routine in the non-banked area. At the same time, you must ensure that "sectionNON_BANKED" does not appear in the .prm file. At the end of the interrupt service routine, you need to add "#pragma CODE_SEG DEFAULT", otherwise, the following functions will also be located in the "non-banked" area.


So our interrupt service routine must be surrounded by "#pragma CODE_SEG NON_BANKED" and "#pragma CODE_SEG DEFAULT".

Keywords:S12 Reference address:About S12 interrupt routine

Previous article:MC9S12XS128 8-bit PWM servo control
Next article:Detailed explanation of s19 file format

Recommended ReadingLatest update time:2024-11-16 10:28

Method for measuring PA S12 S22 and power using vector network
The large signal measurement of DUT is crucial, especially S22 (related to the matching with the antenna) and saturation power (Psat, directly related to the transmission power). When testing high-power PA, since the output power of PA generally ranges from a few W to hundreds of W, if such a large signal is directly
[Test Measurement]
Method for measuring PA S12 S22 and power using vector network
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号