/******************************************************************************/ /* Files to Include */ /******************************************************************************/ #if defined(__XC) #include /* XC8 General Include File */ #elif defined(HI_TECH_C) #include /* HiTech General Include File */ #endif #include /* For uint8_t definition */ #include /* For true/false definition */ #include "system.h" #include "user.h" /******************************************************************************/ /* User Functions */ /******************************************************************************/ /* */ void InitApp(void) { /* set watchdog to 4 seconds and enable it */ WDTCONbits.WDTPS = 0b01100; WDTCONbits.SWDTEN = 1; /* Select pins 4&5 as the uart - page 102 */ APFCONbits.RXDTSEL = 0; /* RX/DT on RA1 */ APFCONbits.TXCKSEL = 0; /* TX/CK on RA0 */ TRISAbits.TRISA1 = 1; /* RA5 as input */ TRISAbits.TRISA0 = 0; /* RA4 as output */ ANSELA = 0; /* no analog */ /* enable weak pullups, clear them all */ WPUA = 0; //WPUAbits.WPUA0 = 0x00000100; // RA0 pullup for 1-wire bus OPTION_REGbits.nWPUEN = 1; /* Enabling transmitter 26.1.1.1 page 259 - TX/CK I/O pin */ TXSTAbits.TXEN = 1; TXSTAbits.SYNC = 0; RCSTAbits.SPEN = 1; /* Enabling receiver 26.1.2 page 262 - RX/DT I/O pin */ RCSTAbits.CREN = 1; /* 4MHz clock, 57k6 baud */ TXSTAbits.BRGH = 1; BAUDCONbits.BRG16 = 1; //SPBRG = 16; // 57k6 SPBRG = 51; // 19k2 //SPBRG = 103; // 9k6 // enable debug LED on RA4 TRISAbits.TRISA4 = 0; ANSELAbits.ANSA4 = 0; // setup timer1 // enable the timer (off for now, not gated mode) T1CONbits.TMR1ON = 0; T1GCONbits.TMR1GE = 0; T1CONbits.TMR1CS = 0b00; // instruction clock T1CONbits.T1CKPS = 0b11; // div 8 // enable TIMER1 interupt PIE1bits.TMR1IE = 1; /* Enable interrupts */ INTCONbits.GIE = 1; INTCONbits.PEIE = 1; /* enable uart receiver interupt */ PIE1bits.RCIE = 1; }