serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780


+ Reply to Thread
Results 1 to 40 of 60

Hybrid View

  1. #1
    Join Date
    Feb 2022
    Posts
    78

    Default serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780

    Hello everyone,

    I'de like to share this project, may come handy for hobbyist working around LCD display.

    My search for a serial LCD that can receive serial data from 300 to 19200 baud on the internet was not successful
    then I roll-up my sleeves and build this LCD backpack that use a common Hitachi HD44780 display. (still popular today)

    My project was simple with parts already on hand like PIC16F690, NPN smd transistor, potentiometer, resistor. and PBP3 Basic code.

    So enjoy,

    Code:
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Name  : 16F690 LCD BACKPACK
    ' Date  : Sep 27-2025
    ' Note  : 393 words used  of 2048
    ' Notes : Serin2 Baud Rate 300 ~ 19200 Intrc_OSC 8Mhz
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT 
    cfg&= _WDT_OFF
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_OFF
    cfg&= _IESO_OFF
    cfg&= _FCMEN_OFF
      __CONFIG cfg
    #ENDCONFIG
    DEFINE OSC 8        ' Core is running at EXT-CRYSTAL 16MHz PBP 33,217
    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
    
    
    ' 300=3313  600=1646  1200=813  2400=396  4800=188  9600=84  19200=32
    BaudR var byte : baudr = 32 
    
    
    TRISA = 0 : TRISB = 100000 : TRISC = 0
    PORTA = 0 : PORTB = 0 : PORTC = 0
    OSCCON = $70  
    
    
    high Porta.0              ' Backlight ON
    
    
    gosub LCDinit             ' initialise LCD
    
    
    'Serin2
    main:
        serin2 Portb.5,baudr,3,main,[b1]
    
    
        if b1 < 253 then     ' Characters
            PORTC = b1 
            HIGH EN : PAUSEus 5 : LOW EN
            goto main        
        elseif b1 = 254 then  ' LCD Command
            low RS            
            serin2 Portb.5,baudr,3,main,[b1]
            PORTC = b1          ' output the data
            HIGH EN : PAUSEus 5 : LOW EN
            high RS           ' character mode
            goto main         
        elseif b1 = 255 then  
            low rs            ' LCD Command
    
    
        serin2 Portb.5,baudr,3,main,[b1]
            if b1 = 0 then 
                low porta.0   ' Back Light OFF
            high rs
            endif
            if b1 = 8 then 
                high porta.0  ' Back Light ON
            high rs    
            endif
           goto main             ' loop back to top
        ENDIF
    
    
    LCDINIT:                  ' Standard LCD Module Initialisation
    PORTC = 000001          ' 2, Clear Display
        HIGH EN : PAUSEus 300 : LOW EN ' Send data
        pause 4
    PORTC = 000010          ' 4, Return Home
        HIGH EN : PAUSEus 300 : LOW EN
        pause 4
    PORTC = 111000         ' 1, 8 bit, 2 line, 5x8 Characters
        HIGH EN : PAUSEus 300 : LOW EN
        pause 4
    ' PORTC = 001100          ' Display on, no cursor, no blink
    PORTC = 001110          ' 1, Display on, cursor, blink
        HIGH EN : PAUSEus 300 : LOW EN
        pause 4
    PORTC = 000110          ' 1, Entry mode
        HIGH EN : PAUSEus 300 : LOW EN
        pause 4
        high rs                  ' character mode
    RETURN

    Name:  DSC02371.JPG
Views: 143
Size:  89.9 KB


    Name:  DSC02372.JPG
