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

Help with 4x3 Keypad, LCD and PIC16F877A

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



Joined: 18 Mar 2010
Posts: 9

View user's profile Send private message

Help with 4x3 Keypad, LCD and PIC16F877A
PostPosted: Thu Mar 18, 2010 9:02 pm     Reply with quote

I have a problem trying to connect a 4x3 keypad to a LCD using a PIC 16F877A. I can't get the data from the keyboard. Accompanied by the code and diagram on ISIS, maybe you can help me.
Code:

#include <16f877a.h>                      //PIC utilizado
#fuses HS,NOWDT,NOPROTECT,NOLVP           //Configuramos los fuses
#use delay (clock=4000000)                //Oscilador a 4Mhz
#INCLUDE "lcd.c"                         //Incluyo LCD.C
#INCLUDE "kbd.c" 

void lcd_mostrar(void);

#define use_portb_kbd TRUE

void main(void)
{
port_b_pullups(TRUE);
kbd_init();
lcd_init();
lcd_mostrar();
}


void lcd_mostrar(void)
{
char c=0;

while(TRUE){               // Bucle infinito
   do{                     // Espera hasta...
      c=kbd_getc();
   }while(c==0);           //...pulsar una tecla

   lcd_gotoxy(1,1);
   lcd_putc(c);            // Muestra tecla pulsada en lcd
   lcd_putc("\b"); 
}

}


PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 18, 2010 10:52 pm     Reply with quote

Quote:

lcd_gotoxy(1,1);
lcd_putc(c); // Muestra tecla pulsada en lcd
lcd_putc("\b");
}

That's not the correct way to send a control character with lcd_putc().
You need to use single quotes. Example:
Code:

lcd_putc('\b');
elektronische



Joined: 18 Mar 2010
Posts: 9

View user's profile Send private message

PostPosted: Sat Mar 20, 2010 6:57 pm     Reply with quote

I did change that, but still doesn't works! any other suggestion? thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 1:21 pm     Reply with quote

There is another problem with your code. The #define statement below
in your code, affects all the code that occurs after it. You want
it to affect the kbd.c driver, but it will not, because you put it after the
#include "kbd.c" line.
Quote:

#include <16f877a.h> //PIC utilizado
#fuses HS,NOWDT,NOPROTECT,NOLVP //Configuramos los fuses
#use delay (clock=4000000) //Oscilador a 4Mhz
#INCLUDE "lcd.c" //Incluyo LCD.C
#INCLUDE "kbd.c"

void lcd_mostrar(void);

#define use_portb_kbd TRUE


You need to move it above the #include "kbc.c" line, as shown below:
Quote:

#include <16f877a.h> //PIC utilizado
#fuses HS,NOWDT,NOPROTECT,NOLVP //Configuramos los fuses
#use delay (clock=4000000) //Oscilador a 4Mhz

#INCLUDE "lcd.c" //Incluyo LCD.C
#define use_portb_kbd TRUE
#INCLUDE "kbd.c"

void lcd_mostrar(void);

Then the keypad code will be configured to run on Port B.
elektronische



Joined: 18 Mar 2010
Posts: 9

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 1:54 pm     Reply with quote

Finally it works !!

Thanks for the clarification about define the Port B.
saqi



Joined: 24 Mar 2010
Posts: 2

View user's profile Send private message

PostPosted: Wed Mar 24, 2010 1:11 am     Reply with quote

I have made the hardware for this coding. It is working on Proteus but
does not work on the hardware. Plz give me some suggestions. I am new
in this. I don't know about coding.
Thank you Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 24, 2010 12:56 pm     Reply with quote

The Proteus schematic doesn't show a crystal (with 22 pf capacitors), or
an MCLR pull-up resistor (10K ohms). It doesn't show power and ground
connections (Vdd and Vss) to the PIC. It doesn't show a 100 nF (0.1 uF)
capacitor between each Vdd pin and ground.

All of these things are necessary in the real world.
saqi



Joined: 24 Mar 2010
Posts: 2

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 4:33 pm     Reply with quote

still not working Sad i have an idea about the basic circuit of pic but its not working
elektronische



Joined: 18 Mar 2010
Posts: 9

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 5:18 pm     Reply with quote

saqi wrote:
still not working Sad i have an idea about the basic circuit of pic but its not working


Are you sure that the pins order in the keypad is the correct?
smanzer



Joined: 14 Sep 2009
Posts: 24
Location: Ontario, Canada

View user's profile Send private message Visit poster's website

Did you try flex_KBD.c?
PostPosted: Mon Apr 05, 2010 7:43 pm     Reply with quote

Just a thought, I use a derivative of the flex_KBD.c for some of my projects.

I have modified it to use a buffer for keys, and call:

Key=kbd_getc(); in the #int_rtcc real time clock interrupt. This gets called 38 times per second and works perfectly.

Originally, I was not calling the kbd_getc() often enough...

Hope you get it going, a keypad with LCD and RS232 terminal make coding/debugging and using it so much nicer.

Cheers!

Steven
_________________
"I am always doing that which I can not do, in order that I may learn how to do it."
- Pablo Picasso
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