-2
我在使用MPLAB 8.89和c18編譯器時遇到pic18f4550中斷問題。中斷問題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時將代碼編輯器設置爲注入空格。 – Lundin
對不起,縮進,我只是改變代碼,使其簡單的中斷目的。 –
'INTCON3 = 0b00011000; 'INT1IE'和'INT2IE'都被置位,這意味着'INT2'外部中斷被使能。但是相應的標誌不處理是中斷函數。可以'INTCON3 = 0b00001000;'解決問題? – francis