您好,我正在尝试在PIC18F26K83上使用Timer1中断。我使用Micro C作为编译器。因此,我将计时器设置为30毫秒,然后在30毫秒后输入中断并点亮LED。但是它永远不会点亮LED(永远不会进入中断/永远不会发生中断。)。代码是:
#define led LATA.RA2
void Clk_8Mhz(){
//8 MHz clock
// OSCCON1 REGISTER
NOSC2_BIT=1;
NOSC1_BIT=1;
NOSC0_BIT=0;//HF INTERNAL OSC
//OSCFRQ REGISTER HFINTOSC FREQ. SELECTION
OSCCON1 =0b01100000; //HFINTOSC, Divider =1;
FRQ3_BIT=0;
FRQ2_BIT=0;
FRQ1_BIT=1;
FRQ0_BIT=1; // 0011 :8MHz //0100 = 16 Mhz
}
//Timer1
//Prescaler 1:1; TMR1 Preload = 5536; Actual Interrupt Time : 30 ms
void InitTimer1(){
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0x15;
TMR1L = 0xA0;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void main (){
TRISA.B2=0;
led=0;
clk_8Mhz();
InitTimer1();
while(1){
delay_ms(10);
} }
void Interrupt(){
if (TMR1IF_bit){
TMR1IF_bit = 0;
TMR1H = 0x15;
TMR1L = 0xA0;
led=1;
}
}
此永不发生中断的原因可能是什么?预先感谢。
答案 0 :(得分:0)
尝试将MVECEN配置位设置为OFF(CONFIG2L的一部分),因为您的void Interrupt()
代码要求这样做,另请参见Official statement regarding the K42 and K83 family issues (Mikro C)
Support for Interrupt Vector table for K42/K83 families was not implemented, only the legacy interrupt approach was supported.