View previous topic :: View next topic |
Author |
Message |
elektronische
Joined: 18 Mar 2010 Posts: 9
|
Help with 4x3 Keypad, LCD and PIC16F877A |
Posted: Thu Mar 18, 2010 9:02 pm |
|
|
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");
}
}
|
![](http://img228.imageshack.us/img228/3786/keypad.png) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 18, 2010 10:52 pm |
|
|
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:
|
|
![](templates/subSilver/images/spacer.gif) |
elektronische
Joined: 18 Mar 2010 Posts: 9
|
|
Posted: Sat Mar 20, 2010 6:57 pm |
|
|
I did change that, but still doesn't works! any other suggestion? thanks |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 21, 2010 1:21 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
elektronische
Joined: 18 Mar 2010 Posts: 9
|
|
Posted: Sun Mar 21, 2010 1:54 pm |
|
|
Finally it works !!
Thanks for the clarification about define the Port B. |
|
![](templates/subSilver/images/spacer.gif) |
saqi
Joined: 24 Mar 2010 Posts: 2
|
|
Posted: Wed Mar 24, 2010 1:11 am |
|
|
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](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 24, 2010 12:56 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
saqi
Joined: 24 Mar 2010 Posts: 2
|
|
Posted: Wed Mar 31, 2010 4:33 pm |
|
|
still not working i have an idea about the basic circuit of pic but its not working |
|
![](templates/subSilver/images/spacer.gif) |
elektronische
Joined: 18 Mar 2010 Posts: 9
|
|
Posted: Wed Mar 31, 2010 5:18 pm |
|
|
saqi wrote: | still not working 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? |
|
![](templates/subSilver/images/spacer.gif) |
smanzer
Joined: 14 Sep 2009 Posts: 24 Location: Ontario, Canada
|
Did you try flex_KBD.c? |
Posted: Mon Apr 05, 2010 7:43 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|