CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Simple code keypad- lcd (help)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nick...7



Joined: 03 Dec 2013
Posts: 4
Location: Greece

View user's profile Send private message

Simple code keypad- lcd (help)
PostPosted: Tue Dec 03, 2013 7:46 am     Reply with quote

Hi, I have this simple code which I can print captured key to lcd. I want to use this number that I print to lcd to another part of code if I push e.g. the # key. How can I modify this code?

e.g. if I push 2(two) 4(four) and # I want to use the 24 (twenty-four) number to do something else

Thanks in advance!

Code:
#include "16f877a.h"
#use delay(clock=4000000)
#fuses XT, NOLVP, NOWDT, NOPROTECT
#include "flex_lcd.c"
#include "kbd.c"

void main()
{
   char k=0;                     
   delay_ms(1);
   
   lcd_init();                   
   kbd_init();                   
   for(;;){

   lcd_gotoxy(1,1);             
   lcd_putc("puse any button"); 
   lcd_gotoxy(1,2);             

   while(1) // infinite loop
   {
      k = kbd_getc();         
      if(k!=0)                   
      {
         lcd_putc(k);           
         k=0;                   
         delay_ms(250);       
      }
      delay_ms(1);               
   }
}
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Dec 03, 2013 3:04 pm     Reply with quote

Assuming you want the decimal number 24 and not a string with the ascii characters 2 and 4 in it, you need to convert the incoming digits to the number you want. In this case, 24 is actually (2*10) + 4. Each time you press another digit, you need to multiply the existing total by 10 then add the new number to the total. You start with a total of 0. Make sure you define a large enough total variable to hold any possible number you may enter (you may want to be able to handle 3 or 4 digits or whatever is needed for your application.) How to un-do the last digit pressed if you make a mistake is left as an exercise for later :-)

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
nick...7



Joined: 03 Dec 2013
Posts: 4
Location: Greece

View user's profile Send private message

PostPosted: Wed Dec 04, 2013 2:41 pm     Reply with quote

gpsmikey wrote:
Assuming you want the decimal number 24 and not a string with the ascii characters 2 and 4 in it, you need to convert the incoming digits to the number you want. In this case, 24 is actually (2*10) + 4. Each time you press another digit, you need to multiply the existing total by 10 then add the new number to the total. You start with a total of 0. Make sure you define a large enough total variable to hold any possible number you may enter (you may want to be able to handle 3 or 4 digits or whatever is needed for your application.) How to un-do the last digit pressed if you make a mistake is left as an exercise for later :-)

mikey


Thank you for your explanation! My knowledge in programming are few (to do something from the start), so I Will try to modify a code for a calculator that I just found!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group