control parallax lcd with pic16f630, nothing but errors, picbasic pro

Discussion in 'Embedded Systems and Microcontrollers' started by rudyauction8, Sep 8, 2013.

  1. rudyauction8

    Thread Starter Member

    Jan 27, 2012
    252
    2
    Here is the code:

    Code ( (Unknown Language)):
    1. define osc 4
    2.  INCLUDE "modedefs.bas"
    3.  
    4.  
    5.  do
    6.   high porta.0
    7.   high portc.4
    8.   pause 100
    9.  
    10.    serout2 portc.4, 24972, ["abcdefg"]
    11.  
    12.   low porta.0
    13.   pause 500
    14.  loop  
    very very short and simple, yet all that comes up is a bunch of "&"'s, and at that only when the output is inverted. With it set to true, I get nothing. porta.0 is an LED to tell me when the next string is sent, portc.4 is the LCD. I've tried a half dozen ports, my baud rates are correct, checked a dozen times, set configs in programmer, everything works except the data doesn't go through. I've been using this chip to read/write an i2c eeprom, it works fine. Any ideas?

    Yes I know my code is bad, it's just to test the connection before I add the LCD to a real program.
     
  2. rudyauction8

    Thread Starter Member

    Jan 27, 2012
    252
    2
    anyone?? and I turn the serial port high for 100ms before sending the data because that's what it said to do in the datasheet, it does the same thing with or without that line of code. And the LCD works fine on my bs2, so its definitely something in the pic setup or code.
     
  3. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    Not familiar with PicBasic Pro, but it looks like the bit timing is off. If 24792 is supposed to be the baud rate, then I have to say it is really odd. Two flyers at what it might be:
    1) The lcd header file needs a higher clock rate? Try external 8Mhz-20Mhz clock.
    2) Manually adjust the baud rate to see if output can be improved?

    I remember a person trying to get the parallax lcd going in another forum, different compiler, and had similar problems. Not sure if it ever got resolved. Good luck.
     
  4. rudyauction8

    Thread Starter Member

    Jan 27, 2012
    252
    2
    The 24792 baud is 2400 baud inverted open. True driven is 396. I was trying every possible setting, the closest to working was driven inverted. The picbasic manual states that 4mhz clock speed is OK for 4800 baud or less, I lost the osccal value for the internal oscillator during programming (I'm new to this), I left it at 3FFF. Would that cause problems? I do have some 20mhz +-0.2% ceramic resonators in the mail, they should be here within a few days. I also have a few other pics I could try that don't use osccal values, one runs at 8mhz.

    Is it possible that it uses 8 data bits and a 9th parity bit? just found that option, haven't tried it yet.
     
  5. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    Clock frequency should not be a problem at that low of baud rate. Losing the Oscal value could be a problem, as that could account for +/- 15% error. The Pickit 2 programmer can re-establish the Oscal value for you automatically. Check if your programmer can do the same.

    Good idea to try another chip. Doubt that parity bit is being used. Inverted usually means you are running Tx/Rx through a Max232 chip?
     
  6. rudyauction8

    Thread Starter Member

    Jan 27, 2012
    252
    2
    My programmer can only program, I got it for $10. That's what got me into these chips. I'll try another chip. What's the osccal range so I can try a bunch of random values if one of my other chips works? And are there any easy to use serial LCDs that work with these for under $20?
     
  7. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
  8. rudyauction8

    Thread Starter Member

    Jan 27, 2012
    252
    2
    Well it works fine on my 16f627, looks like it was the osccal #. How would I fix that # without any fancy tools?
     
  9. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    Good that it works on the 16f627.

    If the programmer doesn't have the window or tools to set the Oscal directly Then:
    I would do so some search on this, or the Microchip forum, for restoring the Oscal by programming? I am sure it has been asked before, and done before. Personally, I've just taken the easy way out with the Pickit2

    Just a guess:
    Code ( (Unknown Language)):
    1. call  0x3FF ; last program memory location
    2. movwf 0xCF  ; Guess of OSCAL
     
  10. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,025
    It should be:

    Code ( (Unknown Language)):
    1.  
    2. BSF STATUS, RP0 ; Bank 1
    3. CALL 3FFh ; Get the cal value from Program ROM
    4. MOVWF OSCCAL ; at 90h, not 0CFh
    5. BCF STATUS, RP0 ; Bank 0
     
  11. rudyauction8

    Thread Starter Member

    Jan 27, 2012
    252
    2
    @nickelflipper:
    Yes it has been done before, but every thread I found involved a scope (???), pickit 2 or 3 or other tools that I don't have. Either way I got it by increment the OSCCAL register by 4 until my LCD worked, then it displayed the OSCCAL value for me. It probably isn't the best value, but the next speed that my LCD supports requires an external clock source anyway and I don't have any other use for rs-232 serial connections.

    @JohnInTX:
    Will that code work in the picbasic compiler? I have no knowledge of assembly but if it will work I have 2 other pics with erased osccal values that I wouldn't mind restoring and the program I made doesn't seem to increment right, it took 15 minutes at 2 increments per second to get a reading.
     
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    rudy: Just stick in a line in your basic program like so:

    Code ( (Unknown Language)):
    1. OSCCAL = {whatever magic number you discovered}
     
  13. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,025
    True enough but for chips that haven't been clobbered there should be a way to get the factory calibrated value at 3ffh and put it in OSCCAL. Check the compiler docs. I don't use picbasic so don't know but that's what has to be done in the code after reset to calibrate the oscillator. I would expect that the compiler would generate the code in the startup but don't know.

    If its not documented, write a dummy program and look at the disassembly window to see if something like the previous assembler code is present in the startup routine.

    Have fun.
     
  14. rudyauction8

    Thread Starter Member

    Jan 27, 2012
    252
    2
    I entered:
    Code ( (Unknown Language)):
    1. OSCCAL = 0
    2. OSCCAL = OSCCAL + 4
    3. pause 500
    and displayed it on my lcd.

    and got a working number after ~15 minutes. What I'm thinking is that the first 2 #s are a memory address and the second 2 are the actual OSCCAL number, which if true will make figuring out my other 2 chips a lot easier.
     
Loading...