richardlaishram
Member level 4
- Joined
- Jan 6, 2013
- Messages
- 77
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Planet Earth
- Activity points
- 1,804
Code:
#include <htc.h>
#define Count_In RB3
__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & DEBUG_OFF);
void main(void)
{
Button = 0;
TRISB3 = 1;
unsigned int Count = 0;
while(1)
{
if(Button == 1) // Button is pressed
{
while(1)
{
while(Button == 1); // Wait for de-assertion of the button
__delay_ms(10);
Count++;
if(Count ==3)
Count = 1;
switch(Count)
{
case 1:
{
WriteStringToLCD("Loop 1"); // Write Message on LCD
__delay_ms(50);
}break;
case 2:
{
WriteStringToLCD("Loop 1"); // Write Message on LCD
__delay_ms(50);
}break;
}
}
}
}
This is the code in which I'm having problem. When the switch is pressed it goes to case 1 once and then stops. Please tell me a way to make it loop forever and at the same time I can switch to case 2 when the switch is pressed for the second time.
Thanks in advance.