Menu

setting PIC12F509/10 pin directions?

Help
Jonny!!!
2008-01-13
2013-05-30
  • Jonny!!!

    Jonny!!! - 2008-01-13

    I am unsure how to set the pin directions on the PIC12F509 and 510

    I have tried the normal approach

    DIR GPIO.2 OUT

    which brings up this error:
    Error: Cannot set direction of individual pins on 12 bit core chips

    So I tried the entire port form (both in binary and hex), which don't give me an error, but still doesn't light up the LED:

    DIR GPIO b'00000000'

    And I've tried:

    DIR GPIO 0x00

    Then to try to light up the LED on pin GP2:

    SET GPIO.2 ON

    which does NOT power the LED...

    What am I doing wrong?

     
    • Nobody/Anonymous

      Try the following:

         dir gpio b'00000000'
                or
         dir gpio b'11111011'
                or
         set gpio.2 on

        

       
    • Hugh Considine

      Hugh Considine - 2008-01-23

      On the 12F509, GPIO.2 defaults to acting as the input pin for the timer. To make it act as a normal I/O pin, add this code to the start of your program:

      movlw b'11001111'
      option

      This alters the OPTION register, disabling the bit that makes GPIO.2 increment the timer.

       
    • Nobody/Anonymous

      I have tried that, Hugh. The LED now turns on, however, I am unable to then turn it OFF....

      Also, PICKit attempted a bulk erase less then 4.5 volts on one of my 509's, and it appears the OSSCAL value was lost. My other 509 says its "0C06", so could I somehow tell it what that value is? I believe I've seen something done in assembly like this, but I have no clue where that documentation is at...

      My code:

      #CHIP 12F509, 4

      movlw b'11001111'
      option
      DIR GPIO b'00000000'
      goto main

      main:
          set gpio.2 on
          wait 500 ms
          set gpio.2 off
          wait 500 ms
      goto main

      what is also INTERESTING... is that sometimes the chip wont power the LED, unless I tap the chip. Yes, tahts right. tap it with my finger. WTF? I'm assuming its fried, but my second 509 did exactly the same (now its working fine, however). The 1st once i've been careless with (so this is expected), the second one has been sealed since the day i got it. Is there something i'm doing wrong with these?

       
    • Nobody/Anonymous

      Edit: the LED turns on, and stays on, when i touch the soldered pins on the bottom of the chip.

       
    • Nobody/Anonymous

      OK, this is weird. I changed the above program from '500 ms' to '1 sec'. Supposedly, the chip runs at 4 MHZ, but in the program above, i'm getting a blink rate of once every 4 seconds instead of one.

      Getting it to blink:
      I was able to get it to blink in my prototype MOSFET driver circuit (I'm using a cheap MCU as I run hardware tests), where the 1 Megaohm resistor going across the Source and Gate (to ensure it remains off when it's supposed to) is acting as a pull-down resistor on GPIO.2. It blinks just fine under these circumstances. However, it is VERY slow. I told it 1 second, and its going at at a rate of 4 seconds.

      Also, that problem with touching the pins has disappeared. And I think that OSSCAL value "fixed" itself, I think i was just being negligent while swapping chips on the PICKIT2.

      Whats your take (anybody!)?

      Also, am I in the twilight zone? o.O

       
    • Nobody/Anonymous

      509 #1 will blink if you *touch the top of the IC with your finger (plastic casing)* (identical results with MOSFET driver and plain LED). 509 #2 acts the same with and LED only, however in the MOSFET driver, it behaves erratically (sometimes it wont turn off, sometimes it blinks, sometimes nothing).

      Are 12F509's just junk?

      Sorry about the redundant posts, but I could really use some help. =D

       
      • Grant

        Grant - 2008-01-26

        Hi,

        Don't know if it's going to help, but the help file for the Wait command says you can only use up to 255, where here you use 500.

        To fix this, change your code to Wait 50 10ms.

        main:
           set gpio.2 on
           wait 50 10ms
           set gpio.2 off
           wait 50 10ms
        goto main

        Hope this helps.

        Grant

         
    • Jonny!!!

      Jonny!!! - 2008-01-26

      I have tried that, and while it worked on 509 #1 only when i held my finger on top of the chip, the other 2 only lit the LED, but didn't blink it, which of course required me to hold my finger on top of these chips as well, just to get the LED to light.

       

Log in to post a comment.