📄 interrupt.c
字号:
#define __INTERRUPT_H__
#include "Config.h"
/********************************************************************************************************
**函数名称:INTInit
**函数功能:中断初始化:初始化外部中断0,Timer2溢出中断
**输 入:无
**输 出:无
********************************************************************************************************/
void INTInit(void)
{
//-----------------------------------------
//使用下降沿中断:翻转位和感应位分别为0:1
//-----------------------------------------
IPININV1 &= ~BIT0; //翻转位为0
IPINSENS1 |= BIT0; //感应位为1
//-----------------------------------------
//执行返回指令时自动清标志
//-----------------------------------------
INTSRC1 |= BIT0; //使用管脚中断
INTEN1 |= BIT0; //使能外部中断0(INT0)
//-----------------------------------------
//Timer2定时中断
//-----------------------------------------
INTEN2 |= BIT0; //使能Timer2中断
INTSRC2 &= ~BIT0; //选择Timer2为中断源
GENINTEN |= (BIT1 | BIT0); //全局使能
}
//****************************************************************************************************
//外部中断0,由按键产生
//****************************************************************************************************
void INT0ISR(void) interrupt 0
{
UART0_Printf("\n Key:INT0_GEN was pressed \n");
}
//****************************************************************************************************
//SPI发送空
//****************************************************************************************************
void SPITxEmpISR(void) interrupt 1
{
}
//****************************************************************************************************
//SPI接收有效/溢出
//****************************************************************************************************
void SPIRXAVOVISR(void) interrupt 2
{
}
//****************************************************************************************************
//定时器0中断
//****************************************************************************************************
void Timer0ISR(void) interrupt 3
{
}
//****************************************************************************************************
//按键监视中断0,由按键产生
//****************************************************************************************************
/*
void PORTCHG0ISR(void) interrupt 4
{
PORTCHG &= ~BIT3; //清除标志位
}
*/
//****************************************************************************************************
//UART0中断
//****************************************************************************************************
void UART0ISR(void) interrupt 5
{
}
//****************************************************************************************************
//UART1中断
//****************************************************************************************************
void UART1ISR(void) interrupt 6
{
}
//****************************************************************************************************
//Timer1中断
//****************************************************************************************************
void Timer1ISR(void) interrupt 7
{
}
//****************************************************************************************************
//Timer2中断
//****************************************************************************************************
//uchar LEDFlashType; //纪录LED当前闪烁方式的全局变量
uchar LEDSub; //当前闪烁方式下,正在输出的位
uchar LEDINTCnt;
uchar Key;
uchar LEDBuf[4][4] = {{~BIT7,~BIT6,~BIT5,~BIT4}, //闪亮方式1
{~BIT4,~BIT5,~BIT6,~BIT7}, //闪亮方式2
{~(BIT7 | BIT6),~(BIT5 | BIT4),~(BIT7 | BIT6),~(BIT5 | BIT4)}, //闪亮方式3
{~(BIT7 | BIT5),~(BIT6 | BIT4),~(BIT7 | BIT5),~(BIT6 | BIT4)}, //闪亮方式4
}; //每个循环LED的亮灭状态
void Timer2ISR(void) interrupt 8
{
T2CON &= ~BIT7; //清除溢出标志
TH2 = 0x3C;
TL2 = 0xB0; //重装
//---------------------------------------------------------------------------
//控制LED的闪烁
//---------------------------------------------------------------------------
if(LEDINTCnt ++ >= 10) //0.5秒左右闪一次
{
LEDINTCnt = 0; //计数器清零
P6 &= 0x0F; //屏蔽无关位
P6 |= LEDBuf[LEDFlashType][LEDSub]; //设置LED的亮灭状态
if(++ LEDSub >= 4)
{
LEDSub = 0; //闪烁状态循环一次,注意LEDSta为由按键改变的变量
}
UART1_Printf("\n This is UART1! \n");
}
//---------------------------------------------------------------------------
//控制按键的读取,读键的频率要高于LED转换的频率
//关于按键的使用 还可以用中断,不过要保证检测按键时不能变化LED的端口
//---------------------------------------------------------------------------
Key = KeyRead(); //读取健值
if(Key != 0)
{
FlashSet(Key); //根据键值改变LED闪烁方式
UART0_Printf("\n Key%c is Pressed!\n",Key);
}
}
//****************************************************************************************************
//I2C中断
//****************************************************************************************************
void I2CISR(void) interrupt 9
{
}
//****************************************************************************************************
//UART冲突中断
//****************************************************************************************************
void UARTCollisionISR(void) interrupt 10
{
}
//****************************************************************************************************
//PWM中断
//****************************************************************************************************
void PWMISR(void) interrupt 11
{
}
//****************************************************************************************************
//PWM3:0Timer
//****************************************************************************************************
void PWM30ISR(void) interrupt 12
{
}
//****************************************************************************************************
//PWM3:0Timer
//****************************************************************************************************
void PWM74ISR(void) interrupt 13
{
}
//****************************************************************************************************
//WDT/ARTITH
//****************************************************************************************************
void WDTARIISR(void) interrupt 14
{
}
//****************************************************************************************************
//按键监视中断1,由按键产生,但是端口由于与LED混用,现在已经不能用了
//****************************************************************************************************
/*
void PORTCHG1ISR(void) interrupt 15
{
SwitchDelay(1);
PORTCHG &= ~BIT7; //清除标志位
UART0_Printf("\n Key Pressed \n");
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -