Want to use OLED character location stored in variable

wapo54001

Senior Member
I want to write a two digit number to an AXE033Y at various locations on the two lines, and define that location with a value stored in a byte variable.

The code is

Code:
   SEROUT C.7,N2400_16, (254,1) 'clear display
   PAUSE 1000
   SEROUT C.7,N2400_16, (254,#OLEDAddr,#DispVal) 
   PAUSE 500
I have tried OLEDAddr both with, and without the # sign, and neither work, I get jibberish. When I substitute a plain number for #OLEDAddr -- for example "130" it works fine. I must be formatting it wrong, but I cannot see how. DispVal works perfectly with the "#" sign. Can anyone help?
 

inglewoodpete

Senior Member
I think you've already answered your own question. SerOut.....#130 will send three characters "1", "3" and "0".

Since you want the byte value 130, you would do something like:

Code:
SEROUT C.7,N2400_16, (254,130,#DispVal)
- or -
Code:
b10 = 130
SEROUT C.7,N2400_16, (254,b10,#DispVal)
- or -
Code:
Symbol OLEDLocn = b10
OLEDLocn  = 130
SEROUT C.7, N2400_16, (254, OLEDLocn , #DispVal)
(syntax not checked)
 
Last edited:

wapo54001

Senior Member
I think I've tried this six different ways about ten times each and I can't get it to work. One bewildering thing -- I preset OLEDAddr1 & 2 in setup with values 128 and 192 but as I watch the values in terminal, the values seem to ignore the entered values and start counting up from zero. What's with that??

I have tried this using OLEDAddr1, #OLEDAddr1, b24, and #b24. I'm beginning to think that I can't use a variable in a display command.

Can anyone say what's wrong with this code? I've been at this for days now. (Timer is set short for troubleshooting and DisplayON controls when this code operates)

Code:
‘initialize
b24 = 128 'OLEDAddr1 = 128
b25 = 192 'OLEDAddr2 = 192

	IF Timer > 100 AND DisplayON = False THEN 
		
		SEROUT C.7,N2400_16, (254,1) 'clear display
		PAUSE 60
		SEROUT C.7,N2400_16, (254,b24,#DispVal) '
		PAUSE 1000
		SEROUT C.7,N2400_16, (254,1) 'clear display
		PAUSE 60
		SEROUT C.7,N2400_16, (254,b25,#DispVal) '
		PAUSE 1000		
		SEROUT C.7,N2400_16, (254,1) 'clear display
		PAUSE 1000

	SERTXD("b24&25 ",#b24," ",#b25,cr,lf)

		IF b24 < 143 THEN
			b24 = b24 + 1
		ELSEIF b24 = 143 THEN
				b24 = 128
		ENDIF

		IF b25 < 207 THEN
			b25 = b25 + 1
		ELSEIF b25 = 207 THEN
				b25 = 192
		ENDIF

	ENDIF
 

inglewoodpete

Senior Member
You certainly can use a variable to supply a character location. I have done this in many projects, although I don't often use serial comms for LCDs.

The issue may be speed of transmission. Try this:
Code:
b24 = 128
SEROUT C.7,N2400_16, (254, b24)
SEROUT C.7,N2400_16, (#DispVal)
The little gap in sending may be enough to allow the display driver to keep up. (Forget about sending #b24 - the data format will be wrong.)
 

geoff07

Senior Member
What data are you trying to write?

To write a digit 1, for example, you would have

Dispval = 1: serout #Dispval (pseudocode). So the # adds 48 to the value and displays ASCII '1' (code 49)

But this only works if the initial values convert to something that can be displayed. So I would log Dispval to sertxd and see what values you actually have and what they translate to.
 

hippy

Technical Support
Staff member
One bewildering thing -- I preset OLEDAddr1 & 2 in setup with values 128 and 192 but as I watch the values in terminal, the values seem to ignore the entered values and start counting up from zero. What's with that??
My guess would be; initialisation not being called or something later setting the variables to zero.
 
Top