Menu

Blinking LED 12f629

Help
2008-10-25
2013-05-30
  • Nobody/Anonymous

    I'm working on another project after having fixed my programmer this afternoon - I want to blink LEDs on my 12f629. My code looks like this

    =====================
    #chip 12F629, 20       ;chip setup

    #define Pin1 GPIO.1      ;define pins

    DIR GPIO.1 OUT      ;setup pins as out

    start:
        set Pin1 ON                     ;get LED to blink by turning pin1 on and off
        wait 3 s
        set Pin1 OFF
    goto start
    =====================
    The problem I'm having is that my LED won't blink. I've got a battery attached to the power and ground, then I've got the LED going from GPIO.1 to the ground on the PIC. I didn't put any resistors in it, and so far nothing has fried (the PIC and LED are still working). I'm not sure why this doesn't work. It's probably something simple that I can't see because I'm such a n00b.

    Once I figure this out, I want to go back to my xbox project, but I think I should start here, with something simple.

    Thanks for looking at my post!

    -Qlept0

     
    • Hugh Considine

      Hugh Considine - 2008-10-26

      What oscillator are you using? By default, GCBASIC expects an external crystal. If you're using the internal oscillator (I'd recommend that you do on anything where accurate timing isn't essential) you need to add this line:

      #config osc = int

      You'd also have to change the #chip line, as the internal oscillator can only run at 4 MHz on the 12F629.

      Resistors are always a good idea, anything between 150 and 220 Ohm should do the job. You can usually get away with not using a resistor when there's only one LED connected to the PIC, but once you start adding more things start behaving weirdly.

      A couple of other hints, you can use constants in the Dir command (Dir Pin1 out), and at the moment the program you posted will only leave the LED off for about 3 us.

       
    • Grant

      Grant - 2008-10-26

      I'm a n00b myself, but looking at this code:

      start:
      set Pin1 ON ;get LED to blink by turning pin1 on and off
      wait 3 s
      set Pin1 OFF
      goto start

      You set your LED on, then wait to turn it off, but you don't wait to turn it back on.

      Should it be?:

      start:
      set Pin1 ON ;get LED to blink by turning pin1 on and off
      wait 3 s
      set Pin1 OFF
      wait 3 s
      goto start

      You haven't said if your LED is on constant or not on at all. If it's on constant this may be why.

      Hope this helps,

      Grant

       
    • Nobody/Anonymous

      How excellent! Everything is coming together nicely, the PIC is making the LED turn on and off every couple of seconds. The timing isn't correct though, is there any way to make it more accurate without running the chip with an external clock?

      Thank you so much for helping me out, this is a very exciting moment for me :) :) :)!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.