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 support@ccsinfo.com

How to display enter button value in LCD

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



Joined: 23 May 2004
Posts: 7

View user's profile Send private message

How to display enter button value in LCD
PostPosted: Mon Sep 13, 2004 8:17 am     Reply with quote

Hi all
could anyone help me to solve my problem. I'm beginner in this PIC programming. what i want to do is display back button value into LCD.

let says, when i enter button no 1, it will display 1 at LCD. and then when i continue with button 4 then A. it will show "14A" at LCD. how can i do that?.. hope anyone can help me.

below is my code. but it only display current button value that i was enter and did'nt store my previous entered button value.

Code:
#include <18F452.h>
#Fuses HS,NOPROTECT,NOBROWNOUT,NOWDT,PUT,NODEBUG,NOLVP
#use  delay( clock=9830400 )
#include <math.h>
#include "Lcd.c"

// Keypad Layout
// 1 2 3 A
// 4 5 6 B
// 7 8 9 C
// * 0 # D

struct keypad_pin_map
{
    int  key: 4;
    int  row: 4;
} PortC;

#Byte PortC = 0xF82
#Byte PortD = 0xF83

#use fast_io( C )
#use fast_io( D )

struct Keypad_pin_map const WR = {0,0};
struct Keypad_pin_map const RD = {15,0};

//'1'=17, '2'=18, '3'=20, 'A'=24
//'4'=33, '5'=34, '6'=36, 'B'=40
//'7'=65, '8'=66, '9'=68, 'C'=72
//'*'=129 '0'=130 '#'=132 'D'=136
char decodeKey_Pad(int keyPadData)
{
   switch (keyPadData)
   {
      case  17:  return('1');
         break;
      case  18:  return('2');
         break;
      case  20:  return('3');
         break;
      case  24:  return('A');
         break;
      case  33:  return('4');
         break;
      case  34:  return('5');
         break;
      case  36:  return('6');
         break;
      case  40:  return('B');
         break;
      case  65:  return('7');
         break;
      case  66:  return('8');
         break;
      case  68:  return('9');
         break;
      case  72:  return('C');
         break;
      case 129:  return('E'); //* = E, esc
         break;
      case 130:  return('0');
         break;
      case 132:  return('R'); //# = R, return
         break;
      case 136:  return('D');
         break;
   }
}

byte ReadKeyPad()
{
  byte i,k,l,Res;
  Res = 0;
  for (i=0; i<4; i++)
     {
       Set_Tris_C( WR );
       PortC.Key = 0;
       PortC.Row = exp(i*log(2));
       delay_us(50);
       Set_Tris_C( RD );
       k = PortC.Key;
       l = exp((4+i)*log(2));
       if( k!= 0) { Res = k|l; }
     }
  return Res;
}

void main()
{
  byte c;
  int keyPad_Data;
  lcd_init();
  lcd_putc("\f    welcome  \n" );
  lcd_putc(   "    Your Display   " );
  delay_ms(1000);

  while(1)
  {
     keyPad_Data = ReadKeyPad();
     c = decodeKey_Pad(keyPad_Data);
     if (c != 0) printf(lcd_putc, "\f%u", c );

  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 13, 2004 12:35 pm     Reply with quote

All you want to do is to display a keypress on the LCD.
Why don't you just use the CCS drivers that come with the compiler ?Then it would work.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Sep 13, 2004 3:24 pm     Reply with quote

As PCM Programmer told you, use the generic keypad driver KBDD.C
to handle the keypad.
I guess that you are trying to operate arithmetically while scanning the
keypad, wich is not an easy task for a beginner. First try to get the
pressed key and then apply your arithmetics.

FYI, the function exp(value) return a float, so read carefully
the help.
Quote:

PortC.Row = exp(i*log(2));



Humberto
sudu



Joined: 23 May 2004
Posts: 7

View user's profile Send private message

PostPosted: Mon Sep 13, 2004 7:05 pm     Reply with quote

hi there,
thank for your feedback Smile

finally, i can display keypress in LCD without override previous keypress.

just simple mistake in printf
Code:
printf(lcd_putc, "\f%u", c );


i change it to
Code:
printf(lcd_putc, "%u", c );

without \f.

another problems is how can i get value in LCD to manipulate.
eg:
lets says i want to use this LCD in menu function. when user enter their menu using keypad, for example enter 1234. How can i get that number 1234 and manipulate it in my menu function. is there any way to do that?.

thank for your help.
sorry for my bad english. Embarassed
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 13, 2004 9:31 pm     Reply with quote

Well if you are getting the number and displaying it, then you have the number. It really depends on what you are trying to do. You could store the data into a string and then convert that string back to a number. You could store the key press as a number. When the next number is pressed, multiply the previous result by 10 and add the new number.
pixie
Guest







Lcd.c
PostPosted: Tue Dec 14, 2004 7:37 am     Reply with quote

Hello, I'm trying to resolve the same problem, could you put the librarie Lcd.c used with the 18F452 PIC.

Thank You Very Much.
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