#include"main.h"
#include"uart.h"
_FGS(GSS_OFF & GWRP_OFF & GSSK_OFF)
_FOSCSEL(FNOSC_PRI & IESO_OFF)
_FOSC(POSCMD_XT & OSCIOFNC_OFF & FCKSM_CSECMD)
_FWDT(WDTPRE_PR32 & PLLKEN_ON & WINDIS_OFF & FWDTEN_OFF)
_FAS(AWRP_OFF & APL_OFF & APLK_OFF);
_FICD(ICS_PGD3 & RSTPRI_PF & JTAGEN_OFF)
int main()
{
Config_Clock();
Config_UART();
Init_UART();
while(1);
return 0;
}
void Config_Clock(void)
{
PLLFBD = 46; // M = PLLDIV+2
CLKDIVbits.PLLPOST = 0; // N2 = (PLLPOST+1)*2
CLKDIVbits.PLLPRE = 0; // N1 = PLLPRE+2
__builtin_write_OSCCONH( 0x03 ); // Initiate Clock Switch to
__builtin_write_OSCCONL( OSCCON || 0x01 ); // Start clock switching
while( OSCCONbits.COSC != 0b011 );
// Wait for Clock switch to occur
while( OSCCONbits.LOCK != 1 );
}
void Config_UART(void)
{
// PPS
// Unlock Registers
__builtin_write_OSCCONL(OSCCON & 0xbf);
RPINR18bits.U1RXR = 66; //Configure Input Functions , Assign U1RX To Pin RP30 UART1 working
RPOR0bits.RP65R = 1; //Configure Output Functions , Assign U1TX To Pin RP16
__builtin_write_OSCCONL(OSCCON | 0x40);
}
void Init_UART(void)
{
U1BRG = 3124;//1561;
U1MODE = 0x8008; // BRGH = 0;
U1STA = 0x0400; //UTXEN = 1;
printf("UART Ready\n");
}