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

interfacing keypad with 18f4550

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



Joined: 28 Sep 2010
Posts: 4

View user's profile Send private message Yahoo Messenger

interfacing keypad with 18f4550
PostPosted: Sun Oct 03, 2010 7:00 am     Reply with quote

I have a problem with my coding in ccs.
When I compile it show lot of error.
I just edit my program from kbd.c.
Please help me.
Tis is my source code.
Code:

#include <18F4550.h>
#fuses HSPLL, PLL5, CPUDIV1, NOWDT, PUT, BROWNOUT, NOLVP
#use delay (clock=20000000)
#include <kbd.c>
#include <lcd.c>
#define use_portb_kbd TRUE
#define use_portd_lcd TRUE

//Keypad connection:
#define row0 PIN_B4
#define row1 PIN_B5
#define row2 PIN_B6
#define row3 PIN_B7
#define col0 PIN_B0
#define col1 PIN_B1
#define col2 PIN_B2
#define col3 PIN_B3

#define ALL_ROWS (row0|row1|row2|row3)
#define ALL_PINS (ALL_ROWS|col0|col1|col2|col3)

// Keypad layout:
char const KEYS[4][4] = {{'1','2','3','A'},
                         {'4','5','6','B'},
                         {'7','8','9','C'},
                         {'*','0','#','D'}};


#define KBD_DEBOUNCE_FACTOR 33 // Set this number to apx n/333 where
// n is the number of times you expect
// to call kbd_getc each second

void kbd_init()
{
set_tris_b(0xF0);
output_b(0xF0);
port_b_pullups(true); 
}

short int ALL_ROWS (void)
{
if(input (row0) & input (row1) & input (row2) & input (row3))
   return (0);
else
   return (1);
}

char kbd_getc()
{
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;

byte kchar;
byte row;

kchar='\0';

if(++kbd_call_count>KBD_DEBOUNCE_FACTOR)
  {
   switch (col)
     {
      case 0:
        output_low(col0);
        output_high(col1);
        output_high(col2);
        output_high(col3);
        break;
   
      case 1:
        output_high(col0);
        output_low(col1);
        output_high(col2);
        output_high(col3);
        break;

      case 2:
        output_high(col0);
        output_high(col1);
        output_low(col2);
        output_high(col3);
        break;

      case 3:
        output_high(col0);
        output_high(col1);
        output_high(col2);
        output_low(col3);
        break;
      }

   if(kbd_down)
     {
      if(!ALL_ROWS())
        {
         kbd_down=false;
         kchar=last_key;
         last_key='\0';
        }
     }
   else
     {
      if(ALL_ROWS())
        {
         if(!input (row0))
            row=0;
         else if(!input (row1))
            row=1;
         else if(!input (row2))
            row=2;
         else if(!input (row3))
            row=3;

         last_key = KEYS[row][col];
         kbd_down = true;
        }
      else
        {
         ++col;
         if(col==4)
            col=0;
        }
     }
   kbd_call_count=0;
  }
  set_tris_kbd(ALL_PINS);
return(kchar);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 03, 2010 1:53 pm     Reply with quote

You don't have a main() function. You need to learn how to put together
a C program, before you try to use a C compiler. Read a book or an
online tutorial on C programming.

For the kbc.c and lcd.c driver files, there is a test program available.
It's in this directory, for the CCS compiler:
c:\program files\picc\examples\ex_lcdkb.c
Notice how the program does not contain the code for the lcd or kbd.
The program just includes those files with an #include statement.

My suggestion is, start again, and first make a program to blink an LED.
Get that working. Then consider doing more.
andymarrole



Joined: 28 Sep 2010
Posts: 4

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Oct 03, 2010 9:32 pm     Reply with quote

i already have the main program...
the program is to detect which key of 4x4 keypad pressed then display on lcd.. this is my main program...

Code:


void main() {
   char k;

  lcd_init();
  kbd_init();

   lcd_putc("\fReady...\n");

   while (TRUE) {
      k=kbd_getc();
     if(k!=0)
       if(k=='*')
        lcd_putc('\f');
       else
         lcd_putc(k);
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 03, 2010 10:06 pm     Reply with quote

That's not the full program.

It's missing these lines at the top:

1. The #include line for 18F4550.h
2. The #fuses line.
3. The #use delay() line.
4. The #include line for kbd.c
5. The #include line for lcd.c

Read the first part of this thread. It explains some common mistakes:
http://www.ccsinfo.com/forum/viewtopic.php?t=42061
andymarrole



Joined: 28 Sep 2010
Posts: 4

View user's profile Send private message Yahoo Messenger

PostPosted: Mon Oct 04, 2010 5:15 am     Reply with quote

i already define all those declaration as you state in my keypad program...

Quote:
They are driver files. They are not stand-alone programs. They are
required to be included in a larger program. This is done with #include
statements.



do i need to use driver lcd.c and kbd.c in other to complete the program in lcdkb.c?? thank you
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