Connect with us

Newbie: Trying to blink a LED using PIC

Discussion in 'Electronic Basics' started by Jack B. Pollack, Feb 25, 2006.

Scroll to continue with content
  1. Can someone help me get started. I have been trying to blink a LED using a
    16F88 all morning without any success.

    I am not seeing any logic levels on any of the outputs (they are all
    tri-stated). I have tried a different chip and the second one does the same.

    What is wrong with my code?

    OSCCON = $60


    Toggle PORTB.1
    Pause 1000
    GoTo LOOP
  2. PeteG

    PeteG Guest

    After power up the ports are set to input. I don't see anything in those
    commands that set the port or the pin to output before you start writing to
    it. The fact that you say the pins are all tri-stated suggest the same.

    You need to find the command to set the TRISB register to output on that
    pin. Since I'm not sure what language you're writing in I don't know what
    command you need to add but I'm sure you can work it out.

  3. Thanks for your reply.

    I just tried TRISB = %00000000 and Output B.1

    Both are valid commands according to the help file for the MicroCode Studio
    editor/compiler. Unfortunately results are the same (tri-state).
    Any other ideas?
  4. John Fields

    John Fields Guest

  5. PeteG

    PeteG Guest

    Nothing that comes to mind.

    May be someone who has some knowledge of the language you are using can

    There's really not that much more to blinking a LED on a PIC than what I see
    you're doing.

    Also, you should put your reply at the bottom of the message not the top;
    it's newgroup etiquette.

  6. ANSEL = 0
  7. Boon

    Boon Guest

    Put the word "End" inside your code and try again.
  8. Rubicon

    Rubicon Guest


    It looks like PicBasic or PicBasic Pro.

    I haven't used the 16F88 PIC but a search has shown it has the same
    pinout as the 16F84 and uses an internal oscillator. Pete is right in
    that you have to set the TRISA and TRISB registers to what you want.

    For example using a 16F84
    TRISA = %00000 'All PortA output pins output
    PORTA = 0 'Set all PortA pins LOW
    TRISB = %01000010 'RB1 & RB6 input all other PortB pins output
    PORTB = 0 'Set all PortB output pins LOW

    If you go to there is a forum
    and an archive available. However it seems the forum may be down at
    the moment, either that or my PC is playing up.

    I'm no expert but try the program below. I've dressed it up a little
    with remarks as it's a good habit to get into for when you start on
    much larger programs. I'll remember that and three months later when
    you look at it again it's "What?"

    ' Blinking LED program *


    OSCCON = $60 'Enable internal oscillator
    TRISA = %00000 'All PortA pins output
    PORTA = 0 'Set all PortA output pins LOW
    TRISB = %00000000 'All PortB pins output
    PORTB = 0 'Set all PortB output pins LOW

    LOOP: 'Main program start
    Toggle PORTB.1 'Invert RB1 pin
    Pause 1000 'Pause for 1 second
    GoTo LOOP 'Return to main program start



  9. Thanks to all that posted. I found the problem was a bad PIC programmer.
    Everything is working great now.
    Thanks again.
  10. Rubicon

    Rubicon Guest

    Ah yes - just like the CMCON = 7 in Picbasic Pro for the 16F628 I've
    been learning to use.

    Jack have a look at this page. I'm certainly printing it off for
    future reference.


Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day