RS232 GLK12232-25WBL Keypad receive software

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

Post Reply
ReneeLcd
LCD?
Posts: 5
Joined: Sun Sep 24, 2006 5:57 am

RS232 GLK12232-25WBL Keypad receive software

Post by ReneeLcd »

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;
}
Raquel
Matrix Orbital
Matrix Orbital
Posts: 834
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hello Renee,

Please see the next post.
Last edited by Raquel on Mon Sep 25, 2006 10:25 am, edited 1 time in total.
Raquel Malinis
Design and Development
Matrix Orbital
Raquel
Matrix Orbital
Matrix Orbital
Posts: 834
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

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:

Code: Select all

unsigned char GetKey(void) {
  if (RC1IF)
    return RCREG1;
  else 
    return 0;	
} 

while (1) {
  if (GetKey())
    writeLCD (data);
}
Please let me know how it turns out.
Raquel Malinis
Design and Development
Matrix Orbital
ReneeLcd
LCD?
Posts: 5
Joined: Sun Sep 24, 2006 5:57 am

Still no good...

Post by ReneeLcd »

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!
Raquel
Matrix Orbital
Matrix Orbital
Posts: 834
Joined: Thu Aug 19, 2004 3:37 pm
Location: MO Office

Post by Raquel »

Hi Renee,

Is it possible that there is a hardware problem?
The reception of data, as stated in the datasheet p260, is just as how I see you have done in your code.
Raquel Malinis
Design and Development
Matrix Orbital
Post Reply