Using LCD display with PICAXE-20M

peg

Member
Hi
I am using the PICAXE 20M project board. The LCD is connected to B4 and I am using C3 as an input. I get the stand PICAXE message on the LCD display when I have 2 power supplies (linked negative rail). I have run a code in basic on PICAXE.

C3 is pulled low with RA1.

I either get random symbols or a blank screen.

Thanks for any support

#picaxe 20M2
symbol inputPin = C.3 ' Define input pin
symbol lcdPin = B.4 ' Define LCD output pin
b0 = 0 ' Initialize counter variable

main:
if pinC.3 = 1 then ' Check if input is high
pause 200 ' Debounce delay
if pinC.3 = 1 then ' Confirm input is still high
if b0 < 20 then ' Count only up to 20
inc b0 ' Increment the counter
else
b0 = 0 ' Reset counter to 0 after reaching 20
endif
serout lcdPin, N2400, (254, 1) ' Clear LCD
serout lcdPin, N2400, ("Count: ")
serout lcdPin, N2400, (#b0) ' Display count on LCD
do while pinC.3 = 1 : loop ' Wait until input goes low
endif
endif
goto main ' Repeat loop
 
peg,

The AXE133 manual specifies a 'pause 30' command after sending 254, 1 to the LCD:
254,1 Clear Display (must be followed by a ‘pause 30’ command)

The LCD takes some time to execute the 254,1 command and will not respond to any commands that are sent too soon after 254, 1 so try adding the 'pause 30'.
 
Hi
I include and now can count to 2 but then blank screen.
But at least got something.
Thanks



#picaxe 20M2
symbol inputPin = C.3 ' Define input pin
symbol lcdPin = B.4 ' Define LCD output pin
b0 = 0 ' Initialize counter variable



main:
if pinC.3 = 1 then ' Check if input is high
pause 200 ' Debounce delay
if pinC.3 = 1 then ' Confirm input is still high
if b0 < 20 then ' Count only up to 20
inc b0 ' Increment the counter
else
b0 = 0 ' Reset counter to 0 after reaching 20
endif
serout lcdPin, N2400, (254, 1) ' Clear LCD
pause 30
serout lcdPin, N2400, ("Count: ")
serout lcdPin, N2400, (#b0) ' Display count on LCD
do while pinC.3 = 1 : loop ' Wait until input goes low
endif
endif
goto main ' Repeat loop
 
Hi,
Try this in the simulator.
Good luck...........

#picaxe 20M2
symbol inputPin = C.3 ' Define input pin
symbol lcdPin = B.4 ' Define LCD output pin
b0 = 0 ' Initialize counter variable

main:
if pinC.3 = 1 then ' Check if input is high
pause 200 ' Debounce delay
if pinC.3 = 1 then ' Confirm input is still high
inc b0 ' Increment the counter ;<<<<<<<<<<<<<<<<<
if b0 < 20 then ' Count only up to 20
else
b0 = 0 ' Reset counter to 0 after reaching 20
endif
serout lcdPin, N2400, (254, 1) ' Clear LCD
pause 30
serout lcdPin, N2400, ("Count: ")
serout lcdPin, N2400, (#b0) ' Display count on LCD
do while pinC.3 = 1 : loop ' Wait until input goes low
endif
endif
goto main ' Repeat loop
 
Thank you
Yes this works - However (sorry) as the count increase it moves to the right of the screen so for example you can read count 1, count 2 is middle of screen count 3 you just see 'count' then blank screen and then count 11 appears at bottom of screen then count 12 is just count and blank until count 18 appears at top of screen. Should I have serout lcdPin, N2400, (254, 1) ' Clear LCD between each count to clear LCD of previous count?
Thanks
 
Peg,

The text you write to the LCD is written at the current cursor position.
The serout (254,1) command clears the screen and sets the current cursor position to the first column of the first row.

The code you put into this thread in posts #1 and #4 and the code The Bear put into post #5 all have the following sequence of serout commands that clear the screen and set the the current cursor position to the first column of the first row every time before writing the new count text:
Code:
serout lcdPin, N2400, (254, 1) ' Clear LCD
pause 30
serout lcdPin, N2400, ("Count: ")
serout lcdPin, N2400, (#b0) ' Display count on LCD

After the 1st count 0 is written the cursor is positioned at the column after the "0" character on row 1.

The behaviour you describe in your post #6 matches what I would expect to see if the serout (254, 1) command had been moved to only be run once at the start of the program.

If you don't erase the previous text or re-position the cursor to overwrite the previous text the each time you write another count then the next count text will be written starting at the next character on the screen after the end of the previous count text and you will get the text "Count:0Count:1Count:2" etc until the text is written beyond the 16 characters displayed on the first line and then wraps around to continue displaying the counts on line 2.

Try re-loading the code from post #5.
 
Last edited:
Peg,

For my testing I've created this simpler version of the program that just increments the count every 1 second, so try loading this onto your 20M2.
Code:
symbol lcdPin = B.4 ' Define LCD output pin
b0 = 0 ' Initialize counter variable

main:
    serout lcdPin, N2400, (254, 1) ' Clear LCD
    pause 30
    serout lcdPin, N2400, ("Count: ")
    serout lcdPin, N2400, (#b0) ' Display count on LCD
   
    pause 1000
    inc b0
goto main ' Repeat loop

When I run this code it correctly displays your count text starting at the first column of the first row of the LCD with an increasing count value.
 
Back
Top