Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] while loop is not working

Status
Not open for further replies.

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,377
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;
    }    
 }
 

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)
Did as said but nothing happens
 

#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
 
Correct
Code:
#define OK_S    PINC&(1<<6)


Incorrect:
Code:
while(PINC && 64)

Incorrect:
Code:
#define OK_S PINC && (1<<6)

Use & operator (binary AND) instead of && (logical AND).

- - - Updated - - -

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)...
Only if you simultaneously press OK and one of UP or DOWN keys, will the loop-body be executed.
Was that your intention?
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top