serial LCD 1602 Backpack using PIC16F690 for Hitach HD44780 - Page 2


+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 41 to 47 of 47
  1. #41
    Join Date
    May 2013
    Location
    australia
    Posts
    2,670


    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

    My code honours the timing as specified by the lcd defines , timing that most lcd displays need esp the cheapest and oldest examples of them.
    If you send data at a rate that exceeds the specified time constraints as defined it will of course fall. The solution is to either pace data transmission or set the defines to the actual speed the lcd can tolerate . The intent of my code is to match data rate to the real speed that the lcd can manage
    Warning I'm not a teacher

  2. #42
    Join Date
    Jan 2022
    Posts
    67


    Did you find this post helpful? Yes | No

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

    set pace to 1 , and it's working
    sEROUT2 lcd,baudR,pace,[254,128,"ABCDEFGHIJKLMNOP"]

    thanks.

  3. #43
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,166


    Did you find this post helpful? Yes | No

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

    I only tested at 19200 and the Backlight works OK.

    But text, could not send up to this moment.

    WIll try different Baud Rate. Though I test on a PIC16F1827 at 32MHz.

    Ioannis

  4. #44
    Join Date
    Jan 2022
    Posts
    67


    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

    when testing baud rate, usualy I start at 300 and up

    when it stopped working then I set pace = 1

    and re-start from the last baud rate tested.

    16F690 Xtal 20Mhz

    set pace to 1
    sEROUT2 lcd,baudR,pace,[254,128,"ABCDEFGHIJKLMNOP"]


    from my code here's the tested baud rate .
    and when booting the PIC's at different baud rate the sender 12F683 and receiver 16F690 the LCD screen light up right away and start displaying text, and back light on/off
    there's no lag for the first receiving if I remember correctly the pace for the sender is set = 0.


    Name:  Baud Rate Chart-A.jpg
Views: 9
Size:  45.8 KB


    Also I add baud rate selection jumpers on the Backpack''


    Name:  LCD Backpack with Jumpers.jpg
Views: 7
Size:  113.7 KB




    ' Jumpers
    '
    J3 300 600 1200 2400 4800 9600 14400 19200 28800 38400
    ' 1--2 RB7 On On On On On On
    ' 3--4 RA2 On On On On
    ' 5--6 RA1 On On On On
    ' 7--8 RA3 On On On



    ' Baud Rate SW Selection (PCB J3)
    If PORTA = 001110 And PORTB.7 = 1 Then BaudR = 3313 ' 300
    If PORTA = 001110 And PORTB.7 = 0 Then BaudR = 1646 ' 600
    If PORTA = 001010 And PORTB.7 = 1 Then BaudR = 813 ' 1200
    If PORTA = 001100 And PORTB.7 = 1 Then BaudR = 396 ' 2400
    If PORTA = 000110 And PORTB.7 = 1 Then BaudR = 188 ' 4800
    If PORTA = 001010 And PORTB.7 = 0 Then BaudR = 84 ' 9600
    If PORTA = 001100 And PORTB.7 = 0 Then BaudR = 49 ' 14400
    If PORTA = 000110 And PORTB.7 = 0 Then BaudR = 32 ' 19200
    If PORTA = 001000 And PORTB.7 = 0 Then BaudR = 15 ' 28800
    If PORTA = 000000 And PORTB.7 = 0 Then BaudR = 6 ' 38400
    Last edited by jackberg1; Yesterday at 16:41.

  5. #45
    Join Date
    Jan 2022
    Posts
    67


    Did you find this post helpful? Yes | No

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

    from my last edit,

    ' Jumpers
    ' J3 300 600 1200 2400 4800 9600 14400 19200 28800 38400
    ' 1--2 RB7 On On On On On On
    ' 3--4 RA2 On On On On
    ' 5--6 RA1 On On On On
    ' 7--8 RA3 On On On

    I think courier new does not take spaces !
    better use screen cap


    Name:  LCD Backpack with Jumpers code.jpg
