Shop OBEX P1 Docs P2 Docs Learn Events
Serial LCD problems — Parallax Forums

Serial LCD problems

crcordillcrcordill Posts: 29
edited 2008-01-22 02:58 in Propeller 1
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

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-21 04:52
    Can you describe the issue you are having? Exactly what is happening with the LCD?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • crcordillcrcordill Posts: 29
    edited 2008-01-21 11:52
    It will run all the way through the light flashing. Then nothing happens. The LCD either stays blank, or shows what was previously on it. I never makes it through the first line of code. I've run another program, Debug_LCD_Test that runs perfectly (taking into account that I have a smaller LCD). It never has a problem, and its almost the exact same code. Also, did I say something to offend people? Nobody seems like they want to help.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2008-01-21 15:50
    "Also, did I say something to offend people? Nobody seems like they want to help."

    'my LCD screen' doesn't add enough information for me... What's the device exactly?
  • crcordillcrcordill Posts: 29
    edited 2008-01-21 16:30
    In reference to the above comment, its a Parallax 2x16 Serial LCD (non-Backlit). Just the standard one off of the website.
  • MinimumWageMinimumWage Posts: 72
    edited 2008-01-21 17:12
    I'm no expert on all this, but from a quick look at the code you might want to declare two different stack variable arrays, and assign a different one for each COGNEW. Not allocating enough memory space can result in weird results at runtime.

    Mike
  • crcordillcrcordill Posts: 29
    edited 2008-01-21 22:49
    Yup, I tried adding more stack space to no avail.
  • MinimumWageMinimumWage Posts: 72
    edited 2008-01-22 02:58
    Maybe the attached file will help. I played around a bit with your code and added a couple of things. There was no _clkmode or _xinfreq statement set, and I think the various serial objects require the prop to be running at 80MHz for timing. If you don't explicitly define it the prop defaults to a slower internal clock. Also, I did set up new arrays for each of your cognew statements but I had to increase it to 50 longs before the LCD would update. (Change it back to 20 and try it yourself- the code compiles fine but nothing happens on the LCD.)

    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
Sign In or Register to comment.