masashi11
Newbie level 5
I am having troubles with the interruptions on the pic18f4550, with the MPLAB 8.89 and c18 compiler.
The point is, the interruption doesnt get in if the pin change is status. I can see the status change, but it just doesnt change. But, if write the interruption as one it goes and enter the routine.
Here is my code, any idea?
View attachment Bicibici.txt
The point is, the interruption doesnt get in if the pin change is status. I can see the status change, but it just doesnt change. But, if write the interruption as one it goes and enter the routine.
Here is my code, any idea?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 ////// 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); }
View attachment Bicibici.txt
Last edited by a moderator: