【发布时间】:2015-04-15 07:51:09
【问题描述】:
我在使用 MPLAB 8.89 和 c18 编译器时遇到了 pic18f4550 的中断问题。
关键是,如果引脚更改为状态,则不会进入中断。我可以看到状态变化,但它只是没有改变。但是,如果将中断写成一个,它就会进入程序。
这是我的代码,你知道吗?
////// Autonomated Velocity Transmssion for a Bicycle of 9 gears/////
#include <p18f4550.h>
//////////////////////////////////////////// Variables /////////////////////////////////////////////////
unsigned int sensors=0; // Counter of the sensor in the star
unsigned int sensorw=0; // Counter of the sensor in the wheel
unsigned int rpms=0; // Rpms of the star
unsigned int rpmw=0; // Rpms of the wheel
unsigned int velw;
//////////////////////////////////////////// Interruption functions //////////////////////////////////////////////////
void Llanta (void); //Wheel
void Estrella (void); //Star
/////////////////////////////////////// High Priority Interruptions /////////////////////////////////////////////////
#pragma code high_vector=0x08
void high_interrupt (void)
{
_asm nop _endasm
}
//////////////////////////////////////////// Low Priority Interruptions //////////////////////////////////////////////////
#pragma code low_vector=0x18
void low_interrupt (void)
{
if(INTCON3bits.INT1IF==1){ //interruption for INT1 on rising edge
_asm goto Llanta _endasm //Wheel
}
if(INTCONbits.RBIF==1) { //Interruption for change on RB port change
_asm goto Estrella _endasm //Star
}
}
#pragma code
#pragma interruptlow Llanta
void Llanta (void) //Counts when the hall sensor of the wheel is activated
{
INTCON3bits.INT1IF=0; //Turn off flag
sensorw++; //add
}
#pragma interruptlow Estrella //Counts when the hall sensor of the star is activated
void Estrella (void)
{
INTCONbits.RBIF=0; //Turn off flag
if(PORTBbits.RB4 == 1){
sensors++; //Add
}
}
////////////////////////////////////////////// Main program /////////////////////////////////////////////////////////////////////
void main (void)
{
unsigned int temp16;
OSCCON=0b01100000; //Oscillator 4 MHz
//Pins Configuration
TRISBbits.RB1=1; //input sensor wheel
TRISBbits.RB4=1; //input sensor star
TRISB=0xFF; //All as inputs
T1CON=0b01000001; // Oscillator 4 MHz, timer 1
///////////////////////// Priorities ////////////////////////////////
RCONbits.IPEN=1; //Enable priority levels
INTCON=0b11001000; //Enable high, low interrupts and RB port change interrupt
INTCON2=0b01110000; //Pull up disabled, interrupt on rising edge, and low priority on rb change
INTCON3=0b00011000; //low priority interruption, and enables external interruptions.
ADCON1=0x0F; //digital input
do{
INTCON3bits.INT1IF=1; // This was made to make a test. i put this as one, the interruption works and it goes where it should go.
}
while(1);
}
【问题讨论】:
-
请正确缩进您的代码。这是不可读的,所以我懒得读它。如果您使用 tab 键缩进,您应该将代码编辑器设置为在按 tab 时注入空格。
-
抱歉缩进,我只是为了中断而更改代码以使其简单。
-
INTCON3=0b00011000;INT1IE和INT2IE均已设置,这意味着INT2外部中断已启用。但是对应的标志位没有处理的是中断函数。INTCON3=0b00001000;能解决问题吗?
标签: c embedded microcontroller pic