Subversion Repositories Code-Repo

Rev

Blame | Last modification | View Log | RSS feed

#include "maindefs.h"
#include "interrupts.h"
#include "uart.h"
//#include "i2c.h"
//#include "adc.h"
//#include "timers.h"
//#include "xbee.h"
//#include "led_driver.h"
//#include "pwm.h"
//#include "delays.h"
//#include "pin_interrupts.h"
#include <usart.h>
#include <delays.h>

#pragma config WDTEN = OFF          // Turn off watchdog timer
#pragma config XINST = OFF          // Turn off extended instruction set
#pragma config OSC = HSPLL          // Use external oscillator (101)
#pragma config PLLDIV = 3           // Set PPL prescaler to 3 (to get 4MHz)
#pragma config CFGPLLEN = ON        // Enable PLL on startup
#pragma config PLLSEL = PLL96       // Use 96MHz PLL 4MHz -> 96MHz / 2 = 48MHz
//#pragma config SOSCSEL = HIGH       // High Power T1OSC/SOSC circuit selected
//#pragma config ADCSEL = BIT12       // 12-bit ADrC
//#pragma config IOL1WAY = OFF        // IOLOCK bit can be set and cleared as needed

/* ----------- IO Pins -----------
 * RA0 - 
 * RA1 - 
 * RA2 - 
 * RA3 - 
 * RA4 - [CANNOT BE USED (VDDCORE/VCAP)]
 * RA5 - 
 * RA6 - Oscillator
 * RA7 - Oscillator
 * 
 * RC0 - 
 * RC1 - 
 * RC2 - 
 * RC3 - 
 * RC4 - 
 * RC5 - 
 * RC6 - UART Debug Output
 * RC7 - UART Debug Input
 *
 * RB0 - 
 * RB1 - 
 * RB2 - 
 * RB3 - 
 * RB4 - 
 * RB5 - 
 * RB6 - 
 * RB7 - 
 * ---------------------------- */

//static I2C_DATA i2c_data;
//static XBEE_DATA xbee_data;

void main(void) {
    unsigned char i = 0;
    unsigned char length = 0;
    unsigned char buffer[100];
    
    /* --------------------- Oscillator Configuration --------------------- */
//    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
    OSCCONbits.IRCF = 0b111;        // Set INTOSC postscaler to 8MHz
    OSCCONbits.SCS = 0b00; // Use 96MHz PLL as primary clock source
    /* -------------------------------------------------------------------- */

    // Set all ports as digial I/O
    ANCON0 = 0xFF;
    ANCON1 = 0x1F;

    UART1_Init(); // Initialize the UART handler code
//    xbee_init(&xbee_data); // Initialize the XBee handler code
//    i2c_init(&i2c_data); // Initialize the I2C handler code
//    adc_init();                 // Initialize the ADC
//    timers_init(); // Initialize timers
//    port_b_int_init(); // Initialze Port B interrupt handler
//    pwm_init(); // Initialize the PWM output driver
    
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
    interrupt_init(); // Initialize the interrupt priorities

    DBG_PRINT_MAIN("\r\nBegin Program\r\n");
    
    // Loop and process recieved messages from interrupts;

    while (1) {
        length = UART1_Read((char *)buffer);
        if (length != 0) {
            UART1_WriteB((char *)buffer, length) ;
        }
        Delay10KTCYx(255);
    }
}