LK162A-4T-TCI

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

Moderators: Henry, Mods

Post Reply
Dvlindskyz
LCD?
Posts: 6
Joined: Wed May 07, 2014 9:00 pm

LK162A-4T-TCI

Post by Dvlindskyz »

Hello -

I am having troubles setting and using the keypad on the LK162A-4T-TCI. Unfortunately the manual is sort of vague and unclear to me with the key up key down descriptions. Does key down mean "key pressed"? When using the "Assign Keypad Code", I'd like to set these to single digits values when the buttons are pressed. Are these values remembered when the LCD power is cycled or does it always have to be reassigned?

For simple example, would the code look like this to reassign button values on keys(assuming Dec C-coding):

...
putc(254);
putc(213);
putc(new_value_dn1); // orig value 41
putc(new_value_dn2); // orig value 42
putc(new_value_dn3); // orig value 43
putc(new_value_dn4); // orig value 44
putc(new_value_up1); // orig value 61
putc(new_value_up2); // orig value 62
putc(new_value_up3); // orig value 63
putc(new_value_up4); // orig value 64
...

I'm unsure the BIG 'A', little 'a' keypress up/down also??

Sorry.. the LCD documentation is just very vague and unclear, at least to me...

Thank in advance for any help!

Tino
Matrix Orbital
Matrix Orbital
Posts: 158
Joined: Wed May 22, 2013 9:04 am
Location: Matrix Orbital

Re: LK162A-4T-TCI

Post by Tino »

Hi,

Thank you for posting on our forums!

When a key is pressed the manual does describe this as "Key Down" and "Key Up" for when the key is released.

When you are assigning the Key values the values will always be remembered. You can see what commands are remembered and which are not in the Appendix of the manual.

Your code looks correct. When sending the "Assign Keypad Code" command you will send the four values for Key down followed by the four values for Key up.

The Key press up/down for the first button is 'A' as down and 'a' as up.

I hope this helps.
If you have any other questions or concerns please feel free to ask.
Thank you
Martino
Martino DeLeon
Matrix Orbital
Technical Support Representative

Dvlindskyz
LCD?
Posts: 6
Joined: Wed May 07, 2014 9:00 pm

Re: LK162A-4T-TCI

Post by Dvlindskyz »

Thank you for the input. It appears that this has worked correctly. As far as broadcasting the keypress value once assigned, I am using rs232 for my screen, would it be easiest to read this value using getc() including <stdio.h> or what is the suggested method? Thanks again for the help!

Tino
Matrix Orbital
Matrix Orbital
Posts: 158
Joined: Wed May 22, 2013 9:04 am
Location: Matrix Orbital

Re: LK162A-4T-TCI

Post by Tino »

Hi,

It would be completely up to you, whichever works best for your system. Currently I myself am using ReadFile to get my key presses.

Thanks again for posting on our forums.
Martino
Martino DeLeon
Matrix Orbital
Technical Support Representative

Dvlindskyz
LCD?
Posts: 6
Joined: Wed May 07, 2014 9:00 pm

Re: LK162A-4T-TCI

Post by Dvlindskyz »

This would be a good way a person is using a windows platform (computer) or the windows.h include I'd imagine? But if you are using a standalone PIC uC, then what would be the suggested method code? I'm not sure the readfile would be the best way?

Tino
Matrix Orbital
Matrix Orbital
Posts: 158
Joined: Wed May 22, 2013 9:04 am
Location: Matrix Orbital

Re: LK162A-4T-TCI

Post by Tino »

Hi Dvlindskyz,

I am using a Windows based computer yes.

There isn't really a suggested method, the method is totally up to you.
I was just giving you an example as to how I am getting my key press values.

Martino
Martino DeLeon
Matrix Orbital
Technical Support Representative

Dvlindskyz
LCD?
Posts: 6
Joined: Wed May 07, 2014 9:00 pm

Re: LK162A-4T-TCI

Post by Dvlindskyz »

Thank you for the info Tino. I am having troubles reading in these values using a PIC 16F876A uC and this LCD keypad over serial rs232. I know I must be missing something but not sure what. I don't know if you or anyone has some example C-code on what it should look like to assign the correct key press to a variable in C to use in a program?

Dvlindskyz
LCD?
Posts: 6
Joined: Wed May 07, 2014 9:00 pm

Re: LK162A-4T-TCI

Post by Dvlindskyz »

