int main(void)
{
int i;
// Explorer16 LEDs are on lower 8-bits of PORTA and to use all LEDs, JTAG port must be disabled.
mJTAGPortEnable(DEBUG_JTAGPORT_OFF);
// 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);
mPORTAClearBits(0xff); // clear LEDs
mPORTASetPinsDigitalOut(0xff); // make LEDs outputt.
mPORTDSetPinsDigitalIn(BIT_6 | BIT_7); // make switches input
for(i=0;i<50;i++) // blink LEDs on poeer up
{ mPORTAToggleBits(0xff); delay(1000000ul); }
mPORTASetBits(0x55); // set LEDs
UART2Init(PC_BAUDRATE); // initialise UART2 to PC host
UART2PrintString("*** UART and LCD tests ***\r\n");
printf("\nprintf test \n");
Timer1init(); // initialise timer 1
for(i=0;i<20;i++) // blink LEDs 0.1sec using timer
{ mPORTAToggleBits(0xff); mSecDelay(100); printf("*");}
if ( ReadEventWDT() ) // check for watchdog event
{
DisableWDT(); // A WDT event did occur
ClearEventWDT(); // clear the WDT event flag so a subsequent event can set the event bit
printf("watchdog timer event occured \n");
}
UART2PrintString("*** Type some characters and observe echo and RA7 LED toggle ***\r\n");
mSecElapsed(1,1,1);
mPORTAClearBits(0xff); // clear LEDs
// loop
while (1)
{
// if character received from PC echo it and toggle LED
if(UART2CharReady())
{
char ch=UART2GetChar();
UART2PutChar(ch);;
// Toggle LED to indicate UART activity
mPORTAToggleBits(BIT_7);
}
// if 1 second elapted print * and toggle LED
if(mSecElapsed(1, 0, 1000))
{
mSecElapsed(1,1,1); UART2PutChar('*'); mPORTAToggleBits(BIT_0);
printf(" PORTF 0x%x TRISF 0x%x\n", PORTF, TRISF);
}
// test input from switches RD6 and RD7
if(PORTD & 0x40) mPORTASetBits(BIT_1); else mPORTAClearBits(BIT_1);
if(PORTD & 0x80) mPORTASetBits(BIT_2); else mPORTAClearBits(BIT_2);
ClearWDT(); // clear watchdog timer - comment out to test
}
return 0;
}