У меня возникают проблемы с прерываниями на 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);
}
Пожалуйста отступа код правильно. Это невозможно прочитать, поэтому я не могу его прочитать. Если вы отступаете клавишей табуляции, вы должны настроить редактор кода для ввода пробелов при нажатии вкладки. – Lundin
Извините за отступ, я просто изменяю код, чтобы сделать его простым с целью прерывания. –
'INTCON3 = 0b00011000; '' как 'INT1IE', так и' INT2IE' установлены, что означает, что наружное прерывание INT2' включено. Но соответствующий флаг не обрабатывается, это функция прерывания. Может ли 'INTCON3 = 0b00001000;' решить проблему? – francis