serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780


+ Reply to Thread
Results 1 to 40 of 60

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,171


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780

    Tried different baud rate but still only Backlight work. The rest is just irrelevant characters on screen.

    Then tried the new code of Richards, but have 1827 chip, so asm code is not compatible.

    Gave up...

    Ioannis

  2. #2
    Join Date
    Feb 2022
    Posts
    78


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780

    maybe the chip?

    for my part I used

    12F683, 16F690 old regular Pic.

    I tried richard code, and it's impressive asm code, that I can't do for sure.

    so I stick to basic.

    when you're back on this LCD, try this 'self text' backpack for 16F690 maybe it will give a hint.

    Code:
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Name  : 16F690 LCD BACKPACK  Self Text
    ' File  : "D:\PIC\PBP3\16F690\LCD BACKPACK\16F690 LCD BACKPACK Self Text.pbp"
    ' Date  : Oct 4-2025
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Serin2   
    '#CONFIG
    '  __config  _INTRC_OSC_CLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
    '#ENDCONFIG
    
    
     ' HSERIN
    #CONFIG
      __config  _HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 20       ' Core is running at EXT-CRYSTAL 20MHz PBP 33,217
    'DEFINE OSC 8
    ANSEL = 0           ' Set all pins digital
    ANSELH = 0          ' Set all pins digital
    OPTION_REG.7 = 0    ' PORTA/PORTB pull-ups are enabled by individual port latch values
    CM1CON0 = 0         ' Analog comparators off
    
    
    En var Portb.4 : low en
    RS var Portb.6 : low rs
    B1 var byte : b1 = 0
    C VAR BYTE : C = 100
    I VAR BYTE 
    
    
    ' 1602
    ArrayA var Byte [16] : ARRAYWRITE ArrayA,["ABCDEF1234567890"] ' Line 1
    ArrayB var Byte [16] : ARRAYWRITE ArrayB,["1234567890!@#$%^"] ' Line 2
    ' 2004
    'ArrayC var Byte [20] : ARRAYWRITE ArrayC,["ABCDEF1234567890!@#$"] ' Line 1
    'ArrayD var Byte [20] : ARRAYWRITE ArrayD,["1234567890!@#$%^!@#$"] ' Line 2
    'ArrayE var Byte [20] : ARRAYWRITE ArrayE,["ABCDEF1234567890!@#$"] ' Line 3
    'ArrayF var Byte [20] : ARRAYWRITE ArrayF,["1234567890!@#$%^!@#$"] ' Line 4
    
    
    TRISA = 0 : TRISB = %00100000 : TRISC = 0
    PORTA = 0 : PORTB = 0 : PORTC = 0
    OSCCON = $70  
    
    
    pause 100
    high Porta.0              ' Backlight ON
    gosub LCDinit             ' initialise LCD
    pause 100
    
    
    main:
    ' 1602
    Low RS : PORTC = 128 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 1
    For I = 0 To 15
        PORTC = ArrayA[I] 
        High En : PauseUS 1 : Low En
        Pause C
    Next I
    Low RS : PORTC = 192 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 2
    For I = 0 To 15 
        PORTC = ArrayB[I] 
        High En : PauseUS 1 : Low En
        Pause C
    Next I
    
    
    ' 2004 
    'Low RS : PORTC = 128 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 1
    'For I = 0 To 19
    '    PORTC = ArrayC[I] 
    '    High En : PauseUS 1 : Low En
    '    Pause C
    'Next I
    'Low RS : PORTC = 192 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 2
    'For I = 0 To 19 
    '    PORTC = ArrayD[I] 
    '    High En : PauseUS 1 : Low En
    '    Pause C
    'Next I
    'Low RS : PORTC = 148 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 3
    'For I = 0 To 19
    '    PORTC = ArrayE[I] 
    '    High En : PauseUS 1 : Low En
    '    Pause C
    'Next I
    'Low RS : PORTC = 212 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 4
    'For I = 0 To 19 
    '    PORTC = ArrayF[I] 
    '    High En : PauseUS 1 : Low En
    '    Pause C
    'Next I
     
    Pause 1000
    Low RS : PORTC = 1 : High En : PauseUS 1 : Low En : High RS : PauseUS 4  ' Clear display 
    Pause 500
    'Low PORTA.0      ' Bacck Light off
    Pause 200
    High PORTA.0     ' Bacck Light on
    Pause 200
    
    
    C = C - 20
    If C < 20 Then 
    C = 100
    EndIf
    
    
    GoTo main
        
    LCDINIT:				  ' Standard LCD Module Initialisation
    PORTC = %00000001 : HIGH EN : PAUSEus 1 : LOW EN : pause 4 ' Clear Display
    PORTC = %00000010 : HIGH EN : PAUSEus 1 : LOW EN : pause 2 ' Return Home
    PORTC = %00111000 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' 8 bit, 2 line, 5x8 Characters
    PORTC = %00000110 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' Entry mode
    PORTC = %00001100 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' %00001DCB Display on/off, Cursor on/off, Blink y/n	  
    RETURN

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,704


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780

    For a 1827 it would look like this [untested]

    Code:
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
    ' Name  : 16F1827 LCD BACKPACK                                                *
    ' Date  : oct 2025    richard                                                 *
    ' Note  : RING BUFFERED                                                       *
    ' Notes : DEFA BAUD RATE 9600 Intrc_OSC 8Mhz                                  *
    '         eeprom full case is unhandled,factory reset would be advisable      *
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    #CONFIG
      __config  _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
      __config  _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_19 & _LVP_OFF
    #ENDCONFIG
    
    
    ;commands eg   SEROUT2 lcd,84,[255,11]  set baudrate from 9600 to 19200
    '255 0/8  backlight 
    '255 10/11/12  baud rate  9600/19200/38400
    '255 "F"  factory reset
    
    
        DEFINE OSC 8  
        DEFINE INTHAND myint 
        DEFINE WRITE_INT 1
        ANSELA = 0           ' Set all pins digital
        ANSELB = 0          ' Set all pins digital
        OPTION_REG.7 = 0    ' PORTA/PORTB pull-ups are enabled by individual port latch values
        
        CLEAR
        DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
        DEFINE LCD_DREG PORTA	'defines the port where data lines are connected to
        DEFINE LCD_DBIT 4
        DEFINE LCD_RSREG PORTB	'defines the port where RS line is connected to
        DEFINE LCD_RSBIT 6 	'defines the pin where RS line is connected to 
        DEFINE LCD_EREG PORTB 	'defines the port where E line is connected to 
        DEFINE LCD_EBIT 4 	'defines the pin where E line is connected 
        DEFINE LCD_COMMANDUS 1500 	'defines the delay after LCDOUT statement 
        DEFINE LCD_DATAUS 50 		'delay in micro seconds
    
    
    
    
    
    
        RCSTA = $90   ' Enable serial port & continuous receive
        TXSTA = $20   ' Enable transmit, BRGH = 0
        SP1BRG = 51    ' 19200 Baud @ 8MHz, 0.16%, 51 ' 9600 Baud @ 8MHz, 0.16%, 12 ' 38400 Baud @ 8MHz, 0.16%
        SP1BRGH = 0
        BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
        buffer_size      CON 32                ' Sets the size of the ring buffer
        index_in         VAR BYTE bank0         ' Pointer - next empty location in buffer
        index_out        VAR BYTE bank0         ' Pointer - location of oldest character in buffer
        errflag          VAR BYTE bank0         ' Error flag
        UartFlag         VAR errflag.0
        BufferFlag       VAR errflag.1
        buffer           VAR BYTE[buffer_size] ' Array variable for holding received characters 
        bufchar          VAR BYTE              ' Stores the character retrieved from the buffer
        Bl               var byte 
        inx              var byte
        Br               var byte 
    GOTO overint ' Jump over the interrupt handler 
    ASM
    myint
    
    
    ; Check for hardware overrun error
       btfsc   RCSTA,OERR   ; Check for usart overrun
       goto    usart_err    ; jump to assembly error routine
    ; Test for buffer overrun               
       incf   _index_in,W   ; Increment index_in to W
       subwf  _index_out,W  ; Subtract indexes to test for buffer overrun
       btfsc  STATUS,Z      ; check for zero (index_in = index_out)
       goto  buffer_err    ; jump to error routine if zero
    ; Increment the index_in pointer and reset it if it's outside the ring buffer
       incf   _index_in,F   ; Increment index_in to index_in
       movf   _index_in,W   ; Move new index_in to W
       sublw  _buffer_size-1; Subtract index_in from buffer_size-1
       btfss  STATUS, C     ; If index_in => buffer_size
       clrf   _index_in     ; Clear index_in
    ; Set FSR with the location of the next empty location in buffer
       movlw    _buffer  ;Store the High byte of buffer to FSR
       movwf   FSR0
       addwf   _index_in,W  ; Add index_in to point to next empty slot
       movwf   FSR0        ; Store Low byte of pointer in FSR
    ; Read and store the character from the USART           
       movf   RCREG,W       ; Read the received character
       movwf  INDF0         ; Put the received character in FSR location
       BTFSC  PIR1,RCIF     ;ANY MORE ?
       goto    myint
    finished 
       retfie ; Return from interrupt 
    ; Error routines        
    buffer_err              ; Jump here on buffer error
       bsf   _errflag,1     ; Set the buffer flag
    usart_err               ; Jump here on USART error
       bsf   _errflag,0     ; Set the USART flag
       movf  RCREG, W       ; Trash the received character
       goto finished       ; Restore state and return to program
    ENDASM
    overint: 
        
        TRISB = % 00101111
        TRISA = % 11110000 
        OSCCON = $70
        PAUSE 500
        gosub getbaud
        PAUSE 5
        LCDOUT $FE,1 
        hserout [13,"ready"]
        LCDOUT "ready "
        if br==51 then
          hserout ["@9600"]
          LCDOUT  "@9600"
        elseif br==25 then
          hserout ["@19200"]
          LCDOUT  "@19200"
        else       
          hserout ["@38400"]
          LCDOUT  "@38400"
        endif 
        PAUSE 500
    @  bsf   LCD_RSREG ,LCD_RSBIT
        GOSUB error
        INTCON = $C0
        PIE1.5 = 1
    main:
       IF errflag Then GOSUB error ' Goto error routine if needed
       IF index_in = index_out Then main ' loop if nothing in buffer     
       GoSub getbuf         ' Get a character from buffer
       if bl then
            if bufchar = 0 then 
                 porta.0 = 0 ' Back Light OFF
            endif
            if bufchar = 8 then 
                 porta.0 = 1 ' Back Light ON
            endif
            if bufchar = 10 then 
                 write inx+1,51
                 gosub getbaud
            endif
            if bufchar = 11 then 
                 write inx+1,25
                 gosub getbaud
            endif
            if bufchar = 12 then 
                 write inx+1,12
                 gosub getbaud
            endif
            if bufchar = "F" then 
                 gosub factory
            endif
    
    
            bl = 0
            goto main
       endif
       if bufchar = 255 then 
             bl = 1
             goto main
       endif
       if bufchar = 254 then
    @  bcf   LCD_RSREG ,LCD_RSBIT
             goto main 
       endif 
    @  MOVE?BB _bufchar,R3
    @  L?CALL lcdsend
    @  bsf   LCD_RSREG ,LCD_RSBIT
    goto main             ' loop back to top
        
    
    
    error:                          ' Display error message
       INTCON = 0                   ' Disable interrupts while in the error routine
       IF errflag.1 Then            ' Determine the error
          hserout ["B!",13]' Display buffer error on line-2
       Else
          hserout ["U!",13]  ' Display usart error on line_2
       EndIF  
       errflag = 0          ' Reset the error flag    ;clear any rcsta error
       RCSTA.4 = 0           'CREN = 0 Disable continuous receive to clear hardware error
       RCSTA.4 = 1           'CREN = 1 Enable continuous receive
       INTCON = %11000000   ' Enable interrupts
    RETURN         ' repeat
    
    
        
    getbuf:  ' Move the next character in buffer to bufchar
       index_out = index_out + 1     ' Increment index_out pointer (0 to 31)
       IF index_out => buffer_size Then index_out = 0 ' Reset pointer if outside buffer
       bufchar = buffer[index_out]  ' Read buffer location(index_out)
    Return
    
    
    getbaud:
        bufchar = 0
        inx = 255
        read inx,Br
        while Br==255
            read inx,Br
            if  Br==255  then 
                if inx == 0  then  
                    br=51
                    write inx,51
                    hserout [13,"init@9600 " ,dec inx,",",dec Br]
                else
                    inx = inx-1
                endif
            endif
        wend   ;note if inx=255 then eeprom full
        hserout [" index " ,dec inx,",",dec Br]
        SP1BRG = Br
    Return
    
    
    factory:
      write 0,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 16,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 32,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 48,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 64,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 80,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 96,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 112,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 128,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 144,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 160,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 176,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 192,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 208,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 224,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 240,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      gosub getbaud
    Return
    Warning I'm not a teacher

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,704


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780

    a bit out of practice , forgot porta.4 is input only plus 1827 has bits and pieces in other banks

    so tested and working version
    Code:
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
    ' Name  : 16F1827 LCD BACKPACK                                                *
    ' Date  : oct 2025    richard                                                 *
    ' Note  : RING BUFFERED                                                       *
    ' Notes : DEFA BAUD RATE 9600 Intrc_OSC 8Mhz                                  *
    '         eeprom full case is unhandled,factory reset would be advisable      *
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    #CONFIG
      __config  _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
      __config  _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_19 & _LVP_OFF
    #ENDCONFIG
    
    
    ;commands eg   SEROUT2 lcd,84,[255,11]  set baudrate from 9600 to 19200
    '255 0/8  backlight 
    '255 10/11/12  baud rate  9600/19200/38400
    '255 "F"  factory reset
    ;TX PORTB.2  RX PORTB.1 BACKLIGHT PORTB.0
        DEFINE OSC 8  
        DEFINE INTHAND myint 
        DEFINE WRITE_INT 1
        ANSELA = 0           ' Set all pins digital
        ANSELB = 0          ' Set all pins digital
    '    OPTION_REG.7 = 0    ' PORTA/PORTB pull-ups are enabled by individual port latch values
        
        CLEAR
        DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
        DEFINE LCD_DREG PORTA	'defines the port where data lines are connected to
        DEFINE LCD_DBIT 0
        DEFINE LCD_RSREG PORTB	'defines the port where RS line is connected to
        DEFINE LCD_RSBIT 6 	'defines the pin where RS line is connected to 
        DEFINE LCD_EREG PORTB 	'defines the port where E line is connected to 
        DEFINE LCD_EBIT 4 	'defines the pin where E line is connected 
        DEFINE LCD_COMMANDUS 1500 	'defines the delay after LCDOUT statement 
        DEFINE LCD_DATAUS 50 		'delay in micro seconds
    
    
    
    
    
    
        RCSTA = $90   ' Enable serial port & continuous receive
        TXSTA = $20   ' Enable transmit, BRGH = 0
        SP1BRG = 51    ' 19200 Baud @ 8MHz, 0.16%, 51 ' 9600 Baud @ 8MHz, 0.16%, 12 ' 38400 Baud @ 8MHz, 0.16%
        SP1BRGH = 0
        BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
        buffer_size      CON 32                ' Sets the size of the ring buffer
        index_in         VAR BYTE bank0         ' Pointer - next empty location in buffer
        index_out        VAR BYTE bank0         ' Pointer - location of oldest character in buffer
        errflag          VAR BYTE bank0         ' Error flag
        UartFlag         VAR errflag.0
        BufferFlag       VAR errflag.1
        buffer           VAR BYTE[buffer_size] ' Array variable for holding received characters 
        bufchar          VAR BYTE              ' Stores the character retrieved from the buffer
        Bl               var byte 
        inx              var byte
        Br               var byte 
    GOTO overint ' Jump over the interrupt handler 
    ASM
    myint
    
    
    ; Check for hardware overrun error
       banksel RCSTA
       btfsc   RCSTA,OERR   ; Check for usart overrun
       goto    usart_err    ; jump to assembly error routine
    ; Test for buffer overrun 
       banksel 0           
       incf   _index_in,W   ; Increment index_in to W
       subwf  _index_out,W  ; Subtract indexes to test for buffer overrun
       btfsc  STATUS,Z      ; check for zero (index_in = index_out)
       goto  buffer_err    ; jump to error routine if zero
    ; Increment the index_in pointer and reset it if it's outside the ring buffer
       incf   _index_in,F   ; Increment index_in to index_in
       movf   _index_in,W   ; Move new index_in to W
       sublw  _buffer_size-1; Subtract index_in from buffer_size-1
       btfss  STATUS, C     ; If index_in => buffer_size
       clrf   _index_in     ; Clear index_in
    ; Set FSR with the location of the next empty location in buffer
       movlw   High _buffer  ;Store the High byte of buffer to FSR0H
       movwf   FSR0H
       movlw   Low _buffer  ; Get the Low byte of buffer[0]
       addwf   _index_in,W  ; Add index_in to point to next empty slot
       movwf   FSR0L        ; Store Low byte of pointer in FSR0
    ; Read and store the character from the USART 
       banksel RCREG       
       movf   RCREG,W       ; Read the received character
       movwf  INDF0         ; Put the received character in FSR location
       banksel PIR1
       BTFSC  PIR1,RCIF     ;ANY MORE ?
       goto    myint
    finished 
       RST?RP
       retfie ; Return from interrupt 
    ; Error routines        
    buffer_err    ; Jump here on buffer error
       bsf   _errflag,1     ; Set the buffer flag
    usart_err               ; Jump here on USART error
       banksel  _errflag
       bsf   _errflag,0     ; Set the USART flag
       banksel RCREG 
       movf  RCREG, W       ; Trash the received character
       goto finished       ; Restore state and return to program
    ENDASM
    overint: 
        
        TRISB = %10101010
        TRISA = %11110000 
        OSCCON = $70
        PAUSE 500
        gosub getbaud
        PAUSE 5
        LCDOUT $FE,1 
        hserout [13,"ready"]
        LCDOUT "ready "
        if br==51 then
          hserout ["@9600"]
          LCDOUT  "@9600"
        elseif br==25 then
          hserout ["@19200"]
          LCDOUT  "@19200"
        else       
          hserout ["@38400"]
          LCDOUT  "@38400"
        endif 
        PAUSE 500
    @  bsf   LCD_RSREG ,LCD_RSBIT
        GOSUB error
        INTCON = $C0
        PIE1.5 = 1
    main:
       IF errflag Then GOSUB error ' Goto error routine if needed
       IF index_in = index_out Then main ' loop if nothing in buffer     
       GoSub getbuf         ' Get a character from buffer
       if bl then
            if bufchar = 0 then 
                 portB.0 = 0 ' Back Light OFF
            endif
            if bufchar = 8 then 
                 portB.0 = 1 ' Back Light ON
            endif
            if bufchar = 10 then 
                 write inx+1,51
                 gosub getbaud
            endif
            if bufchar = 11 then 
                 write inx+1,25
                 gosub getbaud
            endif
            if bufchar = 12 then 
                 write inx+1,12
                 gosub getbaud
            endif
            if bufchar = "F" then 
                 gosub factory
            endif
    
    
            bl = 0
            goto main
       endif
       if bufchar = 255 then 
             bl = 1
             goto main
       endif
       if bufchar = 254 then
    @  bcf   LCD_RSREG ,LCD_RSBIT
             goto main 
       endif 
    @  MOVE?BB _bufchar,R3
    @  MOVE?CT 1,FLAGS ,0
    @  L?CALL lcdsend
    @  bsf   LCD_RSREG ,LCD_RSBIT
    goto main             ' loop back to top
        
    
    
    error:                          ' Display error message
       INTCON = 0                   ' Disable interrupts while in the error routine
       IF errflag.1 Then            ' Determine the error
          hserout ["B!",13]' Display buffer error on line-2
       Else
          hserout ["U!",13]  ' Display usart error on line_2
       EndIF  
       errflag = 0          ' Reset the error flag    ;clear any rcsta error
       RCSTA.4 = 0           'CREN = 0 Disable continuous receive to clear hardware error
       RCSTA.4 = 1           'CREN = 1 Enable continuous receive
       INTCON = %11000000   ' Enable interrupts
    RETURN         ' repeat
    
    
        
    getbuf:  ' Move the next character in buffer to bufchar
       index_out = index_out + 1     ' Increment index_out pointer (0 to 31)
       IF index_out => buffer_size Then index_out = 0 ' Reset pointer if outside buffer
       bufchar = buffer[index_out]  ' Read buffer location(index_out)
    Return
    
    
    getbaud:
        bufchar = 0
        inx = 255
        read inx,Br
        while Br==255
            read inx,Br
            if  Br==255  then 
                if inx == 0  then  
                    br=51
                    write inx,51
                    hserout [13,"init@9600 " ,dec inx,",",dec Br]
                else
                    inx = inx-1
                endif
            endif
        wend   ;note if inx=255 then eeprom full
        hserout [" index " ,dec inx,",",dec Br]
        SP1BRG = Br
    Return
    
    
    factory:
      write 0,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 16,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 32,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 48,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 64,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 80,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 96,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 112,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 128,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 144,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 160,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 176,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 192,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 208,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 224,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      write 240,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
      gosub getbaud
    Return
    Warning I'm not a teacher

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,171


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780

    Thanks Richard.

    The new code:
    1. works OK with LCD Backlight On/Off
    2. works OK sending text over the serial port
    3. works OK sending commands to LCD over serial port
    4. On power up LCD shows ready@38400 and this does not change. But the communication baud rate is 9600. With 255,10 or 11 or12 can change baud rate but it is not displayed on LCD. Though higher baud rates need pace.
    5. On power up the terminal shows ready@38400U!

    Have done two changes on port b to drive the RS and E signal on PortB.3 and PortB.4.

    PortB.1 is the RS-232 driver TX output from PIC
    PortB.2 is the RS-232 driver RX input to PIC

    Ioannis
    Last edited by Ioannis; - 10th October 2025 at 10:54.

Similar Threads

  1. Using 16F1503 as Serial LCD Backpack
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th March 2015, 20:58
  2. 16F877A and LCD HD44780
    By epilot in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 1st November 2013, 19:17
  3. FREE Serial LCD Backpack Board
    By rmteo in forum Off Topic
    Replies: 36
    Last Post: - 29th July 2010, 03:32
  4. Lcd Hd44780
    By alaaodeh in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th February 2007, 15:04
  5. LCD 4x20 HD44780
    By inteco in forum mel PIC BASIC
    Replies: 13
    Last Post: - 27th June 2006, 17:52

Members who have read this thread : 15

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