Aug 28, 2017 #1 thannara123 Advanced Member level 5 Joined Jan 7, 2010 Messages 1,580 Helped 122 Reputation 244 Reaction score 114 Trophy points 1,353 Location India Activity points 10,384 seems while loop condition is not entering Code: #define BUTTON_H_ #define LEFT_S PINC&(1<<2) #define RIGHT_S PINC&(1<<3) #define UP_S PINC&(1<<4) #define DOWN_S PINC&(1<<5) #define OK_S PINC&(1<<6) /* Function Key Value For UP_Down Key */ void UP_Down_Keyvalue(struct menu s1,int a,int b) { int ch,lower,upper; [COLOR=#ff0000]while(OK_S) //[/COLOR] { if(UP_S) { while(UP_S); LCD_Clear(); LCD_DisplayString("came to 1"); DELAY_ms(1000); } else if(DOWN_S) // down { while(DOWN_S); LCD_Clear(); LCD_DisplayString("came to 2"); DELAY_ms(1000); } } } int Key_pressed(void) { while(1){ if (LEFT_S) { while(LEFT_S);return 1; } if (RIGHT_S){ while(RIGHT_S);return 2; } if (UP_S) { while(UP_S); return 3; } if (DOWN_S) { while(DOWN_S);return 4 ; } if (OK_S) { while(OK_S);return 5 ; } else return 0; } }
seems while loop condition is not entering Code: #define BUTTON_H_ #define LEFT_S PINC&(1<<2) #define RIGHT_S PINC&(1<<3) #define UP_S PINC&(1<<4) #define DOWN_S PINC&(1<<5) #define OK_S PINC&(1<<6) /* Function Key Value For UP_Down Key */ void UP_Down_Keyvalue(struct menu s1,int a,int b) { int ch,lower,upper; [COLOR=#ff0000]while(OK_S) //[/COLOR] { if(UP_S) { while(UP_S); LCD_Clear(); LCD_DisplayString("came to 1"); DELAY_ms(1000); } else if(DOWN_S) // down { while(DOWN_S); LCD_Clear(); LCD_DisplayString("came to 2"); DELAY_ms(1000); } } } int Key_pressed(void) { while(1){ if (LEFT_S) { while(LEFT_S);return 1; } if (RIGHT_S){ while(RIGHT_S);return 2; } if (UP_S) { while(UP_S); return 3; } if (DOWN_S) { while(DOWN_S);return 4 ; } if (OK_S) { while(OK_S);return 5 ; } else return 0; } }
Aug 28, 2017 #2 paulfjujo Advanced Member level 4 Joined Jun 9, 2008 Messages 1,466 Helped 298 Reputation 596 Reaction score 283 Trophy points 1,363 Location France 01800 Activity points 10,559 hello, #define OK_S PINC&(1<<6) if PINC contains other value .. because other PINC at logical TRUE =1 result is allways true isolate this pin to test it Code: while(PINC && 64) // { so #define OK_S PINC && (1<<6)
hello, #define OK_S PINC&(1<<6) if PINC contains other value .. because other PINC at logical TRUE =1 result is allways true isolate this pin to test it Code: while(PINC && 64) // { so #define OK_S PINC && (1<<6)
Aug 28, 2017 #3 thannara123 Advanced Member level 5 Joined Jan 7, 2010 Messages 1,580 Helped 122 Reputation 244 Reaction score 114 Trophy points 1,353 Location India Activity points 10,384 paulfjujo said: hello, #define OK_S PINC&(1<<6) if PINC contains other value .. because other PINC at logical TRUE =1 result is allways true isolate this pin to test it Code: while(PINC && 64) // { so #define OK_S PINC && (1<<6) Click to expand... Did as said but nothing happens
paulfjujo said: hello, #define OK_S PINC&(1<<6) if PINC contains other value .. because other PINC at logical TRUE =1 result is allways true isolate this pin to test it Code: while(PINC && 64) // { so #define OK_S PINC && (1<<6) Click to expand... Did as said but nothing happens
Aug 28, 2017 #4 paulfjujo Advanced Member level 4 Joined Jun 9, 2008 Messages 1,466 Helped 298 Reputation 596 Reaction score 283 Trophy points 1,363 Location France 01800 Activity points 10,559 #define OK_S PINC&(1<<6) is touch OK pressed =0 not pressed=64 ? while(OK_S==64) { // go out the loop when OK_S is not equal to 64
#define OK_S PINC&(1<<6) is touch OK pressed =0 not pressed=64 ? while(OK_S==64) { // go out the loop when OK_S is not equal to 64
Aug 29, 2017 #5 xenos Full Member level 4 Joined May 9, 2015 Messages 212 Helped 82 Reputation 164 Reaction score 81 Trophy points 28 Location 127.0.0.1 Activity points 1,182 Correct paulfjujo said: Code: #define OK_S PINC&(1<<6) Click to expand... Incorrect: Code: while(PINC && 64) Incorrect: paulfjujo said: Code: #define OK_S PINC && (1<<6) Click to expand... Use & operator (binary AND) instead of && (logical AND). - - - Updated - - - thannara123 said: seems while loop condition is not entering Code: /* Function Key Value For UP_Down Key */ void UP_Down_Keyvalue(struct menu s1,int a,int b) { int ch,lower,upper; [COLOR=#ff0000]while(OK_S) //[/COLOR] { if(UP_S)... Click to expand... Only if you simultaneously press OK and one of UP or DOWN keys, will the loop-body be executed. Was that your intention?
Correct paulfjujo said: Code: #define OK_S PINC&(1<<6) Click to expand... Incorrect: Code: while(PINC && 64) Incorrect: paulfjujo said: Code: #define OK_S PINC && (1<<6) Click to expand... Use & operator (binary AND) instead of && (logical AND). - - - Updated - - - thannara123 said: seems while loop condition is not entering Code: /* Function Key Value For UP_Down Key */ void UP_Down_Keyvalue(struct menu s1,int a,int b) { int ch,lower,upper; [COLOR=#ff0000]while(OK_S) //[/COLOR] { if(UP_S)... Click to expand... Only if you simultaneously press OK and one of UP or DOWN keys, will the loop-body be executed. Was that your intention?