Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: testing.c
- * Author: Bennett and Bec
- *
- * Created on 15 October 2019, 14:59
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "ConfigRegsPIC18f4520.h"
- #include <timers.h>
- //#include <math.h>
- //#include <string.h>
- #include <p18f4520.h>
- //void encoderISR(void);
- void lowPriorityISR (void);
- void low_interrupt(void);
- void configureISR(void);
- //Define the low priority interrupt at 0x0018
- //start the service routine for low priority interrupt
- //#pragma interruptlow lowPriorityISR
- //void lowPriorityISR (void){
- // encoderISR();
- //}
- #pragma code lowPriorityInterruptAddress=0x0018
- void low_interrupt(void){
- //All that needs to happen in the interrupt is to goto the service routine
- _asm
- GOTO lowPriorityISR
- _endasm
- }
- //#pragma code //default code section
- //#define M_PI 3.14159265358979323846264338327950288
- // Function declarations
- void configurePORTB(void);
- volatile unsigned int trigger = 0;
- volatile unsigned int trigger2 = 0;
- volatile unsigned int x = 0;
- //unsigned char x;
- #pragma code
- void main(void) {
- configurePORTB();
- configureISR();
- while(1) {
- //x = PORTBbits.RB5;
- //x = LATBbits.LATB4;
- }
- }
- void configurePORTB(void)
- {
- TRISBbits.RB4 = 0;
- TRISBbits.RB6 = 0;
- TRISBbits.RB7 = 0;
- // PORTBbits.RB4 = 0;
- // PORTBbits.RB6 = 0;
- // PORTBbits.RB7 = 0;
- TRISBbits.RB5 = 1; // set RB4 to input
- INTCON2bits.RBPU = 0; // clear pull up to enable
- ADCON1 = 0xFF; // Check why***
- }
- void configureISR(void)
- {
- RCONbits.IPEN = 1; // enable priority interrupts
- INTCONbits.RBIE = 1; // enables interrupt on PORTB change
- INTCON2bits.RBIP = 0; // low priority interrupt
- //INTCON2bits.INTEDG0 = 1; // interrupt on rising edge (RB0)
- //INTCON2bits.INTEDG1 = 1;
- T1CON = 0b10000001; // enable timer 1, prescaler of 1, 16 bit resolution
- //PIE1bits.TMR1IE = 1; // enable timer 1 overflow interrupt
- //INTCONbits.PEIE = 1;
- //INTCONbits.GIE = 1;
- //PIE1bits.TMR1IE = 1; // enable timer 1 overflow interrupt
- INTCONbits.GIEH = 1; //Enable high priority interrupts
- INTCONbits.GIEL = 1; //Enable low priority interrupts
- }
- #pragma interruptlow lowPriorityISR
- void lowPriorityISR(void)
- {
- // if(PIR1bits.TMR1IF == 1)
- // {
- // trigger2 = 1;
- // //encoder_overflow_counter++; // increment counter
- // //if(encoder_overflow_counter)
- // PIR1bits.TMR1IF = 0; // clear overflow bit flag
- // }
- //trigger2 = 1;
- if(INTCONbits.RBIF == 1)
- {
- trigger = 1;
- // // find time difference
- // encoder_left_t2 = ReadTimer1();
- // encoder_time_diff = encoder_overflow_counter*(2^16) + encoder_left_t2 - encoder_left_t1;
- // encoder_left_t1 = encoder_left_t2;
- // encoder_overflow_counter = 0;
- x = PORTBbits.RB5; // Need to read PORTB before clearing the mismatch
- INTCONbits.RBIF = 0; // Clear interrupt flag
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement