View previous topic :: View next topic |
Author |
Message |
thinkpositivex Guest
|
KEYPAD + LCD |
Posted: Tue Dec 29, 2009 6:15 pm |
|
|
I'm doing a project to measure the condition of the 12v battery and display at LCD using LCD VOLTMETER application. This part already done. After this part I want to implement a keypad part that capable the user enter the value of the rated voltage battery and display the voltage at LCD also.
My question is what kind of main command that I should used to interrupt the part of LCD voltmeter. I want to used the keypad 4x4 for this project. Can you all help me... |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
|
warriorfenix
Joined: 29 Dec 2009 Posts: 8 Location: España
|
|
Posted: Thu Dec 31, 2009 11:31 am |
|
|
I hope this code help you with your doubts, not exactly what you want but you will serve
Code: | #include <16f873a.h>
#include <lcd2.c>
#fuses XT, NOWDT
#use delay(clock=4000000)
const int escala = 255;
const float v_max = 5.0;
int valor;
float voltaje;
void calcula_voltaje (int val, float &voltaje) //Funcion conversión pzra conseguir voltaje
{
voltaje=(val*v_max)/escala;
}
void conversor()
{
setup_adc(adc_clock_div_32); //Enciende conversor
setup_adc_ports(ra0_ra1_ra3_analog); //Selecciona los puertos
set_adc_channel(3); //Selecciona canal
valor=read_adc(); //Conversión AD almacenada en valor
calcula_voltaje(valor,voltaje); //Llamamos a la funcion de conversión
setup_adc(adc_off); //Apaga el conversor
setup_adc_ports(no_analogs); //Configura terminales como digitales
}
main() //Programa principal
{
while(1) //Bucle
{
conversor(); //Llamamos al conversor para realizar la medida y lo apagamos
lcd_init(); //Inicializamos la lcd y representamos el valor
lcd_putc("voltios = ");
lcd_gotoxy(16,1);
lcd_putc("V");
lcd_gotoxy(11,1);
printf(lcd_putc,"%1.2f",voltaje);
}} |
|
|
|
thinkpositivex Guest
|
|
Posted: Thu Jan 07, 2010 8:39 pm |
|
|
I'm using PIC 16f877a, and ccs compiler 4.084 version.
For your information I already run 1 example program from this forum that consist of keypad and driver. My problem is why my lcd is active low after execute. I used the driver keypad and lcd from program files and loaded to this program.
Code: |
#include <16f877a.h>
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#include <LCD.C>
#include <KBD.C>
void main()
{
char c;
lcd_init();
kbd_init();
while(TRUE)
{
c=kbd_getc();
if(c!=0)
if(c=='*')
lcd_putc('\f');
else
lcd_putc(c);
}
}
|
The lcd connection:
Code: |
RD0 - E
RD1 - R/S
RD2 - R/W
RD3 - no connection
RD4-D4
RD5-D5
RD6-D6
RD7-D7
|
For keypad connection I refer from keypad driver using port B, added with 10K resistor at row.
Code: |
#define COL0 (1 << 5)
#define COL1 (1 << 6)
#define COL2 (1 << 7)
#define ROW0 (1 << 1)
#define ROW1 (1 << 2)
#define ROW2 (1 << 3)
#define ROW3 (1 << 4)
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 08, 2010 1:55 pm |
|
|
In a previous thread, you said you're using Proteus. Post your Proteus
schematic on a free image posting website. Then post a link to it, so we
can look at it. |
|
|
thinkpositivex23
Joined: 20 Dec 2009 Posts: 7
|
circuit picture |
Posted: Wed Jan 13, 2010 8:46 am |
|
|
|
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Wed Jan 13, 2010 10:10 am |
|
|
I compared that circuit diagram to the LCD wiring in one of my projects, and I had pin 1 of the LCD connected to GND, where you have it going to VCC. Are you sure this is right? Also, the 4-bit mode of operation of the LCD is fine and it's what I used, but you should connect the unused input pins to GND. And finally, I had an unpleasant surprise when I changed to a different brand of LCD. The display was invisible when the LCD pin 3 (contrast setting) was grounded. I had to wire up a voltage divider between GND and VCC before I could see anything. So beware. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 13, 2010 2:51 pm |
|
|
LCD's have internal pullups on the unused data bus pins (DB0-DB3), so
they're not floating. You don't have to connect them to ground.
Connect the Vdd pin on the LCD to power, and the Vss pin to ground.
Then it will probably work. |
|
|
thinkpositivex Guest
|
|
Posted: Wed Jan 13, 2010 9:41 pm |
|
|
I already try what you are suggest...but it could not operated also.
Can you help me? I think it caused by the coding. Maybe the driver for the LCD or KEYPAD must be altered before execute this circuit. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 13, 2010 9:52 pm |
|
|
You're using the CCS keypad driver, not the flex keypad driver.
In that case, you need to tell it to use Port B. The #define statement
must be above the #include statement for the KBD.C file.
Quote: |
#include <16f877a.h>
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#define use_portb_kbd TRUE
#include <LCD.C>
#include <KBD.C>
void main()
{
char c; |
|
|
|
thinkpositivex Guest
|
thanks...PCM programmer |
Posted: Wed Jan 13, 2010 10:50 pm |
|
|
Thank you very much. I have 1 question, if I want to change the keypad to the 4x4 keypad, can you teach me how to alter the CCS keypad driver ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
thinkpositivex Guest
|
keypad |
Posted: Thu Feb 04, 2010 9:09 am |
|
|
I already learn the command for the keypad...
but I want to know the command which, the user capable to enter 2.54 v using keypad and display to LCD. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
thinkpositivex Guest
|
FLOATING KEYPAD |
Posted: Thu Feb 04, 2010 9:04 pm |
|
|
I'm new to this forum but I am willing to learn. Rolling Eyes.
If user enter on the keypad:
12.50 ( 1 2 dot 5 0 )
- How to format entered number so that it's 12.50 and not 1 2 . 5 0 or something in this matter ?
I already search the link, and I do not understand the answer of this question.
Can you explain to me.....how can we determine either the keypad is floating keypad or normal keypad? |
|
|
|