Subversion Repositories Code-Repo

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
163 Kevin 1
#include <xc.h>
2
#include "defines.h"
3
#include "base_INTERRUPTS.h"
4
//#include "base_UART.h"
5
#include "base_CPS.h"
6
#include "base_PWM.h"
7
 
8
// <editor-fold defaultstate="collapsed" desc="Configuration Registers">
9
/* Config Register CONFIGL @ 0x8007 */
10
#pragma config CPD = OFF    // Data memory code protection is disabled
11
#pragma config BOREN = OFF   // Brown-out Reset disabled
12
#pragma config IESO = OFF   // Internal/External Switchover mode is disabled
13
#pragma config FOSC = INTOSC    // INTOSC oscillator: I/O function on CLKIN pin
14
#pragma config FCMEN = OFF  // Fail-Safe Clock Monitor is disabled
15
#pragma config MCLRE = ON   // MCLR/VPP pin function is MCLR
16
#pragma config WDTE = OFF   // WDT disabled
17
#pragma config CP = OFF     // Program memory code protection is disabled
18
#pragma config PWRTE = OFF  // PWRT disabled
19
#pragma config CLKOUTEN = OFF   // CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
20
 
21
/* Config Register CONFIG2 @ 0x8008 */
22
#pragma config PLLEN = OFF  // 4x PLL disabled
23
#pragma config WRT = OFF    // Write protection off
24
#pragma config STVREN = OFF // Stack Overflow or Underflow will not cause a Reset
25
#pragma config BORV = HI    // Brown-out Reset Voltage (Vbor), high trip point selected.
26
#pragma config LVP = OFF    // High-voltage on MCLR/VPP must be used for programming
27
// </editor-fold>
28
 
29
int main() {
30
 
31
    // Oscillator configuration (16Mhz HFINTOSC)
32
    OSCCONbits.SCS = 0b00;
33
    OSCCONbits.IRCF = 0b1111;
34
 
35
    ANSELA = 0x00;  // All pins set to digital I/O
36
    APFCONbits.CCP1SEL = 1; // Switch CCP1 from RA2 to RA5
37
    APFCONbits.TXCKSEL = 1; // Switch TX/CK from RA0 to RA4
38
    APFCONbits.RXDTSEL = 1; // Switch RX/DT from RA1 to RA5
39
 
40
    /* Set pins as analog */
41
    /* 0x01 = ANSA0 (RA0)
42
     * 0x02 = ANSA1 (RA1)
43
     * 0x04 = ANSA2 (RA2)
44
     * 0x10 = ANSA4 (RA4) */
45
    ANSELA = 0x03;
46
 
47
    Interrupt_Enable();
48
 
49
//    UART_DATA uart_data;
50
//    UART_Init(&uart_data);
51
 
52
    CPS_DATA cps_data;
53
    CPS_Init(&cps_data);
54
 
55
    PWM_Init();
56
 
57
//    char msg[] = "Begin Program\n";
58
//    UART_Write(msg, 14);
59
 
60
    LED_TRIS = 0;
61
 
62
    while(1) {
63
//        __delay_ms(10);
64
 
65
//        unsigned int value = cps_data.btn_last_value[cps_data.channel];
66
//        unsigned int avg = cps_data.btn_avg_value[cps_data.channel];
67
//        unsigned char output[9];
68
//        output[0] = cps_data.channel;
69
//        output[1] = 0;
70
//        output[2] = value >> 8;
71
//        output[3] = value;
72
//        output[4] = 0;
73
//        output[5] = avg >> 8;
74
//        output[6] = avg;
75
//        output[7] = 0;
76
//        output[8] = cps_data.btn_pct_value[cps_data.channel];
77
//        UART_WriteD(output, 9);
78
 
79
        if (cps_data.btn_pressed[0] || cps_data.btn_pressed[1]) {
80
            LED_LAT = 1;
81
            PWM_Set_Width(1350);
82
        } else {
83
            LED_LAT = 0;
84
            PWM_Set_Width(800);
85
        }
86
    }
87
}