LCD output technique

adumas77

New Member
Hi... I am reading a light sensor and am having issues with writing out the data to an LCD. I have figured out 1 way to do it, but am looking at alternate techniques and commands.

symbol light w3
'read light sensor - this will be a 5 digit number
count 2, 1000, light
'put lcd in mode to receive data
rs = lcddata

After I assign the variable (light), I need to parse each digit and send it to the
lcd.

I tried to use the following Table command, but it did not like the syntax... I can't figure out why. Can someone show me what is wrong?

TABLE 0, (light) ' doesnt like this syntax / assignment

for b8 = 0 to 4
readtable b8,b9
outbyte = b9
gosub lcdout
next b8

I then tried another technique - reading in 1 character at a time and saving in each value to a different variable, and then looping again to write out the digits in correct order to the lcd. This seems a bit tedious and unsophisticated. Can someone show me another method?

Code:
'****************************************************** 
     'read digits 1 through 5
     'this reads 1 digit at a time from the right
     ' if write out immediately, number will be reversed
 
'****************************************************** for counter = 1 to 5
 
        outbyte = light // 10 + $30
 
        select case counter
            case 1 
                b8 = outbyte
            case 2 
                b9 = outbyte
            case 3 
                b10 = outbyte
            case 4 
                b11 = outbyte
            case 5 
                b12 = outbyte 
     endselect
 
        light = light / 10 
 
     next counter 
 
'******************************************** 
     'now write the number in reverse / correct order, taking up positions 1-5 
 
 
     for counter = 1 to 5
 
        select case counter
            case 1 
                outbyte = b12 
            case 2 
                outbyte = b11 
            case 3 
                outbyte = b10 
            case 4 
                outbyte = b9 
            case 5 
                outbyte = b8 
     endselect
 
        gosub lcdout
 
     next counter
 
Last edited by a moderator:

Technical

Technical Support
Staff member
First program should use " - then it will work.

Code:
TABLE 0, ("light") 
 
for b8 = 0 to 4
readtable b8,outbyte
gosub lcdout
next b8
 

adumas77

New Member
Thanks for answering... I copied in the code and ran it - but I just get a series of black boxes - I reran my program without the eeprom table entry and it works fine...

??? any ideas for debugging this?
 

adumas77

New Member
I am confused why ("light") will work. Doesn't that signify that it is essentially a hard coded string? The code below will successfully output the word light - which is not what I want... light should be a number that is received after reading the light sensor... (see my code above)...

Does it need to be converted to a decimal value? I tried #light - which of course did not work...

Also, if I use the read command, I can display an enclosed string - but not with the readtable command.

EEPROM 100, ("light")
EEPROM 105, (" aaabbb ")
EEPROM 113, ("123")

for b10 = 100 to 104
read b10,outbyte
gosub lcdout
next b10
for b10 = 105 to 112
read b10,outbyte
gosub lcdout
next b10
for b10 = 113 to 115
read b10,outbyte
gosub lcdout
next b10
 

adumas

Member
Hi Technical - or anyone else... I don't know if you read my last message, but I don't know what to do next... Can you look at that message and let me know what the problem might be?

I would appreciate it...
 

hippy

Ex-Staff (retired)
It all go too complicated for me to follow earlier but I've had time to re-read the thread ... seems it's gone all over the place. If I'm correct you want to display a number you've read into your 'light' variable on an LCD ?

Code:
symbol light = w3
count 2, 1000, light
outbyte = light / 10000       + "0" : Gosub lcdout
outbyte = light / 1000  // 10 + "0" : Gosub lcdout
outbyte = light / 100   // 10 + "0" : Gosub lcdout
outbyte = light / 10    // 10 + "0" : Gosub lcdout
outbyte = light         // 10 + "0" : Gosub lcdout
 

madguernseyboy

New Member
hiya all i am having a similar problem to adumas77

I am reciving a bad syntax error for my table command.


Code:
symbol delay = b1
delay = 0


Table 0, ("TIME")
table 8, (delay,"ms")

