/*******************************************************************************
*
* Use Timer 1 to flash LED
*
******************************************************************************/
#include <htc.h>
//-----------------------------------------------------------------------------
//Configuration bits
//Internal osc is 7.37Mhz
__CONFIG (FOSC, CLKSWDIS & FSCMDIS & FRCPLL4);
__CONFIG (FBORPOR, MCLRDIS);
__CONFIG (FWDT, WDTDIS);
//-----------------------------------------------------------------------------
//Program Specific Constants
#define FCY 7370000 //Instruction cycle rate (Osc x PLL / 4)
//=============================================================================
//Main routine
//Set up LEDs and timer, wait for timer periods, and flash one of the two LEDs
//int main(void);
void main(void){
LATD = 0xfffe; //Initialize LED pin data to off state
TRISD = 0xfffe; //Set LED pin as output
LATDbits.LATD0 = 1; //Turn LED on
T1CON = 0; //Turn off Timer1 and clear settings
TMR1 = 0; //Start Timer1 at zero
PR1 = FCY/256/5; //Set period register value for 1/5 second
T1CON = 0x8030; //Turn on Timer1 with 1:256 prescaler
while(1) //Loop forever
{
while(!IFS0bits.T1IF){} //Wait for timer period
IFS0bits.T1IF = 0; //Clear timer flag for next period
LATDbits.LATD0 ^= 1; //Toggle LED
}
} //End of main()