4Mhz Circuit with a 20Mhz PIC


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

    Default 4Mhz Circuit with a 20Mhz PIC

    Good day Picers!

    I have layout an easy LED blink circtuit at 4Mhz.
    I only have 20Mhz PICs, 1 x PIC16F877-20l/P and 2 x PIC16F877-20/P

    When I program the PIC16F877-20l/P @ 4Mhz it works fine, but when I program the PIC16F877-20/P it does not work and it's exactly the same circuit.

    Is there any setting to get this Pics working @ 4Mhz?


    Thank you!
    Koossa

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    I assume you have the following line at the top of your PBP program:

    DEFINE OSC 4

    Thats the only setting I can think of that you would need to worry about.

    What does happen? Does everything happen at the wrong speed, or does the PIC refuse to do anything at all?

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Here is my code, and nothing at all happen
    With the PIC16F877-20l/P it is working, but when I switch it with the PIC16F877-20/P it does not work.


    <code>
    &nbsp;&nbsp;Include "Modedefs.bas"

    &nbsp;&nbsp;DEFINE OSC 4 ' Set the Xtal frequency to 4mHz

    &nbsp;&nbsp;LEDPin VaR PORTC.2
    &nbsp;&nbsp;i var byte

    Main:
    &nbsp;&nbsp;for i = 1 to 10
    &nbsp;&nbsp;&nbsp;&nbsp;High LEDPin
    &nbsp;&nbsp;&nbsp;&nbsp;Pause 400
    &nbsp;&nbsp;&nbsp;&nbsp;Low LEDPin
    &nbsp;&nbsp;&nbsp;&nbsp;Pause 400
    &nbsp;&nbsp;next i
    end
    </code>

  4. #4
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Config bits?

    Hi,

    At 20 MHz I guess you use "HS" for 20 MHz but for 4 MHz "XT" would be a better choice.

    What do you clock it with? do you have a 4MHz x-tal or osc?

    /me

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Jumper

    Thank you very much for your feedback.
    I do have my Oscillator setting on "XT" and I'm using a 4Mhz X-tal.

    Koossa

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    ... a long shot but try blinking RB0 instead of RC2 (and report back).
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7


    Did you find this post helpful? Yes | No

    Default

    I have moved my LED to RB0 and change my code, but not one of them are working now.
    Am I missing something?


    <code>
    &nbsp;&nbsp;Include "Modedefs.bas"

    &nbsp;&nbsp;DEFINE OSC 4 ' Set the Xtal frequency to 4mHz

    &nbsp;&nbsp;LEDPin VaR PORTB.0
    &nbsp;&nbsp;i var byte
    Main:
    &nbsp;for i = 1 to 10
    &nbsp;&nbsp;High LEDPin
    &nbsp;&nbsp;Pause 400
    &nbsp;&nbsp;Low LEDPin
    &nbsp;&nbsp;Pause 400
    &nbsp;next i
    end
    </code>

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


    Did you find this post helpful? Yes | No

    Default

    Have you tried Oscillator setting on "HS"?
    Dave
    Always wear safety glasses while programming.

  9. #9


    Did you find this post helpful? Yes | No

    Default

    No
    I will try

  10. #10


    Did you find this post helpful? Yes | No

    Default

    I have set it to HS, but still nothing.

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


    Did you find this post helpful? Yes | No

    Default

    Attach the compiled .HEX file that you are programming into the PIC here. If there's a
    problem with your config settings, that makes it easy for someone to spot.
    Regards,

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

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Bruce

    Attached the zipped hex file.

    Thank you very much for your time!
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Default

    Hi Koossa,

    The good news is - config settings look fine. XT osc, WDT on, PWRT on, brownout on,
    LVP off, protection off. Looking good here if you're using a 4MHz external crystal.

    The bad news is - this code isn't anywhere near what you show above just trying to
    toggle an LED.

    It sets up the USART for 19,200bps at 4MHz, shoots out a single letter f, then sits & spins
    waiting for serial data input, in a loop watching the RCIF flag bit.

    Are you 100% sure you're actually programming the file you expect into your 877?

    The .HEX file you have attached is for sure not the one you show above trying to toggle
    an LED....;o}
    Regards,

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

  14. #14
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello Koossa,
    try adding this to your code:

    CCP1CON = 0 ' DISABLE CAPTURE COMPARE MODULE
    TRISC = %00000000 ' SET ALL PORT C TO OUTPUTS


    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  15. #15
    Join Date
    Sep 2007
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    I think this code was compiled using the MicroCode Studio Plus ICD Compile. It won't run in the PIC unless there is an ICD connection to the PC.

    If you intended to run the code without the ICD, find the "normal" compile/program buttons in MicroCode Studio Plus. Don't use ICD Compile or ICD Compile And Program unless you have the ICD connection hooked up.
    Charles Leo
    microEngineering Labs, Inc.
    http://melabs.com

  16. #16


    Did you find this post helpful? Yes | No

    Default

    I think this code was compiled using the MicroCode Studio Plus ICD Compile
    Thank you Charles_Leo, you are correct, it's been a while since I last use this software so I was a bit rusty.

    Joe S., I have added your code and everything is working now
    CCP1CON = 0 ' DISABLE CAPTURE COMPARE MODULE
    TRISC = %00000000 ' SET ALL PORT C TO OUTPUTS
    Thank you very much!!!

Similar Threads

  1. PIC backup power supply: switchover ???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 18th April 2008, 17:05
  2. Circuit Diagram for interfacing AC to PIC IC?
    By wellyboot in forum Schematics
    Replies: 3
    Last Post: - 8th March 2008, 19:40
  3. Pic driven digital audio delay
    By skimask in forum Off Topic
    Replies: 12
    Last Post: - 19th April 2007, 20:42
  4. Circuit needed to allow a PIC to turn something on or off
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th October 2005, 21:17
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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