View Full Version : Hserin/out BYVAC serial LCD
RFsolution
- 6th November 2014, 22:16
Hi all
I'm trying to interface a serial LCD by byvac with keypad via HSERIN/OUT
http://www.byvac.com/index.php/BV4619
but have the following problem
If I want to read a "keypress" ,following the datasheet i need to send:
rg(carriage return)
if no key is pressed i get the following back from the LCD module 0ack in hex (30 06)
if a key is pressed it returns 4 bytes example key 1 pressed it returns 238ack (hex 32 33 38 06)
how can i handle for eaxmple the STR hserin function to check if a key is pressed = 4 bytes returned or unpressed 2 bytes returned
Thanks
aerostar
- 8th November 2014, 07:22
From the looks of it you have a terminator character 06, so use the STR see manual
"STR followed by a byte array variable, count and optional ending character will receive a string of characters. The string length is determined by the count or when the optional character is encountered in the input."
So regardless of how many characters you are expecting put into the command the MAX COUNT characters it will return and then the optional ending character.
Then all you need to do is look down the array and pick out the value you need - the 06 is the terminator.
RFsolution
- 8th November 2014, 16:03
From the looks of it you have a terminator character 06, so use the STR see manual
"STR followed by a byte array variable, count and optional ending character will receive a string of characters. The string length is determined by the count or when the optional character is encountered in the input."
So regardless of how many characters you are expecting put into the command the MAX COUNT characters it will return and then the optional ending character.
Then all you need to do is look down the array and pick out the value you need - the 06 is the terminator.
Thanks aerostar
something like this:
get_key:
hserout ["rg", 13]
Hserin 1000, start, [STR char\4\$06] '
pause 10
if char[0] = $30 then
goto get_key
endif
char[0] = char[0] - %110000
char[0] = char[0] << 6
char[1] = char[1] - %110000
char[1] = char[1] << 4
char[2] = char[2] - %110000
b0 = char[0]+char[1]+char[2]
lookdown b0, [101,184,183,181,162,161,153,208,201,199,177,149,19 5,89,102,99],keypressed
hserout ["rdkey= "dec keypressed,13,10]
pause 10
return
is it possible to simplify the pressed key number ?
aerostar
- 8th November 2014, 20:48
Thing to do is try it and see if it works ! I do not see 238 in your lookdown table, you said key 1 returns 238
converting your bytes so
char(0)=$32
char(1)=$33
char(2)=$38
char(0) = (char(0)-$30) * 100 'answer 200
char(1) = (char(1)-$30) * 10 'answer 30
char(2) = char(2)-$30 'answer 8
b0 = char(0)+char(1)+char(2) 'answer 238
compiles but not tested !
RFsolution
- 8th November 2014, 21:13
Hi
Thanks for the char handling
thisone is working perfectly
hserout ["rg", 13]
Hserin 1000, start, [STR char\4\$06] ' Get a char from serial port
pause 10
if char[0] = $30 then
goto get_key
endif
char(0) = (char(0)-$30) * 100 'answer 200
char(1) = (char(1)-$30) * 10 'answer 30
char(2) = char(2)-$30 'answer 8
serout2 tx,84,[dec char[0]," ",dec char[1]," ",dec char[2],13,10]
b0 = char[0]+char[1]+char[2]
serout2 tx,84,[dec b0,13,10]
lookdown b0, [125,238,237,235,222,221,219,190,189,187,231,215,18 3,119,126,123],keypressed
serout2 tx,84,[dec keypressed,13,10]
pause 10
Hserout ["rc1", 13] ' Send text followed by carriage return and linefeed
pause 10
Hserout ["rd","key= ",dec keypressed,13]
'keypressed = 0
pause 10
return
aerostar
- 9th November 2014, 20:41
If this is in a subroutine and get_key is not in the subroutine then you will get problems by not using RETURN, do not jump out of a subroutine.
if char[0] = $30 then
goto get_key
endif
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.