#include <htc.h>
__CONFIG(UNPROTECT & BORDIS & MCLRDIS & PWRTEN & WDTDIS & INTIO);
const unsigned char TrisIOArray[] =
{0b000110, 0b000110, 0b100010, 0b100010, 0b010010, 0b010010, 0b110000, 0b110000};
//Array containing all neccessary TRSIO register values
const unsigned char GpioArray[] =
{0b010000, 0b100000, 0b010000, 0b000100, 0b100000, 0b000100, 0b000100, 0b000010};
//Array containing all neccessary GPIO register values
#define LED_ON(n) TRISIO=TrisIOArray[n];GPIO = GpioArray[n] //define LED_ON() macro
void main()
{
unsigned int i;
unsigned int n;
unsigned int j = 0;
INTCON = 0; //disable interrupts
ANSEL = 0x00; //clear ansel register
CMCON = 0x07; //disable comparator
while (1){ //loop continuously
for(n = 0; n < 8; n++) //cycle through the array values from 0-7
{
LED_ON(n); //call LED_ON() macro, assign variable n to it
j++; //increment j every time loop runs
if (j <= 20)
for(i = 0; i < 10000; i++)
{
// do nothing, slower busy wait loop
}
else
for(i = 0; 1 < 5000; i++)
{
// do nothing, faster busy wait loop
}
}
}
}