2015-04-15 3 views
-2

У меня возникают проблемы с прерываниями на pic18f4550, с 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); 
} 
+0

Пожалуйста отступа код правильно. Это невозможно прочитать, поэтому я не могу его прочитать. Если вы отступаете клавишей табуляции, вы должны настроить редактор кода для ввода пробелов при нажатии вкладки. – Lundin

+0

Извините за отступ, я просто изменяю код, чтобы сделать его простым с целью прерывания. –

+0

'INTCON3 = 0b00011000; '' как 'INT1IE', так и' INT2IE' установлены, что означает, что наружное прерывание INT2' включено. Но соответствующий флаг не обрабатывается, это функция прерывания. Может ли 'INTCON3 = 0b00001000;' решить проблему? – francis

ответ

1

Проверьте некоторые из следующих мыслей

  1. проверить конфигурационные биты, более конкретно ваш CONFIG3H: CONFIGURATION REGISTER 3 и PBADEN бита

    PBADEN: PORTB A/D Enable bit 
    
    1 = PORTB<4:0> pins are configured as analog input channels on Reset 
    0 = PORTB<4:0> pins are configured as digital I/O on Reset 
        If set to analog it won't register your pin status changes. 
    
  2. Убедитесь, что другие выводы PORTB не плавающими, заземлить их или включить в выходы. Руководство государства

    RBIF: RB Port Change Interrupt Flag bit(1) 
    1 = At least one of the RB7:RB4 pins changed state (must be cleared in software) 
    0 = None of the RB7:RB4 pins have changed state 
    
    Note 1: A mismatch condition will continue to set this bit. 
    Reading PORTB, and then waiting one additional instruction cycle, 
    will end the mismatch condition and allow the bit to be cleared. 
    
  3. Я хотел бы также очистить бит прерывания флаг в качестве последней команды перед выходом из прерывания не как первый

  4. Руководство также утверждает, что

    «Функция прерывания по изменению уровня рекомендуется для пробуждения при работе и действиях нажатия клавиши , где PORTB используется только для функции прерывания при переключении. Опрос PORTB не рекомендуется при использовании прерывания -он-изменение ".

Вы опроса/чтения порта внутри прерывания

Смежные вопросы