Need idea hove to..?


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105

    Question Need idea hove to..?

    I need to displey specific data on LCD 4x20 chr.
    Data will be received via RS232 on PIC 16F877 on HSER on PIC MCU.
    Did someone have best idea what to I send from PC to PIC?
    Example from me:
    If I send somethig like 1DOG that maybe I can decode in pic like print on LCD in first line DOG.
    But what about if I want to specific also on wich position of disply I will display that word DOG ?
    Do someone want help with some simple example PLEASE.

    That problem is part of my idea to bulid some type of terminal with 4x4 matrix keyboard where I will send No of key waht was push ( I was test mister_e keyboard rutine and it work super).And also I need in same time to display return from PC on LCD 4x20 chr when specific key is push.

    Any suggest is welcome please.
    Regards to all Mr.Robert - phoenix_1

  2. #2
    Join Date
    Mar 2008
    Location
    Gerogetown, Texas
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Mr Robert

    Here is some code I used for a 4X40 display (the reason for E1 and E2). It may give you an idea how to send data to the LCD from the PC. I assume you have a program that can be written to send and receive data via the serial port in your PC.

    Code:
    ' PicBasic program to demonstrate operation of an LCD in 4-bit mode
    ' LCD DMC40457 W/backlight 16F876
    ' LCD should be connected as follows:
    '  PIN--LCD     PIC                             4016
    '  4    DB4     PortB.4
    '  3    DB5     PortB.5
    '  2    DB6     PortB.6
    '  1    DB7     PortB.7
    '  11   RS      PortB.0
    '       E       PortB.1                         pin 8 & 11
    '  10   RW      Ground
    '  14   Vdd     5 volts
    '  13   Vss     Ground
    '  12   Vo      10K potentiometer (or ground)
    '       DB0-3   No connect
    '   9   E1      To enable logic ckt             pin 9
    '   15  E2      as above                        pin 10
    'Backlight controled via a NPN transistor with 1K resistor from porta.2 to base.
    ' E1 & E2 controlled via a bilaterial switch 4016
    '               portc.4                         pin 6
    '               portc.5                         pin 12
    '*********************************************************************************
    
    DEFINE LOADER_UESD 1    'Enable bootloader
    DEFINE OSC 20           ' 20Mhz Xtl
    DEFINE HSER_RCSTA 90h   'Set up USART
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 9600
    
    
    DEFINE LCD_DREG PORTB       'Set up LCD  Data Portb
    DEFINE LCD_DBIT 4           ' bit 4 - 8 data bus
    DEFINE LCD_RSREG PORTB      'RS portb.0
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB       'E portb.1
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4           '4 data bits
    DEFINE LCD_LINES 2          '2 lines
    DEFINE LCD_COMMANDUS 2000   
    DEFINE LCD_DATAUS 50
    ADCON1 = 7              'Make porta all digital
    trisa = %00000000       'Make porta all outputs
    output portc.4      ' E1 to 4016
    output portc.5      ' E2 to 4016
    
    
    RCIF    VAR     PIR1.5          ' Alias RCIF (USART Receive Interrupt Flag)
    OERR    VAR     RCSTA.1         ' Alias OERR (USART Overrun Error Flag)
    CREN    VAR     RCSTA.4         ' Alias CREN (USART Continuous Receive Enable)
    
    buffer_size     CON     32              ' Sets the size of the ring buffer
    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
    bufchar1        VAR     BYTE
    i               VAR     BYTE            ' loop counter
    col             VAR     BYTE            ' Stores location on LCD for text wrapping
    errflag         VAR     BYTE            ' Holds error flags
    A               VAR     BYTE
    E1              VAR     portc.4     'E1 control to 4016
    E2              VAR     portc.5     'E2 control to 4016
    
    index_in = 0                    'Initalize varialbles
    index_out = 0
    i = 0
    col = 1
    low porta.2                     'turn off backlight
    errflag = 0                     ' Reset the error flag
    INTCON = %11000000              ' Enable interrupts
    On INTERRUPT GoTo serialin      ' Declare interrupt handler routine
    PIE1 .5 = 1                     ' Enable interrupt on USART
    high E1                         ' Enable E1  
    High E2                         ' Enable E2
    
            
            
           
    Pause 500                       ' Wait for LCD to startup
    
    START:
        GOSUB OPENING                'Staart lcd display indication
        Lcdout $fe, 1               'clear LCD
        low E2                      ' Disable E2 turn off second half of display
        GOTO LOOP
    LOOP:
    
        
    
    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
        'IF bufchar = 253 THEN CONT  'if control character is detected go to control
        LCDOut bufchar  ' Send the character to LCD
                    
    
    GoTo display                    ' Check for more characters in buffer
    
    
    
    ' Subroutines
    
    Disable                                 ' Don't check for interrupts in this section
    
    getbuf:                                 ' move the next character in buffer to bufchar
            index_out = (index_out + 1)                     ' Increment index_out pointer (0 to 63)
            If index_out > (buffer_size - 1) Then index_out = 0     ' Reset pointer if outside of buffer
            bufchar = buffer[index_out]                     ' Read buffer location
            IF bufchar = 253 THEN CONT  'if control character is detected go to control
    Return
    
    error:                                  ' Display error message if buffer has overrun
            IF errflag.1 Then       ' Determine the error
                    LCDOut $FE,$c0,"Buffer Overrun" ' Display buffer error on line-2
            Else
                    LCDOut $FE,$c0,"USART Overrun"  ' Display usart error on line-2
            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
            
            errflag = 0                     ' Reset the error flag
            CREN = 0                        ' Disable continuous receive to clear overrun flag
            CREN = 1                        ' Enable continuous receive
    
            GoTo display            ' Carry on
            
            
    ' Interrupt handler
    
    serialin:       ' Buffer the character received
            If OERR Then usart_error                        ' Check for USART errors
            index_in = (index_in + 1)                       ' Increment index_in pointer (0 to 63)
            If index_in > (buffer_size - 1) Then index_in = 0 'Reset pointer if outside of buffer
            If index_in = index_out Then buffer_error       ' Check for buffer overrun
            HSerin [buffer[index_in]]                       ' Read USART and store character to next empty location
            If RCIF Then serialin                           ' Check for another character while we're here
            
    Resume            ' Return to program
    
    buffer_error:
            errflag.1 = 1         ' Set the error flag for software
    ' Move pointer back to avoid corrupting the buffer. MIN insures that it ends up within the buffer.
            index_in = (index_in - 1) MIN (buffer_size - 1)
            HSerin [buffer[index_in]]       ' Overwrite the last character stored (resets the interrupt flag)
    usart_error:
            errflag.0 = 1          ' Set the error flag for hardware
            
    Resume                                  ' Return to program
    
    
    
    cont:
        
        index_out = (index_out + 1)                     ' Increment index_out pointer (0 to 63)
        If index_out > (buffer_size - 1) Then index_out = 0     ' Reset pointer if outside of buffer
        bufchar = buffer[index_out]                     ' Read buffer location
        if bufchar = "A" then E1_          ' enable 1st half of display
        if bufchar = "C" then E2_           'enable 2nd half of display
        if bufchar = "B" then BL_On         'backlight on
        if bufchar = "F" then BL_Off        'backlight off
        
        goto display
    
    
    E1_:
    high E1
    Low E2
    PAUSE 50
    Lcdout $fe, 2
    goto display
    
    E2_
    low E1
    High E2
    Pause 50
    Lcdout $fe, 2
    goto display
    
    BL_On:
        high porta.2
    goto display
    
    BL_Off:
        low porta.2
    goto display
    
    
    OPENING:
         FOR A = 1 TO 2
            Lcdout $fe, 1   ' Clear LCD screen
            Lcdout "LCD"  ' Display Hello
      
            Pause 500       ' Wait .5 second
            'enable debug
            
            Lcdout $fe, 1   ' Clear LCD screen
            Lcdout $FE, $C0
            Lcdout "ACTIVE"
      
            Pause 500       ' Wait .5 second
            'enable debug
    
        NEXT A
        
        RETURN
        
    end

  3. #3
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Default How to define 4x20 display

    via hserout i can get pushed key 100% ok but can't drive 4x20lcd,how to define ???
    data lines are on a0 to a43 port and command are on c0 and c1

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by phoenix_1 View Post
    but can't drive 4x20lcd,how to define ???
    data lines are on a0 to a43 port and command are on c0 and c1
    phoenix,
    Read the PBP manual, specifically the section on how to define the pins to be used for driving an LCD and your project will rise from the ashes.

    Another case of RTFM...

  5. #5
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    phoenix,
    Read the PBP manual, specifically the section on how to define the pins to be used for driving an LCD and your project will rise from the ashes.

    Another case of RTFM...
    I was probe on 2x16 chr and work fine with 4x20 don't want work .
    I dont know what is problem becouse i was never use 4x20!
    Any sugest
    Sorry for my bad english!
    Regards

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by phoenix_1 View Post
    I was probe on 2x16 chr and work fine with 4x20 don't want work .
    I dont know what is problem becouse i was never use 4x20!
    Any sugest
    Sorry for my bad english!
    Regards
    Yes, a good suggestion is to re-read the PBP manual...as suggested in my last post. The define's you need are there.
    Between that and the datasheet for the 16F877(a?), you should be able to figure out what is wrong.
    We haven't seen any of the code you may (or may not) have written, no idea of your schematic (except for a vague idea of how you have connected your LCD, which leaves a bit to be desired), and not really much of an idea what you have tried so far.

    For example, my truck's 'Check Engine' lamp is illuminated. What's wrong with it?
    Not a lot of information is there?
    And your English, while not perfect, is fine.

  7. #7
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Yes, a good suggestion is to re-read the PBP manual...as suggested in my last post. The define's you need are there.
    Between that and the datasheet for the 16F877(a?), you should be able to figure out what is wrong.
    We haven't seen any of the code you may (or may not) have written, no idea of your schematic (except for a vague idea of how you have connected your LCD, which leaves a bit to be desired), and not really much of an idea what you have tried so far.

    For example, my truck's 'Check Engine' lamp is illuminated. What's wrong with it?
    Not a lot of information is there?
    And your English, while not perfect, is fine.
    Here are defines:

    define OSC 20
    ADCON0.0 = 0
    ADCON1 = 7
    DEFINE LCD_DREG PORTA
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 4 ******************when is 2 and I use 2x16 it work 100%
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    As you see:

    LCD Wire PIC
    RS --------------portc.0 -----> 4K7 pullup to +5V
    E----------------portc.1
    D4---------------porta.0
    D5---------------porta.1
    D6---------------porta.2
    D7---------------porta.3

    And that work 100% fine with 2x16 when I redefine No:. of lines of LCD.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Try increasing the 'startup pause', give the LCD more time to start itself before you start sending data. Double check your contrast wiring/voltage.

  9. #9
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Exclamation

    Quote Originally Posted by skimask View Post
    Try increasing the 'startup pause', give the LCD more time to start itself before you start sending data. Double check your contrast wiring/voltage.
    Hi skimask I was probe 1000 ms pause on startup and was probe on same pcb 2x16 chr it work and last solution is to lcd is fabric dead or bad ?!

    pinout is same on 2x16 and that 4x20 and when 2x16 work and that not must be something with 4x20 wrong or maybe is problem in pbp2.50 maybe some bug ????

    Really it is big problem for me...
    Many thanks to all who was and will probe to help me !

    Regards

    p.s " The diference is only in define of no:. of lines betwin 2x16 and 4x20. and with same hardware 2x16 work and 4x20 have after reset time back all chr on screen !"
    Last edited by phoenix_1; - 14th May 2008 at 15:46. Reason: tiping error

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Do you have pin #3 on the display going to a pot as a voltage divider for contrast?
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Cool

    Quote Originally Posted by mackrackit View Post
    Do you have pin #3 on the display going to a pot as a voltage divider for contrast?
    You have 100% good question !!!!
    When I was use 2x16chr display it have bad contrast and I was see TEST on it,but 4x20 have extra contrast and with same value all poligons are black at these oment I was reduce fix resistors on network on pin 3 and problem go out I can look normaly and 4x20 work fine.

    The best thing is have mentors out of personal laboratory !
    Other can find what you cant in your project ;-)).

    The best regards to all

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    So, can we infer that all is well now and is working ok?
    (a few things are getting lost in the English translation )

  13. #13
    Join Date
    May 2007
    Location
    Republic Serbia
    Posts
    105


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by skimask View Post
    So, can we infer that all is well now and is working ok?
    (a few things are getting lost in the English translation )
    Yes my dear friend work 100% ok.
    Many hank's o all you !!!
    I little think about some small problems but in core all work good.

    Here is little more about what I probe to do.

    In project I have one RS232 conection via hser in 877 to pc via max 232,one 4x20 chr lcd (that problematic hehehe) and 4x4 matrix keyboard.
    Device must work on next way:
    1.it must send no:. of key what is push by persone who use it.
    2.in middle time it must display what return application from pc via rs232 on lcd.
    3.application return some instructions like words like "DOG" or "CAT"or...and position where it will be displayed on lcd by line and row - position in line 1,2,3 or 4.
    It is something like terminal for PC.

    For now I success send key no:. with mister_e rutine for matrix keyboard
    But I stil look hove to configure that famose from PC to PIC...

    Maybe somethin like 1,5,DOG or ???
    And hove to I decode that ?

    I was use 877 with Nokia 6210 and there I was use skip xxx chr and get message and decode it like bite but here I dont know hove to start.


    Regards to all ( any suggest is welcome).

    Sorry for bad english again !!!

    Robert

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This might get you started.

    Read all data from the PC into an array in the PIC.
    Code:
    [WAIT("?"),STR NUMS\8]
    The above will wait for "?" (could be whatever you want) and the next part will put the rest of the data in an array that has 8 places.

    The array will start at 0, so if you wrote it out it would look like this:
    NUMS[0]
    NUMS[1]
    NUMS[2]
    NUMS[3]
    NUMS[4]
    NUMS[5]
    NUMS[6]
    NUMS[7]

    Now you can make each part a variable that is a bit easier to work with:
    X1 = NUMS[0]
    X2 = NUMS[1]
    X3 = NUMS[2]
    X4 = NUMS[3]
    X5 = NUMS[4]
    X6 = NUMS[5]
    X7 = NUMS[6]
    X8 = NUMS[7]

    Now lets say X1 is equal to 1 and you want to start display at line 1 position 2.
    Code:
    LCDOUT $FE, $80 + X1
    $80 is line 1 position 1. (refer to the manual for more)

    Now to display some of the other data:
    Code:
    LCDOUT $FE,$80 + X1,X2,X3,X4
    X2 = D
    X3 = O
    X4 = G

    Something like that maybe.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. How do they do this? Any idea?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 28th August 2011, 17:17
  2. Giving power to MCU upon button press - Good Idea?
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st July 2009, 07:34
  3. Idea of master/slave serial comm.
    By sirvo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th December 2007, 08:36
  4. Replies: 5
    Last Post: - 18th July 2007, 10:43
  5. Replies: 10
    Last Post: - 17th July 2006, 02:23

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