Subversion Repositories Code-Repo

Rev

Rev 316 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
312 Kevin 1
#include "defines.h"
2
#include "IOC.h"
315 Kevin 3
#include "STEPPER.h"
312 Kevin 4
 
5
void IOC_Init(void) {
6
    INTCONbits.IOCIE = 1;
7
 
8
    // Enable interrupt on both edges on RA3 and RA4
9
    IOCAPbits.IOCAP3 = 1;
10
    IOCANbits.IOCAN3 = 1;
11
    IOCAPbits.IOCAP4 = 1;
12
    IOCANbits.IOCAN4 = 1;
13
}
14
 
15
void IOC_Interrupt_Handler(void) {
316 Kevin 16
    STEP_LAT = 1;
17
    STEP_LAT = 0;
18
 
312 Kevin 19
    if (IOCAFbits.IOCAF3) {
20
 
316 Kevin 21
        // Delay to debounce button on any edge
22
        __delay_ms(1);
23
 
314 Kevin 24
        if (SW_1_PORT) {
312 Kevin 25
            switch (Get_Cur_Mode()) {
26
                case SINGLE_STEP:
315 Kevin 27
                    STEPPER_Step();
312 Kevin 28
                    break;
29
                case AUTO_STEP:
315 Kevin 30
                    STEPPER_Toggle_Auto();
312 Kevin 31
                    break;
32
                case SET_MICROSTEP:
315 Kevin 33
                    STEPPER_Set_Next_Step();
312 Kevin 34
                    break;
35
            }
36
        }
37
 
314 Kevin 38
        // Delay to debounce button on any edge
316 Kevin 39
        __delay_ms(1);
315 Kevin 40
 
312 Kevin 41
        IOCAFbits.IOCAF3 = 0;
316 Kevin 42
        return;
312 Kevin 43
    }
44
 
45
    if (IOCAFbits.IOCAF4) {
46
 
316 Kevin 47
        // Delay to debounce button on any edge
48
        __delay_ms(1);
49
 
314 Kevin 50
        if (SW_2_PORT) {
312 Kevin 51
            Set_Next_Mode();
52
        }
53
 
314 Kevin 54
        // Delay to debounce button on any edge
316 Kevin 55
        __delay_ms(1);
312 Kevin 56
 
57
        IOCAFbits.IOCAF4 = 0;
316 Kevin 58
        return;
312 Kevin 59
    }
60
}