Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Problem in taking users's inputs ~

Status
Not open for further replies.

Tarneem

Newbie level 6
Joined
Mar 25, 2015
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
264
Hi ;

I m facing problem in taking inputs from the user by using push buttons ~

Here is the code of the function that taking from the user the inputs ..
(inc= increments , Dec= decrements , Next to exit )

Code:
Timerr() // set Timer
 {
 k=1;
 minutes=0;
 while(K!=6)
 {
   if(inc==0)
      {minutes++;
      Lcd_Cmd(0xc0);
      Lcd_Out_Cp(minutes);
      }

    if(dec==0)
      {
       minutes=minutes--;
       Lcd_Cmd(0xc3);
       Lcd_Out_Cp(minutes);
      }
      
   if(next==0)
   {k=6;while(next==0);}
  }
}

this is just to have the input form the user ,, but in each time that i clicked , it shows me garbage values ..

Any one can help ..??
Plz :-(
 

Vbase

Full Member level 6
Joined
Apr 7, 2015
Messages
367
Helped
74
Reputation
148
Reaction score
72
Trophy points
28
Activity points
1,997
When you click inc or dec the minutes keep on counting and displaying new value while your finger is on the button.
Add this kind of line while(next==0);
 

mdorian

Member level 2
Joined
Oct 15, 2008
Messages
48
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,288
Location
Romania
Activity points
1,566
You also have to skip push button transitions
Maybe something like this would be better:
Code:
Timerr() // set Timer
 {
 k=1;
 minutes=0;
        Lcd_Cmd(0xc0);
        Lcd_Out_Cp(minutes);// to see something if no button pressed
 while(K!=6)
 {
   while(inc==0)
      {minutes++;
        Lcd_Cmd(0xc0);
        Lcd_Out_Cp(minutes);
        i=0
        do { 
           delay_ms(100);//  small delay to skip transitions
           i++; 
            } while ((i<5) & (inc==0))// repeat with long delay if button still pressed
       }
.............
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,372
Helped
4,727
Reputation
9,469
Reaction score
4,496
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,634
Just as important - what value is 'minutes' to start with?
To work as text on an LCD you can't just use 0 to 9, you have to use 0x30 to 0x39 (48 to 57 in decimal) and maybe cater for numbers outside that range too.

Brian.
 

mdorian

Member level 2
Joined
Oct 15, 2008
Messages
48
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,288
Location
Romania
Activity points
1,566
I missed that ,if you're using MikroC ,a string must be passed to Lcd_Out_Cp.
Use a conversion function like ByteToStr
Code:
char txt[4];
.....
 ByteToStr(minutes,txt);
        Lcd_Cmd(0xc0);
        Lcd_Out_Cp(txt);
assuming that minutes is a char
 

Tarneem

Newbie level 6
Joined
Mar 25, 2015
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
264
sir , It's give me better result ..

peevishly it was shown me garbage values .. but now it shows numbers only .. ^_^
Thank u so muuuuch mdorian and every one else helped ..

but still i m having problem .. now see .. this is the initialization

Code:
 char seconds = 0;
  char minutes = 0;
  char i;
  char txt[4];
and this is the function of timer in main :

Code:
if(Timer==0)    //check Timer set button press
  {
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Out(1,2,"Countdown  ");
    Timerr();    //call Timer set function
}
and her is the function Timerr():

Code:
Timerr() // set Timer
 {
 k=1;
        minutes=0;
        Lcd_Cmd(0xc4);
        ByteToStr(minutes,txt);// to see something if no button pressed
 while(K!=6)
 {
   if(inc==0)
      { minutes++;while(inc==0);
        ByteToStr(minutes,txt);
        Lcd_Cmd(0xc4);
        Lcd_Out_Cp(txt);
       }

    if(dec==0)
      {
       minutes--; while(inc==0);
      ByteToStr(minutes,txt);
        Lcd_Cmd(0xc4);
        Lcd_Out_Cp(txt);
      }
      
   if(next==0)
   {k=6;while(next==0);}
  }
}
}

The problem is when i first ckliked inc buttons , it shows mw 46 then i cliked again it shows 78 then 22 then 53 ...

What do u think the problem can be ? ?

- - - Updated - - -

IT woooooooorks ..

Thanks for every body who helped me .. I m really thankful to u ppl so much

Yes .. I m using MikroC program ,, and this is the initialization data :

This is the if statment in main function :
Code:
char seconds = 0;
  char minutes = 0;
  char i;
  char txt[4];

Code:
if(Timer==0)    //check alarm set button press
  {
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Out(1,2,"Countdown  ");
    Timerr();    //call Timer set function

    for (i=60; i >= 0; i--)
    {
    seconds = i;
    minutes = i / 60;
    seconds = seconds - (minutes * 60);
       Delay_ms(500);
    IntToStr(seconds, txt);
    Lcd_Out(2, 5, txt);
    IntToStr(minutes, txt);
    Lcd_Out(2, 1, txt);
    Delay_ms(100);
    }
and this is the Timerr() function :

Code:
Timerr() // set Timer
 {
 k=1;
        minutes=0;
        Lcd_Cmd(0xc4);
        ByteToStr(minutes,txt);// to see something if no button pressed
 while(K!=6)
 {
   if(inc==0)
      { minutes++;while(inc==0);
        ByteToStr(minutes,txt);
        Lcd_Cmd(0xc4);
        Lcd_Out_Cp(txt);
      }

    if(dec==0)
     {
       minutes--; while(dec==0);
      ByteToStr(minutes,txt);
        Lcd_Cmd(0xc4);
        Lcd_Out_Cp(txt);
     }
      
   if(next==0)
   {k=6;while(next==0);}
  }
}

I want to take the minutes that is taken from the user and start the countingdown function ..


the role that i wrote is nor function right ..

minutes = i / 60;
seconds = seconds - (minutes * 60);

Any one can suggest me a good way to do that ?

Thank u so much again .. i really appreciated
 

Vbase

Full Member level 6
Joined
Apr 7, 2015
Messages
367
Helped
74
Reputation
148
Reaction score
72
Trophy points
28
Activity points
1,997
Code:
if(seconds == 60) 
{
seconds = 0;
minutes++;
}
Brian.
It's a countdown;
Code:
if(seconds == 255) 
{
seconds = 59;
minutes--;
}
Brian, I believe you can improve on this code.
 
Last edited:

Tarneem

Newbie level 6
Joined
Mar 25, 2015
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
264
IT dowsn't work by this way =(

- - - Updated - - -

I m working now by this way ..

But I m having problem ..

when I entered 4 munits .. It show in LCD 3 : 59 and stopped .. it is not conteniously decreasing



Code:
if(Timer==0)    //check alarm set button press
  {
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Out(1,2,"Countdown  ");
    Timerr();    //call Timer set function

    while (minutes)
    {
    minutes--;
    ByteToStr(minutes,txt);
        Lcd_Cmd(0xc2);
        Lcd_Out_Cp(txt);
       for ( i=59 ; i>0 ; i-- )
       {
       seconds = 59;
       byteToStr(seconds,txt);
       Lcd_Cmd(0xc6);
       Lcd_Out_Cp(txt);
       Delay_ms(500);
       seconds--;
       
        if (seconds==0)
           {minutes--;
           ByteToStr(minutes,txt);
        Lcd_Cmd(0xc2);
        Lcd_Out_Cp(txt);}
       }
    }
- - - Updated - - -

DOOOOOOONE ..

the problem has been fixed .. ALHamduleAllah .. ~

Thank u so much for ur help ..

I really thankfull to u ALL .. ~
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top