📄 isr.c
字号:
/* metrowerks sample code */
/*
this source illustrates code called by ISR
and #pragma directives necessary for ISR-safe code
*/
#include <stdio.h>
#include "DSP56F807.h"
#include "led.h"
#include "isr.h"
static void delay ();
int led_position = 0;
int led_group = 0;
void initIsr ()
{ /////111111111111111111
asm (bfset #$0100,sr);
asm (bfclr #$0200,sr); /* allow lowest priority */
asm (bfset #$fe12,X:IPR); /* enable both IRQ A & B, and all other interrupts */
/// 1111 1110 0001 0010
asm (bfset #$0100,X:GPR10); /* Timer A Ch 0 lowest priority */
//0000 0001 0000 0000 中断优先级寄存器组 #define GPR10 ITCN_BASE + 0xa
/* stop timer 0*/
asm (move #$0000,X:TMRA0_CTRL); //定时器A, 通道0控制寄存器
///000(计数器模式控制位) 0 000(计数器源控制位,计数器输入引脚#0) 0 0
// 000 0000
/* timer 0 compare 1/2, load, counter */
asm (move #$ffff,X:TMRA0_CMP1); //定时器A, 通道0比较寄存器1
asm (move #$0000,X:TMRA0_CMP2);///比较寄存器2
asm (move #$ffff,X:TMRA0_LOAD);//定时器A, 通道0 预置寄存器
asm (move #$ffff,X:TMRA0_CNTR);//定时器A, 通道0 计数寄存器
/* enable timer0 compare interrupt */
asm (move #$4000,X:TMRA0_SCR); //定时器A, 通道0 状态和控制寄存器
// 0100 0000 0000 0000 比较中断允许
/* timer0 primary source on bus / 128 */
asm (move #$3e30,X:TMRA0_CTRL);//定时器A, 通道0 控制寄存器
//001(计数器模式控制位:在主时钟的上升沿计数)
//1*111(主计数源控制位:预分频(IP总线时钟128分频))
//0*0(第二计数源控制位:计数器输入引脚#0)
//0(单次计数控制位ONCE,:连续计数) 1(LENGTH) 1(DIR) *0(Co Init) 000(OutPut Mode)
}
/* Interrupt-safe function:
A function call that conserves all register content
(excluding PC,SP) across a call. Please note that
Standard C libary is not interrupt-safe */
/* ISR that call non interrupt-safe functions need
#pragma interrupt saveall to:
1. call a runtime routine that save all register (except SP,PC)
2. return with RTI */
#pragma interrupt saveall
//已经看懂//已经看懂//已经看懂//已经看懂//已经看懂//已经看懂
void isrIRQA ()
{ //////22222222222222222
/* debounce key with delay for simplicity, disadvantage:
1. high latency
2. no repoll of switch state after deounce delay */
/////////////+++++++++++++++++++++++++++++++++
delay ();
/////////////////////++++++++++++++++++++++++++++++++
puts ("IRQA detected"); /* Standard C library call */
///led_group 若初始为0 则值为 1,灯1灭; 否则值为 3 ,灯3 灭
offLED (led_group == 0 ? 1 : 3); /* switch off LED from last group */
//offLED() 函数 声明和定义分别在 led.h 和 led.c 中
led_group = 0;
///**isrIRQA ()函数 与 void isrIRQB ()函数 的唯一区别******
}
/* ISR that call non interrupt-safe functions need
#pragma interrupt saveall to:
1. call a runtime routine that save all register (except SP,PC)
2. return with RTI */
#pragma interrupt saveall
//已经看懂//已经看懂//已经看懂//已经看懂//已经看懂//已经看懂
void isrIRQB ()
{ ////////33333333333333333333
/* debounce key with delay for simplicity, disadvantage:
1. high latency
2. no repoll of switch state after deounce delay */
/////////////+++++++++++++++++++++++++++++++++
delay ();
/////////////////////++++++++++++++++++++++++++++++++
puts ("IRQB detected"); /* Standard C library call */
///led_group 若初始为0 则值为 1,灯1灭; 否则值为 3 ,灯3 灭
offLED (led_group == 0 ? 1 : 3); /* switch off LED from last group */
//offLED() 函数 声明和定义分别在 led.h 和 led.c 中
led_group = 1;
//////**isrIRQA ()函数 与 void isrIRQB ()函数 的唯一区别******
}
/* ISR that does not call interrupt-unsafe functions can use #pragma interrupt to:
1. save all used register
2. return with RTI
*/
#pragma interrupt
void isrTimerA0Compare ()
{ ////4444444444444444
/* next LED */
/// led_group == 0 ? 1 : 3;若led_group=0成立,则此表达式的值为 1,从而改变第
//1 个灯的明亮状态
//若不成立,则此表达式的值为 3,从而改变第3 个灯的明亮状
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -