// store new index
At this point, we almost have everything we need to
communicate using any one of the serial ports. It would
be nice to be able to delay precisely and flash some LEDs
if we have to. We will use the PIC32MX575F512H’s core
timer to build our millisecond delay function:
return USART1_RxBuf[tmptail];
// return data
}
BYTE CharInQueue1(void)
{
return(USART1_RxHead != USART1_RxTail);
}
BYTE CharInQueue2(void)
{
return(USART2_RxHead != USART2_RxTail);
}
BYTE CharInQueue4(void)
{
return(USART4_RxHead != USART4_RxTail);
}
BYTE CharInQueue5(void)
{
return(USART5_RxHead != USART5_RxTail);
}
#define GetSystemClock() 80000000UL
#define GetPeripheralClock() 80000000UL
#define CoreTicksPerMs GetSystemClock() / 2000)
We check for characters in the ring buffers that need
to be processed by calling the CharInQueue functions:
//***********************************************
//* DELAY MILLISECOND FUNCTIONS
//***********************************************
void delayms(unsigned int ms)
{
unsigned int msDelayTime, currentTickCnt;
currentTickCnt = ReadCoreTimer();
msDelayTime = (CoreTicksPerMs ms) +
currentTickCnt;
while((ReadCoreTimer()) < msDelayTime);
}
Eye Candy
Precision Timing
Blinking LEDs is my specialty. The
PIC32MX575F512H’s native SET, CLR, and INV atomic
operations make manipulating the PIC32MX575F512H’s
I/O pins a walk in the park:
/** LEDS ***************************************/
#define bluLED
LATEbits.LATE4
#define bluLED_Off LATECLR = 0x0010;
September 2015 73