Hi,
I recently purchased a GLK12232-25WBL LCD and am using 20 key keypad. So far things are going great and it is a really good product except for one problem.
I can send text to my LCD (I am uisng the 18f6627 pic microcontroller) using the RS232 interface and can receive keypad output using hyperterm but am unable to read my keypad output using my pic.
Is there any c code to do this. Currently I have just set up uart and then am attempting to read the contents of the recieve register and then write it back to the lcd so I can see it being displayed but nothing happens....
Any clues?
here is my code
#include "LCDtest.h"
#include <p18f6627.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "LCDtest.h"
#include <usart.h>
#include <delays.h>
#include <string.h>
#pragma config OSC = HSPLL //type of oscillator
#pragma config WDT = OFF //turning off "Watch Dog Timer"
#pragma config MCLRE = ON //enable reset pin
//#pragma config PBADEN = OFF //port B starts as digital
#pragma config LVP = OFF //low voltage programming disabled
#pragma code
void main(void)
{
char data;
init();
AutoTransmitKeyPress();
PollKeypad();
writecommand( 0x41); //autotransmit key press
while (1)
{
data= RCREG1;
writeLCD (data);
}
}
char DataRdyUSART(void)
{
if(PIR1bits.RCIF) // If RCIF is set
return 1; // Data is available, return TRUE
else
return 0; // Data not available, return FALSE
}
void init(void)
{
TXSTA = 0; // Reset USART registers to POR state
RCSTA = 0;
ADCON1 = 0x0f;
TRISCbits.TRISC7 = CLEAR;
TRISCbits.TRISC6 = SET;
SPBRG = 0x1F; // set baud rate to be 19200
TXSTA1bits.BRGH = CLEAR; //low speed baud rate gives the best result
TXSTA1bits.SYNC = CLEAR; // asynchronous
RCSTA1bits.SPEN = SET; //asynchronous
RCSTA1bits.CREN = SET; //enable reception
TXSTAbits.TXEN = 1; // Enable transmitter
RCSTAbits.SPEN = 1; // Enable receiver
}
void writeLCD (char txdata)
{
while(!TXSTA1bits.TRMT)
{
}
TXREG = txdata;
}
void writecommand( char txdata)
{
while(!TXSTAbits.TRMT)
{
}
TXREG = 0XFE; // initiat command 0xfe =254
while (!TXSTAbits.TRMT)
{
}
TXREG = txdata;
}
void SetTextInsertionPoint( char col, char row )
{
while(!TXSTAbits.TRMT)
{
}
TXREG = 0XFE; // initiat command 0xfe =254
while (!TXSTAbits.TRMT)
{
}
TXREG = 0x47;
while (!TXSTAbits.TRMT)
{
}
TXREG = col;
while (!TXSTAbits.TRMT)
{
}
TXREG = row;
}
void SetTextInsertionPointPixel( char x, char y)
{
while(!TXSTAbits.TRMT)
{
}
TXREG = 0XFE; // initiat command 0xfe =254
while (!TXSTAbits.TRMT)
{
}
TXREG = 0x79;
while (!TXSTAbits.TRMT)
{
}
TXREG = x;
while (!TXSTAbits.TRMT)
{
}
TXREG = y;
}
void InitialisBarGraph( char ref, char type , char x1, char y1, char x2, char y2)
{
while(!TXSTAbits.TRMT)
{
}
TXREG = 0XFE; // initiat command 0xfe =254
while (!TXSTAbits.TRMT)
{
}
TXREG = 0x67;
while (!TXSTAbits.TRMT)
{
}
TXREG = ref;
while (!TXSTAbits.TRMT)
{
}
TXREG = type;
while (!TXSTAbits.TRMT)
{
}
TXREG = x1;
while (!TXSTAbits.TRMT)
{
}
TXREG = y1;
while (!TXSTAbits.TRMT)
{
}
TXREG = x2;
while (!TXSTAbits.TRMT)
{
}
TXREG = y2;
}
void WriteToBarGraph( char ref, char value, char y )
{
while(!TXSTAbits.TRMT)
{
}
TXREG = 0XFE; // initiat command 0xfe =254
while (!TXSTAbits.TRMT)
{
}
TXREG = 0x69;
while (!TXSTAbits.TRMT)
{
}
TXREG = ref;
while (!TXSTAbits.TRMT)
{
}
TXREG = value;
while (!TXSTAbits.TRMT)
{
}
TXREG = y;
}
void DisplaySavedBitmap( char ref, char x, char y )
{
while(!TXSTAbits.TRMT)
{
}
TXREG = 0XFE; // initiat command 0xfe =254
while (!TXSTAbits.TRMT)
{
}
TXREG = 0x62;
while (!TXSTAbits.TRMT)
{
}
TXREG = ref;
while (!TXSTAbits.TRMT)
{
}
TXREG = x;
while (!TXSTAbits.TRMT)
{
}
TXREG = y;
}
void AutoTransmitKeyPress(void)
{
while(!TXSTAbits.TRMT)
{
}
TXREG = 0XFE; // initiat command 0xfe =254
while (!TXSTAbits.TRMT)
{
}
TXREG = 0x4f;
}
void PollKeypad(void)
{
while(!TXSTAbits.TRMT)
{
}
TXREG = 0XFE; // initiat command 0xfe =254
while (!TXSTAbits.TRMT)
{
}
TXREG = 0x26;
}
RS232 GLK12232-25WBL Keypad receive software
Hello Renee,
Thanks for posting on the forum.
Code looks good. After looking at the data sheet for PIC18F6627, the one thing I can suggest right now is a check for RC1IF which indicates that reception is complete, so something like the following:
Please let me know how it turns out.
Thanks for posting on the forum.
Code looks good. After looking at the data sheet for PIC18F6627, the one thing I can suggest right now is a check for RC1IF which indicates that reception is complete, so something like the following:
Code: Select all
unsigned char GetKey(void) {
if (RC1IF)
return RCREG1;
else
return 0;
}
while (1) {
if (GetKey())
writeLCD (data);
}
Raquel Malinis
Design and Development
Matrix Orbital
Design and Development
Matrix Orbital
Still no good...
Still nothing! I know my keypad is working because it works with hyperterm, there must be something wrong with my receive setup in my pic, anymore suggestions? Does anyone else have some working code?
This is frustrating!
This is frustrating!