Serial LCD problems
crcordill
Posts: 29
Hey guys I'm having trouble with my LCD screen. What I have going on here, is that I have 1 cog run a timer. I hold down a button on pin 21 and I count to see how long I hold it down. I can run it without the WriteLCD method, and it seems to work without a hitch. Any suggestions would be helpful. Thanks. Please note that I am new, and I have looked on the forum for help. Here is the code that I have written:
''CountLCD
'' Counts how long the button is pressed for and
'' displays it on the LCD
CON
LCD_Pin = 0 'The LCD is connected to pin A0.
LCD_Baud = 19_200 'Baud
LCD_Lines = 2 'The number of lines on this LCD
Off = 0
On = 1
OBJ
LCD: "Debug_lcd"
VAR
LONG stack[noparse][[/noparse]50]
BYTE TOG
PUB Main
TOG := 0
cognew(Countdown, @stack[noparse][[/noparse]0])
cognew(Button, @stack[noparse][[/noparse]10])
PUB Countdown
dira[noparse][[/noparse]1..5]~~
outa[noparse][[/noparse]1..5]~~
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %111110
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %111100
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %111000
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %110000
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %100000
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5]~
TOG := 1
PUB Button | count1, count2, count
count1 := 0
count2 := 0
dira[noparse][[/noparse]21]~ 'Set pin 21 to input
dira[noparse][[/noparse]6]~~ 'Set pin 6 to output
outa[noparse][[/noparse]6]~
repeat while TOG == 0
repeat while ina[noparse][[/noparse]21] == 0
count1 := cnt
repeat while ina[noparse][[/noparse]21] == 1
outa[noparse][[/noparse]6]~~
outa[noparse][[/noparse]6]~
count2 := cnt
count := count2-count1
WriteLCD(count)
PRI WriteLCD(count)
repeat 10
!outa[noparse][[/noparse]6]
waitcnt(clkfreq/20 + cnt)
dira[noparse][[/noparse]LCD_Pin]~~
if LCD.Start(LCD_Pin, LCD_Baud, LCD_Lines)'Initialize the LCD object
LCD.Cursor(Off) 'Set cursor off
LCD.Cls 'Clear the LCD screen
LCD.Str(string("Button time")) 'Print string on LCD
LCD.Gotoxy(5, 1)
LCD.DecF(count, 8) 'Print count as a signed decimal
''CountLCD
'' Counts how long the button is pressed for and
'' displays it on the LCD
CON
LCD_Pin = 0 'The LCD is connected to pin A0.
LCD_Baud = 19_200 'Baud
LCD_Lines = 2 'The number of lines on this LCD
Off = 0
On = 1
OBJ
LCD: "Debug_lcd"
VAR
LONG stack[noparse][[/noparse]50]
BYTE TOG
PUB Main
TOG := 0
cognew(Countdown, @stack[noparse][[/noparse]0])
cognew(Button, @stack[noparse][[/noparse]10])
PUB Countdown
dira[noparse][[/noparse]1..5]~~
outa[noparse][[/noparse]1..5]~~
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %111110
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %111100
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %111000
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %110000
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5] := %100000
waitcnt(clkfreq*2 + cnt)
outa[noparse][[/noparse]1..5]~
TOG := 1
PUB Button | count1, count2, count
count1 := 0
count2 := 0
dira[noparse][[/noparse]21]~ 'Set pin 21 to input
dira[noparse][[/noparse]6]~~ 'Set pin 6 to output
outa[noparse][[/noparse]6]~
repeat while TOG == 0
repeat while ina[noparse][[/noparse]21] == 0
count1 := cnt
repeat while ina[noparse][[/noparse]21] == 1
outa[noparse][[/noparse]6]~~
outa[noparse][[/noparse]6]~
count2 := cnt
count := count2-count1
WriteLCD(count)
PRI WriteLCD(count)
repeat 10
!outa[noparse][[/noparse]6]
waitcnt(clkfreq/20 + cnt)
dira[noparse][[/noparse]LCD_Pin]~~
if LCD.Start(LCD_Pin, LCD_Baud, LCD_Lines)'Initialize the LCD object
LCD.Cursor(Off) 'Set cursor off
LCD.Cls 'Clear the LCD screen
LCD.Str(string("Button time")) 'Print string on LCD
LCD.Gotoxy(5, 1)
LCD.DecF(count, 8) 'Print count as a signed decimal
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
'my LCD screen' doesn't add enough information for me... What's the device exactly?
Mike
I didn't have time to test the button functions code, so I commented most of it out and just set up a counter to pass a number to WriteLCD. At least you know the LCD function is working, so you should be able to debug the rest.
NOTE: I'm testing this on a Spinstamp, so if you run this on a protoboard or demoboard you need to change the timing constants accordingly. I also changed the LCD pin to pin 12 since mine was already connected there.
Mike