PDA

View Full Version : Blinking LCD with using loop



Jųan
- 4th August 2005, 10:51
How can I rewrite the following code to display the text constantly instead of looping. It blinks because of the pause but if I take the pause off then the timing gets out of wack and the LCD displays funny characters. Also when I switch on the circuit, the LCD displays "pressed" for a few cycles before going back to "press button" mode. Basically I would like the "press button" constantly without blinking until the button is pressed and then to display "button pressed" without blinking.

Thanks in advance

Juan



Include "modedefs.bas" ' Include serial modes
DEFINE BUTTON_PAUSE 20 ' button debounce delay is 50ms

TRISA = %00000000 ' All the PORTA pins to outputs.
TRISB = %11111111 ' All the PORTB pins to inputs.


I con 254 '254h = 1111 1110 (Sets LCD to command mode)
ClrScr con 1 '01h = 0000 00001 (Clears Screen & goes to position 1)
Line2 con $C0 'COh = 1100 0000B (sets address to positionn 40 on LCD)
DispCur con 12 '12h = 0000 1100 (activates display & cursor mode)
'Commands obtained from LCD article in epemag.com
pause 400 ' Allow LCD to boot up


LOOP: IF PORTB.2 = 0 THEN
serout PORTA.1,T9600,[I,clrscr]
pause 100
Serout PORTA.1,T9600,["Press Button"]
endif
if PORTB.2 = 1 THEN
serout PORTA.1,T9600,[I,clrscr]
pause 100
SEROUT PORTA.1,T9600,["Button Pressed!"] ' Indicate Button Pressed
endif
goto loop
end

Acetronics2
- 4th August 2005, 12:31
Hi, juan

you just send your message to the LCD ... IF there is a change for button position ...

Alain

mister_e
- 4th August 2005, 14:02
Since it's your first post...


Include "modedefs.bas" ' Include serial modes

TRISA = %00000000 ' All the PORTA pins to outputs.
TRISB = %11111111 ' All the PORTB pins to inputs.


I con 254 '254h = 1111 1110 (Sets LCD to command mode)
ClrScr con 1 '01h = 0000 00001 (Clears Screen & goes to position 1)
Line2 con $C0 'COh = 1100 0000B (sets address to positionn 40 on LCD)
DispCur con 12 '12h = 0000 1100 (activates display & cursor mode)

'Commands obtained from LCD article in epemag.com
pause 400 ' Allow LCD to boot up

Start:
serout PORTA.1,T9600,[I,clrscr]
pause 100
Serout PORTA.1,T9600,["Press Button"]

while PORTB.2=0
' Wait untill push-button is pressed
wend

serout PORTA.1,T9600,[I,clrscr]
pause 100
SEROUT PORTA.1,T9600,["Button Pressed!"] ' Indicate Button Pressed
pause 1000 ' delay 1 sec
goto start
BUT more than often PORTA contain some analog stuff... SEROUT may work properly or not. Look for CMCON or ADCON1 to see how to disable them

Your Define BUTTON will not do anything if you don't use BUTTON command.

Acetronics2
- 4th August 2005, 14:40
Just 3 lines to add between PAUSE 1000 and goto start ( at the end ...) in case you keep the finger on the pressed button ...


while PORTB.2=1
' Wait until push-button is released
wend


Alain

Dwayne
- 4th August 2005, 15:03
Only do a clr screen at the beginning of your program. before your loop.


Send a command to position curser at the beginning of the LCD line. in your loop



granted it will be overwriting what is already there, but who cares?


Dwayne

Jųan
- 5th August 2005, 13:24
Lovely, thanks fellas, much appreciated. I got picBasic a few weeks ago and I havent stopped playing what I call "lego for adults" since. Hope I can be as good as you guys one day.

Much appreciated!

:-)

Juan