crcordill
01-20-2008, 08:39 AM
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[50]
BYTE TOG
PUB Main
TOG := 0
cognew(Countdown, @stack[0])
cognew(Button, @stack[10])
PUB Countdown
dira[1..5]~~
outa[1..5]~~
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %111110
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %111100
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %111000
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %110000
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %100000
waitcnt(clkfreq*2 + cnt)
outa[1..5]~
TOG := 1
PUB Button | count1, count2, count
count1 := 0
count2 := 0
dira[21]~ 'Set pin 21 to input
dira[6]~~ 'Set pin 6 to output
outa[6]~
repeat while TOG == 0
repeat while ina[21] == 0
count1 := cnt
repeat while ina[21] == 1
outa[6]~~
outa[6]~
count2 := cnt
count := count2-count1
WriteLCD(count)
PRI WriteLCD(count)
repeat 10
!outa[6]
waitcnt(clkfreq/20 + cnt)
dira[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[50]
BYTE TOG
PUB Main
TOG := 0
cognew(Countdown, @stack[0])
cognew(Button, @stack[10])
PUB Countdown
dira[1..5]~~
outa[1..5]~~
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %111110
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %111100
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %111000
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %110000
waitcnt(clkfreq*2 + cnt)
outa[1..5] := %100000
waitcnt(clkfreq*2 + cnt)
outa[1..5]~
TOG := 1
PUB Button | count1, count2, count
count1 := 0
count2 := 0
dira[21]~ 'Set pin 21 to input
dira[6]~~ 'Set pin 6 to output
outa[6]~
repeat while TOG == 0
repeat while ina[21] == 0
count1 := cnt
repeat while ina[21] == 1
outa[6]~~
outa[6]~
count2 := cnt
count := count2-count1
WriteLCD(count)
PRI WriteLCD(count)
repeat 10
!outa[6]
waitcnt(clkfreq/20 + cnt)
dira[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