| 119 |
Kevin |
1 |
#include "maindefs.h"
|
|
|
2 |
#include "interrupts.h"
|
|
|
3 |
#include "uart.h"
|
|
|
4 |
//#include "i2c.h"
|
|
|
5 |
//#include "adc.h"
|
|
|
6 |
//#include "timers.h"
|
|
|
7 |
//#include "xbee.h"
|
|
|
8 |
//#include "led_driver.h"
|
|
|
9 |
//#include "pwm.h"
|
|
|
10 |
//#include "delays.h"
|
|
|
11 |
//#include "pin_interrupts.h"
|
|
|
12 |
#include <usart.h>
|
|
|
13 |
#include <delays.h>
|
|
|
14 |
|
|
|
15 |
#pragma config WDTEN = OFF // Turn off watchdog timer
|
|
|
16 |
#pragma config XINST = OFF // Turn off extended instruction set
|
|
|
17 |
#pragma config OSC = HSPLL // Use external oscillator (101)
|
|
|
18 |
#pragma config PLLDIV = 3 // Set PPL prescaler to 3 (to get 4MHz)
|
|
|
19 |
#pragma config CFGPLLEN = ON // Enable PLL on startup
|
|
|
20 |
#pragma config PLLSEL = PLL96 // Use 96MHz PLL 4MHz -> 96MHz / 2 = 48MHz
|
|
|
21 |
//#pragma config SOSCSEL = HIGH // High Power T1OSC/SOSC circuit selected
|
|
|
22 |
//#pragma config ADCSEL = BIT12 // 12-bit ADrC
|
|
|
23 |
//#pragma config IOL1WAY = OFF // IOLOCK bit can be set and cleared as needed
|
|
|
24 |
|
|
|
25 |
/* ----------- IO Pins -----------
|
|
|
26 |
* RA0 -
|
|
|
27 |
* RA1 -
|
|
|
28 |
* RA2 -
|
|
|
29 |
* RA3 -
|
|
|
30 |
* RA4 - [CANNOT BE USED (VDDCORE/VCAP)]
|
|
|
31 |
* RA5 -
|
|
|
32 |
* RA6 - Oscillator
|
|
|
33 |
* RA7 - Oscillator
|
|
|
34 |
*
|
|
|
35 |
* RC0 -
|
|
|
36 |
* RC1 -
|
|
|
37 |
* RC2 -
|
|
|
38 |
* RC3 -
|
|
|
39 |
* RC4 -
|
|
|
40 |
* RC5 -
|
|
|
41 |
* RC6 - UART Debug Output
|
|
|
42 |
* RC7 - UART Debug Input
|
|
|
43 |
*
|
|
|
44 |
* RB0 -
|
|
|
45 |
* RB1 -
|
|
|
46 |
* RB2 -
|
|
|
47 |
* RB3 -
|
|
|
48 |
* RB4 -
|
|
|
49 |
* RB5 -
|
|
|
50 |
* RB6 -
|
|
|
51 |
* RB7 -
|
|
|
52 |
* ---------------------------- */
|
|
|
53 |
|
|
|
54 |
//static I2C_DATA i2c_data;
|
|
|
55 |
//static XBEE_DATA xbee_data;
|
|
|
56 |
|
|
|
57 |
void main(void) {
|
|
|
58 |
unsigned char i = 0;
|
|
|
59 |
unsigned char length = 0;
|
|
|
60 |
unsigned char buffer[100];
|
|
|
61 |
|
|
|
62 |
/* --------------------- Oscillator Configuration --------------------- */
|
|
|
63 |
// OSCTUNEbits.PLLEN = 1; // Enable 4x PLL
|
|
|
64 |
OSCCONbits.IRCF = 0b111; // Set INTOSC postscaler to 8MHz
|
|
|
65 |
OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
|
|
|
66 |
/* -------------------------------------------------------------------- */
|
|
|
67 |
|
|
|
68 |
// Set all ports as digial I/O
|
|
|
69 |
ANCON0 = 0xFF;
|
|
|
70 |
ANCON1 = 0x1F;
|
|
|
71 |
|
|
|
72 |
UART1_Init(); // Initialize the UART handler code
|
|
|
73 |
// xbee_init(&xbee_data); // Initialize the XBee handler code
|
|
|
74 |
// i2c_init(&i2c_data); // Initialize the I2C handler code
|
|
|
75 |
// adc_init(); // Initialize the ADC
|
|
|
76 |
// timers_init(); // Initialize timers
|
|
|
77 |
// port_b_int_init(); // Initialze Port B interrupt handler
|
|
|
78 |
// pwm_init(); // Initialize the PWM output driver
|
|
|
79 |
|
|
|
80 |
interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
|
|
|
81 |
interrupt_init(); // Initialize the interrupt priorities
|
|
|
82 |
|
|
|
83 |
DBG_PRINT_MAIN("\r\nBegin Program\r\n");
|
|
|
84 |
|
|
|
85 |
// Loop and process recieved messages from interrupts;
|
|
|
86 |
|
|
|
87 |
while (1) {
|
|
|
88 |
length = UART1_Read((char *)buffer);
|
|
|
89 |
if (length != 0) {
|
|
|
90 |
UART1_WriteB((char *)buffer, length) ;
|
|
|
91 |
}
|
|
|
92 |
Delay10KTCYx(255);
|
|
|
93 |
}
|
|
|
94 |
}
|