PS - I am using the #USE RS232() to set the serial port with my CCS PCM Compiler. Just an FYI. :)

Dvlindskyz
LCD?
Posts: 6
Joined: Wed May 07, 2014 9:00 pm

Re: LK162A-4T-TCI

Post by Dvlindskyz »

Anyone have some ideas for me that may help?

Tino
Matrix Orbital
Matrix Orbital
Posts: 158
Joined: Wed May 22, 2013 9:04 am
Location: Matrix Orbital

Re: LK162A-4T-TCI

Post by Tino »

Hi Dvlindskyz,

Sorry for the delay. Here is some example code that should be of some help to you.

I am using the default values for the keys.

Thank you
Martino

Code: Select all

#include <Windows.h>
#include <stdint.h>
#include <stdio.h>
#include <conio.h>

DWORD bytes = 0;
DWORD bytes_written = 0;
HANDLE port;
char key_press[] = { 0 };

void clearscreen()
{
	char command[2] = { 254, 88 };
	WriteFile(port, command, sizeof(command), &bytes_written, NULL);
}

void autokeytxoff()
{
	char command[2] = { 254, 79 };
	WriteFile(port, command, sizeof(command), &bytes_written, NULL);
}

int PollKeyPress(char key[])	//Send the poll command and read a 1 byte response, report errors
{
	char command[] = { 254, 38 };
	WriteFile(port, &command, sizeof(command), &bytes, NULL);
	return (ReadFile(port, key, sizeof(key), &bytes, NULL));

}

void Example()
{
	
	char* message[] = { "A Key", "B Key", "C Key", "D Key" };
	PollKeyPress(key_press);
	switch (key_press[0])
	{
	case 'A': //Up
		clearscreen();
		WriteFile(port, message[0], strlen(message[0]), &bytes_written, NULL);
		key_press[0] = 0;
		break;
	case 'B': //Down
		clearscreen();
		WriteFile(port, message[1], strlen(message[1]), &bytes_written, NULL);
		key_press[0] = 0;
		break;
	case 'C':  //Top Right
		clearscreen();
		WriteFile(port, message[2], strlen(message[2]), &bytes_written, NULL);
		key_press[0] = 0;
		break;
	case 'D': //Bottom Right
		clearscreen();
		WriteFile(port, message[3], strlen(message[3]), &bytes_written, NULL);
		key_press[0] = 0;

	default:
		key_press[0] = 0;
		break;
	}
}

int main(int argc, char ** argv)
{
	DCB serial_parameters = { 0 };	//Sturcture for serial port parameters
	COMMTIMEOUTS serial_timeouts = { 0 };	//Sturcture for serial port timeout parameters

	fprintf(stderr, "C Example LK Test\n");
	port = CreateFile("\\\\.\\COM3", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

	if (port == INVALID_HANDLE_VALUE)
	{
		DWORD error_code = GetLastError();
		fprintf(stderr, "Error opening port!\n");
		system("pause>nul");
		return 1;
	}
	serial_parameters.DCBlength = sizeof(serial_parameters);
	if (GetCommState(port, &serial_parameters) == 0)
	{
		fprintf(stderr, "Error getting port state!\n");
		CloseHandle(port);
		system("pause>nul");
		return 1;
	}
	serial_parameters.BaudRate = CBR_19200;
	serial_parameters.ByteSize = 8;
	serial_parameters.Parity = NOPARITY;
	serial_parameters.StopBits = ONESTOPBIT;
	if (SetCommState(port, &serial_parameters) == 0)
	{
		fprintf(stderr, "Error setting port state!\n");
		CloseHandle(port);
		system("pause>nul");
		return 1;
	}
	serial_timeouts.ReadIntervalTimeout = 100;
	serial_timeouts.ReadTotalTimeoutConstant = 100;
	serial_timeouts.ReadTotalTimeoutMultiplier = 10;
	serial_timeouts.WriteTotalTimeoutConstant = 100;
	serial_timeouts.WriteTotalTimeoutMultiplier = 10;
	if (SetCommTimeouts(port, &serial_timeouts) == 0)
	{
		fprintf(stderr, "Error setting port timeouts!\n");
		CloseHandle(port);
		system("pause>nul");
		return 1;
	}
	autokeytxoff();

	do
	{
		Example();
	} 
	while (1);

}
Martino DeLeon
Matrix Orbital
Technical Support Representative

Post Reply