PIT中断问题
时间:10-02
整理:3721RD
点击:
/*---------------------------------------------------------*/
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define LEDCPU PTP_PTP0
#define LEDCPU_dir DDRP_DDRP0
#define START_MCU PORTB_PB4
#define START_MCU_dir DDRB_DDRB4
#define D_MCU PORTB_PB3
#define D_MCU_dir DDRB_DDRB3
#define R_MCU PORTB_PB1
#define R_MCU_dir DDRB_DDRB1
#define AIRHIGH_MCU PORTD_PD0
#define AIRHIGH_MCU_dir DDRD_DDRD0
#define CHARGE_MCU PORTD_PD2
#define CHARGE_MCU_dir DDRD_DDRD2
#define BP_MCU PORTD_PD3
#define BP_MCU_dir DDRD_DDRD3
#define BUS_CLOCK 32000000 //总线频率
#define OSC_CLOCK 16000000 //晶振频率
unsigned int i,j;
/*************************************************************/
/* 初始化锁相环 */
/*************************************************************/
void INIT_PLL(void)
{
CLKSEL &= 0x7f; //set OSCCLK as sysclk
PLLCTL &= 0x8F; //Disable PLL circuit
CRGINT &= 0xDF;
#if(BUS_CLOCK == 40000000)
SYNR = 0x44;
#elif(BUS_CLOCK == 32000000)
SYNR = 0x43;
#elif(BUS_CLOCK == 24000000)
SYNR = 0x42;
#endif
REFDV = 0x81; //PLLCLK=2×OSCCLK×(SYNR+1)/(REFDV+1)=64MHz ,fbus=32M
PLLCTL =PLLCTL|0x70; //Enable PLL circuit
asm NOP;
asm NOP;
while(!(CRGFLG&0x08)); //PLLCLK is Locked already
CLKSEL |= 0x80; //set PLLCLK as sysclk
}
/*************************************************************/
/* PIT模块初始化函数 */
/*************************************************************/
void init_PIT(){
PITMTLD0=249; //为0通道8位计数器赋值
PITLD0=63999; //为0通道16位计数器赋值 //(249+1)*(63999+1)=16000000个总线周期=0.5秒
PITMUX_PMUX0=0; //第0通道使用微计数器0
PITCE_PCE0=1; //第0通道计数器工作
PITCFLMT=0X80; //使能周期中断定时器
PITINTE_PINTE0=1; //0通道定时器定时中断被使能
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED //中断函数
void interrupt PIT_INTER(void)
{
if (PITTF==0x01&&BP_MCU==1) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=2)
LEDCPU=1;
}
if (PITTF==0x01&&START_MCU==1) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=4)
LEDCPU=1;
}
if (PITTF==0x01&&D_MCU==0) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=6)
LEDCPU=1;
}
if (PITTF==0x01&&R_MCU==1) {
PITTF=0x01;
LEDCPU=~LEDCPU;
j++;
if(j>=8)
LEDCPU=1;
}
if (PITTF==0x01&&AIRHIGH_MCU==0) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=10)
LEDCPU=1;
}
if (PITTF==0x01&&CHARGE_MCU==0) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=12)
LEDCPU=1;
}
}
#pragma CODE_SEG DEFAULT
/*************************************************************/
/* 主函数 */
/*************************************************************/
void main(void) {
INIT_PLL();
LEDCPU_dir=1;
LEDCPU=1;
START_MCU_dir=0;
D_MCU_dir=0;
R_MCU_dir=0;
AIRHIGH_MCU_dir=0;
CHARGE_MCU_dir=0;
BP_MCU_dir=0;
init_PIT();
EnableInterrupts;
for(;;) { ;
}
}
这是我的全部程序,比较简单,但是现在我觉得在中断部分的程序有一个条件触发了之后,第二个中断进来,还是触发那一个中断,如何改一下,能让他们并行触发呢?
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define LEDCPU PTP_PTP0
#define LEDCPU_dir DDRP_DDRP0
#define START_MCU PORTB_PB4
#define START_MCU_dir DDRB_DDRB4
#define D_MCU PORTB_PB3
#define D_MCU_dir DDRB_DDRB3
#define R_MCU PORTB_PB1
#define R_MCU_dir DDRB_DDRB1
#define AIRHIGH_MCU PORTD_PD0
#define AIRHIGH_MCU_dir DDRD_DDRD0
#define CHARGE_MCU PORTD_PD2
#define CHARGE_MCU_dir DDRD_DDRD2
#define BP_MCU PORTD_PD3
#define BP_MCU_dir DDRD_DDRD3
#define BUS_CLOCK 32000000 //总线频率
#define OSC_CLOCK 16000000 //晶振频率
unsigned int i,j;
/*************************************************************/
/* 初始化锁相环 */
/*************************************************************/
void INIT_PLL(void)
{
CLKSEL &= 0x7f; //set OSCCLK as sysclk
PLLCTL &= 0x8F; //Disable PLL circuit
CRGINT &= 0xDF;
#if(BUS_CLOCK == 40000000)
SYNR = 0x44;
#elif(BUS_CLOCK == 32000000)
SYNR = 0x43;
#elif(BUS_CLOCK == 24000000)
SYNR = 0x42;
#endif
REFDV = 0x81; //PLLCLK=2×OSCCLK×(SYNR+1)/(REFDV+1)=64MHz ,fbus=32M
PLLCTL =PLLCTL|0x70; //Enable PLL circuit
asm NOP;
asm NOP;
while(!(CRGFLG&0x08)); //PLLCLK is Locked already
CLKSEL |= 0x80; //set PLLCLK as sysclk
}
/*************************************************************/
/* PIT模块初始化函数 */
/*************************************************************/
void init_PIT(){
PITMTLD0=249; //为0通道8位计数器赋值
PITLD0=63999; //为0通道16位计数器赋值 //(249+1)*(63999+1)=16000000个总线周期=0.5秒
PITMUX_PMUX0=0; //第0通道使用微计数器0
PITCE_PCE0=1; //第0通道计数器工作
PITCFLMT=0X80; //使能周期中断定时器
PITINTE_PINTE0=1; //0通道定时器定时中断被使能
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED //中断函数
void interrupt PIT_INTER(void)
{
if (PITTF==0x01&&BP_MCU==1) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=2)
LEDCPU=1;
}
if (PITTF==0x01&&START_MCU==1) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=4)
LEDCPU=1;
}
if (PITTF==0x01&&D_MCU==0) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=6)
LEDCPU=1;
}
if (PITTF==0x01&&R_MCU==1) {
PITTF=0x01;
LEDCPU=~LEDCPU;
j++;
if(j>=8)
LEDCPU=1;
}
if (PITTF==0x01&&AIRHIGH_MCU==0) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=10)
LEDCPU=1;
}
if (PITTF==0x01&&CHARGE_MCU==0) {
PITTF=0x01;
LEDCPU=~LEDCPU;
i++;
if(i>=12)
LEDCPU=1;
}
}
#pragma CODE_SEG DEFAULT
/*************************************************************/
/* 主函数 */
/*************************************************************/
void main(void) {
INIT_PLL();
LEDCPU_dir=1;
LEDCPU=1;
START_MCU_dir=0;
D_MCU_dir=0;
R_MCU_dir=0;
AIRHIGH_MCU_dir=0;
CHARGE_MCU_dir=0;
BP_MCU_dir=0;
init_PIT();
EnableInterrupts;
for(;;) { ;
}
}
这是我的全部程序,比较简单,但是现在我觉得在中断部分的程序有一个条件触发了之后,第二个中断进来,还是触发那一个中断,如何改一下,能让他们并行触发呢?