中级会员
- 积分
- 411
- 威望
- 285
- 贡献
- 72
- 兑换币
- 0
- 注册时间
- 2010-10-2
- 在线时间
- 27 小时
|
我是个初学者,最近在实验的过程中想到同时使用PIT模块的0,1定时通道,实现两盏LED灯实现2比1频率的闪动。
程序代码如下:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define unsigned int uint
#define BUS_CLOCK 24000000
uint i=0;
uint j=0;
byte shuma[20]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, //0~9对应的段码
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
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
}
void PitInit(void){
PITCFLMT_PITE = 1; //使能PIT模块
PITCE = 0X00; //通道0,1 PIT模块禁止
PITINTE = 0x03; //通道0,1中断使能
PITMUX = 0x00; //16位定时通道0使用0号8位微计数器,16位定时器1使用1号微计数器
PITLD0 = 240-1;
PITMTLD0 = 100-1;
PITLD1 = 120-1;
PITCE = 0X03; //通道0,1 PIT模块使能
}
void InitPortb(void){
DDRB = 0XFF;
PORTB = 0XFF;
}
void main(void) {
INIT_PLL(); //设置锁相环
PitInit();
InitPortb();
EnableInterrupts;
for(;;) {
} /* loop forever */
/* please make sure that you never leave main */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt 66 void PIT0(void){
PITTF_PTF0 = 1;
i++;
if(i==1000){
i = 0;
PORTB_PB0 = ~PORTB_PB0;
}
}
interrupt 67 void PIT1(void){
PITTF_PTF1 = 1;
j++;
if(j==1000){
j = 0;
PORTB_PB1 = ~PORTB_PB1;
}
}
但是我实际运行发现,两盏灯居然同频率闪,我之前已经设置了PITLD0,PITLD1一个是240-1,一个是120-1,两个通道同时使用0微计数器,数值为100-1,中断向量也对了,感觉也没什么问题,大惑不解。我感觉两个中断都进入了,那么我就试着改了一下PITLD,把他们都改成同一个数值240-1,结果一运行,晕死我了,这回只有一盏灯在闪(亮一秒灭一秒),PIT通道2中断感觉是进不去了,非常疑惑。
请高手赐教到底什么原因。 |
|