blinking problem with PIC16f887


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1


    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.

  2. #2
    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

  3. #3
    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 : 0

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