PIC16F819 LED not blinking


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15

    Default PIC16F819 LED not blinking

    Using a PIC16F819 and below PBP program. My volt meter does not show a HIGH/LOW cycle occuring on the pin for the LED. (Pins 10 and 17). 31.25kHz is desired OSC speed and internal. All pins converted to digital.

    MPASM Code:

    @__Config_INTRC_OSC
    @__Config_PWRT_OFF
    @__Config_MCLR_OFF
    @__Config_BOREN_OFF
    @__Config_DEBUG_OFF

    DEFINE OSC 3
    OSCCON = %00000000
    ADCON1=7
    TRISA = %00000000
    TRISB = %00000000
    TRISB.4 = 0
    TRISA.0 = 0
    PORTB.4 = 0
    PORTB.4 = 0

    LOOP:

    PULSOUT PORTB.4,20
    PAUSE 20
    PULSOUT PORTA.0,20
    PAUSE 20

    'Goto LOOP

    Please help if you can. I have been using other posts to fix, but I have been unsucessful.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Oooohhhh.... not good...

    The DEFEINE OSC 3 tells PICBasic that you're running at 3.58MHz, whereas you are actually running almost 110x slower at 32kHz...

    This means that EVERY time critical function (including PULSEOUT) will be totally shot to pieces.

    As a test... try this...

    Loop:
    High PortB.4
    Pause 2
    Low PortB.4
    Pause 2
    Goto Loop

    You might find the LED blinks at about 2Hz (give or take)...

    I don't recall if PICBasic (my manual is a little old) allowed definitions below 3.58 MHz... but I think 32kHz will cause numerous problems.

    May I also suggest you SWITCH OFF the WATCHDOG TIMER (which is ON by default with PICBasic). The program may be running so slowly that your PIC is actually timing-out and resetting before it actually executes anything.

  3. #3
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    I have been reading a lot of posts you have made over the years on this issue Melanie, and I am very happy to hear from you in particular. You seem to be well versed in the changes that have been made to this chip over the years. Is it worth using?, or would the 16F87/88 be better? NANO and 16-pins I/O are my only requirements on this......and also, I am going to be using a Timer that will require me to use MPASM. This section will be added to the program IF I get this chip running properly (IF being key word here!).

    As you can see, I am trying to preserve power and was hoping to get 31.25kHz on this project internally. But due to problems at this point, I can go higher on the OSC to get this thing going in the right direction if need be.

    I removed the "Define OSC 3" statement, as well as the commands as you suggested. No Luck.

    So in order to move forward, what would be the best settings on this chip to get the LED's (pin 10 & 17) to blink the LED? 1MHz?

    Note: What is the FOSC0:FOSC2 needing to be set to 100 all about? I saw this somewhere and don't understand this area.

  4. #4


    Did you find this post helpful? Yes | No

    Default check your code :-)

    Hi Ron

    I noticed your LOOP code seems to have a problem at the end ....
    The GOTO LOOP has a comment in the beginning , at first it looked like a spec of dust ;-)
    Look carefully at the beginning of the GOTO line :-)
    your code...
    Code:
    LOOP:
    
    PULSOUT PORTB.4,20
    PAUSE 20
    PULSOUT PORTA.0,20
    PAUSE 20
    
    'Goto LOOP
    Corrected code
    Code:
    LOOP:
    
    PULSOUT PORTB.4,20
    PAUSE 20
    PULSOUT PORTA.0,20
    PAUSE 20
    
    Goto LOOP
    Did you try Melanie's code in place of yours ?

    Hope that works ...
    Dennis
    Last edited by Dennis; - 30th November 2009 at 21:19.

  5. #5
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=Dennis;81575]Hi Ron

    I noticed your LOOP code seems to have a problem at the end ....
    The GOTO LOOP has a comment in the beginning , at first it looked like a spec of dust ;-)
    Look carefully at the beginning of the GOTO line :-)
    your code...

    Good eyes Dennis, but this is only on the forum post....I already corrected that on the program! Thanks for the help in any case. I am still trying to get this thing running, so any addidtional help is appreciated.

    No luck with Melanies info changes.....Datasheet 35-37 are on the INTRC and INTOSC settings. What do we do when going to higher OSC frequency in this area?
    Last edited by ronbowalker; - 30th November 2009 at 21:28. Reason: Info Update

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


    Did you find this post helpful? Yes | No

    Default

    Your config options have ZERO effect on actual config settings.
    Code:
    @__Config_INTRC_OSC 
    @__Config_PWRT_OFF
    @__Config_MCLR_OFF
    @__Config_BOREN_OFF
    @__Config_DEBUG_OFF
    So your config settings are whatever the default config options are set to in your
    PBP 16F819.INC file for the MPASM assembler.

    And, like Melanie mentioned, you for sure will want the WDT disabled since DEFINE OSC 3
    is for a 3MHz osc & not 32kHz osc, so your timing is way off.

    Try this just to verify it's working;
    Code:
    DEFINE OSC 4 
    @ __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF
    OSCCON = %01100000  ' 4MHz 
    ADCON1=7 
    TRISA = %00000000 
    TRISB = %00000000 
    TRISB.4 = 0 
    TRISA.0 = 0 
    PORTA.0 = 0 
    PORTB.4 = 0 
    
    LOOP: 
    
    PULSOUT PORTB.4,20 
    PAUSE 20
    PULSOUT PORTA.0,20 
    PAUSE 20 
    
    Goto LOOP
    And, for PBP 2.6 you'll want to change LOOP to something like LOOPS since LOOP is now a
    reserved word.
    Last edited by Bruce; - 30th November 2009 at 21:38.
    Regards,

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

  7. #7
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    @ __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF

    This gives me illegal character "&" error message......asm.51

    So I need to go and make these settings permanent in MPASM file to keep from having to make this statement, correct?

    Also, datasheet (DS39598E)2004 shows:
    A. WDT is WDTEN (Watchdog Timer)
    B. MCLR is MCLRE (Memory Clear)
    C. BODEN is BOREN (Brown-Out)

    Is this correct?
    Thanks for the info Bruce....I appreciate all the help I can get.
    I will try to change the file settings...can you tell me what to have for pic16f819.inc file, I think I messed mine up.
    Here is mine:
    ;************************************************* ***************
    ;* 16F819.INC *
    ;* *
    ;* By : Leonard Zerman, Jeff Schmoyer *
    ;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
    ;* All Rights Reserved *
    ;* Date : 01/07/04 *
    ;* Version : 2.45 *
    ;* Notes : *
    ;************************************************* ***************
    NOLIST
    ifdef PM_USED
    LIST
    include 'M16F81x.INC' ; PM header
    device pic16F819, intrc_IO, wdt_off, pwrte_off, lvp_off, protect_off
    XALL
    NOLIST
    else
    LIST
    LIST p = 16F819, r = dec, w = -302
    INCLUDE "P16F819.INC" ; MPASM Header
    __config _INTRC_osc & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _CP_OFF
    NOLIST
    endif
    LIST
    Last edited by ronbowalker; - 30th November 2009 at 22:12. Reason: Info Update

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


    Did you find this post helpful? Yes | No

    Default

    This gives me illegal character "&" error message......asm.51
    I have no clue what this error message is. What assembler are you using?

    asm.51
    Almost looks like you're trying to use an 8051 assembler?
    Last edited by Bruce; - 30th November 2009 at 22:13.
    Regards,

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

  9. #9
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    I am using PICBASIC PRO from MicroCode Studio.

    In the settings window, I have selected the MPASM assembler checkbox.

    This is all I know. I reset the .inc file to where is was originally. Here it is....

    ;************************************************* ***************
    ;* 16F819.INC *
    ;* *
    ;* By : Leonard Zerman, Jeff Schmoyer *
    ;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
    ;* All Rights Reserved *
    ;* Date : 01/07/04 *
    ;* Version : 2.45 *
    ;* Notes : *
    ;************************************************* ***************
    NOLIST
    ifdef PM_USED
    LIST
    include 'M16F81x.INC' ; PM header
    device pic16F819, hs_osc, wdt_off, pwrt_off, lvp_off, protect_off
    XALL
    NOLIST
    else
    LIST
    LIST p = 16F819, r = dec, w = -302
    INCLUDE "P16F819.INC" ; MPASM Header
    __config _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _CP_OFF
    NOLIST
    endif
    LIST

    I have been trying to get this MPASM Header, the way you wrote it, to compile correctly all day, but it still gives me errors.

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


    Did you find this post helpful? Yes | No

    Default

    If you prefer to edit your 16F819.INC file, then just change it to;

    __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF

    If not, then just comment it out in the .INC file & add your config settings to your code.

    Melanie posted a nice intro here http://www.picbasic.co.uk/forum/showthread.php?t=543 on setting config options.

    NOTE: This applies only to the 16F819.INC file in your PBP directory. Not the P16F819.INC
    file in your MPLAB directory. These are different. You shouldn't ever need to modify the
    P16F819.INC file in your MPLAB directory.
    Regards,

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

  11. #11
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    This compiles without error.....

    @__CONFIG_HS_OSC_WDT_OFF_PWRTE_ON

    But more than this will cause a "Label truncated at 32 characters" error.

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


    Did you find this post helpful? Yes | No

    Default

    Try the config line I posted above. What you're trying to do here isn't any good.
    Regards,

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

  13. #13
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Try the config line I posted above. What you're trying to do here isn't any good.
    Okay...I now understand what is to be done, and the changes were made as you said to the .inc file. Compile is now error free. Pop-up window settings are now as per your suggestion. Sorry for the crazy rookie mistakes. Let's see what happens now....

    Update...LED is on steady. No blinking
    Last edited by ronbowalker; - 30th November 2009 at 22:57. Reason: Info Updated...

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


    Did you find this post helpful? Yes | No

    Default

    Update...LED is on steady. No blinking
    You might want to try something like this to see your LEDs blink;
    Code:
    DEFINE OSC 4 
    @ __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF
    OSCCON = %01100000  ' 4MHz 
    ADCON1=7 
    TRISA = %00000000 
    TRISB = %00000000 
    TRISB.4 = 0 
    TRISA.0 = 0 
    PORTA.0 = 0 
    PORTB.4 = 0 
    
    LOOP: 
      PORTB.4 = PORTB.4 ^ 1
      PAUSE 250
      PORTA.0 = PORTA.0 ^ 1
      PAUSE 250 
      Goto LOOP
    Check your PBP manual to see why your LEDs aren't visibly blinking with PULSEOUT...;o)
    Regards,

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

  15. #15
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    You might want to try something like this to see your LEDs blink;
    Code:
    DEFINE OSC 4 
    @ __CONFIG _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _MCLR_OFF & _BODEN_OFF & _DEBUG_OFF
    OSCCON = %01100000  ' 4MHz 
    ADCON1=7 
    TRISA = %00000000 
    TRISB = %00000000 
    TRISB.4 = 0 
    TRISA.0 = 0 
    PORTA.0 = 0 
    PORTB.4 = 0 
    
    LOOP: 
      PORTB.4 = PORTB.4 ^ 1
      PAUSE 250
      PORTA.0 = PORTA.0 ^ 1
      PAUSE 250 
      Goto LOOP
    Check your PBP manual to see why your LEDs aren't visibly blinking with PULSEOUT...;o)
    Still no blink. Tried above program as well. PULSOUT did not work either...?

  16. #16
    Join Date
    Oct 2009
    Location
    Austin, Texas
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    I now have blimking LED's....

    DEFINE 4 statement was not needed.

Similar Threads

  1. Simple Blinking LED - WTF!!
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2010, 06:19
  2. Blinking an led problem on P16F84
    By aimenbukharie in forum General
    Replies: 1
    Last Post: - 20th March 2009, 05:00
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. simple LED Blinking project
    By koossa in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th December 2004, 01:25

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