Views: 132
Size:  103.3 KB

  2. #2
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    Here's an code update

    on the LCD backpack code the line

    BaudR var byte should be replace with: BaudR var Word

    and here's the serial sender code updated as well. (use an 12F683)

    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Project : 12F683 Serial LCD Test 300 ~ 19200 baud for 16F690 Lcd Backpack
    'Date    : Sep 27-2025
    'Notes   : 285 words used  of 2048                                             
    'Notes   : Serout2 300 ~ 19200  Intrc_OSC 8Mhz
    '300=3313  600=1646  1200=813  2400=396  4800=188  9600=84  19200=32 
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    #CONFIG
     __config  _INTOSCIO & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOD_OFF  & _CP_OFF & _CPD_OFF
    #ENDCONFIG
    DEFINE OSC 8           ' Core is running at EXT-CRYSTAL 16MHz PBP 33,217
    LCD Var GPIO.0         ' Serial out
    ANSEL = 0              ' Set all digital  PULLUP Resistor  page:10
    TRISIO = %00000000     ' INPUT=1 OUTPUT = 0
    OSCCON = $70           ' $70=8Mhz  $60=4mhz  $50=2MHZ  $40=1MHZ  $30=500KHZ   
    
    
    BaudR var word
    baudR = 32 ' 300=3313  600=1646  1200=813  2400=396  4800=188  9600=84  19200=32 
    Pace var byte          ' for serout2 
    pace = 0
    
    
    SEROUT2 lcd,baudR,pace,[ 254, 1] ' Clear LCD
    pause 40
    
    
    DO
    ' LCD 1602
        sEROUT2 lcd,baudR,pace,[254,128,"ABCDEFGHIJKLMNOP"] ' Line 1 16 Char.
        SEROUT2 lcd,baudR,pace,[254,192,"0123456789-=,./>"] ' Line 2 16 Char.
    
    
    ' LCD 2004
        'SEROUT2 lcd,BaudR,pace,[254,128,"ABCDEFGHIJkLMNOPQRST"] ' Line 1 20 Char.
        'SEROUT2 lcd,BaudR,pace,[254,192,"0123456789-=,./;!@#$"] ' Line 2 20 Char.
        'SEROUT2 lcd,BaudR,pace,[254,148,"ABCDEFGHIJkLMNOPQRST"] ' Line 3 20 Char.
        'SEROUT2 lcd,BaudR,pace,[254,212,"0123456789-=,./;!@#$"] ' Line 4 20 Char.
    
    
        PAUSE 2000
        SEROUT2 lcd,baudR,pace,[ 255, 0] ' Back Light OFF
        PAUSE 200    
        SEROUT2 lcd,baudR,pace,[ 255, 8] ' Back Light ON
        PAUSE 2000
     
        SEROUT2 lcd,baudR,pace,[ 254, 1] ' Clear LCD
        pause 1000
    LOOP
    END

  3. #3
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    final code update in "16F690 LCD BACKPACK"
    the low rs and high rs lines are not needed, since it control PortA.0 and not the HD44780 chip.


    elseif b1 = 255 then
    ' low rs ' LCD Command
    serin2 Portb.5,baudr,3,main,[b1]
    if b1 = 0 then
    low porta.0 ' Back Light OFF
    ' high rs
    endif
    if b1 = 8 then
    high porta.0 ' Back Light ON
    ' high rs
    endif
    Last edited by jackberg1; - 28th September 2025 at 20:27.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

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

    Thanks for posting your project.

    But why not use the Hardware USART instead of the Software one?

    Ioannis

  5. #5
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    Hello Ioannis,

    good question,

    when I design the PCB I used the PortB.5 with a 20Mhz crystal with bigger pcb foot print 46x17mm
    then I decided to lower the parts count and the PCB foot print to a bare minimum (41 x 17mm)
    Also theses HD44780 are still in use by many hobbyist around the world, I guess, and the baud rate I was looking is plenty for this kind of display.

    thank's for asking.

    Name:  new PCB 41x17mm.jpg
