PDA

View Full Version : serout HEX values in lower-case?



OakGraphics
08-09-2005, 04:16 AM
Howdy Gang,

I am working with a serial to parallal lcd controller from Peter H. Anderson's website:
http://www.phanderson.com/lcd106/lcd108.html
·- actually I have the kit from the Australian company that made a pcb for it at:
http://www.oatleyelectronics.com/kits/k221.html
Together with the lcd I picked up on ebay - I have a working 4x20 serial lcd for less then 25$.

As for the kit - it does work, but I would probably use either a more packaged serial lcd, or opt for just using the lcd in parallal in the future (and opting for a basic stamp or SX with higher i/o pins to accomidate the loss of pins for parallal)

either way - it works for the most part, but I am having a little difficulty with the backlight command.
basically it accepts a parameter in 2 digit hex - but the hex must be in lower case.

THe problem is the BS2 HEX command translates to·UPPER CASE·values only. http://forums.parallax.com/images/smilies/rolleyes.gif

To demonstrate this -·here is a·quick program:

' {$STAMP BS2}
' {$PBASIC 2.5}
dimmer·VAR·Byte
Main:
····· FOR dimmer = 250 TO 255······
····· DEBUG HEX dimmer, CR
NEXT
end

the debug terminal output would look like:
FA
FB
FC
FD
FE
FF

(i.e. all uppercase)

is there a way to generate hex values in lower case? I could probably do it by comparing the high and low nibble and replacing them with lowercase versions for the letters I guess. :-?



·

Jon Williams
08-09-2005, 04:49 AM
That's a little odd that it won't accept HEX values in upper and lower case; no problem though, you can do it with a bit of code.· Here are the working bits:

HexDigits··· DATA··· "0123456789abcdef"

... which get used by this subroutine:

Send_LC_Hex:
· READ (HexDigits + theValue.NIB1), char
· SEROUT Spin, Baud, [char]
· READ (HexDigits + theValue.NIB0), char
· SEROUT Spin, Baud, [char]
· RETURN

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

OakGraphics
08-09-2005, 05:19 AM
Thanks Jon. I thought it was odd as well. I have another pic from the kits I bought and I am going to swap it out and see if it also have the same issue. I suspect a revison difference or something stupid like that.

Wow - your code is more gracefull then what I hacked together for sure. http://forums.parallax.com/images/smilies/smile.gif (see below)
In the process of finding this controller's quirkyness - I have found it needs delays of 29ms from the last text send, to the backlight command or it will crash. It further needs 1ms after the backlight command to the next ascii stream or it will crash. fun. Add that to the 5 seconds it needs for power-up (!) and you get what you paid for. I did like working with the parallax 16x2 a lot more then this one. http://forums.parallax.com/images/smilies/smile.gif I just needed more screen space and wanted to try to keep the costs down for the display. Oh well. Probably works great in parallal mode, but I intended using these on Prop-1 controllers later on.


' {$STAMP BS2}
' {$PBASIC 2.5}
lcd CON 12
baudrate CON 396 'T2400 equiv
dimmer VAR Byte
x VAR Byte

init:
SEROUT lcd, baudrate, ["starting test?n"] ' see if all commands completed and lcd is okay
PAUSE 29 ' silly thing needs at least 29ms pause before trying to use
' backlight command or further ascii will fail.

Main:
FOR dimmer = 0 TO 255
SEROUT lcd, baudrate, ["?B"]
GOSUB HexLowerCase
PAUSE 1 ' silly thing needs a pause or will not display futher text
NEXT ' but will still allow higher functions. (go figure)

SEROUT lcd, baudrate, ["Did I survive???n"] ' see if all commands completed and lcd is okay
END

HexLowerCase:
x = dimmer / 16 'first the high nibble
x=x+48 'throw it into ASCII
IF x <= 57 THEN HexLowerCase_1 'it is alphabetic; a, b, c, d, e, f
x = x+39 ' ascii values 097=a 065=A

HexLowerCase_1:
SEROUT 12, 396, [x]
x= dimmer // 16 'then the low nibble
x=x+48 'Throw it into ASCII
IF x <=57 THEN HexLowerCase_2
x=x+39 'it is alphabetic again ; a, b, c, d, e, f

HexLowerCase_2:
SEROUT 12, 396, [x]
RETURN