LCD and PIC18F4550


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38

    Cool LCD and PIC18F4550

    I finally got the USB runningon this chip, but I can't get the LCDout function to work. Could there be a conflict within the config settings that prevent the LCD and USB to function at the same time?

    To keep things simple, I have used the sample LCD code from the manual, but had to change some pin assignments.

    Cheers,

    Sterling

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    As usual... post your code here, the whole thing.

    Make sure you have disabled the analog stuff on PORTA, PORTB.

    Without the right config fuses setting, it may ruine your life.. sure there's a few to set.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Unhappy

    See attached, for settings and code.

    On the Microchip forum, I was given this info:

    Most example LCD code is written for chips operating a bit slower than the 48 MHz that the 18F USB chips can run. Much of the code also uses dead-loop timing (executing NOP instructions) to set the timing. You may very well be violating one or more of the timing requirements of the LCD.

    You have several options:

    1) Change the PIC's configuration to run the CPU at a slower clock rate to see if the timing is the problem. (Even with the PLL enabled, you can run the CPU as low as 16 MHz by just changing the CPUDIV value to divide-by-6. Lower frequencies can be set by disabling the PLL.) If the LCD works at the lower clock speed, you can proceed to either step 2 or 3 to resolve the problem. If not, there's something other than the timing causing the problem.

    2) Check the code with the MPLAB simulator to ensure that all of the timing for the LCD control signals meets all of the timing requirements as specified in the LCD datasheet.

    3) Check the controls signals with an oscilloscope rather than using the MPLAB simulator.
    Attached Images Attached Images  
    Last edited by SterlingY; - 10th March 2007 at 21:32.

  4. #4
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    I have it working. The solution was to replace PORTB abd PORTA with LATB and LATA.

    This is a major omission from the compiler docs.

    -Sterling

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    All you've done is treat the symptom.
    The problem is still there.
    And you've created some new problems in the process.

    Changing the LCD DEFINEs to LATA/B just overcomes the R-M-W (Read-Modify-Write) problem when ports are set to analog mode. It might seem like it's working fine, but it's not the right way to go.

    By doing that, the LCDOUT routines can't find the TRIS registers. Normally it finds TRIS by adding 12h to the Defined PORTx address. PORTA is F80h, if you add 12h, you get F92h which is the correct address for TRISA. But when you specify LATA (F89h), add 12h and you get F9Bh which is the OSCTUNE register.

    The only reason it worked is because you had already set all pins to output with the TRISA and TRISB assignments. (and you weren't using the internal oscillator)

    But, here's the good news.

    ADCON1 = $0F

    should fix it.

    Be sure to change the LCD DEFINEs back to PORTA/B
    DT

  6. #6
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Smile

    Thanks,

    I'll try your solution when I get my stepper motors running. They seem to just vibrate, and I'm sure the wiring is correct as I had it working on a PIC16F877.

    Cheers,

    Sterling

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    If your steppers are on PORTA or PORTB. ADCON1 will probably fix them too.
    <br>
    DT

  8. #8
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Question

    I tried that:

    DEFINE OSC 48

    ADCON1 = $0F

    ' set variables:
    x VAR BYTE
    steps VAR WORD
    stepArray VAR BYTE(4)
    clear

    TRISB = %11110000
    PORTB = 255

    Pause 1000

    stepArray[0] = %00001010
    stepArray[1] = %00000110
    stepArray[2] = %00000101
    stepArray[3] = %00001001


    main:
    if 1 = 1 then
    steps = steps + 1
    else
    steps = steps - 1
    endif

    PORTB = stepArray[steps //4]
    pause 2

    GoTo main

  9. #9
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    you may wonder about some of the code. It was originally written for a button to determine the direction, but to make it less confusing, I just say 1=1 to get to the heart of the code. I could have taken it out, but it will go back in.

    -Sterling

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I figured as much.

    When I look at this page ...
    http://www.sas.org/E-Bulletin/2002-0...ctro/body.html

    Your phase sequence seems to be different.
    I guess it depends on which pin connects to which phase.

    Might try a little more than 2ms delay to start too.
    <br>
    DT

  11. #11
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Question

    I've monkeyed around with the delay, gone all the way up to 20ms.

    I had this wiring working on another PIC, so I am pretty sure it should work, unless that program, written ASM was sending different bytes out the port.

    I'll check, if I can decipher it.

    Cheers,

    Sterling

  12. #12
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    So I looked into the ASM code that sucessfully drove the motor, and made the BYTE output changes to match, but still no luck.

    I'm wondering if it could have something to do with the chips high speed of 48MHz?

    -Sterling

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    could be many things, any code, link, picture, D-D bra are welcome
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Red face

    OKay, attached is the latest version of code, and my config settings. The config settings work for both LCD output and USB connection.

    -Sterling
    Attached Images Attached Images  

  15. #15
    Join Date
    Mar 2006
    Posts
    41


    Did you find this post helpful? Yes | No

    Smile Read-Modify-Write???

    Quote Originally Posted by Darrel Taylor View Post
    All you've done is treat the symptom.
    The problem is still there.
    And you've created some new problems in the process.

    Changing the LCD DEFINEs to LATA/B just overcomes the R-M-W (Read-Modify-Write) problem when ports are set to analog mode. It might seem like it's working fine, but it's not the right way to go.

    By doing that, the LCDOUT routines can't find the TRIS registers. Normally it finds TRIS by adding 12h to the Defined PORTx address. PORTA is F80h, if you add 12h, you get F92h which is the correct address for TRISA. But when you specify LATA (F89h), add 12h and you get F9Bh which is the OSCTUNE register.

    The only reason it worked is because you had already set all pins to output with the TRISA and TRISB assignments. (and you weren't using the internal oscillator)

    But, here's the good news.

    ADCON1 = $0F

    should fix it.

    Be sure to change the LCD DEFINEs back to PORTA/B

    Sir Darrel:
    I'm a bit confused,does it mean when I'm trying to read a Port configured as output in PIC16F877A, I will get the state of the Pin even if it's already an output, rather than the state of the Latch that switch that particular pin to output? is "LAT*" a work-around in PIC18F series?
    Last edited by leisryan; - 1st September 2008 at 10:02.

  16. #16
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by leisryan View Post
    Sir Darrel:
    I'm a bit confused,does it mean when I'm trying to read a Port configured as output in PIC16F877A, I will get the state of the Pin even if it's already an output, rather than the state of the Latch that switch that particular pin to output? is "LAT*" a work-around in PIC18F series?
    Exactly!

    On 16F's, reading a pin in output mode reads the state of the pin itself, not the state you told it to output.

    Usually they are the same thing, unless there is capacitance on the pin that makes it change slowly. Or if the pin is in analog mode, the digital input is disabled and ALWAYS reads 0.

    On the 18F's, the LATx latches allow you to read the requested output state regardless of the actual state of the pin. This makes it easy to overcome the R-M-W problem found on the 16F's.
    <br>
    DT

Similar Threads

  1. DS18B20 and PIC18F4550
    By sjohansson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th April 2006, 19:57
  2. Replies: 5
    Last Post: - 26th March 2006, 19:26

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