Views: 100
Size:  64.6 KB



  6. #6
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    Hello,

    you're right
    my assumption was that software or hardware control serial communication are the same
    and one way or another I'll get the same result.

    if I may ask in this project what the benefit of hardware over software serial control.

    thank's again.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    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

    Less code usage. If for some reason you need Serin, it may hang if the device is not replying correctly. Hserin has timout and will save the day.

    For your project it may not have any meaning, but I think it is good practice to use as much as you can the hardware features than the emulated software.

    Ioannis
    Last edited by Ioannis; - 30th September 2025 at 14:31.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,682


    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

    if I may ask in this project what the benefit of hardware over software serial control.
    doubtful there is any since the 690 does nothing else anyway and the lcd's speed is the real bottle neck
    Warning I'm not a teacher

  9. #9
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    ASM , very impressif code,

    thanks.

  10. #10
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    I aggree on both comment, Hserin is more convenient than Serin2

    the goal of this project was to learn base on inexpensive parts on-hand

    you can strech the total cost for less than $12 pcb included not bad for an hobbyist who's looking to add a simple but pratical alphanumeric display

    I really appreciate comments

    btw , what is happening with MELab Forum, is it close for good.
    Last edited by jackberg1; - 1st October 2025 at 02:01.

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

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

    The Melabs Forum is(was?) supported by the company itself. So little is known as to what is happening.

    The company does not really have a future.

    Some of us here are also dinosaures and reluctant to switch to C or other platforms. So we stay and try to support its operation, as long as our host, honorable Lester, allows this forum to live.

    Ioannis

  12. #12
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    very kind of you to reply,

    Roughly 12 years ago, I started learning Basic Pic programming with Picaxe, then GCBasic
    now I'm mostly using MELab PBP Pro, and Positron both are like twin of Pic Basic compiler.

    my guess is these IDE Compilers are the last ones on the market, now the current trend is
    with Arduino, Python etc..

    if I may ask,

    are you aware of any good sources on how,
    to learn asm, and understand the asm files structure, to write assembler code, compile it and to download to a PIC

    regards.

  13. #13
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

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

    What is the use of learning ASM when C is better with great support and portable too?

    I think it is a waste of time if you choose ASM. Also you have to deal with pages, Banks and will be very much difficult to keep your mind checking all the time if your code has to change banks, pages etc in order to access registers correctly.

    But if you insist on diving in the deep dark waters of ASM, then I guess Microchip is the first to think. But these video tutorials also help https://www.youtube.com/@IESD2013

    Ioannis

  14. #14
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    thanks for the advice, it's helping what to consider.

  15. #15
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    as for C is considered, which IDE/Compiler you use or recommend

  16. #16
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    quick update for the Backpack code: High RS line should be remove to avoid random character on screen when booting.

    PORTC = %00000110 : High En : DelayUS 1 : Low En : DelayMS 1 ' Entry mode
    ' High RS
    Return

  17. #17
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    correct order for display control

    PORTC = %00001110 ' %00001DCB Display on/off, cursor on/off, blink y/n

  18. #18
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    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

    Regarding C, MPLABX is the one to try and sure the last. It includes also the MCC tool to setup any microcontroller with ease.

    Tried a couple of times C but i guess i am too old to change ...

    Ioannis

  19. #19
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    I did try MPLAB X a year ago and it's was a bitter chalenge comparing to what I'm used to do with PBP3,Picaxe, Positron

  20. #20
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    Excellent news,,

  21. #21
    Join Date
    May 2013
    Location
    australia
    Posts
    2,682


    Did you find this post helpful? Yes | No

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

    removed debug messages that are sent before spbrg set to correct value
    since 1827 has more resources have increased buffer size, u may not need pacing any longer to compensate for
    the 4 bit lcd interface being a bit slower

    baud rate is only shown on lcd at boot , setting is stored in eeprom


    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 64                ' 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 = % 00101010
        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
                 portB.7 = 1 ' Back Light OFF
            endif
            if bufchar = 8 then 
                 portB.0 = 1 ' Back Light ON
                 portB.7 = 0 ' Back Light OFF
            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 [" Buffer overflow",13]' Display buffer error on line-2
       Else
          hserout [" Uart reset",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

  22. #22
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    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

    Great work Richard!

    Works very well. Thank you.

    I had to change LCD_COMMANDUS to 2000 from 1500 for best performance.

    I just did not understood what all these ff's at the end of the code do.

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

  23. #23
    Join Date
    May 2013
    Location
    australia
    Posts
    2,682


    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

    I had to change LCD_COMMANDUS to 2000 from 1500 for best performance
    not to be unexpected, the LCD timing defines need to match the display in use. some are very slow


    Code:
    I just did not understood what all these ff's at the end of the code do.
    not pretty I agree but its one simple way to erase the eeprom at run time, hence "factory" as in factory reset
    Warning I'm not a teacher

  24. #24
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    Oct 2 2025

    update on 16F690 Backpack, new LCDINT pause to accomodate 28800,38400 baud rate for (Xtal = 20Mhz)

    #CONFIG
    __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
    #ENDCONFIG

    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 = %00001110 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' %00001DCB Display on/off, Cursor on/off, Blink y/n
    RETURN

  25. #25
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    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

    Agree that MPLABX is a bit scarry but has all the tools to complete a task regarding C at least.

    You have MCC, Simulator, breakpoints etc. Basic does not give all these goodies.

    As for your LCD driver, I think it is a little bit dependant on the specific LCD characteristics. Some are slow and some are a bit faster, so user has take that into account.

    Ioannis

  26. #26
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    totally agree, the LCD is kind of an old tech, but for an hobbyist it's a good learning tool.

    to clarify the baud rate turn around, just include this chart to figure it out.

    with each OSC setup, it can manage baud rate from 300 ~ 38400.


    Name:  Baud Rate Chart.jpg
Views: 91
Size:  57.6 KB

  27. #27
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    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

    I meant the LCD timing specs that have differencies. So the end user may have to take into account that.

    Things to adjust include these DEFINEs (from the manual):

    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 1500

    ' Set data delay time in us
    DEFINE LCD_DATAUS 44

    44 maybe on the edge. 50 maybe more safe.

    Ioannis
    Last edited by Ioannis; - 3rd October 2025 at 11:31.

  28. #28
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    thanks, to clarify

  29. #29
    Join Date
    Nov 2019
    Posts
    21


    Did you find this post helpful? Yes | No

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

    Newhaven Display (newhavendisplay.com) offers a collection of 10 different character LCDs in 2x16, 2x20 and 4x20 formats that are exclusively serial inputs -- I2C, SPI and Async TTL -- and reasonably priced at $15 to $20 U.S. I have a couple of the 2x20's, and they work nicely in all 3 interface modes. Nevertheless, this is a very interesting project as I (like everyone else) have a drawer full of parallel interface HD44780 type LCDs that will be put to better use with this serial interface. Many thanks, and I'll provide you feedback if I have anything useful to contribute.

  30. #30
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    one last update:

    added an PGM Sw on RA3

    to edit the baud rate:

    turn off the LCD display, press & hold the PGM sw, turn on the LCD
    line 1 will show "Press to Select" , line 2 : "Baud Rate:"
    release the sw and press it again to select next value (at this point the new value is save to EEPROM memory)
    when the desire value is reach, turn off the LCD and turn it on again at this point the LCD will display the baud rate on line 2
    and the display is ready to receive a clear LCD command, and data from the sender.

    As for different LCD module eg: 1601,1602,2004 1 line, 2 lines 4 lines etc.. the LCD commands is use to control position of the data on the screen.

    as of today the 1601, 1602, 2004 have been tested successfuly.


    Code:
    #CONFIG               
      __config  _HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 20                           ' Running @ 20MHz PBP 33,217
    ANSEL = 0 : ANSELH = 0                  ' Set all pins digital
    TRISA = 001000 : TRISB = 100000 : TRISC = 0 ' 0 = OUT, 1 = IN
    PORTA = 000001 : PORTB = 0 : PORTC = 0         ' 0 = Low  1 = High
    OSCCON = $78                            ' $78=External Xtal $70 = Internal 
    
    
    BaudR var word                          ' Baud Rate word var
    En var Portb.4                          ' LCD Enable
    RS var Portb.6                          ' LCD Register Set
    B1 var byte                             ' Serial IN Byte
    Flag var bit                            ' Display Baud Rate on Power-up
    I VAR BYTE : II VAR BYTE : III VAR BYTE ' use in Set1
    
    
    read 0, word baudr,ii : pause 2         ' Read Baud Rate from EEPROM
    if ii < 0 or ii > 7 then
        baudr = 84 : ii = 3
        WRITE 0, Word baudr,ii : pause 2    ' Write to EEPROM
    endif
    
    
    ArrayA var Byte [65] 
    ' Array index (III) 0    5    10   15   20   25   30   35   40~55           56~65
    ARRAYWRITE ArrayA,[" 1200 2400 4800 960014400192002880038400Press to Select:Baud Rate:"] 
    gosub LCDinit                           ' Initialise LCD
    
    
    IF PORTA.3  = 1 THEN                    ' PGM Switch 
        GOTO Set1
    else
        flag = 1
        gosub set2
        pause 500
    ENDIF
    
    
    main:                    
        serin2 Portb.5,baudr,3,main,[b1]    ' Serial IN
        if b1 < 253 then                    ' if Characters
            PORTC = b1 
            HIGH EN : PAUSEus 1 : LOW EN
            goto main        
        elseif b1 = 254 then                ' if LCD Command
            low RS            
        serin2 Portb.5,baudr,3,main,[b1]
            PORTC = b1                      ' output the data
            HIGH EN : PAUSEus 1 : LOW EN
            high RS                         ' character mode
            goto main         
        elseif b1 = 255 then                ' if Port Command
        serin2 Portb.5,baudr,3,main,[b1]
            if b1 = 0 then TOGGLE PORTA.0   ' Toggle Back Light OFF / ON
            if b1 = 1 then TOGGLE PORTB.7   ' Toggle PORTB.7 ON / OFF
            if b1 = 2 then TOGGLE PORTA.2   ' Toggle PORTA.2 ON / OFF
           goto main                           ' loop back to top
        ENDIF
    
    
    LCDINIT:                                ' Standard LCD Module Initialisation
    PORTC = 000001 : HIGH EN : PAUSEus 1 : LOW EN : pause 4 ' Clear Display
    PORTC = 000010 : HIGH EN : PAUSEus 1 : LOW EN : pause 2 ' Return Home
    PORTC = 111000 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' 8 bit, 2 line, 5x8 Characters
    PORTC = 000110 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' Entry mode
    PORTC = 001110 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' 001DCB Display on/off, Cursor on/off, Blink y/n      
    RETURN
    
    
    Set1: ' Baud Rate Selection and EEPROM Save at Power ON with Switch press
    PAUSE 10                               ' "Press to Select:"
    Low RS : PORTC = 128 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 1
    For I = 40 To 55
        PORTC = ArrayA[I] 
        High En : PauseUS 1 : Low En
        PAUSE 2
    Next I
    
    
    Set2:
    PAUSE 10                               ' "Baud Rate:"
    Low RS : PORTC = 192 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 2
    For I = 56 To 65
        PORTC = ArrayA[I] 
        High En : PauseUS 1 : Low En
        PAUSE 2
    Next I
    
    
    Set3:
    Low RS : PORTC = 203 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 2
    PAUSE 2       ' Index     
    IF II = 0 THEN III = 0  : baudr = 813 ' 1200
    IF II = 1 THEN III = 5  : baudr = 396 ' 2400
    IF II = 2 THEN III = 10 : baudr = 188 ' 4800
    IF II = 3 THEN III = 15 : baudr = 84  ' 9600
    IF II = 4 THEN III = 20 : baudr = 49  ' 14400
    IF II = 5 THEN III = 25 : baudr = 32  ' 19200
    IF II = 6 THEN III = 30 : baudr = 15  ' 28800
    IF II = 7 THEN III = 35 : baudr = 6   ' 38400
    For I = III To (IIi + 4)
        PORTC = ArrayA[I]
        High En : PauseUS 1 : Low En
        PAUSE 2
    Next I
    
    
    if flag = 1 then 
        flag = 0 : return
    endif
    
    
    WRITE 0, Word baudr,ii : pause 2        ' Write to EEPROM
    II = II + 1
    IF II > 7 THEN II = 0
    
    
    while PORTA.3 = 1                       ' Switch Press
    wend
    PAUSE 250
    
    
    while PORTA.3 = 0                       ' Switch Release
    wend
    pause 250
    GOTO set3

  31. #31
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    Here's a shrink down version for displaying messages from internal arrays no serial input involved.
    practical if just an operating device with control buttons attach to the remaining 5 ports is needed


    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Project : LCD Backpack Self Text  (Write text on LCD no serial port)
    ' Name    : 16F690 LCD BACKPACK for Hitachi HD44780  1601 / 1602 / 2004
    ' Date    : Oct 3 2025
    ' Notes   : 320 words used of 4096
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Device = 16F690
    'Declare Xtal = 8
    'Config INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, IESO_OFF, FCMEN_OFF
    Declare Xtal = 20
    Config HS_OSC, WDT_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, IESO_OFF, FCMEN_OFF
    ANSEL = 0           ' Set all pins digital
    ANSELH = 0          ' Set all pins digital
    TRISA = 0 : TRISB = %00100000 : TRISC = 0 : PORTA = 0 : PORTB = 0 : PORTC = 0
    OSCCON = $70  
    
    
    Dim I As Byte
    
    
    ' 1601 1602 16 Char 1/2 Lines
    Dim MyArrayA[16] As Byte = "0123456789ABCDEF"
    Dim MyArrayB[16] As Byte = "abcdefghijklmnop"
    
    
    ' 2004  20 Char 4 Lines
    'Dim MyArrayC[20] As Byte = "ABCDDE1234567890ABCD"
    'Dim MyArrayD[20] As Byte = "abcdefghijklmnop1234"
    'Dim MyArrayE[20] As Byte = "ABCDDE1234567890abcd"
    'Dim MyArrayF[20] As Byte = "abcdefghijklmnop1234"
    
    
    GoSub LCDINIT                ' initialise LCD
    PORTA = 1                      ' Backlight ON
    
    
    main:
    ' 1601 / 1602    
    PORTB = 0 : PORTC = 128 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : PORTB = %01000000 : DelayMS 3 ' Line 1
    For I = 0 To 15
        PORTC = MyArrayA[I] : PORTB = %01010000 : DelayUS 1 : PORTB = %01000000 : DelayMS 1
    Next I
    
    
    PORTB = 0 : PORTC = 192 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : PORTB = %01000000 : DelayMS 3 ' Line 2
    For I = 0 To 15 
        PORTC = MyArrayB[I] : PORTB = %01010000 : DelayUS 1 : PORTB = %01000000 : DelayMS 1
    Next I
    
    
    ' 2004 
    (*PORTB = 0 : PORTC = 128 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : PORTB = %01000000 : DelayMS 3 ' Line 1
    For I = 0 To 19
        PORTC = MyArrayC[I] : PORTB = %01010000 : DelayUS 1 : PORTB = %01000000 : DelayMS 1
    Next I
    PORTB = 0 : PORTC = 192 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : PORTB = %01000000 : DelayMS 3 ' Line 2
    For I = 0 To 19 
        PORTC = MyArrayD[I] : PORTB = %01010000 : DelayUS 1 : PORTB = %01000000 : DelayMS 1
    Next I
    PORTB = 0 : PORTC = 148 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : PORTB = %01000000 : DelayMS 3 ' Line 3
    For I = 0 To 19
        PORTC = MyArrayE[I] : PORTB = %01010000 : DelayUS 1 : PORTB = %01000000 : DelayMS 1
    Next I
    PORTB = 0 : PORTC = 212 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : PORTB = %01000000 : DelayMS 3 ' Line 4
    For I = 0 To 19 
        PORTC = MyArrayF[I] : PORTB = %01010000 : DelayUS 1 : PORTB = %01000000 : DelayMS 1
    Next I*)
    
    
    DelayMS 2000
    PORTB = 0 : PORTC = 1 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : PORTB = %01000000 : DelayMS 4  ' Clear display 
    DelayMS 255
    PORTA = 0             ' Bacck Light off
    DelayMS 255
    PORTA = %00000001     ' Bacck Light on
    DelayMS 255
    
    
    GoTo main
    
    
    LCDINIT:				  
    PORTC = %00000001 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : DelayMS 4  ' Clear display 
    PORTC = %00000010 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : DelayMS 2  ' Return Home     
    PORTC = %00111000 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : DelayMS 2  ' 5x8 Character 8 Bit, 2 Line
    PORTC = %00001100 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : DelayMS 2  ' %00001DCB Display on/off, cursor on/off, blink y/n
    PORTC = %00000110 : PORTB = %00010000 : DelayUS 1 : PORTB = 0 : DelayMS 2  ' Entry mode
    Return

  32. #32
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

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

    This code is not for PicBasic dialect...

    Ioannis

  33. #33
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

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

    Tried to test Richards code, but seems i cant make the LCD work at all.

    For starters the Backlight does not turn off.

    What is the sequence that should be sent over the serial port to control backlight and then send some text over to LCD?

    Ioannis

  34. #34
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

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

    The backlight is controlled by 255d and 0d or 255d and 8d.

    Have yet to send some text over the LCD.

    Ioannis

  35. #35
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    just set:

    BaudR var word


    work fine here

  36. #36
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    the code I use are similar, you can try to adapt.

    for the Hitachi HD44780 the decimal 254 represent the low RS then you need ot receive the line # as 128 line #1, 192 line #2, 148 line #3, 212 line #4

    sEROUT2 lcd,baudR,pace,[254,128,"ABCDEFGHIJKLMNOP"] ' Line 1 16 Char


    as for Richard code , for the Back Light he's using a toggle on,off with b1. (by receiving b1 turn On, then again turn Off)

  37. #37
    Join Date
    May 2013
    Location
    australia
    Posts
    2,682


    Did you find this post helpful? Yes | No

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

    as for Richard code , for the Back Light he's using a toggle on,off with b1. (by receiving b1 turn On, then again turn Off)
    Or more like
    SEROUT2 lcd,baudR,pace,[ 255, 8] ' Back Light OFF
    SEROUT2 lcd,baudR,pace,[ 255, 0] ' Back Light ON

    depending on how you connected the backlight of course
    Warning I'm not a teacher

  38. #38
    Join Date
    Feb 2022
    Posts
    78


    Did you find this post helpful? Yes | No

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

    OOP'S!

    usualy I code in both Positron & PBP3.

    here's the PBP3 code. (added Pause C)


    Code:
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Name  : 16F690 LCD BACKPACK  Self Text
    ' 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
    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 = 10
    I VAR BYTE 
    
    
    ' 1601 - 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:
    ' 1601 - 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
    
    
    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

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 : 13

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