anilmanisingh
Joined: 31 Mar 2011 Posts: 6
|
unable to restart my loop from zero again |
Posted: Wed Apr 08, 2015 3:47 am |
|
|
Hello Everyone.
I want my program to start from LED One again .
But I am stuck after the switch is incremented to 3.
Code: |
#include <18F4520.h>
#fuses INTRC_IO, BROWNOUT, PUT, NOWDT
#use delay(clock=4M)
#define BUTTON_PIN PIN_B0 // This pin must have a pull-up.
#define DEBOUNCE_PERIOD_IN_MS 10
#define DEBOUNCE_COUNT 2
void wait_for_keypress(void);
//==================================
void wait_for_keypress(void)
{
char count;
// First, wait for the button to be released. With the debounce
// values as given above, the button must be in the "up" state
// for two consecutive readings, spaced 10 ms apart.
count = 0;
while(TRUE)
{
if(input(BUTTON_PIN) == 1)
count++;
else
count = 0;
if(count == DEBOUNCE_COUNT)
break;
delay_ms(DEBOUNCE_PERIOD_IN_MS);
}
// Now that the button is up, wait until the user presses it.
// In order for the keypress to be considered valid, based
// on the debounce values listed at the beginning of the
// program, the button must be held down for two consecutive
// readings, spaced 10 ms apart.
count = 0;
while(TRUE)
{
if(input(BUTTON_PIN) == 0)
count++;
else
count = 0;
if(count == DEBOUNCE_COUNT)
break;
delay_ms(DEBOUNCE_PERIOD_IN_MS);
}
}
//====================================
void main()
{
int8 count;
port_b_pullups(TRUE);
count = 0;
while(TRUE)
{
wait_for_keypress();
count++;
if (count==1)
{
output_high(PIN_C1);
delay_ms(1000);
output_low(PIN_C1);
}
else if (count==2)
{
output_high(PIN_C2);
delay_ms(1000);
output_low(PIN_C2);
}
else if (count==3)
{
output_high(PIN_C3);
delay_ms(1000);
output_low(PIN_C3);
}
}
}
|
Thanks |
|