飞思卡尔MC9S12XS128单片机中断优先级设置简易教程.docx

上传人:scccc 文档编号:13093708 上传时间:2021-12-14 格式:DOCX 页数:4 大小:38.88KB
返回 下载 相关 举报
飞思卡尔MC9S12XS128单片机中断优先级设置简易教程.docx_第1页
第1页 / 共4页
飞思卡尔MC9S12XS128单片机中断优先级设置简易教程.docx_第2页
第2页 / 共4页
飞思卡尔MC9S12XS128单片机中断优先级设置简易教程.docx_第3页
第3页 / 共4页
飞思卡尔MC9S12XS128单片机中断优先级设置简易教程.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《飞思卡尔MC9S12XS128单片机中断优先级设置简易教程.docx》由会员分享,可在线阅读,更多相关《飞思卡尔MC9S12XS128单片机中断优先级设置简易教程.docx(4页珍藏版)》请在三一文库上搜索。

1、本教程试图用最少的时间教你飞思卡尔XS128单片机的中断优先级设置方法和中断嵌套的使用,如果是新手请先学习中断的基本使用方法。先来看看XS128 Datasheet中介绍的相关知识,只翻译有用的:Each of the I bit maskable interrupt requests can be assigned to one of seven priority levels supporting a flexible priority sc tie me. For interrupt requests that are contigured ro be handled by the CP

2、U, the priority sclietne can be used to implement nested interrupt capability where interrupts from a lower level are iiutomatitally blocked if a higher level interrupt is being processed. Interrupt requests configured to be handled by the XGA1E moduk tan be nested one level deepJ七个中断优先级 Lach I bit

3、masknbk imciTupt request has a configurable priority level and can be configured to be handled by either the CPU er the XGATE module2.每一个中断源都有一个可以设置的级别I bit maskable interrupts can be nested, depending on their priority levels.高优先级中断的可以嵌套低优先级中断system reset all interrupt requests with a vector addres

4、s lower than or equal ro (vector base + OxOOF2) are enabled, are set up to be handled by tlie CPU and have a pre-configured priority level of I. Exceptions to this rule arc the non-maskable interrupt requests and the spurious imeirupt ectur request at (vector bast + 0x0010) which cannot be disabled,

5、 are always handled by the CPU and have a fixed priority levels. A priority level of 0 effectively disables the associated 1 bit maskable interrupt requetit.复位后可屏蔽中断默认优先级为1If more tiian one interrupt request is configured to the same interrupt priority level the interrupt request witi the higher vec

6、tor address wins the priontization.同一优先级的中断同时触发时,高地址(中断号较小)的中断先响应注意:高地址中断只能优先响应,但不能嵌套同一优先级低地址的中断下面直接进入正题,看看怎么设置中断优先级:XS128中包括预留的中断一共有128个中断位,如果为每个中断都分配一个优先级寄存器的话会非常浪费资源,因此飞思卡尔公司想出了这样一种办法:把128个中断分为16个组,每组8个中断。每次设置中断时,先把需要的组别告诉某个寄存器,再设置 8个中 断优先寄存器的某一个,这样只需 9个寄存器即可完成中断的设置。分组的规则是这样的:中断地址位7到位4相同的中断为一组,比如

7、MC9SX128.h中VReserved23 VatdO Vsc i 1 Vsc i 0 Vsp i o Vt i mpa i e Vt impaaovf Vt i movf#def i ne#def i ne#def i ne#def i ne#def i ne#def i ne#def i ne#def i neOxOOOOFf'D 0x0000FFD4 OxOOOOFFD OxOOOOFRDOxOOOOFfftlfc2DCOxOOOOFFpA OxOOOOFFOxOOOOFFpf这些中断的位 7到位3都为D,他们就被分成了一组。0F正好16个组。INT CFADDR就是上面说到的

8、用来设置组别的寄存器4.3.2.3Interrupt Request Configuration Address Register (INT_CFADDR)我们需要设置某个组别的中断时,只要写入最后8位地址就行了,比如设置SCI0的中断优先级,就写入 0xD0。0x0000FFD6#def i ne Vsc i 0设置好组别之后,我们就要该组中相应的中断进行设置,设置中断的寄存器为4.3.2.4Interrupt Request Configuration Data Registers (INT_CFDATA0-7)这其实是一组寄存器,一共有8个,每个都代表中断组中的一个中断。对应规则是这样的

9、:中断地址的低四位除以 2比如还是SCI0,低四位是6,除以二就是3,那么我们就需要设置 INT_CFDATA3往INT CFDATAx 中写入07就能设置相应的中断优先级了拿我本次比赛的程序来举个例子:我们的程序中需要 3个中断:PIT0,PORTH,SCI0 。 PIT0定时检测传感器数值, PORTH连接干簧管进行起跑线检测,SCI0接收上位机指令实现急停等功能。因此中断优先级要 SCI0>PORTH>PIT0 。我们先要从头文件中找出相应中断的地址:#define VpitO0x0000FF7A#define VporthOxOOOOFFCC#define VsciO0x0

10、000FFD6PIT0【7:4】位为7,选择中断组:INT_CFADDR=0x70;【3:0】为A, A/2=5,设置为第5优先级那么INT_CFDATA5=5;porth【7:4】位为C,选择中断组:INT_CFADDR=0xC0;【3:0】为C, C/2=6,设置为第6优先级那么INT_CFDATA6=6;Sci0【7:4】位为D,选择中断组:INT_CFADDR=0xD0;【3:0】为6, 6/2=3,设置为第7优先级那么INT_CFDATA3=7;最终程序为:void Interr upt_Priority_Set(void)INT_CFADDR=0x70;INT_CFDATA5=0x

11、05;INT_CFADDR=0xC0;INT_CFDATA6=0x06;INT_CFADDR=0xD0;INT_CFDATA3=0x07;还要注意一点,如果要实现中断嵌套,需要在低级中断中再开一次总中断,比如/PH口中断,干簧管检测用void iinterrupt 25 PortH_INTSvr (void) (En北I e Interrupts /开启 象高一钏中断一.一IB f J'1 且1/PI TO定时器中断vo i d i nter r upt 66 PI T0_ I NITSvr (vo i d) stat i c byte P lfTO_l ncome_Cnt=0; /iEnab lei门terrupts;/i这样才能实现中断的嵌套QufuNormalUniversitySonicTeam2011

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1