PIC16F767 blinking code


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

    Default PIC16F767 blinking code

    Hello Guys,

    I'm having some problems trying to make this pic to work, do you see anything wrong with my blinking code?

    @ DEVICE PIC16F767, INTRC_OSC_NOCLKOUT, WDT_ON, PROTECT_OFF
    OSCCON=%01111000 '8Mhz
    TRISB = 0

    loop:
    High PORTB.7
    Pause 500
    Low PORTB.7
    Pause 500
    GoTo loop
    End

    Anything missing on the @ statement?

    Thank you very much.

    Regards,
    Daniel.

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


    Did you find this post helpful? Yes | No

    Smile

    Two ideas to try:

    1) Try OSCCON %01110000 instead of %01111000 (you do not appear to be switching from a Primary OSC - see first few paragraphs of datasheet section 4.6 and description (and foot note) of OSCCON<3>)

    2) What are you doing with MCLR - is it tied high?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Paul,

    Thanks for your help, I've been working with pics for almost four years now, but never used the internal oscillator before.

    I think I'm having some problems with my parallel programmer, because is not programming the code.

    Do you know if the 16F767 need any special requirement to be programmed?

    Thank you very much.

    Regards,
    Daniel.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    At last, after two weeks and a new programmer, a 16F767 working blinking code:

    @ DEVICE PIC16F767, INTRC_OSC_NOCLKOUT ; System Clock Options
    @ DEVICE PIC16F767, WDT_ON ; Watchdog Timer
    @ DEVICE PIC16F767, PWRT_ON ; Power-On Timer
    @ DEVICE PIC16F767, MCLR_OFF ; Master Clear Options (Internal)
    @ DEVICE pic16F767, PROTECT_OFF ; Code Protect Off

    OSCCON=%01110000

    main:
    High PORTB.7
    Pause 500

    Low PORTB.7
    Pause 500

    GoTo main
    End

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi Daniel,

    Is "DEFINE OSC 8" necessary in this case or not?

    Eventhough you set OSCCON, how does PBP know that it is 8Mhz?

    ------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Because OSCCON=%01110000 sets the internal oscillator to 8Mhz...

    Read the 16F767 datasheet section 4.6.3 for other frequencies...

    PICs makes me love and hate them at the same time....

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


    Did you find this post helpful? Yes | No

    Default

    In those situation, you need to take a break and have a cup of coffee
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1118&stc=1&d=116054038 5">
    Attached Images Attached Images  
    Steve

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

  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by danielhr77
    Because OSCCON=%01110000 sets the internal oscillator to 8Mhz...
    For sure it does set it to 8Mhz but don't we also need to state DEFINE?


    ---------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  9. #9


    Did you find this post helpful? Yes | No

    Default

    I don't think so... So far It's working fine...

    I think that DEFINE OSC is for external oscillators only, but not sure...

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


    Did you find this post helpful? Yes | No

    Default

    NOPE, DEFINE is a compiler directive and MUST be added at the top of the code. OSCCON is a PIC register that must be set like all the otheres. Let's Say TXSTA, RCSTA, SPBRG.

    Do a simple Test, with your current OSCCON setting do a simple LED blink. use DEFINE OSC 4.. then use DEFINE OSC 8

    what happen?
    Steve

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

  11. #11
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    NOPE, DEFINE is a compiler directive and MUST be added at the top of the code. OSCCON is a PIC register that must be set like all the otheres. Let's Say TXSTA, RCSTA, SPBRG.

    Do a simple Test, with your current OSCCON setting do a simple LED blink. use DEFINE OSC 4.. then use DEFINE OSC 8

    what happen?

    That is what I thought so.
    Daniel, could you pls test it and post the result?


    -----------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  12. #12


    Did you find this post helpful? Yes | No

    Default

    With DEFINE OSC 8 the LEDs are blinking slowly...

    With DEFINE OSC 4 the LEDs are blinking faster...

    I'm confused... :|
    Last edited by DanPBP; - 16th October 2006 at 14:50.

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


    Did you find this post helpful? Yes | No

    Default

    Normal... they have to blink twice the speed of DEFINE OSC 8 right?
    Steve

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

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  4. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26

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