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); }
Code C - [expand] 1 2 3 4 5 6 #pragma config PBADEN = OFF, PLLDIV = 1, CPUDIV = OSC1_PLL2, USBDIV = 2, FOSC = XT_XT, FCMEN = ON #pragma config IESO = OFF, PWRT = ON, BOR = ON, BORV = 2, VREGEN = OFF, WDT = OFF, WDTPS = 2048 #pragma config CCP2MX = ON, LPT1OSC = OFF, MCLRE = OFF, STVREN = OFF, LVP = OFF, ICPRT = OFF #pragma config XINST = ON, CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF, CPB = OFF, CPD = OFF #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF, WRTC = OFF, WRTB = OFF, WRTD = OFF #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF, EBTRB = OFF
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 ////// Autonomated Velocity Transmssion for a Bicycle of 9 gears///// #include <p18f4550.h> //////////////////////////////////////////// Pragmacode ///////////////////////////////////////////////// #pragma config PBADEN = OFF, PLLDIV = 1, CPUDIV = OSC1_PLL2, USBDIV = 2, FOSC = XT_XT, FCMEN = ON #pragma config IESO = OFF, PWRT = ON, BOR = ON, BORV = 2, VREGEN = OFF, WDT = OFF, WDTPS = 2048 #pragma config CCP2MX = ON, LPT1OSC = OFF, MCLRE = OFF, STVREN = OFF, LVP = OFF, ICPRT = OFF #pragma config XINST = OFF, CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF, CPB = OFF, CPD = OFF #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF, WRTC = OFF, WRTB = OFF, WRTD = OFF #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF, EBTRB = OFF //////////////////////////////////////////// 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 Llanta1 (void); //Wheel void Llanta2 (void); //Wheel void Llanta3 (void); //Wheel void Estrella (void); //Star /////////////////////////////////////// High Priority Interruptions ///////////////////////////////////////////////// #pragma code high_vector=0x08 void high_interrupt (void) { INTCONbits.RBIF = 0; _asm nop _endasm } //////////////////////////////////////////// Low Priority Interruptions ////////////////////////////////////////////////// #pragma code low_vector=0x18 void low_interrupt (void) { if(INTCONbits.INT0IF){ //interruption for INT1 on rising edge INTCONbits.INT0IF = 0; //Turn off flag LATDbits.LATD0 = ~LATDbits.LATD0; _asm goto Llanta1 _endasm //Wheel } if(INTCON3bits.INT1IF){ //interruption for INT1 on rising edge _asm goto Llanta2 _endasm //Wheel } if(INTCON3bits.INT2IF){ //interruption for INT1 on rising edge _asm goto Llanta3 _endasm //Wheel } if(INTCONbits.RBIF) { //Interruption for change on RB port change _asm goto Estrella _endasm //Star } } #pragma code #pragma interruptlow Llanta3 void Llanta1 (void) //Counts when the hall sensor of the wheel is activated { } #pragma interruptlow Llanta3 void Llanta2 (void) //Counts when the hall sensor of the wheel is activated { INTCON3bits.INT1IF = 0; //Turn off flag LATDbits.LATD1 = ~LATDbits.LATD1; } #pragma interruptlow Llanta3 void Llanta3 (void) //Counts when the hall sensor of the wheel is activated { INTCON3bits.INT2IF = 0; //Turn off flag LATDbits.LATD2 = ~LATDbits.LATD2; } #pragma interruptlow Estrella //Counts when the hall sensor of the star is activated void Estrella (void) { if(PORTBbits.RB4){ LATDbits.LATD3 = ~LATDbits.LATD3; //Add } INTCONbits.RBIF = 0; //Turn off flag } ////////////////////////////////////////////// Main program ///////////////////////////////////////////////////////////////////// void main (void) { ADCON1 = 0x0F; //Pins Configuration TRISB = 0xFF; //All as inputs TRISD = 0x00; T1CON = 0b01000001; // Oscillator 4 MHz, timer 1 ///////////////////////// Priorities //////////////////////////////// INTCON = 0b11111000; //Enable high, low interrupt, INT0 and TMR0overflow and RB port change interrupt INTCON2 = 0b01110000; //Pull up enabled, interrupt on rising edge, and low priority on rb change and tmr0 interrupt INTCON3 = 0b00011000; //low priority interruption, and enables INT1 & INT2 interruptions. //digital input INTCONbits.INT0IF = 0; // Initialize flag of interrupt INTCON3bits.INT1IF = 0; // Initialize flag of interrupt INTCON3bits.INT2IF = 0; // Initialize flag of interrupt LATD = 0x00; do{ } while(1); }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?