#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#pragma config FOSC = INTOSC,WDTE = OFF, MCLRE = ON, PLLEN = OFF
#define Data_PWM PORTAbits.RA2 //pin5 pwm input
#define Ser_out PORTAbits.RA0 //pin7 serial output to LCD
#define _XTAL_FREQ 32000000
// putting variables here makes them Global, probably bad programming practice
unsigned int CCP_T0, CCP_T1, CCP_T2, CCP_T3 = 0;
void init() { // I ususally set the oscillator first.
OSCCON = 0b01111010; // 1111 = 16MHz internal OSC
while (OSCSTATbits.HFIOFS == 1) { // wait till oscilator's stable
}
T1CON = 1; // T1CON,0 = TMR1 start/stop, 1=enables, 0=stops
T1GCON = 0;
ADCON0 = 0;
TRISA = 0b00001100; // RA2,RA3(MCLR)are input,others output
OPTION_REG = 0; // weak pullups?
CM1CON0bits.C1ON = 0; // comparators off
ANSELA = 0; // all digital
// I assume the Parallax LCD is serial? 9600,N,8,1?
__delay_ms(50);
}
void main() {
init;
while (1) {
// mainline code goes here, loops forever
TMR1 = 0; // clear the timer
}
}