1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PIC doesn't run with internal oscillator

Discussion in 'Oshonsoft' started by camerart, Apr 13, 2014.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    Hi,

    I'm trying to get a 16F819 to run with a 4X20 LCD screen using it's internal oscillator.

    The program uses the pins where a XTL would be used.

    Here is the code:
    Define CONF_WORD = 0x3f72 'internal oscillator
    Define CLOCK_FREQUENCY = 4 'Changed from 12
    AllDigital
    ADCON1 = 0x0e

    Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY

    Define LCD_BITS = 8
    Define LCD_DREG = PORTA
    Define LCD_DBIT = 0
    Define LCD_RSREG = PORTB
    Define LCD_RSBIT = 0
    Define LCD_RWREG = PORTB
    Define LCD_RWBIT = 1
    Define LCD_EREG = PORTB
    Define LCD_EBIT = 2
    Define LCD_READ_BUSY_FLAG = 1
    Lcdinit

    Dim an0 As Word

    loop:
    Adcin 0, an0
    Lcdcmdout LcdClear
    Lcdout "Analog input AN0"
    Lcdcmdout LcdLine2Home
    Lcdout "Value: ", #an0
    Toggle RB4
    WaitMs 250
    Goto loop

    Can anyone suggest why it doesn't run? or can I change the used XTL pins so that Ican use a XTL?

    Camerart.
     
  2. skimask87

    skimask87 Member

    Joined:
    Mar 23, 2014
    Messages:
    128
    Likes:
    10
    Location:
    Logan (Minot), ND
    Wish I could put this in a way that would effectively convey the thought that I am speaking very slowly...

    I am asking nicely.... Please try and be helpful WITHOUT the sarcasm!!!
     
    Last edited by a moderator: Apr 13, 2014
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    camerart Try to start using the identifiers when using the config bits...
    Define CONF_WORD = 0x3f72 'internal oscillator.... This is wrong!!!!


    0x3F72 means RC osc is on... MCLR is on, brown out and power up are on

    If you need internal oscillator then use 0x3F50 for MCLR as digital pin and both osc pins as digital.
    Use 0x3F70 for MCLR on...

    Also include

    OSCCON = 0x70 to set the internal OSC to 4Mhz
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.

    Hi, You mentioned an indicator LED in your message, I used one all afternoon, but didn't post that code.

    Cheers, Camerart.
     
  6. skimask87

    skimask87 Member

    Joined:
    Mar 23, 2014
    Messages:
    128
    Likes:
    10
    Location:
    Logan (Minot), ND
    That would've been helpful to know...
    Got anything hooked up to the contrast pin?

    EDIT: Is this on a simulator? Or do you have actual hardware hooked up?
     
  7. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    Posted by mistake
     
  8. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    Actually, I looked again and the Toggle is the LED indicator.

    Contrast to GND at the moment.

    First in the simulator second with hardware.
     
  9. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    Removed posting as it was solved.
     
    Last edited: Apr 15, 2014
  10. Inquisitive

    Inquisitive Super Moderator

    Joined:
    Aug 31, 2011
    Messages:
    947
    Likes:
    87
    Location:
    Georgia, USA
    How was it solved?
     
  11. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    Sorry to mislead you! I was asking a little problem, that was solved minutes after posting, but the initial problem is still here.

    If there's a way of removing posts, I would like to know?
     
  12. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    I've tried various combinations, of configurations, but failed. I've now added a crystal and changed to 16F648A (I don't need analogue inputs)

    I have attached a program that works, with the main LCD part commented out as a test, so the XTL and chip are working, but with the LCD connected and un-commented, it doesn't work, no LED flashing either. It all works in the Oshonsoft simulator.
     

    Attached Files:

  13. skimask87

    skimask87 Member

    Joined:
    Mar 23, 2014
    Messages:
    128
    Likes:
    10
    Location:
    Logan (Minot), ND
    So, works in the simulator, and not on actual hardware...is that correct?
    And what is your "actual hardware"?
    Got a schematic you care to share with the rest of the world?
    Maybe a few pictures to go along with it?
     
  14. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    270
    Likes:
    15
    Location:
    Helsinki, Finland
    Post your schematic.
    Post the code in the message.
    Is the Ra1 pin output as default?
     
  15. skimask87

    skimask87 Member

    Joined:
    Mar 23, 2014
    Messages:
    128
    Likes:
    10
    Location:
    Logan (Minot), ND
    So, let's review...

    1st post...
    Code (text):

    .........
    AllDigital   ---- ok all digital
    ADCON1 = 0x0e   ---- ok RA0 is an analog pin

    Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY

    Define LCD_BITS = 8    ---- ok, 8 bit LCD interface
    Define LCD_DREG = PORTA   ---- Hmmmm......Port A - all 8 bits go out to the LCD.  Wait a minute, didn't you just set RA0 to be an analog input?  Hmmmm....
    Define LCD_DBIT = 0
    Define LCD_RSREG = PORTB
    Define LCD_RSBIT = 0
    Define LCD_RWREG = PORTB
    Define LCD_RWBIT = 1
    Define LCD_EREG = PORTB
    Define LCD_EBIT = 2
    Define LCD_READ_BUSY_FLAG = 1
    Lcdinit

    Dim an0 As Word

    loop:
    Adcin 0, an0
    Lcdcmdout LcdClear
    Lcdout "Analog input AN0"
    Lcdcmdout LcdLine2Home
    Lcdout "Value: ", #an0
    Toggle RB4
    WaitMs 250
    Goto loop
     
    See anything wrong?
     
  16. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    Yes, I have swapped it round a few times, and #11 should be the last.
     
  17. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    PICSIM.jpg SCH.gif
    I added the TRIS's to make them all output.
    The image shows incorrect readout in the SIM, but I tried again and it is OK.
    I looked up schematics similar to the one I posted, I used R/W, but I've tried swapping the pins and ports around quite a bit as tests. Are there any wiring configurations that should not be used? Iadded a XTL after trying with out.
    I assume you mean post HEX?
     

    Attached Files:

    Last edited: Apr 16, 2014
  18. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
     

    Attached Files:

  19. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    Posted in error
     
    Last edited: Apr 16, 2014
  20. skimask87

    skimask87 Member

    Joined:
    Mar 23, 2014
    Messages:
    128
    Likes:
    10
    Location:
    Logan (Minot), ND
    Maybe you go back thru and re-do your wiring and your program completely.
    First look at the wiring for the circuit shows me 5 immediate problems for sure, and another 4 possible problems.
    First look at the code shows me another 4 problems that don't match up to the circuit with 9 possible problems.
     
  21. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,426
    Likes:
    11
    Location:
    Dorset UK.
    I'm rewiring it, but from those immediate wiring problems you can see, can you give me any clues, so I don't simply repeat my mistakes? I hope you are looking at the program I posted in #16? Noting that the schematic posted is only a guide, as I have changed it since.
     

Share This Page