blinking problem with PIC16f887


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    14

    Default blinking problem with PIC16f887

    I'm using PIC16f887 with 20MHZ osc...my led connect to RD2.

    Define OSC 20

    TRISD = 0
    PORTD = 0

    MAIN:

    PORTD.2 = 1
    PAUSE 500
    PORTD.2 = 0
    PAUSE 500

    GOTO MAIN
    end

    why my led not blinking with 500ms ?? when i remove define osc 20...my led blinking correctly (500ms).
    Last edited by larzazral; - 25th January 2010 at 14:54.

  2. #2
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Manuel says ;


    These definitions must be in all upper case.
    Define >>>>> DEFINE

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


    Did you find this post helpful? Yes | No

    Default Configs

    Hello larzazral,
    I do not see a config statement in your code which means either:
    A. you simply did not share them with us, or
    B. You are using the default config statement located in the 16f887.inc
    file in the root directory of PBP.

    The 16f887.inc file is as below:
    Code:
            NOLIST
        ifdef PM_USED
            LIST
            include 'M16F88x.INC'	; PM header
            device  pic16F887, intrc_osc_noclkout, wdt_on, mclr_on, lvp_off, protect_off
            XALL
            NOLIST
        else
            LIST
            LIST p = 16F887, r = dec, w = -302
            INCLUDE "P16F887.INC"	; MPASM  Header
            __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            NOLIST
        endif
            LIST
    You will take note of the OSCILLATOR config . . . intrc_osc_noclkout
    which obfuscates the use of the crystal / resonator. Which is to say, it runs on internal at 4 mhz and will not DO 20MHZ. To use the crystal, . . . Put a semi colon just before the config statement and install your own config in your code <B> OR </B> simply change the configs to use the "high speed osc. ". Look at this thread, no study it, absorb it, know it, seriously, if you do not study anything else, study this, it is that important.
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    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.

  4. #4


    Did you find this post helpful? Yes | No

    Default the BLINKING led :)

    Hi larzazral

    Check what Joe said and read it all carefully and then check if you have an external oscillator (20 MHZ crystal).

    In the code below I have the defines setup and also ocsillator setting for the internal clock , code is commented as much as possible!

    Hope this helps

    Dennis

    Code:
    '*************************************
    'Blink and LED for 16F887 on PORTd.2
    '*************************************
    'Un-comment the lines below if you need to 
    '@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & '_LVP_OFF & _CP_OFF
     
    'Ocsillator selections here
      'OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz
    '        OSCCON = %01110001           'Int CLK 8MHz
    '        ANSEL= %11111111       '$0F = disable A/D converter
    '        option_reg = 7     'switch pull-ups ON
    'END of oscillator selections
     
    'timer/oscillator defines 
    
    OSCCON = %01110001          'Int CLK 8MHz
    DEFINE OSC 8                '8MHz << NOTICE UPPERCASE ON DEFINE
    
    'END of timer/oscillator defines
    
    
    ANSEL = %00000000           'All digital
    OPTION_REG.7 = 0            'Weak pull-ups enabled
    
    
    
    'port clear 
    PORTA=0
    PORTB=0
    PORTC=0
    PORTD=0
    PORTE=0
    'end of port clear
    
    'Port IO directions and presets for port pins begin here
    'TRISX = %76543210   << TRIS bit order numbering
    'TRISA = %11111111    <<   'All pins are outputs
    '// Define port pins as inputs and outputs ...
            TRISA = %00000000 'all output
            TRISB = %00000000 'all output
            TRISC = %00000000 'all output
            TRISD = %00000000 'all output
            TRISE.0 = 0  'all output
            TRISE.1 = 0  'all output
            TRISE.2 = 0  'all output
    'End of Port IO directions and presets for port pins begin here
    
    'includes begin here
            INCLUDE "modedefs.bas"
           
    'end of includes
                       
    'variables begin here
            
    LED var PORTd.2   ' Alias PORTD.0 to LED
    
    'end of variables
    
    
    
    
        
    blinky: ' a program label called blinky
            high LED  ' LED on
            Pause 500       ' Delay for .5 seconds
    	low led  'LED off
            Pause 500       ' Delay for .5 seconds
          
               Goto blinky  ' Go back to blinky label and do it all over again
            End
    'End of all code
    Last edited by Dennis; - 25th January 2010 at 20:43.

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


    Did you find this post helpful? Yes | No

    Default

    The PBP default config settings for this PIC are;
    device pic16F887, intrc_osc_noclkout, wdt_on, mclr_on, lvp_off, protect_off

    So, it's actually running on the internal oscillator.

    And the PIC default setting of OSCCAL (for the internal oscillator) is for 4MHz.

    Define OSC 20 forces PBP tro assume it's running at 20MHz, but its actually running on
    the 4MHz internal osc, so Define OSC 20 screws the timing .. when it's running at 4MHz.

    For it to work as expected, at 20MHz, you would need to connect an external 20MHz
    crystal (or resonator), and change config settings to;

    device pic16F887, hs_osc, wdt_on, mclr_on, lvp_off, protect_off.

    Then use the DEFINE OSC 20.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    The PBP default config settings for this PIC are;
    device pic16F887, intrc_osc_noclkout, wdt_on, mclr_on, lvp_off, protect_off

    So, it's actually running on the internal oscillator.

    And the PIC default setting of OSCCAL (for the internal oscillator) is for 4MHz.

    Define OSC 20 forces PBP tro assume it's running at 20MHz, but its actually running on
    the 4MHz internal osc, so Define OSC 20 screws the timing .. when it's running at 4MHz.

    For it to work as expected, at 20MHz, you would need to connect an external 20MHz
    crystal (or resonator), and change config settings to;

    device pic16F887, hs_osc, wdt_on, mclr_on, lvp_off, protect_off.

    Then use the DEFINE OSC 20.
    See Bruce,
    We need your book
    Can I get that on Amazon ?
    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.

Similar Threads

  1. Blinking an led problem on P16F84
    By aimenbukharie in forum General
    Replies: 1
    Last Post: - 20th March 2009, 05:00
  2. PIC16F887 Config problem
    By Agent36 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th November 2008, 22:38
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. 7-segment display blinking problem?
    By serdar_ozcan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th March 2006, 14:43
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59

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