|
在kinetis.c中修改了这个,,
中断服务函数:
void Pit0ISR(void)
{
unsigned int c;
//turn off timer
PIT_TCTRL_REG(PIT0,0)&=~(PIT_TCTRL_TIE_MASK|PIT_TCTRL_TEN_MASK);
//PIT_TFLG0 = PIT_TFLG_TIF_MASK;
PIT_TFLG_REG(PIT0,0) |= PIT_TFLG_TIF_MASK;
GPIOD_PTOR |= GPIO_PTOR_PTTO(GPIO_PIN(0)|GPIO_PIN(1));
c = PIT_CVAL0;
//turn on timer
PIT_TCTRL_REG(PIT0,0)|=(PIT_TCTRL_TIE_MASK|PIT_TCTRL_TEN_MASK);
}
下面是其它相应的设置:
#include "derivative.h" /* include peripheral declarations */
#define GPIO_PIN_MASK 0x1Fu
#define GPIO_PIN(x) (((1)<<(x & GPIO_PIN_MASK)))
extern PIT_MemMapPtr PIT0;//declaration
extern NVIC_MemMapPtr basePit0;//declaration
void delay(long int n)
{
while(n--);
}
void EnableIRQ(int irq)
{
int div=0;
PIT_TCTRL_REG(PIT0,0)|=PIT_TCTRL_TIE_MASK|PIT_TCTRL_TEN_MASK;
//if(irq>91) irq=91;
div = irq/32;//68/32=2
//is NVICISER2, NVICICER2, NVICISPR2, NVICICPR2, NVICIABR2 connected to PIT0
switch (div)
{
case 0x0:
NVICICPR0 = 1 << (irq%32);
NVICISER0 = 1 << (irq%32);
break;
case 0x1:
NVICICPR1 = 1 << (irq%32);
NVICISER1 = 1 << (irq%32);
break;
case 0x2:
NVICICPR2 = 1 << (irq%32);
NVICISER2 = 1 << (irq%32);
break;
}
}
void PitIntInitial(void)
{
SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;//enable the clock of PIT module
//PIT_TFLG_REG(PIT0,0) |= PIT_TFLG_TIF_MASK; //clear flag
PIT_MCR = 0x00;
//PIT_MCR_REG(PIT0) &= ~PIT_MCR_MDIS_MASK;//enable PIT module
PIT_LDVAL0 = 14400000;
//PIT_LDVAL_REG(PIT0,0) = 14400000;//setup timer 0 for 256000 cycles
PIT_TCTRL_REG(PIT0,0) |= PIT_TCTRL_TEN_MASK;
PIT_TCTRL_REG(PIT0,0) &= ~PIT_TCTRL_TIE_MASK;
}
int main(void)
{
//unsigned long counter;
//char reg;
//reg = 0;
//counter = 0;
//printf("Toggle LED2£¡\n\r");
//coreClk_mhz = pll_init();
//coreClk_khz = coreClk_mhz * 1000;
//periphClk_khz = coreClk_khz / (((SIM_CLKDIV1 & SIM_CLKDIV1_OUTDIV2_MASK) >> 24)+ 1);
//=========================== Code for test GPIO==================================================
/* Turn on led port clocks */
SIM_SCGC5 = SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK;
//turn on PIT module clock
/* Set pin0,pin1 of PORTD as GPIO */
PORTD_PCR0=(0|PORT_PCR_MUX(1));
PORTD_PCR1=(0|PORT_PCR_MUX(1));
PORTD_PCR4=(0|PORT_PCR_MUX(1));
PORTD_PCR5=(0|PORT_PCR_MUX(1));
/* set pin0,pin1 to be output*/
GPIOD_PDDR=GPIO_PDDR_PDD(GPIO_PIN(0)|GPIO_PIN(1)|GPIO_PIN(4)|GPIO_PIN(5));
GPIOD_PDOR &= ~(GPIO_PDOR_PDO(GPIO_PIN(0)|GPIO_PIN(1)|GPIO_PIN(4)|GPIO_PIN(5)));
//
PitIntInitial();
EnableIRQ(68);
//EnableInterrupts;
while(1){GPIOD_PTOR |= GPIO_PTOR_PTTO(GPIO_PIN(4)|GPIO_PIN(5));delay(256000);};
}
但是为什么就是进不了中断服务函数:
而是进入默认的:
void isr_default(void)
{
/* Write your interrupt code here ... */
// GPIOD_PTOR |= GPIO_PTOR_PTTO(GPIO_PIN(0)|GPIO_PIN(1));
// delay(8000000);
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|