Blinking LCD with using loop


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2005
    Posts
    18

    Default Blinking LCD with using loop

    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

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi, juan

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

    Alain

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Since it's your first post...
    Code:
    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    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
    Last edited by Acetronics2; - 4th August 2005 at 14:45.

  5. #5
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    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
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  6. #6
    Join Date
    Jul 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Thumbs up

    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

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 05:02
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  4. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  5. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts