LCD serial backpacks


Closed Thread
Results 1 to 40 of 68

Hybrid View

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

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

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

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

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