int main(void)
{
// Configure the device for maximum performance but do not change the PBDIV
// Given the options, this function will change the flash wait states, RAM
// wait state and enable prefetch cache but will not change the PBDIV.
// The PBDIV value is already set via the pragma FPBDIV option above..
SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
mJTAGPortEnable(DEBUG_JTAGPORT_OFF);
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
INTEnableInterrupts();
PPSOutput(3, RPD9, U4TX); // Set RPF5 pin as output for U2TX
//PPSInput(4,U4RX,RPD5);
PPSInput(4, U4RX, RPB2);
PORTSetPinsDigitalIn(IOPORT_B, BIT_2);
// Explorer-16 uses UART4 to connect to the PC.
// This initialization assumes 36MHz Fpb clock. If it changes,
// you will have to modify baud rate initializer.
UARTConfigure(UART4, UART_ENABLE_PINS_TX_RX_ONLY);
UARTSetFifoMode(UART4, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTSetLineControl(UART4, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
//U4MODE = 1 << 3;
UARTSetDataRate(UART4, GetPeripheralClock(), DESIRED_BAUDRATE);
UARTEnable(UART4, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
// Configure UART4 RX Interrupt
// INTEnable(INT_SOURCE_UART_RX(UART4) | INT_SOURCE_UART_TX(UART4), INT_ENABLED);
INTSetVectorPriority(INT_VECTOR_UART(UART4), INT_PRIORITY_LEVEL_3);
INTSetVectorSubPriority(INT_VECTOR_UART(UART4), INT_SUB_PRIORITY_LEVEL_0);
INTEnable(INT_U4RX,INT_ENABLED);
// INTEnable(INT_U4TX,INT_ENABLED);
// configure for multi-vectored mode
//WriteString("22");
// Let interrupt handler do the work
while (1)
{
// int data = 0;
// if (UARTReceivedDataIsAvailable(UART4))
// {
// // Echo what we just received.
// //PutCharacter(UARTGetDataByte(UART4));
// // Clear the RX interrupt Flag
// INTClearFlag(INT_SOURCE_UART_RX(UART4));
// }
}
return 0;
}
|