Why can i not show my variable into the Table command

Regards
Brendan
 

nick12ab

Senior Member
Why can i not show my variable into the Table command
The Table command isn't executed in-program but is just an instruction to the tokeniser to put the specified bytes into the table at the specified location which cannot be done with a variable because a variable changes but the table is read-only once the program starts. If you want the variable, use the LOOKUP command.

IMHO, The Table command should be a directive (#table) to avoid confusion to newbies.
 

MartinM57

Moderator
From Manual 2...

Syntax:
TABLE {location},(data,data...)
- Location is an optional constant which specifies where to begin storing the
data in the program memory table. If no location is specified, storage
continues from where it last left off. If no location was initially specified,
storage begins at 0.
- Data are byte constants (0-255) which will be stored in the table

As pointed out, you are trying to use the value of a variable, not a constant

IMHO, The Table command should be a directive (#table) to avoid confusion to newbies.
That's sounds a nice idea...after all, #NO_TABLE is a directive so it's only a small thought extension to make the definition of a table also a directive.
 

madguernseyboy

New Member
oh ic

thats why there is no info from googling online.

how do i use the Lookup command to output the variable i want to an lcd then? I am a bit confused now.

sorry.
 

nick12ab

Senior Member
how do i use the Lookup command to output the variable i want to an lcd then? I am a bit confused now.
Look in PICAXE Manual 2. It says:
Syntax:
LOOKUP offset,(data0,data1...dataN),variable
- Offset is a variable/constant which specifies which data# (0-N) to place in
Variable.
- Data are variables/constants.
- Variable receives the result (if any).
Function:
Lookup data specified by offset and store in variable (if in range).
Description:
The lookup command is used to load variable with different values. The value to
be loaded in the position in the lookup table defined by offset. In this example if
b0 = 0 then b1 will equal “a”, if b0 =1 then b1 will equal “b” etc. If offset exceeds
the number of entries in the lookup table the value of variable is unchanged.
Each lookup is limited to 256 entries, but each entry may be a bit byte of word
constant or variable.
 

madguernseyboy

New Member
Hiya

I tried this but it still doesnt work. I know its beacuse I really still dont understand. I think you for you time and help.


Code:
' *** Constants ***
	symbol enable = C.7		' LCD enable pin connected to C.7
	symbol RegSel = C.4		' LCD RegSel pin connected to C.4
	symbol UP	  = pinC.2		' UP SW connected to pin C.2
	symbol DOWN   = pinC.1		' DOWN SW connected to pin C.1
	
' *** Variables ***
	symbol char = b0			' character to be sent to LCD
	symbol index = b1			' a counter in For-Next loops
	symbol delay = b3			' delay time used for the trigger
	delay = 0			' set inital delay time for 0 ms
		
' *** Directives ***
	#com 3				' specify download port
	#picaxe 20M2			' specify processor
	#no_data				' save time downloading
	#terminal off			' disable terminal window
	
' *** Table ***
	Table 0, (" Delay  ")
	lookup 8, (delay, "ms"),b9

' *************************************************************
' ********************* Begin Main Program ********************
' *************************************************************

' *** Set up the input and output pins ***
 	dirsB = %11111111			' set all portB pins as outputs
 	dirsC = %10010001			' set C pins 65321 as inputs
'	pullup  %00000000			' internal pullup resistor not 
						' used
 	
' *** Initialize the LCD ***								 
	pause 200				' pause 200 ms for LCD Statup
	char = 56				' setup for 8-bits, 2 lines 
						' & 5X8 dots  i.e. binary 111000
 	gosub OutCmd			' send instruction to LCD
	char = 12				' display on, cursor off   
						' i.e binary 1100
	gosub OutCmd			' send instruction to LCD	

	








' *************************************************************
' *** Main Program Loop				  			***	
' *** 								  	***	
' ***	Check Sensors and buttons					***
' ***	Send data to the LCD						***
' *************************************************************

	gosub WriteLCD					' Update Display text

do

	if  UP = 1 then gosub UpButton		' if Pin UP is High
								' then add 50 ms
	if  DOWN = 1 then gosub DownButton	' if Pin DOWN is High
								' then sub 50 ms 

loop
	
' *************************************************************
' ********************* End Main Program **********************
' *************************************************************



' *************************************************************
' *********************** Subroutines *************************
' *************************************************************

' *** Write Text to LCD Screen Subroutine ***
WriteLCD:
 	char = 1				' clear display & go home	
						' i.e binary 1
 	gosub OutCmd			' send instruction to LCD
	pause 200				' waits for LCD to do command
	
 	for index = 0 to 7		' send line 1 to LCD
 	  readtable index, char		' send line one to LCD
 	  gosub OutTxt
 	next index
 	pause 200				' waits for LCD to do command
 	
	char = 192				' move cursor to start of line 2
						' i.e binary 11000000
 	gosub OutCmd			' send instruction to LCD 		
  	for index = 8 to 15		' send line 2 to LCD
 	  readtable index, char
 	  gosub OutTxt
 	next index
 	pause 1000				' waits for LCD to do command
	return



' *** OutCmd & OutTxt Subroutine ***
OutCmd:
	low RegSel				' set up for command byte
	goto Doit				' After setting up pin C.4 to 
						' send a command byte goto Doit
						' and send the Byte. after it 
						' will return to where OutCmd was
						' called
OutTxt:
	high RegSel				' set up for text byte   set up 
						' pin C.4 so send the text byte 
						' to the LCD then contimute on to
						' the Doit to send the byte. 
						' after the code returns to where
						' OutTxt was called.
Doit:
	outpinsB = char			' load byte onto outpinsB
	pulsout enable,1			' send data
	return


UpButton:
	let delay = delay + 50 		' add 50 to delay time
	gosub WriteLCD			' Update Display text
	return

DownButton:
'	if delay = "0" the return		' if delay is 0 then go back to
						' prevent getting a negitve INT
	let delay = delay - 50
	gosub WriteLCD			' Update Display text
	return
 

Texy

Senior Member
Hi,
I do things slightly different for strings :

Code:
for b1 = 0 to 15
lookup b1,("Set Timer ") ,char
gosub SendDataByte
next b1
and to send the value of a variable, eg this routine displays variable w1 :

Code:
display_celc:
BINTOASCII w1,b8,b7,b6,b5,b4 
IF b8="0" and b7 =  "0"  THEN : b7 = " "  :ENDIF      ' zero blanking b7
if b8<>"0" then
char = b8
gosub SendDataByte
endif
char = b7
gosub SendDataByte
char = b6
gosub SendDataByte
char = "."
gosub SendDataByte
char = b5
gosub SendDataByte
char = 0
gosub SendDataByte
return
Note the char 0 at the end is a user defined degree's celcius graphic defined here :

Code:
char = 64
gosub SendCmdByte
for b1 = 0 to 7
lookup b1, (40, 52, 40, 39, 40, 40, 40, 39), char ; character cgram 0 degrees c sign
gosub SendDataByte
next b1
Incidently, you will probably find your do NOT need all those 'pause 200' statements.

Hope this helps, Texy
 
Last edited:

nick12ab

Senior Member
I tried this but it still doesnt work. I know its beacuse I really still dont understand. I think you for you time and help.
You don't put the LOOKUP exactly in the same place as the TABLE command - you use it where READTABLE would have been and adapt your code for it like Texy shows.
 

madguernseyboy

New Member
thank you all

Hey all.

thank you nick12ab, MartinM57 and Texy

after sleeping on the promblem lastnight and letting the subconcius work on it. i finally understand your code and explainations.

I put here below an exerpt of my code so that any people in the future are struggling may be helped

Code:
' *************************************************************
' **********************INIALIZE THE PICAXE********************
' *************************************************************

' *** Constants ***
	symbol enable = C.7		' LCD enable pin connected to C.7
	symbol RegSel = C.4		' LCD RegSel pin connected to C.4
	symbol UP	  = pinC.2		' UP SW connected to pin C.2
	symbol DOWN   = pinC.1		' DOWN SW connected to pin C.1
	
' *** Variables ***
	symbol char = b0			' character to be sent to LCD
	symbol index = b1			' a counter in For-Next loops
	symbol delay = w6			' delay time used for the trigger
	delay = 0			' set inital delay time for 0 ms
		
' *** Directives ***
	#com 3				' specify download port
	#picaxe 20M2			' specify processor
	#no_data				' save time downloading
	#terminal off			' disable terminal window
	
' *** Table ***
	Table 0, (" Delay  ")

' *************************************************************
' ********************* Begin Main Program ********************
' *************************************************************

' *** Set up the input and output pins ***
 	dirsB = %11111111			' set all portB pins as outputs
 	dirsC = %10010001			' set C pins 65321 as inputs
'	pullup  %00000000			' internal pullup resistor not 
						' used
 	
' *** Initialize the LCD ***								 
	pause 200				' pause 200 ms for LCD Statup
	char = 56				' setup for 8-bits, 2 lines 
						' & 5X8 dots  i.e. binary 111000
 	gosub OutCmd			' send instruction to LCD
	char = 12				' display on, cursor off   
						' i.e binary 1100
	gosub OutCmd			' send instruction to LCD	

	








' *************************************************************
' *** Main Program Loop				  			***	
' *** 								  	***	
' ***	Check Sensors and buttons					***
' ***	Send data to the LCD						***
' *************************************************************

	gosub WriteLCD					' Update Display text

do
	if  UP = 1 then gosub UpButton		' if Pin UP is High
								' then add 50 ms
	if  DOWN = 1 then gosub DownButton	' if Pin DOWN is High
								' then sub 50 ms 
debug


loop
	
' *************************************************************
' ********************* End Main Program **********************
' *************************************************************



' *************************************************************
' *********************** Subroutines *************************
' *************************************************************

' *** Write Text to LCD Screen Subroutine ***
WriteLCD:
 	char = 1				' clear display & go home	
						' i.e binary 1
 	gosub OutCmd			' send instruction to LCD
	
 	for index = 0 to 7		' send line 1 to LCD
 	  readtable index, char		' send line one to LCD
 	  gosub OutTxt
 	next index
 	
	char = 192				' move cursor to start of line 2
						' i.e binary 11000000
 	gosub OutCmd			' send instruction to LCD 		
  	for index = 0 to 7		' send line 2 to LCD
 	  BINTOASCII delay, b14 ,b15,b16,b17,b18   ' the number stored in the variable delay is in binary and must be converted to ascii. each number is stored to a different variable
 	  lookup index,(b14, b15, b16, b17, b18 ," ","m","s"), char  'give the variablein the table indicated by index to the output char
 	  
 	  gosub OutTxt
 	
 	next index
	return



' *** OutCmd & OutTxt Subroutine ***
OutCmd:
	low RegSel				' set up for command byte
	goto Doit				' After setting up pin C.4 to 
						' send a command byte goto Doit
						' and send the Byte. after it 
						' will return to where OutCmd was
						' called
OutTxt:
	high RegSel				' set up for text byte   set up 
						' pin C.4 so send the text byte 
						' to the LCD then contimute on to
						' the Doit to send the byte. 
						' after the code returns to where
						' OutTxt was called.
Doit:
	outpinsB = char			' load byte onto outpinsB
	pulsout enable,1			' send data
	return


UpButton:
	let delay = delay + 50 		' add 50 to delay time
	gosub WriteLCD			' Update Display text
	return

DownButton:
'	if delay = "0" the return		' if delay is 0 then go back to
						' prevent getting a negitve INT
	let delay = delay - 50
	gosub WriteLCD			' Update Display text
	return
 
Last edited:

Texy

Senior Member
Great!
Now that the display is stable and working (it is stable, right?), you can start removing or reducing, those pause statements - you should find you need little or no pauses once the LCD is correctly initialised.

Texy
 
Top