Hi Guys,
I am stuck on experiment 18 in this book. Posted below is the code. Basically the issue I am having is that now I want to go in reverse order once after LED 7 lights up. I don't know what to say, but I am stumped. I understood how k was able to increment and thus change the case order, but I am having trouble figuring out a formula for doing the reverse. I don't really want people giving me the answer straight up, but can someone please point me in the right direction?
I am stuck on experiment 18 in this book. Posted below is the code. Basically the issue I am having is that now I want to go in reverse order once after LED 7 lights up. I don't know what to say, but I am stumped. I understood how k was able to increment and thus change the case order, but I am having trouble figuring out a formula for doing the reverse. I don't really want people giving me the answer straight up, but can someone please point me in the right direction?
Rich (BB code):
#include <pic.h>
/* cPKLED.c - Roll Through PICkit 8 LEDs
This Program will roll through each of the 8 LEDs built
into the PICkit PCB.
The LED values are:
LED Anode Cathode
D0 RA4 RA5
D1 RA5 RA4
D2 RA4 RA2
D3 RA2 RA4
D4 RA5 RA2
D5 RA2 RA5
D6 RA2 RA1
D7 RA1 RA2
myke predko
04.09.10
*/
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
& UNPROTECT & BORDIS & IESODIS & FCMDIS);
int i, j, k;
main()
{
PORTA = 0;
CMCON0 = 7; // Turn off Comparators
ANSEL = 0; // Turn off ADC
k = 0; // Start at LED 0
while(1 == 1) // Loop Forever
{
for (i = 0; i < 255; i++) // Simple Delay Loop
for (j = 0; j < 129; j++);
switch (k) { // Select Which LED to Display
case 0:
PORTA = 0b010000;
TRISA = 0b001111;
break;
case 1:
PORTA = 0b100000;
TRISA = 0b001111;
break;
case 2:
PORTA = 0b010000;
TRISA = 0b101011;
break;
case 3:
PORTA = 0b000100;
TRISA = 0b101011;
break;
case 4:
PORTA = 0b100000;
TRISA = 0b011011;
break;
case 5:
PORTA = 0b000100;
TRISA = 0b011011;
break;
case 6:
PORTA = 0b000100;
TRISA = 0b111001;
break;
case 7:
PORTA = 0b000010;
TRISA = 0b111001;
break;
} // hctiws
k = (k + 1) % 8; // Increment k within range of 0-7
} // elihw
} // End cPKLED