Simple 4 line LCD display with 18F4550


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2007
    Posts
    11

    Post Simple 4 line LCD display with 18F4550

    I have written a few lines of code to implement common functions such as displaying a single line and clearing a single line on the 18F4550...spent a long time trying to get this working...this is because some interrupt keeps stopping the LCD routine on the 4550.

    This is mainly for beginners and I have tried to include the line display and clear functions similar to the Ohonsoft PIC simulator. This is where i found PBP really lacking so here are the functions, please use them !



    DEFINE LCD_LINES 4 ' it is a 4x16 standard LCD
    DEFINE LCD_BITS 8 ' LCD is in 8-bit mode connected to PORT0-7
    DEFINE LCD_DREG PORTB ' Define LCD connections
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 1

    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 500 'You can try experimenting with this value

    'the following statements make all ports Digital I/O and disable interrupts/comparators etc
    TRISD=%00000000
    TRISA=%00000000
    TRISE=%00000000
    ADCON1 = %00001111
    CMCON = %00000111
    CVRCON = 0
    INTCON=%10100001
    INTCON2=%01110101
    INTCON3=%11000011
    T0CON=%00000000


    TRISA = %11111111
    TRISB = %00000000
    TRISC = %00000000
    TRISD = %11111111

    B1 var byte 'To clear the display
    B1=32 '32 is ASCII for space

    time1 var Word
    time2 var Word
    time3 var Word
    time4 var Word
    msg1 var Byte[64]
    msg2 var Byte[64]
    tmp var Byte
    tmp1 var Byte
    j var Byte
    mlen var Byte[3]
    i var Byte
    k var byte
    RND var word

    mlen(1) = 25


    msg1(1) = 72
    msg1(2) = 101
    msg1(3) = 108
    msg1(4) = 108
    msg1(5) = 111
    msg1(6) = 32
    msg1(7) = 87
    msg1(8) = 104
    msg1(9) = 97
    msg1(10) = 116
    msg1(11) = 32
    msg1(12) = 105
    msg1(13) = 115
    msg1(14) = 32
    msg1(15) = 89
    msg1(16) = 111
    msg1(17) = 117
    msg1(18) = 82
    msg1(19) = 32
    msg1(20) = 78
    msg1(21) = 97
    msg1(22) = 77
    msg1(23) = 101
    msg1(24) = 63
    msg1(25) = 63

    WaitMs 500
    LCDOUT $FE, $0D 'Cursor=Large Blinking thing

    k=0
    start:

    tmp = mlen(1) - 15
    For i = 1 To tmp
    if K<4 then
    k=k+1
    else
    k=1
    endif
    if k=1 then gosub lcdline1home
    if k=2 then gosub lcdline2home
    if k=3 then gosub lcdline3home
    if k=4 then gosub lcdline4home
    tmp1 = i + 14
    For j = i To tmp1
    Lcdout msg1(j)
    Next j
    Gosub time500
    if k=1 then GOSUB LCDLINE1CLEAR
    if k=2 then gosub LCDline2clear
    if k=3 then gosub lcdline3clear
    if k=4 then gosub lcdline4clear
    Next i
    Goto start
    End

    time500:
    For time1 = 1 To 32767
    'This is a delay so u can check your interrupts here
    Next time1
    Return






    LCDClear:
    LCDOUT $FE,1
    return

    LCDLine1Home:
    LCDOUT $FE,2
    return

    LCDLine2Home:
    LCDOUT $FE,$C0
    RETURN

    LCDLine3Home:
    LCDOUT $FE,$90
    RETURN

    LCDLine4Home:
    LCDOUT $FE,$D0
    RETURN

    LCDLine1Clear:
    'Your cursor will goto line three for a brief period after clearing the line
    'If you have problems with the cursor remove ONE b1 from the following LCDOUT statements
    LCDOUT $FE,2,B1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1 ,b1
    LCDOUT $FE,2
    return

    LCDLine2Clear:
    LCDOUT $FE,$C0,B1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1, b1,b1
    LCDOUT $FE,$C0
    RETURN

    LCDLine3Clear:
    LCDOUT $FE,$90,B1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1, b1,b1
    LCDOUT $FE,$90
    RETURN

    LCDLine4Clear:
    LCDOUT $FE,$D0,B1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1,b1, b1,b1
    LCDOUT $FE,$D0
    RETURN
    Last edited by pic-ker; - 7th April 2007 at 19:06.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    This program will never work.
    And if it's interrupts you're worried about, disable them before using the LCD command.

  3. #3
    Join Date
    Feb 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    I have no idea why you think it wont work...because I have already tested it

    My defines are declared in the .INC file and not in the program.
    The interrupts are disabled here:


    ADCON1 = %00001111
    CMCON = %00000111
    CVRCON = 0
    INTCON=%10100001
    INTCON2=%01110101
    INTCON3=%11000011
    T0CON=%00000000

    ok...i may have defined a few TRIS commands twice...but it still works

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Since you've already tested it.

    How did you get WaitMs 500 to work?

    Perhaps, with Proton+
    <br>
    DT

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Since you've already tested it.

    How did you get WaitMs 500 to work?

    Perhaps, with Proton+
    <br>
    My point exactly...
    Also notice the uselessness of the lcdout commands at the end...
    Why not just use...
    LCDOUT STR 32\20
    to clear out a line on an LCD...which works very well in PICBASICPRO.
    Go figure...

Similar Threads

  1. Simple LCD code not working!...WHY?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th November 2009, 20:48
  2. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 17:56
  3. assembly in Pic
    By lerameur in forum Off Topic
    Replies: 11
    Last Post: - 1st May 2008, 21:06
  4. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 13:22
  5. 4 line LCD with 16F88
    By anj in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th February 2004, 10:06

Members who have read this thread : 1

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