First time with external oscillator - 16F877a Not working


Closed Thread
Results 1 to 9 of 9
  1. #1

    Exclamation First time with external oscillator - 16F877a Not working

    Hello everyone
    It was easy for me upto now using PICKIT2 and 16F690 for all my experiments.

    This is the first time I am using an PIC with an external oscillator. My PIC is 16F877A. I have placed the 4Mhz ceramic two pin oscillator as said in the datasheet (between os1 and os2) and 15pF from osc pins to gnd. My program is simple and all pins need to be Digital I\O.
    I am creating an .Hex file using PBP with MPLAB and then loading it onto my PIC using MELAB U2 USB programmer (Hope I can do it this way?)
    Oscillator selection is XT, wdt on, PUT on, BOD on, Low V. Prog Disabled, Data EE.... On, Flash program Write Off, Code protect On AND my simple code is :
    DEFINE OSC 4
    intcon=0
    adcon0=%000
    adcon1=%1110
    cmcon=%000
    @ ERRORLEVEL -306 ( It is for my actual code which is very loooooooooooong)
    trisb=%00111111
    portb=0

    Include "modedefs.bas"

    while 1
    toggle portb.6
    pause 30
    wend

    The above is not working. Please help.
    ___________________
    WHY things get boring when they work just fine?

  2. #2


    Did you find this post helpful? Yes | No

    Exclamation

    Ok, now I even tried it with just the following code

    while 1
    toggle portb.6
    pause 30
    wend

    Tried capacitor value from 15 pF to 39 Pf, but no response. By the way I am making the circuit in a breadboard & not a PCB
    ___________________
    WHY things get boring when they work just fine?

  3. #3
    Join Date
    Jan 2009
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    osc1=input
    osc2=output

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


    Did you find this post helpful? Yes | No

    Default

    Using MPLAB, GOOD!

    First:
    Turn off the setting of the fuses in your programmer software and do it in code or the *.inc file.

    Second:
    To make this all digital use
    Code:
    ADCON1=7
    CMCON=7
    Third:
    Try this code before you write something "looooong", just to make sure everything is working.
    Code:
    '****************************************************************
    '16F877A       HEART_BEAT
        DEFINE OSC 4
    '####################
        @ __config _XT_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF &_BODEN_OFF
        ADCON1=7
        CMCON=7
        
    START:
        HIGH PORTD.2
        PAUSE 100
        LOW PORTD.2
        PAUSE 100
        GOTO START
    Dave
    Always wear safety glasses while programming.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bogdan View Post
    osc1=input
    osc2=output
    How do you figure that out with the ceramic oscillator? I only see two pins comming out and no specific I\O marking.
    ___________________
    WHY things get boring when they work just fine?

  6. #6


    Did you find this post helpful? Yes | No

    Exclamation

    Quote Originally Posted by mackrackit View Post
    Using MPLAB, GOOD!

    First:
    Turn off the setting of the fuses in your programmer software and do it in code or the *.inc file.

    Second:
    To make this all digital use
    Code:
    ADCON1=7
    CMCON=7
    Third:
    Try this code before you write something "looooong", just to make sure everything is working.
    Code:
    '****************************************************************
    '16F877A       HEART_BEAT
        DEFINE OSC 4
    '####################
        @ __config _XT_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF &_BODEN_OFF
        ADCON1=7
        CMCON=7
        
    START:
        HIGH PORTD.2
        PAUSE 100
        LOW PORTD.2
        PAUSE 100
        GOTO START
    Hi, thanks for replying. My Loooong code is working fine (Code is good) on 16F690. I want to transffer the code to 16F877 but since it uses external oscillator and I have never used one before, I only have intentions to blink an LED first.
    I have tried your advise above but its not working still. Timing of blinking is not right (when it is blinking), it blinks sometimes when I touch the capacitor leg, touch the bench where the circuit is left on, sometimes its just sitting bright on. I feel the problem is with hardware configuration.
    I am building the circuit on a breadboard with 4MHz ceramic oscillator and two 22pF ceramic capacitors. But just don't know what is wrong and it is taking me towards insanity....
    ___________________
    WHY things get boring when they work just fine?

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


    Did you find this post helpful? Yes | No

    Default

    Tell about the MCLR pin connection.
    Is it pulled high?
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,613


    Did you find this post helpful? Yes | No

    Talking

    10 Bucks on Mackrackit ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9


    Did you find this post helpful? Yes | No

    Wink

    Did I mentioned that some people here really know there stuff?
    Thank you very much, this problem was due to MCLR!

    But

    I'LL BE BACK (with more problems ofcourse)

    ___________________
    WHY things get boring when they work just fine?

Similar Threads

  1. I don't understand this code!
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 13th February 2008, 02:55
  2. Working with indivividual bytes of an array
    By J_norrie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd January 2007, 19:16
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  4. help with 16f628a
    By thalia in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd May 2006, 08:16
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 14:24

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