LCD serial backpacks


Closed Thread
Results 1 to 40 of 68

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352

    Smile

    Hi Joe S.

    I really am trying to figure out how to offer some help to you. I too have had a problem using serial LCD's in the past. I have one from SEETRON, a 2x16 that has served me well in the past few years. I don't understand why it should take a "special" type of serial adaptor for every type of project though. The only difference between setups is the baud rate that I can see. You use either 2400 or 9600. The difference is on the PIC side. If you are going to do any serial data out, you really should use an external crystal or resonator. This is because the PIC's internal clock isn't always accurate for the higher baud rates. This fact has been stated many times in the past on the various forums here. Your PIC only needs the statement: "SEROUT GPIO.0,6,[72,72,58,77,77] 'Display HH:MM", for example, to get data to the display. Obviously, the PIC must be configured for the baud rate. (I took the statement from Paul Borgmeier's Easy Clock program). There is far less setup and PIC pin usage with a serial display than with a parallel display so I think that's why they are shown more than the parallel displays. As for someone specifying certain types of backpacks, it shouldn't matter. All you are doing is sending serial data out at a certain rate. Most backpacks have jumper selectable baud rates.

    You should be able to buy a couple of backpacks, keep them in a parts drawer, then when you need one, plug in the LCD and away you go. I just bought 4 from a place called Wulfeden for a reasonable price and I have them available when I need them. I have been mostly been using 4 x 20 VFDs on a few larger projects. I bought a dozen of Melanie's Blue 2 x 16 LCDs last year and they are great for adding the backpack to. You don't need to solder the backpack to the LCD. Just use plugable headers. So If you go from parallel to serial you just plug in the backpack and away you go.

    I hope this helps.

    BobK

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382

    Default

    I've made serial to parallel LCD backpacks before. When I did it the LCD, or in this case VFD, had an odd protocol and I was trying to standardize it. I located a serial protocol from another manufacturer as my model. (matrix orbital or crystal fontz) While it did work well I ended up not completing the code because the VFD got damaged.

    The two commands I used were HSERIN (serial in), and LCDOut. Most of the code was taken up with a Select Case routine to convert incoming command codes to something the VFD could understand. The process was listen for serial commands, buffer incoming serial data, parse command codes, and send data to LCD/VFD. You already have a start on this with your code, now you need to add in the additional commands (see either another serial protocol or use the LCDOut information).

    All that being said, if all you want is an inexpensive backpack or you want an idea of what a pic based on looks like try this:
    http://www.sparkfun.com/commerce/pro...roducts_id=258
    Last edited by DynamoBen; - 6th November 2006 at 14:57.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default Still Going . . .

    Hi All,
    The serial adapter I currently use can be found at a reasonable price really, from
    http://phanderson.com/lcd106/lcd107.html, 2.95 each in 100 qty, having said that, I still do not want to us them as I do not have confidence in any device I have not seen the code for, especially when it comes to embedding operations code into my applications for products I wish to sell to a manufacturer, additionally I do not care to have his test routine or splash screen on my application. For a gadget to use around the house, then sure, I will use them. I have seen 1 or 2 out there written in assembler or C, C++, I suppose I will continue to hammer on the listed code until I am satisfied it works as expected every time and always. Right now I waiting for an order of 4x20 displays from China.
    JS

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default Fine print . .

    Quote Originally Posted by BobK
    As for someone specifying certain types of backpacks, it shouldn't matter.

    BobK
    Ahh not so . . the hitachi chip does display data the same regardless of who's backpack drives it, assuming the data doesnt get filtered first. The problem here is everyone who sells one of these has his/her own little initialization routines and that's what will trip me up, if I code for Anderson's unit and my customer finds a better deal on Seetron's display, now I get a nasty phone call. .I always try to put the fire out before it is lit. The best way to do that is control the code.
    Thank You for your input (everyone!) and anyone who wants to ring in an opinion on this, I think that would be super. Im trying to get around the 8 track / vs cassette , vhs vs beta, why won't my Chevy wheels fit a Ford Scenerio. I can go buy basicly anybodys video card and put in my Computer p/c or mac, so I think the way to workable standards is through the public domain. My Opinion, for better or worse.
    JS

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Smile Ok Here it is

    Ok enough of my whining, here is some workable code, thanks to Darrel Taylor, well mostly about 99 percent. He wrote it for something else, I added a monkey wrench and a screwdriver and it works for my needs, could it be better? Well you can judge for your self, it works good enough for my application as is
    Thanks Once again Darrel for the post I extracated this code from.

    Code:
    @ DEVICE pic16F628A, HS_OSC
    
    @ DEVICE pic16F628A, WDT_OFF
    ' Watchdog Timer
    
    @ DEVICE pic16F628A, PWRT_ON
    ' Power-On Timer
    
    @ DEVICE pic16F628A, MCLR_ON 
    ' Master Clear Options (Internal)
    
    @ DEVICE pic16F628A, BOD_OFF
    ' Brown-Out Detect
    
    @ DEVICE pic16F628A, LVP_OFF
    ' Low-Voltage Programming
    
    @ DEVICE pic16F628A, CPD_OFF
    ' Data Memory Code Protect
    ' Set to CPD_OFF for Development Copy
    ' Set to CPD_ON for Release Copy
    
    @ DEVICE pic16F628A, PROTECT_OFF
    ' Program Code Protection
    ' Set to PROTECT_OFF for Development Copy
    ' Set to PROTECT_ON for Release Copy
    
    trisb = %00000010
    trisA = %11110011
    include "modedefs.bas"
    ' Define LCD registers and bits
    Define  LCD_DREG        PORTB
    Define  LCD_DBIT        4
    Define  LCD_RSREG       PORTA
    Define  LCD_RSBIT       0
    Define  LCD_EREG        PORTA
    Define  LCD_EBIT        1
    
    DEFINE LCD_LINES 4             'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000     'Define delay time between sending LCD commands
    DEFINE LCD_DATAUS 50         'Define delay time between data sent.
    DEFINE OSC 20
    
    DEFINE HSER_RCSTA 90h        ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h        ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 32         ' FOR 20MHZ 129 = 2400, 32=9600,25 @ 4 for 2400
    DEFINE HSER_CLROERR 1        ' Clear overflow automatically
    
            RCIF VAR PIR1.5      ' Receive  interrupt flag (1=full , 0=empty)
            TXIF VAR PIR1.4      ' Transmit interrupt flag (1=empty, 0=full)
    LED VAR PORTA.4
    
    OERR    VAR    RCSTA.1             ' Alias OERR (USART Overrun Error Flag)
    CREN    VAR    RCSTA.4             ' Alias CREN (USART Continuous Receive Enable)
    buffer_size    CON    64             ' Sets the size of the ring buffer, set up from 32
    buffer    VAR    BYTE[buffer_size]' Array variable for holding received characters
    index_in    VAR    BYTE          ' Pointer - next empty location in buffer
    index_out    VAR    BYTE         ' Pointer - location of oldest character in buffer
    bufchar    VAR    BYTE             ' Stores the character retrieved from the buffer
    i        VAR    BYTE             ' loop counter 
    Col        VAR    BYTE             ' Stores location on LCD for text wrapping
    errflag    VAR    BYTE             ' Holds error flags
    index_in = 0
    index_out = 0
    i = 0
    col = 1
    
                                    'RxData var byte        
            CMCON = 7               ' PORTA is digital
            Pause 100               ' Wait for LCD to startup
            high PortA.2            ' power for backlight
            low  PortA.3            ' backlight ground
    INTCON = %11000000                ' Enable interrupts
    ON INTERRUPT GoTo serialin        ' Declare interrupt handler routine
    PIE1.5 = 1                        ' Enable interrupt on USART
    pause 1500
    lcdout $FE,1
    lcdout $FE,2
    LCDOUT "Your Text Goes Here"
    PAUSE 2000
    
    ' * * * * * * * * * * * * *   Main program starts here - blink an LED at 1Hz
    ' I removed some code here, it seems to require what's left
    loop:  
            For i = 0 to 10     ' Delay for .02 seconds (10*2mS)
                Pause 2           ' Use a short pause within a loop
            Next i                ' instead of one long pause
            
            For i = 0 to 10     ' Delay for .02 seconds (10*2mS)
                Pause 2           ' Use a short pause within a loop
            Next i                ' instead of one long pause
    
    
    display:                          ' dump the buffer to the LCD
            IF errflag Then error    ' Handle error if needed
            IF index_in = index_out Then loop    ' loop if nothing in buffer
    
            GoSub getbuf            ' Get a character from buffer    
            LCDOut bufchar            ' Send the character to LCD
            
            
            IF col > 20 Then        ' Check for end of line
                col = 1                ' Reset LCD location
                LCDOut $fe,$c0,REP " "\20    ' Clear line-2 of LCD
                LCDOut $FE,2        ' Tell LCD to return home
            EndIF
    
    GoTo display            ' Check for more characters in buffer
    
    
    
                            ' Subroutines
    
    Disable                    ' Don't check for interrupts in this section
    
    getbuf:                    ' move the next character in buffer to bufchar
        index_out = (index_out + 1)            ' Increment index_out pointer (0 to 63)
                                            ' Reset pointer if outside of buffer
        IF index_out > (buffer_size-1) Then index_out = 0    
        bufchar = buffer[index_out]            ' Read buffer location
    Return
    
    
    error:                              ' Display error message if buffer has overrun
        IF errflag.1 Then              ' Determine the error
            LCDOut $FE,$c0,"Clearing Display    Buffer"    ' Display buffer error on
                                                        ' line-2 and 3 Buff overrun
        Else
            LCDOut $FE,$D4,"USART Overrun"    ' Display usart error on line-4
        EndIF
        
        LCDOut $fe,2                    ' Send the LCD cursor back to line-1 home
        For i = 2 to col                ' Loop for each column beyond 1
            LCDOut $fe,$14                ' Move the cursor right to the right column
        Next i                          ' $14 = 20 DEC.
        
        errflag = 0            ' Reset the error flag
        CREN = 0            ' Disable continuous receive to clear overrun flag
        CREN = 1            ' Enable continuous receive
    
        GoTo display        ' Errors cleared, time to work.
        
        
    ' * * * * * * * * * * * * * * *  Interrupt handler
    
    serialin:                        ' Buffer the character received
        IF OERR Then usart_error    ' Check for USART errors
        index_in = (index_in + 1)    ' Increment index_in pointer (0 to 63)
        IF index_in > (buffer_size-1) Then index_in = 0    'Reset pointer if outside of buffer
        IF index_in = index_out Then buffer_error    ' Check for buffer overrun
        HSerin [buffer[index_in]]    ' Read USART and store character to next empty location
        IF RCIF Then serialin        ' Check for another character while we're here
        
    Resume                            ' Return to program
    
    buffer_error:
        errflag.1 = 1        ' Set the error flag for software
    ' Move pointer back to avoid corrupting the buffer. MIN insures that it ends up within the buffer.    
        index_in = (index_in - 1) MIN (buffer_size - 1)    
        HSerin [buffer[index_in]]    ' Overwrite the last character stored (resets the interrupt flag)
    usart_error:
        errflag.0 = 1        ' Set the error flag for hardware
        
    Resume                    ' Return to program
    
    
    End
    As I gain coding experience I will revisit this code unless someone else does so first ;-)
    JS

    Oh, what I really like about this is you use the standard formatting commands as used with LCDOUT, no funky commands.
    Last edited by ScaleRobotics; - 21st May 2010 at 15:42. Reason: added code tags

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

    Default

    Hi Joe,

    Glad you got it working!
    That must have been a really old one.
    It doesn't look familiar at all.
    DT

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

    Default

    That's what i thought when i saw...
    Code:
    ON INTERRUPT GoTo ....
    Steve

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

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

    Default

    Quote Originally Posted by mister_e
    That's what i thought when i saw...
    Code:
    ON INTERRUPT GoTo ....
    That's right!
    Nobody uses ON INTERRUPT anymore!! errr, uhhh...

    DT

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Quote Originally Posted by Darrel Taylor
    That's right!
    Nobody uses ON INTERRUPT anymore!! errr, uhhh...
    That's because they use . . . assembler . . . or D_T_Interrupts?

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default Must've been the screwdriver . . .

    Quote Originally Posted by Darrel Taylor
    Hi Joe,

    Glad you got it working!
    That must have been a really old one.
    It doesn't look familiar at all.
    Hmmmmm, it must have been the screwdriver . . .
    JS

  11. #11
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Joe S.
    Ok enough of my whining, here is some workable code, thanks to Darrel Taylor, well mostly about 99 percent. He wrote it for something else, I added a monkey wrench and a screwdriver and it works for my needs, could it be better? Well you can judge for your self, it works good enough for my application as is
    Thanks Once again Darrel for the post I extracated this code from.
    ..........................
    .........................
    .......................
    ....................
    ..................
    ...............
    ............
    ..........
    ......
    .......
    ........
    .........
    .........
    ..........
    End

    As I gain coding experience I will revisit this code unless someone else does so first ;-)
    JS

    Oh, what I really like about this is you use the standard formatting commands as used with LCDOUT, no funky commands.


    I must've missed something in the translation here....
    I've been basically working on the same type of thing for a couple of weeks now, and I think I might be shooting myself in the foot or something trying to figure this out...

    How are you passing the lcdout 'commands'? i.e. lcdout $fe, 01 to clear the display and things like that?

    If my guess is right, like me, you are basically replacing 'lcdout' with 'serout' on the main board, and this code is to read everything coming the serial port, and sending it out, character by character using a single 'lcdout'.

    And if I'm reading this right, PBPro knows that if you send an '$FE', the next character down the line, whether it's in the same statement or not, will be an lcd 'command'.

    Maybe that's where I'm tripping myself up. I'm trying to split data and commands apart at the lcd end of things...

    Why did MeLabs pick $FE as the 'command' character anyways? Why not $FF or $CD or whatever?

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

    Default

    Hi Jeremy,

    And if I'm reading this right, PBPro knows that if you send an '$FE', the next character down the line, whether it's in the same statement or not, will be an lcd 'command'.
    You got it.

    When PBP see's a $FE, it sets FLAGS.0 (LCDCDFLAG).
    Which means that the next character is a command. And then when sending the next char, it sets the RS pin LOW.

    And, while of no use but an example, if you were to do this...
    Code:
    FLAGS.0 = 1
    LCDOUT 1
    It would do a Clear Screen.

    Why did MeLabs pick $FE as the 'command' character anyways? Why not $FF or $CD or whatever?
    For the HD44780's Character Table, The last 2 characters $FE and $FF are "all pixels OFF" and "all pixels ON" respectively. And, since "all pixels OFF" is the same thing as a Space, it's likely to assume that $FE will never be used to display a character. So it's available to initiate the Command sequence.

    So all you really need to do for a backpack is, make sure that you don't miss any incomming data, and pass it all on to the LCDOUT command.

    But, there can be some advantage to separating the Clear Screen and Home commands, like you've been doing.
    They take the longest to execute (1.6-4.5ms) depending on the display. But LCD_COMMANDUS delays the same amount no matter which command is supplied. Commands like moving the cursor to a new location may only take between 40-120us (same as LCD_DATAUS), but LCDOUT will still wait the full LCD_COMMANDUS time (usually 2000us).

    For a backpack, if you reduce the LCD_COMMANDUS time, and detect the Clear Screen and Home to add a longer pause. It can increase the speed to a point where you don't even need to buffer the data up to 9600 baud.
    DT

  13. #13
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default yep

    Quote Originally Posted by skimask
    How are you passing the lcdout 'commands'? i.e. lcdout $fe, 01 to clear the display and things like that?

    If my guess is right, like me, you are basically replacing 'lcdout' with 'serout' on the main board, and this code is to read everything coming the serial port, and sending it out, character by character using a single 'lcdout'.
    Hi Skimask,
    That was the whole point of the endever, to use the standard commands common to lcdout, so as not to have several different codes to control how the lcd prints to screen. It seems most makers of these things have their own little routines, I started with:
    Code:
     serin N2400.PortB.7,char
    lcdout char
    I saw the core code in a post of Darrel's using Hserin
    and knew it would work so I started cutting and sewing,
    Darrel took it and added his instant interrupts, i snipped
    out some more of the unneeded stuff and am still working
    on all the bells and whistles. I like it better than all the
    others I've seen, because it uses unmolested, lcdout type code.
    JS

  14. #14
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Joe S.
    Hi Skimask,
    That was the whole point of the .......................
    things have their own little routines, I started with:
    Code:
     serin N2400.PortB.7,char
    lcdout char
    I saw the core code in a post of Darrel's.............
    seen, because it uses unmolested, lcdout type code.
    JS

    I get what you're cooking...I hope
    LCDOut is a familiar command, why mess with it? Replace it with SerOut, and you're done.
    My master plan includes throwing a few buttons on the unit and using a 4 wire hookup (v+, gnd, tx, rx, maybe an RJ11 phone connector).
    If my figuring is right, I'm going to throw in a bit of code that looks for a double $fe (or whatever) and that'll be my signal to send back a code if any keys are pressed. Using an equivalent to an LCDIn command might be a bit trickier (not by much), but that'll come later...

    The only big thing left to do is to find a dozen or so LCDs with backlights. ebay maybe?
    JDG

  15. #15
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default Yes

    Quote Originally Posted by skimask
    I get what you're cooking...I hope
    LCDOut is a familiar command, why mess with it? Replace it with SerOut, and you're done.
    My master plan includes throwing a few buttons on the unit and using a 4 wire hookup (v+, gnd, tx, rx, maybe an RJ11 phone connector).
    If my figuring is right, I'm going to throw in a bit of code that looks for a double $fe (or whatever) and that'll be my signal to send back a code if any keys are pressed. Using an equivalent to an LCDIn command might be a bit trickier (not by much), but that'll come later...

    The only big thing left to do is to find a dozen or so LCDs with backlights. ebay maybe?
    JDG
    Hi skimask,
    Yeah well partly, it is much easier to put a display in a difficult place if you only need to run 3 wires to it, whereas you may have 20 or so going to your main p/c board and it might be real inconveinient to run 20 to your display. I have bought LCD displays from sure electronics on ebay and thay are cheap. I did have one fail though, I think from ESD.
    http://cgi.ebay.com/ws/eBayISAPI.dll...tem=7617627971
    for larger order check his store: http://stores.ebay.com/Sure-Electronics

Similar Threads

  1. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  2. Please help with EDE702 - Serial to LCD interface
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th October 2008, 02:48
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 16:56
  4. Serial LCD
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th November 2007, 08:31
  5. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07

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