Views: 7
Size:  12.3 KB
    Last edited by jackberg1; Yesterday at 16:54.

  6. #46
    Join Date
    Jan 2022
    Posts
    67


    Did you find this post helpful? Yes | No

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

    edited BaudR var word : baudr = 3313 and TRISA = 111110

    1st receiving random characters
    2nd normal

    what could be done to avoid the first
    thanks.

    Name:  Richard A.jpg
Views: 5
Size:  57.3 KB

  7. #47
    Join Date
    May 2013
    Location
    australia
    Posts
    2,670


    Did you find this post helpful? Yes | No

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

    its always better to use the hardware than bit-banged routines and there is nothing better than a ring-buffer to overcome traffic snarls

    Code:
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
    ' Name  : 16F690 LCD BACKPACK
    ' Date  : oct 2025    richard
    ' Note  : RING BUFFERED
    ' Notes : 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  
        DEFINE INTHAND myint 
        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
        
        CLEAR
        DEFINE LCD_BITS 8     'defines the number of data interface lines (4 or 8) 
        DEFINE LCD_DREG PORTC    'defines the port where data lines are connected to
        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
        SPBRG = 25    ' 19200 Baud @ 8MHz, 0.16%
        SPBRGH = 0
        BAUDCTL.3 = 1 ' Enable 16 bit baudrate generator
    
    
        wsave VAR BYTE $70 SYSTEM ;wsave in access RAM
        ssave VAR BYTE BANK0 SYSTEM
        psave VAR BYTE BANK0 SYSTEM
        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_size      CON  32                               ' Sets the size of the ring buffer  
        buffer           VAR  BYTE[buffer_size]     ' Array variable for holding received characters 
        bufchar          VAR  BYTE          ' Stores the character retrieved from the buffer
        Bl               var byte 
     
        
    
    
    GOTO overint ' Jump over the interrupt handler 
    ASM
    myint
       if CODE_SIZE <= 2 ; If less than 2K code space
            ; Save the state of critical registers (PIC12/PIC16)
           movwf wsave ; Save W
           swapf STATUS,W ; Swap STATUS to W (swap avoids changing STATUS)
           clrf STATUS ; Clear STATUS
           movwf ssave ; Save swapped STATUS
           movf PCLATH,W ; Move PCLATH to W
           movwf psave ; Save PCLATH
       endif
    ; 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   FSR
       addwf   _index_in,W  ; Add index_in to point to next empty slot
       movwf   FSR        ; Store Low byte of pointer in FSR
    ; Read and store the character from the USART           
       movf   RCREG,W       ; Read the received character
       movwf  INDF          ; Put the received character in FSR  location
       BTFSC  PIR1,RCIF     ;ANY MORE ?
       goto    myint
    finished 
    ; Restore the state of critical registers (PIC12/PIC16)
       movf psave,W ; restore PCLATH
       movwf PCLATH
       swapf ssave,W ; restore STATUS
       movwf STATUS
       swapf wsave,F ; restore W (swap avoids changing STATUS)
       swapf wsave,W
       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: 
        TRISC = 0
        TRISB = % 10101111
        TRISA = % 11111110 
        OSCCON = $70
        PAUSE 500
        hserout ["ready @19200"]
        LCDOUT $FE,1
        LCDOUT "ready @19200"
        PAUSE 500
    @  bsf   LCD_RSREG ,LCD_RSBIT
        INTCON = $C0
        PIE1.5 = 1
    GOSUB ERROR
    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   
    '   hserout [bufchar]        ' Send the character to terminal
       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
            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
       PIR1.5=0      
       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
    Warning I'm not a teacher

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, 19:58
  2. 16F877A and LCD HD44780
    By epilot in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 1st November 2013, 18:17
  3. FREE Serial LCD Backpack Board
    By rmteo in forum Off Topic
    Replies: 36
    Last Post: - 29th July 2010, 02:32
  4. Lcd Hd44780
    By alaaodeh in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th February 2007, 14:04
  5. LCD 4x20 HD44780
    By inteco in forum mel PIC BASIC
    Replies: 13
    Last Post: - 27th June 2006, 16:52

Members who have read this thread : 9

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