// Configuration bits: selected in the GUI
// CONFIG1
#pragma config FEXTOSC = OFF // External Oscillator mode selection bits->Oscillator not enabled
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits->HFINTOSC (1MHz)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; i/o or oscillator function on OSC2
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit->FSCM timer enabled
// CONFIG2
#pragma config MCLRE = ON // Master Clear Enable bit->MCLR pin is Master Clear function
#pragma config PWRTS = OFF // Power-up Timer Enable bit->PWRT disabled
#pragma config LPBOREN = OFF // Low-Power BOR enable bit->ULPBOR disabled
#pragma config BOREN = ON // Brown-out reset enable bits->Brown-out Reset Enabled, SBOREN bit is ignored
#pragma config BORV = LO // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (VBOR) set to 2.45V
#pragma config ZCDDIS = OFF // Zero-cross detect disable->Zero-cross detect circuit is disabled at POR.
#pragma config PPS1WAY = ON // Peripheral Pin Select one-way control->The PPSLOCK bit can be cleared and set only once in software
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a reset
// CONFIG3
#pragma config WDTCPS = WDTCPS_31 // WDT Period Select bits->Divider ratio 1:65536; software control of WDTPS
#pragma config WDTE = OFF // WDT operating mode->WDT Disabled, SWDTEN is ignored
#pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits->window always open (100%); software control; keyed access not required
#pragma config WDTCCS = SC // WDT input clock selector->Software Control
// CONFIG4
#pragma config BBSIZE = BB512 // Boot Block Size Selection bits->512 words boot block size
#pragma config BBEN = OFF // Boot Block Enable bit->Boot Block disabled
#pragma config SAFEN = OFF // SAF Enable bit->SAF disabled
#pragma config WRTAPP = OFF // Application Block Write Protection bit->Application Block not write protected
#pragma config WRTB = OFF // Boot Block Write Protection bit->Boot Block not write protected
#pragma config WRTC = OFF // Configuration Register Write Protection bit->Configuration Register not write protected
#pragma config WRTD = OFF // Data EEPROM write protection bit->Data EEPROM NOT write protected
#pragma config WRTSAF = OFF // Storage Area Flash Write Protection bit->SAF not write protected
#pragma config LVP = ON // Low Voltage Programming Enable bit->Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.
// CONFIG5
#pragma config CP = OFF // UserNVM Program memory code protection bit->UserNVM code protection disabled
void PIN_MANAGER_Initialize(void)
{
/**
LATx registers
*/
LATA = 0x00;
LATC = 0x00;
/**
TRISx registers
*/
TRISA = 0x00;
TRISC = 0x00;
/**
ANSELx registers
*/
ANSELC = 0x00;
ANSELA = 0x00;
/**
WPUx registers
*/
WPUA = 0x00;
WPUC = 0x00;
/**
ODx registers
*/
ODCONA = 0x00;
ODCONC = 0x00;
/**
SLRCONx registers
*/
SLRCONA = 0x00;
SLRCONC = 0x00;
RC5PPS = 0x0F; //RC5->EUSART1:TX1;
RX1DTPPS = 0x14; //RC4->EUSART1:RX1;
}
void OSCILLATOR_Initialize(void)
{
// NOSC HFINTOSC; NDIV 1;
OSCCON1 = 0x60;
// CSWHOLD may proceed; SOSCPWR Low power;
OSCCON3 = 0x00;
// MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
OSCEN = 0x00;
// HFFRQ 32_MHz;
OSCFRQ = 0x06;
// HFTUN 0;
OSCTUNE = 0x00;
}
void PMD_Initialize(void)
{
// CLKRMD CLKR enabled; SYSCMD SYSCLK enabled; FVRMD FVR enabled; IOCMD IOC enabled; NVMMD NVM enabled;
PMD0 = 0x00;
// TMR0MD TMR0 enabled; TMR1MD TMR1 enabled; TMR4MD TMR4 enabled; TMR5MD TMR5 enabled; TMR2MD TMR2 enabled; TMR3MD TMR3 enabled; TMR6MD TMR6 enabled;
PMD1 = 0x00;
// NCO1MD NCO1 enabled;
PMD2 = 0x00;
// ZCDMD ZCD enabled; CMP1MD CMP1 enabled; ADCMD ADC enabled; CMP2MD CMP2 enabled; DAC1MD DAC1 enabled;
PMD3 = 0x00;
// CCP2MD CCP2 enabled; CCP1MD CCP1 enabled; CCP4MD CCP4 enabled; CCP3MD CCP3 enabled; PWM6MD PWM6 enabled; PWM7MD PWM7 enabled;
PMD4 = 0x00;
// CWG2MD CWG2 enabled; CWG1MD CWG1 enabled;
PMD5 = 0x00;
// U1MD EUSART1 enabled; MSSP1MD MSSP1 enabled; MSSP2MD MSSP2 enabled;
PMD6 = 0x00;
// CLC3MD CLC3 enabled; CLC4MD CLC4 enabled; DSM1MD DSM enabled; SMT1MD SMT1 enabled; CLC1MD CLC1 enabled; CLC2MD CLC2 enabled;
PMD7 = 0x00;
}
void SYSTEM_Initialize(void)
{
PMD_Initialize();
PIN_MANAGER_Initialize();
OSCILLATOR_Initialize();
}
void main(void)
{
// initialise the device
SYSTEM_Initialize();
}