I am trying to write a program to light LEDs on a guitar neck. With the way i have it wired i need turn on and off LEDs fast so that you can't tell they are blinking. I wrote a loop for one section to light up an A chord on the neck(the S1-S6 and F0s and F2s are defined in the program earlier) but it seems like the loop only goes through once and then waits for the first switch(RD7) to be pressed. When hooked up to a multimeter it only shows whatever the last declarations on that port was (PORTA=0 and PORTF=0 in this case gives zero volts output.) Can anyone tell me where the error is in my code? Thanks
Also RD6 and RD7 are the switches and i put the delay in so that it wouldn't scroll through the sections too fast.
while((section==1)&&(scroll==0))
{
mPORTDClearBits(BIT_2);
mPORTDSetBits(BIT_0); // Switch ON LED1
if(!_RD7){
TMR1=0;
while(TMR1<DELAY){
} //delay loop
scroll=1;
} // check switch 2 loop
if(!_RD6){
TMR1=0;
while(TMR1<DELAY){
} //delay loop
section=2;
scroll=0;
} // check switch 1 loop
} //Chords Section Loop
while((section==1)&&(scroll==1)) //CHORD A
{
PORTF=S1;
PORTA=F0;
PORTF=0;
PORTA=0;
PORTF=S2;
PORTA=F0;
PORTF=0;
PORTA=0;
PORTF=S3;
PORTA=F2;
PORTF=0;
PORTA=0;
PORTF=S4;
PORTA=F2;
PORTF=0;
PORTA=0;
PORTF=S5;
PORTA=F2;
PORTF=0;
PORTA=0;
PORTF=S6;
PORTA=F0;
PORTF=0;
PORTA=0;
if(!_RD7){
TMR1=0;
while(TMR1<DELAY){
} //delay loop
scroll=2;
} //check switch 2 loop
if(!_RD6){
TMR1=0;
while(TMR1<DELAY){
} //delay loop
section=2;
scroll=0;
} //check switch 1 loop
} //Chord Section A Chord Loop
Also RD6 and RD7 are the switches and i put the delay in so that it wouldn't scroll through the sections too fast.
while((section==1)&&(scroll==0))
{
mPORTDClearBits(BIT_2);
mPORTDSetBits(BIT_0); // Switch ON LED1
if(!_RD7){
TMR1=0;
while(TMR1<DELAY){
} //delay loop
scroll=1;
} // check switch 2 loop
if(!_RD6){
TMR1=0;
while(TMR1<DELAY){
} //delay loop
section=2;
scroll=0;
} // check switch 1 loop
} //Chords Section Loop
while((section==1)&&(scroll==1)) //CHORD A
{
PORTF=S1;
PORTA=F0;
PORTF=0;
PORTA=0;
PORTF=S2;
PORTA=F0;
PORTF=0;
PORTA=0;
PORTF=S3;
PORTA=F2;
PORTF=0;
PORTA=0;
PORTF=S4;
PORTA=F2;
PORTF=0;
PORTA=0;
PORTF=S5;
PORTA=F2;
PORTF=0;
PORTA=0;
PORTF=S6;
PORTA=F0;
PORTF=0;
PORTA=0;
if(!_RD7){
TMR1=0;
while(TMR1<DELAY){
} //delay loop
scroll=2;
} //check switch 2 loop
if(!_RD6){
TMR1=0;
while(TMR1<DELAY){
} //delay loop
section=2;
scroll=0;
} //check switch 1 loop
} //Chord Section A Chord Loop
Last edited: