LCD serial backpacks


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 68
  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default LCD serial backpacks

    Hi Everyone,
    It seems as if, . . . the LCD serial backpack device must be the
    Crown Jewels, of PICdome as I have been unable to wrestle suitable
    code out of the internet. Posted below is a modified version of some code
    I found somewhere, probably for a BS1, anyway I tweaked it some and it works after a fashion, but I think it needs something in the way of a buffer
    and some code to make changes on the fly, like does the cursor blink or not
    etc. . . I think it would be way cool to fashion a workable public domain
    serial unit, so newbies and non-newbies have access without forking up $35 bucks for a serial LCD.

    Anyone up to the challange? As I have been coding PIC micros only since 08/06, My coding skills are not there yet, but thanks to you all I am learning.
    Joe


    Code:
    @ DEVICE pic16F628A, HS_OSC
     
    @ DEVICE pic16F628A, WDT_ON
    ' 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 = %00000001
    trisA = %11110011
    include "modedefs.bas"
    ' Define LCD registers and bits
    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 2
    Define LCD_EREG PORTB
    Define LCD_EBIT 3
     
    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
     
    char Var byte ' Storage for serial character
     
     
     
    CMCON = 7 ' PORTA is digital
     
    Pause 100 ' Wait for LCD to startup
    high PortA.2 ' power for backlight
    low PortA.3 ' backlight ground
     
    main:
     
    Lcdout $FE, 1 ' Initialize and clear display
    LCDOUT $FE, $0C
     
    LCDOUT "My Flash Text" 
    pause 800
    Lcdout $FE, 1,$FE, 2
     
    goto loop
     
     
    loop: Serin PORTB.1,N9600,char ' Get a char from serial input
    Lcdout char ' Send char to display
     
    Goto loop ' Do it all over again
     
    End
    Last edited by ScaleRobotics; - 30th May 2010 at 01:24.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185

    Default

    Hi Joe,

    Howzit?

    Could you give some more details?

    I am not sure what you want to have is?


    -------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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

    Exclamation Serial in LCD out

    Sayzer,
    Greetings !
    Here is the Rub:
    every time I or tons of others out there need a serial display, we have to stop what we are doing and order a preprogrammed chip, a kit, or an already assembled serial display at significant cost. A year from now I will likely be able to write enough code to handle this, for now NO. sometimes it is just better to connect the display via a serial connection, for instance, you homebrew a burgular alarm, you keep the alarm chip safely inside, and display can live outdoors. Nowhere have I been able to find code already written and available to home roll a suitable serial display and it really is agrivating to have to stop and order and wait for one when you need it. This seems to be the only PIC related everyday item where near zero code is in the public domain
    The code I posted seems to work with a 2 X 16 display but I doubt it is suitable as is to use as a general purpose serial LCD adapter, I think it needs USART support to provide a data buffer so data doesn't get lost. Additionally
    the LCDOUT routine is great for a finished project, but these push in wire type breadboards are so clumbsy as to make you waste too much time fiddling with connections, whereas a serial lcd is more convienent. I have seen in books authors who use shift registers to do this, curiously enough they were books about PICs * * * * So what I am looking for is a serial backpack device common to all who use this forum that we all get familiar with using so your code or Darrels, or Bruces, ETC does not have to be modified to work on as it seems every serial backpack out there uses different initialization routiens, and you still have to wait for and pay for every time you want one.
    Thanks
    Joe

  4. #4
    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

  5. #5
    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.

  6. #6
    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

  7. #7
    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

  8. #8
    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

  9. #9
    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

  10. #10
    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.

  11. #11
    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

  12. #12
    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

  13. #13
    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?

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

    Talking

    Exactly!

    And even with assembly, they still use DT_INTS

    Well, at least 5 or so of them do.

    BTW, it would make your backpack more responsive. Fewer dropped characters, and faster baud rates. Just a suggestion.

    DT

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

    Smile All smiles

    Quote Originally Posted by Darrel Taylor
    Exactly!

    BTW, it would make your backpack more responsive. Fewer dropped characters, and faster baud rates. Just a suggestion.
    Hi Darrel,
    I don't have a firm grasp on "ON INTERRUPT" yet, but I put in a few hours each day, Playing(WORKING) with PBP and this forum and I will get there. You just learn a little slower after 50. I am thinking about your bargraphs too, still I'm thinking with only 4 months of experience at this, not too bad,I can look at my earliest programs and see the progress,

    You all have been a tremendus resource, the brain trust here truly amazing.

    In my world I have to learn things over and over in order to retain it, I make little code snippet files and then study them to see how things work, change things to see how the outputted behavior changes, all very interesting all very time consuming. It looks as if assembler is simpler in syntax but 100 times more tedious, as you have to guide it through every move, how long have you been doing this? anyway, I will visit and revisit DT_INTS and try to figure how to implement it into the backpack. I still have to learn how to use eprom too . . . so much to learn, so many posts to study . . . are we havin' fun yet ? ....You bet! Thanks Darrel,
    JS

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

    Default

    >> You just learn a little slower after 50.

    Oh No! I better hurry up and learn more, I've only got 3 years left.

    >> ... with only 4 months of experience at this ...

    Well, for only 4 months, you're doing pretty good.

    >> ... how long have you been doing this? anyway

    PicBasic Pro - about 5 years
    Programming - Umm, one month after the first TRS-80 hit the market, I guess that makes it about oh 28 years.


    I know DT_INTS looks intimidating at the begining, but it's really not that bad, and you don't need to learn assembly language to use it. But I can understand why you might not want to try it out. The biggest obstacle is that you have to be using MPASM.

    So whenever you get around to DT_INTS, you can come back to this thread and try out this program.
    It's your backpack program modified for Instant Interrupts.
    I've highlighted most of the changes (red is added, blue is removed).
    Tested it on a 16F877A
    Code:
    ;---- Config settings for MPASM ----------------------------------------------
    @  __config _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    
    trisb = %00000010
    trisA = %11110011
    ;include "modedefs.bas"
    
    ;----Added by DT--------------------------------------------------------------
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
    
    ASM
    INT_LIST  macro   ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    RX_INT,    _serialin,   PBP,  no
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   RX_INT     ; enable external (INT) interrupts
    ;-----------------------------------------------------------------------------
    
    ' 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
      @ INT_DISABLE  RX_INT
    	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
      @ INT_ENABLE  RX_INT
    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	
    @  INT_RETURN   		        ; 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	
    @  INT_RETURN   		        ; Return to program
    
    
    End
    Hope you can use it some day,
    DT

  17. #17
    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?

  18. #18
    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

  19. #19
    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

  20. #20
    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

  21. #21
    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

  22. #22
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Joe S.
    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

    Ain't that the truth!
    On every one of my little projects up until the last few, I've always had to design in a method for control and display, and always at the expense of pins, which could be better used for something else. So, on the last few, I built up a control/display module with 4 wires running to it using various LCDs/LEDs and switches/keypads laying around. For each different type of LCD, I have to modify the code to handle it, not to mention mount the thing up. I'm getting tired of that now also.
    It's about time I'm making this standardized module, with a standard LCD, in a standard mount, with standard buttons, using a standard 'library' to run it, and connect it with a standard cable.

    You want to go in and buy up a bunch of LCDs in bulk and save some $$$?

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

    Default $$$$ and it aint hex

    Quote Originally Posted by skimask
    You want to go in and buy up a bunch of LCDs in bulk and save some $$$?
    Sorry, no can do, I got a couple of extras right now ,no space, no bucks.
    JS

  24. #24
    skimask's Avatar
    skimask Guest

    Default

    Oh well...

    Any other takers? 16x2 (or whatever, I'm up for ideas) LCDs in some sort of a quantity buy, split the savings amongst a few of us?

    JDG

  25. #25
    Join Date
    Oct 2006
    Location
    Cape Town SA
    Posts
    23

    Default Much simpler for newbie like me

    That code with interupts and all is pretty hot, but going back to the very first question all he wanted to do was emulate a serial LCD, ie PIC is doing nothing else. I knocked this up yesterday and it works, and doesn't miss anything, very simple - like me! Go on eat me alive!

    A back space key tells pic next char is a command - see commands in the select case area
    A double back space makes it spit out a pangram back at you.


    DEFINE LCD_DREG PORTC 'DATA PORT
    DEFINE LCD_DBIT 4 'STARTING BIT (0 OR 4)
    DEFINE LCD_RSREG PORTC 'REGISTER SELECT PORT
    DEFINE LCD_RSBIT 1 'REGISTER SELECT BIT
    DEFINE LCD_RWREG PORTC 'READ/WRITE SELECT PORT
    DEFINE LCD_RWBIT 2 'READ/WRITE SELECT BIT
    DEFINE LCD_EREG PORTC 'ENABLE PORT
    DEFINE LCD_EBIT 0 'ENABLE BIT
    DEFINE LCD_BITS 4 'BUS SIZE (4 OR 8)
    DEFINE LCD_LINES 2 'LINES IN DIPLAY
    DEFINE LCD_COMMANDUS 2000 'CMD DELAY TIME IN uS
    DEFINE LCD_DATAUS 50 'Data DELAY TIME IN uS
    define Osc 4
    '************************************************* ***********
    ADCON1 = 7 'disable A/d work digital
    TRISB = %00000000 'unused port b set to o/p
    TRISA = %00000000 ' PortA outputs
    TRISC = %00000000 ' PortC outputs
    OPTION_REG.7 = 0 ' Enable PORTB pull-ups

    'T2400 con 16780 '2400bd, driven, inverted, no parity
    T2400 con 396 '2400bd, driven, true, no parity
    'will need to use rs232 inverter
    comsout var PORTA.0
    comsin var PORTA.1
    datarray var byte[1] 'incoming array on rs232
    '************************************************* ***********
    start:
    Pause 500 ' Wait for LCD to startup
    Lcdout $FE, $0C 'turn cursor off


    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout $fe, 2 ' go home
    Lcdout "GPL PIC System"
    Lcdout $FE, $C0 'move cursor to begin of line 2
    Lcdout "Serial in at ",DEC T2400

    Pause 1000 ' Wait 1 second
    Lcdout $fe, 1 ' Clear LCD screen
    '************************************************* ***********
    main: while 1 'forever loop
    serin2 comsin, T2400, [ datarray[0]] 'get a char
    if datarray[0] = 8 then 'next byte is a LCD command after BS received
    serin2 comsin, T2400, [ datarray[0]]
    select case datarray[0]
    case 48 '0 = Clear LCD screen
    Lcdout $fe, 1
    case 49 '1 = move cursor to begin of line 1
    Lcdout $fe, 2
    case 50 '2 = move cursor to begin of line 2
    Lcdout $fe, $C0
    case 51 '3 = move cursor to begin of line 3
    Lcdout $fe, $94
    case 52 '4 = move cursor to begin of line 4
    Lcdout $fe, $D4
    case 8 'BS again so transmit a pangram
    gosub send
    case else 'do nothing
    end select
    else
    Lcdout str datarray\1 'show 1 char to LCd
    endif
    wend

    send: serout2 comsout,T2400,["How quickly daft jumping zebras vex",13,10]
    return
    '************************************************* ***********

    END
    '************************************************* ***********

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

    Default Now Why Would Anybody Do That ?

    Quote Originally Posted by websmith
    Go on eat me alive!
    THERE ALWAYS MULTIPLE WAYS OF DOING ANYTHING. There is nothing wrong with brewing an alternative, I will study your code and learn something from it, therefore I am grateful for your post. Thank You, JS

  27. #27

    Wink

    hey joe! almost started singing that hendrix song. lol. Did you ever finish polishing off the bells and whistles? i'm a newbie and already tired of all the display wires, which keep getting pulled out of the breadboard! weeeeeeee

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

    Default

    Quote Originally Posted by nomad View Post
    hey joe! almost started singing that hendrix song. lol. Did you ever finish polishing off the bells and whistles?
    Ya' Know, it works really well as is, after Darrel converted it to instant interrupts, and I have been doing everything but. What I intend to add is really just some unimportant fluff anyway, take the code off Darrel's post #16, it works quite well as is.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  29. #29
    Join Date
    Jul 2007
    Posts
    65

    Default

    Nice to find some code already made for serial LCD, I just burned the backpack on my cool Serial LCD

    no prob, I had 4 LCDs waiting for me to drive them with a16F628

    I just tried the code with INstant interupt, which took me an hour to setup the whole thing to compile(not bad actually), but now I see only stranges characters appearing on the LCD.

    like I send "b" char, and the dipslay will do '

    do I need to create a map of matching characters, or is there a tweak to get the correct display?

    in attached picture, I've sent AAAAAAAAAAAAaaaaaaaaaa using the serial communicator from Mecanique,
    it displayed ___________________000000000000000 on the LCD?


    it's driven by a 16F628a, running at 20mhz
    Display is 4x20 from Orient Display, saying it's requiring a S6A0069 and is compatible with HD44780 4/8bit.
    http://character-lcd-lcds.shopeio.co...haracter%20Lcd

    I've blanked all define to run from default except for
    DEFINE LCD_LINES 4
    because I ain't know how to tweaks all the parameters.
    Started to play with other defines but not luck yet.

    maybe the answer is in there?
    Attached Images Attached Images  

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

    Default

    Quote Originally Posted by flipper_md View Post
    Nice to find some code already made for serial LCD, I just burned the backpack on my cool Serial LCD

    no prob, I had 4 LCDs waiting for me to drive them with a16F628

    I just tried the code with INstant interupt, which took me an hour to setup the whole thing to compile(not bad actually), but now I see only stranges characters appearing on the LCD.

    like I send "b" char, and the dipslay will do '

    do I need to create a map of matching characters, or is there a tweak to get the correct display?

    in attached picture, I've sent AAAAAAAAAAAAaaaaaaaaaa using the serial communicator from Mecanique,
    it displayed ___________________000000000000000 on the LCD?


    it's driven by a 16F628a, running at 20mhz
    Display is 4x20 from Orient Display, saying it's requiring a S6A0069 and is compatible with HD44780 4/8bit.
    http://character-lcd-lcds.shopeio.co...haracter%20Lcd

    I've blanked all define to run from default except for
    DEFINE LCD_LINES 4
    because I ain't know how to tweaks all the parameters.
    Started to play with other defines but not luck yet.

    maybe the answer is in there?
    You have to send the data true, if you send it inverted for some reason then invert it again with a transistor to get true. If you change the defines for the LCD this code will work with the PC boards sold by wulfden too.
    here is a snippet to give you an idea of how to format your code
    serout PortB.4,T9600,[254,128,"9600 baud line 1 T~"] '128 so as not to add space
    serout PortB.4,T9600,[254,192,"9600 baud line 2~"]
    pause 100
    Last edited by Archangel; - 13th October 2008 at 09:17.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  31. #31
    Join Date
    Jul 2007
    Posts
    65

    Default

    well, for some esoteric reasons the thing started to work by itself after a few restart... this I hate
    I noticed one time i've got one capacitor disconnected on the Xtal... and it seems the PIC woulndt bother?? replugged it live and it kept working.


    since I was sending data from a PC, I assume it was regular RS232.
    Tried to get data from my PIC heartbeat system(which is using N9600) and as you said this format is not ok as is, text was garbaged. I'll need a max232 one day to invert signal.

    In the little time I had to play with the thing, I wondered how I could send data to drive other functions, else than display text?
    Can I do custom characters?
    clear screen? etc

    Another weird thing is that the LCD believe it's second line is the 3rd, when I send a long text. It start filling 1st, then 3rd, then 2nd, and finally 4th one?

    anyways I was just sooooo happy to see some text scrolling


    BUT, this morning it doesn't wan't to behave again, showing garbage text with the same steup! arg :/
    I suspect power problem from my regulator, although it's rated for 1amp.
    it's running way too hot when I plug the backlight of this 4lines monster. I guess this may cause some power problems.
    Actually, this is what fried my other LCD! PLugged in too many things, the regulator busted and started shooting 10V or so...smoke show B]

    for now I just keep doing short tests.

    thanks for the infos!

  32. #32
    Join Date
    Jul 2007
    Posts
    65

    Default

    hummm

    some more testing led me to find that disconnecting the usual ground/Power capacitor can help the whole thing to work?!
    Also switched to a new regulator but this haven't changed anything.

    I couln't get back to have correct display yet. only garbage and ghosts...

    I ran a quick test with regular LCDOUT prg and this do work ok. Even the Lines were accesibles in correct order.
    I suspect USART sync problems, which I couldn't resolve in other projects :/
    How come it is supposed to be the performant solution and 10times more buggy than the software Serin??

    And now this thing wants to play PacMan with me!!
    All the ghost appeared by themself!


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

    Default

    Quote Originally Posted by flipper_md View Post
    well, for some esoteric reasons the thing started to work by itself after a few restart... this I hate
    I noticed one time i've got one capacitor disconnected on the Xtal... and it seems the PIC woulndt bother?? replugged it live and it kept working.


    since I was sending data from a PC, I assume it was regular RS232.
    Tried to get data from my PIC heartbeat system(which is using N9600) and as you said this format is not ok as is, text was garbaged. I'll need a max232 one day to invert signal.

    In the little time I had to play with the thing, I wondered how I could send data to drive other functions, else than display text?
    Can I do custom characters?
    clear screen? etc

    Another weird thing is that the LCD believe it's second line is the 3rd, when I send a long text. It start filling 1st, then 3rd, then 2nd, and finally 4th one?

    anyways I was just sooooo happy to see some text scrolling


    BUT, this morning it doesn't wan't to behave again, showing garbage text with the same steup! arg :/
    I suspect power problem from my regulator, although it's rated for 1amp.
    it's running way too hot when I plug the backlight of this 4lines monster. I guess this may cause some power problems.
    Actually, this is what fried my other LCD! PLugged in too many things, the regulator busted and started shooting 10V or so...smoke show B]

    for now I just keep doing short tests.

    thanks for the infos!
    Ok this thing is written to display with the same commands as used with LCDOUT, so line 1 is 2, line 2 is $C0 or 192, line 3 is $94 or 148, line 4 is $D4 or 212. The LCD we all use having 4 lines are really 2 lines cut in half and displayed as 4 with line 3 being the second half of line 1 and line 4 being the second half of line 2. Put a .01 µF cap on the lcd power terminals. PC COM Port outputs serial data iinverted and must be flipped for use by MAX232 or even a lousey old transistor. Have you tried sending data from another PIC? Just to be sure which post in this thread are you using the code from ? should be post 16.
    Oh it likes to boot up with the serial in pin in the HI state and herserin likes to Idle High as well. I have hooked this up to my computer with a max232 and sent large text files and not overrun the buffer, I say this because it did not go to buffer overrun and always ended with the ending text in the file, it went by WAY too fast to read. I think the little Ghosts are 60 hz due to open input on the PIC.
    Last edited by Archangel; - 14th October 2008 at 08:32.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  34. #34
    Join Date
    Jul 2007
    Posts
    65

    Default

    thanks Joe

    I will have to try some more when some free time appears!

  35. #35
    Join Date
    Jul 2007
    Posts
    65

    Default

    well,
    f-i-n-a--l-l--y went back into this and made it work, but I think it was a bad component somewhere causing problem (my regulator used to run very hot, and now it's not warm at all!)
    Oh mysteries

  36. #36
    Join Date
    Jul 2007
    Posts
    65

    Default

    added some code into the Instant Interrupt version, to get control of HPWM for the backlight of the LCD. Running a 16F628A @ 20Mhz
    Here is the *working* version ...so far

    I made it to behave like my other LCDs, so to control the backlight it wants to see code like:
    $14$FF 'full power
    $14$00 'off

    I also upped a little program that I use to test the LCD.
    http://www.flipperdesign.com/FlipLCD_control.rar

    Code:
    getbuf:					' move the next character in buffer to bufchar
      @ INT_DISABLE  RX_INT
    
        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
    
        if skipLCDComm>0 then
           skipLCDComm=skipLCDComm-1
           endif
        ;Routine for buffering LCD commands
        if (GrabBkLt=1) then
           ; WE have signal to watch for value for LCD backlight next
           ; LCDOut $FE,$94,"BACKLIGHT set:<",#bufchar,">"  ; for debug only
    
           HPWM 1,bufchar ,1250    ; Setting Pulse Mod to desired value
           	' Observe minimum FREQ for given OSC speed. 20Mhz is 1221Hz
           ' Next set bufchar to a null char, so I wont be seen/displayed
           bufchar = 24
           Low LedPort 	; Debug only	
           GrabBkLt=0    ; All is done, signal to close the loop
           ;Re-Enable Int and go back up, to skip displaying this char
           @ INT_ENABLE  RX_INT
           goto display
           endif
        ;Following will trigger the routine up here on the next chr received
        ; but if skip if $fe has been called 2 shots ago
        if (bufchar=20) and (skipLCDComm=0) then  ; 14h, trigger for special LCD command
           HIGH LedPort  ; Debug only
           GrabBkLt=1  ; Signal to get the value of backlight level
           ;Re-Enable Int and go back up, to skip displaying this char
           @ INT_ENABLE  RX_INT
           goto display
           endif
        ;Prevent value of 14h to be trapped for other command, we memorize previous call of $FE (254)
        if bufchar=254  then
           skipLCDComm=2 ;
           endif
     
      @ INT_ENABLE  RX_INT
    Return

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

    Default

    Ah ha, enhancements ...

    Small problem though ...
    getbuf: is a Subroutine.

    Jumping out of a subroutine to the main loop with ...
    Code:
          goto display
    is going to cause some stack problems.

    Try using RETURN at each of those goto's.

    DT

  38. #38
    Join Date
    Jul 2007
    Posts
    65

    Default

    oh! poor stack
    I will look into options to do it another way.

    stack seemed to survive so far. LOL

    thanks for the tip Darrel

  39. #39
    Join Date
    Aug 2009
    Posts
    33

    Default I wonder?

    Darrel sir, I am new on this forum and also programming PICs. I was looking for exactly what you have done here. I wonder first if I could use your programming on a 16F628 pic second, on what pin of which port should I connect the input to that 16F628 that will drive the parallel LCD and third, where should I find the two include “DT_INTS-14.bas and the ReEnterPBP.bas programs that the pbp compiler is asking for. Sorry for these silly questions but I really would like to learn. Thanks.


    Quote Originally Posted by Darrel Taylor View Post
    >> You just learn a little slower after 50.

    Oh No! I better hurry up and learn more, I've only got 3 years left.

    >> ... with only 4 months of experience at this ...

    Well, for only 4 months, you're doing pretty good.

    >> ... how long have you been doing this? anyway

    PicBasic Pro - about 5 years
    Programming - Umm, one month after the first TRS-80 hit the market, I guess that makes it about oh 28 years.


    I know DT_INTS looks intimidating at the begining, but it's really not that bad, and you don't need to learn assembly language to use it. But I can understand why you might not want to try it out. The biggest obstacle is that you have to be using MPASM.

    So whenever you get around to DT_INTS, you can come back to this thread and try out this program.
    It's your backpack program modified for Instant Interrupts.
    I've highlighted most of the changes (red is added, blue is removed).
    Tested it on a 16F877A
    Code:
    ;---- Config settings for MPASM ----------------------------------------------
    @  __config _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    
    trisb = %00000010
    trisA = %11110011
    ;include "modedefs.bas"
    
    ;----Added by DT--------------------------------------------------------------
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
    
    ASM
    INT_LIST  macro   ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    RX_INT,    _serialin,   PBP,  no
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   RX_INT     ; enable external (INT) interrupts
    ;-----------------------------------------------------------------------------
    
    ' 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
      @ INT_DISABLE  RX_INT
    	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
      @ INT_ENABLE  RX_INT
    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	
    @  INT_RETURN   		        ; 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	
    @  INT_RETURN   		        ; Return to program
    
    
    End
    Hope you can use it some day,

  40. #40
    Join Date
    Aug 2009
    Posts
    33

    Default Parallel LCD to Serial.

    I am new on this forum and also on programming PICs. I was looking for a program that helps me turn my parallel LCD into a serial. That’s what Mr. Darrel Taylor’s program does on “LCD Serial backpacks post #16. I wonder first if I could use his program on a 16F628 because the compiler doesn’t like it as is. Second, on what pin of which port should I connect the serial input on that 16F628 that will drive the parallel LCD. Sorry for these silly questions but I really would like to learn how to do that. Thanks.

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