#include "main.h"
#include "p33FJ128MC804.h"
#include "pps.h"
#include "uart.h"
#define FCY 40000000
#define UART_BAUD 57600
#define BRGVAL ((FCY/UART_BAUD)/16)-1
_FGS(GWRP_OFF&GCP_OFF);
_FOSCSEL (FNOSC_PRI&IESO_ON);
_FOSC(POSCMD_HS&OSCIOFNC_OFF&IOL1WAY_OFF&FCKSM_CSECME);
_FWDT(WDTPOST_PS32768&WDTPRE_PR128&WINDIS_OFF&FWDTEN_OFF);
_FPOR(FPWRT_PWR2&ALTI2C_OFF);
_FICD(ICS_PGD1&JTAGEN_OFF);
unsigned char RcvBuff=0;
int RcvBuffPtr=0;
int main(void)
{
unsigned int UxMODEval=0;
unsigned int UxSTAval=0;
unsigned int UxINTval=0;
_TRISC5=0;
_TRISC8=1;
_TRISC9=0;
PLLFBD=38;
CLKDIVbits.PLLPRE=0b00010;
CLKDIVbits.PLLPOST=0;
__builtin_write_OSCCONH(0x03);
__builtin_write_OSCCONL(0x01);
while (OSCCONbits.COSC != 0b011);
while(OSCCONbits.LOCK != 1) {};
PPSUnLock;
RPINR18bits.U1RXR=24;
RPOR12bits.RP25R=3;
PPSLock;
UxMODEval = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & UART_MODE_SIMPLEX &UART_UEN_00 & UART_DIS_WAKE &UART_DIS_LOOPBACK & UART_DIS_ABAUD &UART_BRGH_SIXTEEN & UART_NO_PAR_8BIT & UART_1STOPBIT;
UxSTAval = UART_INT_TX_BUF_EMPTY & UART_TX_ENABLE & UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR & UART_IrDA_POL_INV_ZERO & UART_SYNC_BREAK_DISABLED;
UxINTval=UART_RX_INT_EN&UART_RX_INT_PR4&UART_TX_INT_DIS&UART_TX_INT_PR4;
OpenUART1(UxMODEval, UxSTAval, BRGVAL);
ConfigIntUART1(UxINTval);
_U1RXIF=0;
_U1RXIE=1;
putsUART1("PWNED as FUCK!\0");
while (1)
{
}
}
void __attribute__((interrupt,no_auto_psv)) _U1RXInterrupt(void)
{
RcvBuff=ReadUART1();
WriteUART1(RcvBuff);
_U1RXIF=0;
}