serial lcd with 16f628


Closed Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166

    Default serial lcd with 16f628

    Im having lots of problems getting my serial lcd to work properly. the screen is a matrix orbital lcd4021 set to 2400baud (i think) and im using a 16f628 as a controller.. i have just started to learn this stuff, and i dont know that much about it. i have been learning by just looking at examples on the net and reading this site. i have attached the code below. if anyone can help, it would be greatly apreciated.

    @ device INTRC_OSC_NOCLKOUT
    cmcon = 7
    TRISA = %00000000
    TRISB = %00001000

    lcd VAR PORTA.3
    baud CON 2400

    Pause 4000

    start:
    SerOut2 lcd, baud,["hello world"]
    Pause 1000
    GoTo start
    End



    thanks; dan

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    In the back of your PBP manual you can find a chart showing Serin2/Serout2
    baud modes.

    baud CON 2400 creates a constant value named baud which = to 2,400.

    SerOut2 lcd, baud,["hello world"] is not going to give you 2400 bps inverted.

    SerOut2 lcd, 16780,["hello world"] ' would.

    You could opt for something like this rather than using the numeric value for
    2400 inverted mode with Serout2;

    baud CON 16780 ' Create CONstant baud which = 16780.

    SerOut2 lcd, baud,["hello world"]
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    thanks Bruce. i didnt know that i was doing that wrong, although i realized i have another problem too.. i have been trying to change the baud rate on the screen, however i cant seem to do it, so it should still work at 19200 baud as long as i use the correct number from the book (19200, Driven, Inverted, Even*, 24608) right??? so i would put "baud con 24608"... so my other problem is, how do i change the internal osc of the 16f628? and if i change it, do i need to change the baud #???

    thanks
    dan

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    24608 will give you 19200, driven, inverted, even parity, but I doub't you're going to get solid results with the internal 4MHz osc.

    Are you sure the serial LCD you're using requires "even" parity? You might want to try 16416 for 19200, driven, inverted, no parity? I've never used the Matrix Orbital serial LCD's, but the ones I have used require no parity.

    The internal 4MHz osc doesn't provide a stable clock for any timing critical stuff like serial communications, and, Serout2 probably isn't going to work reliably at 19200bps with a 4MHz clock (if it works at all).

    See the **'s next to 9600 & 19200 in the Serin2/Serout2 Mode Examples chart with the note at the bottom stating ** Oscillator faster than 4MHz may be required?

    Just assume it's never going to be 100% reliable with 4MHz at any data rate showing the **'s next to it.

    The internal osc is for non timing critical apps. It will drift & it's not always super precise to begin with on the older 16F62x series. Newer parts with 1% internal oscillators normally work really well, but not some of the older series.

    The internal osc isn't a good option for "reliable" serial comms for sure, and definitely not for data rates that are already marginal at 4MHz.

    You can use DEBUG for 19200bps with a 4MHz osc, but it may or may not be reliable with the internal osc.

    DEFINE OSC 4
    DEFINE DEBUG_REG PORTA
    DEFINE DEBUG_BIT 3
    DEFINE DEBUG_BAUD 19200
    DEFINE DEBUG_MODE 1 '1=inverted, 0 = true

    how do i change the internal osc of the 16f628?
    Not sure what you mean by this. You can switch from the default 4MHz to 37kHz by clearing PCON.3.

    If you want to use an external crystal VS the internal osc, then see Melanies thread here http://www.picbasic.co.uk/forum/showthread.php?t=543

    and if i change it, do i need to change the baud #???
    No. You should use whatever baud rate the LCD data sheet states. Just be sure to use an oscillator speed that supports the baud rate, or switch to another command that supports the baud rate at the osc frequency you're using like the DEBUG example above.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    thanks again. in my last post i thought that the internal osc could be changed, but then i realized that it wont go above 4mhz anyways... i changed to a 10.000mhz external and changed the code a bit, and it seems close, but its still not working, and im still not sure what im doing wrong... im getting a lot more digits displayed on the screen, and it displays every 2 seconds like it should from the code.


    cmcon = 7
    TRISA = %00000000
    TRISB = %00001000

    lcd VAR PORTA.3
    baud CON 24608

    Pause 4000

    start:
    SerOut2 lcd, baud,["hello world"]
    Pause 2000
    GoTo start
    End

    thanks for all the help
    dan

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Insert DEFINE OSC 10 & be sure to set HS in config word.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    im probably sounding like an idiot now, but i just cant seem to get it to work and i have been trying for 3 days now...

    i really apreciate the help.

    @ DEVICE HS_OSC
    DEFINE OSC 10
    cmcon = 7
    TRISA = %00000000
    TRISB = %00001000

    lcd VAR PORTA.3
    baud CON 16416 '24608 16416

    Pause 2000

    start:

    SerOut2 lcd, baud,["Hello World"]
    Pause 2000
    GoTo start
    End


    thanks
    dan

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Do you have a link to the data sheet for this LCD?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    here is the link to the datasheet...

    http://www.bipom.com/lcds/manuals/lcd2041.pdf

    thanks for the help...

    danny

  10. #10
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Is the protocol select jumper set for TTL or RS232?

    If it's setup for RS232 then you should be able to talk to it with the Matrix uProject software. If not, check your comms wiring.

    If it's setup for TTL then you should be able to use the PIC with inverted serial.

    Have you tried resetting it to factory defaults? Might not be a bad idea just so you know it's at a specific baud rate.

    Do you have a common ground between the LCD & PIC power supplys?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  11. #11
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    i have tried uproject, i changed the startup screen and displayed some stuff on it, then i made some custom characters... i tried changing the baud rate, but it didnt seem to work. i have since changed it to ttl by desoldering the rs232 contacts and soldering across the ttl ones.. i checked them with a mm and everything seems to be right.. it still displays my startup screen and displays other weird characters when the pic program tells it to display the "hello world".

    my setup has both the pic and the display running off of one 1A 5V reg, and a 6V battery. so it shares the same ground and the same power.

    danny

  12. #12
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Most 1A 5V regulators require >6V input to maintain a regulated +5V out. Have you tried bumping up the input voltage to your regulator?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  13. #13
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    i measured across the output on the vreg while under load, and i still get 5v so i dont think that is the problem, but to make sure, i also hooked up 9v to the input and im still getting the same problem...

  14. #14
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Try this and see what happens;
    Code:
    @ DEVICE MCLR_OFF, HS_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON
    
    DEFINE OSC 10
    
    CMCON = 7
    
    Pause 2000
    
    start:
    
    SerOut2 PORTA.3, 17197,["N1200"]
    Pause 2000
    SerOut2 PORTA.3, 16780,["N2400"]
    Pause 2000
    SerOut2 PORTA.3, 16468,["N9600"]
    Pause 2000
    SerOut2 PORTA.3, 16416,["N19200"]
    Pause 2000
    
    SerOut2 PORTA.3, 813,["T1200"]
    Pause 2000
    SerOut2 PORTA.3, 396,["T2400"]
    Pause 2000
    SerOut2 PORTA.3, 84,["T9600"]
    Pause 2000
    SerOut2 PORTA.3, 32,["T19200"]
    Pause 2000
    
    GoTo start
    End
    Do any of these print as expected?

    Try using a different port pin and see what happens.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  15. #15
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    thanks bruce.. i wish i had thought of that... as soon as i saw the code you wrote, it just kinda clicked that i should have done it 2 days ago... so it works with t19200 so i needed to use "32"... so i put that # back into my original code, and it displays the "hello world" multiple times..

    with my code, it repeats itself every 2 seconds, so the first time it display the "hello world" the hello is all messed up, and it displays world fine... then the second cycle it displays everything fine... so the display looks like

    B PPx world hello w
    orld hello world hel
    lo world hello world

    @ DEVICE HS_OSC
    DEFINE OSC 10
    cmcon = 7
    TRISA = %00000000
    TRISB = %00001000

    lcd VAR PORTA.3
    baud CON 32

    Pause 2000

    start:

    SerOut2 lcd, baud,[" Hello World"]
    Pause 2000
    GoTo start
    End


    thanks for all your help.. i think im finally learning a bit!!!
    danny

  16. #16
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    ok, i think my only problem now is trying to get it to display something on the second line, instead of just wrapping the text... i want to be able to specify where it is displaying certain info..

    thanks
    danny

  17. #17
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    That really boils down to getting familiar with the LCD's data sheet & commands available.

    Looks to me like;

    SerOut2 PORTA.3, 32,[254,"D"] 'would turn off auto line wrap

    Then;

    SerOut2 PORTA.3, 32,[254,"G",1,2] ' would let you position the cursor manually, and should put you on column #1, row #2?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  18. #18
    Join Date
    Apr 2006
    Location
    Alberta Canada
    Posts
    166


    Did you find this post helpful? Yes | No

    Default

    thanks bruce... i was actually just playing around with the different commands, i got it to clear, turn on and off, change the contrast and stuff like that... thanks for all the help, i think i have finally got it now...

    danny

Similar Threads

  1. LCD problem with 16F628
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 19th September 2016, 08:28
  2. LCD serial backpacks
    By Archangel in forum Serial
    Replies: 67
    Last Post: - 30th December 2010, 04:51
  3. Please help with EDE702 - Serial to LCD interface
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th October 2008, 02:48
  4. Serial LCD
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th November 2007, 08:31
  5. Gps with 16f628
    By dragons_fire in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th June 2006, 03:38

Members who have read this thread : 0

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