Pic 12f629


Closed Thread
Results 1 to 15 of 15

Thread: Pic 12f629

  1. #1
    Join Date
    Jan 2008
    Posts
    6

    Unhappy Pic 12f629

    Hi I am very new to the 8pin pics
    I need some help using a 12f629 and all I want is for it to sense
    a hi or low on GP0 pin 7 and output on GP4 pin 3
    I am using an ICD2 programmer
    Configuration bits are:
    internal RC no clock
    Watchdog timer on
    power up timer off
    mclr enable external
    brown out detect on
    I have a 8k resistor connected from vdd to pin 4 MCLR
    I do not seem to get the pic to read an input condition
    my code is as follows

    DEFINE OSCCAL_1K 1
    DEFINE OSC 4

    RELAY VAR GPIO.4

    Pswitch VAR GPIO.0

    INITIALISE:
    CLEAR
    TRISIO = %00000001 '0 in rest output
    INTCON = %00000000
    PIR1 = %00000000
    PIE1 = %00000000
    WPU = %00000000
    CMCON = %11111111 'disable comparators
    PAUSE 10

    MAIN:
    While(pswitch = 1)
    relay = 0



    wend
    relay = 1

    GOTO MAIN
    end
    I would be grateful if anyone could help

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by runrite View Post
    Hi I am very new to the 8pin pics
    I need some help using a 12f629 and all I want is for it to sense
    a hi or low on GP0 pin 7 and output on GP4 pin 3
    Program looks ok, even used CMCON. Have you tried the old blinky LED program yet?
    Put an LED an GP4 and make it blink. When that works, put the switch on GP0, and turn the LED on and off with that switch under program control.
    After that, it should be easy to change it over to do what you want.

  3. #3
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Hi There thanks
    I have done just that on the input I have
    100k to ground permanently on GP0
    the switch is wired in this order +5V 10K switch then GP0
    still no luck
    It just does nt want to check the input condition I have a relay conected via a transistor to the output
    This is quite a puzzling problem

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by runrite View Post
    Hi There thanks
    I have done just that on the input I have
    100k to ground permanently on GP0
    the switch is wired in this order +5V 10K switch then GP0
    still no luck
    It just does nt want to check the input condition I have a relay conected via a transistor to the output
    This is quite a puzzling problem
    Your answer is just a little bit cryptic...
    Have you gotten the blinky LED thing to work?
    You have a relay connected to the output?
    Does it have a 'flyback diode' connected across the coil?
    Is the same power supply driving the PIC that's driving the relay coil?

  5. #5
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Hi there
    Yes 12V to relay and 5V to pic
    flyback diode
    If I change the code I can get the relay to go on and off
    I have used the 16f876's never had a problem like this
    am i not doing something wrong with the configuration in MP Lab
    I am using microcode studio with PBP

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by runrite View Post
    Yes 12V to relay and 5V to pic
    flyback diode
    If I change the code I can get the relay to go on and off
    am i not doing something wrong with the configuration in MP Lab
    I am using microcode studio with PBP
    Maybe try turning off the WDT?
    Try different code, just for grins...
    main:
    if pswitch = 1 then relay = 0
    if pswitch = 0 then relay = 1
    goto main
    end

  7. #7
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Hi There thanks will try
    to morrow let you know the outcome

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by runrite View Post
    I have done just that on the input I have
    100k to ground permanently on GP0
    the switch is wired in this order +5V 10K switch then GP0
    still no luck
    Not sure if it's 10k or 100k. 100k would be too high.
    But, either way ...

    Turn off the Pull-up's, by commenting the WPU statement.
    It's not letting the voltage go far enough towards Vss.
    <br>
    DT

  9. #9
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Many thanks it works..
    It is sensing now..
    the relay chatters when I get it on
    Is it to do with the external MCLR
    There is an error message that comes on it says that ICD can not program internal clock and internal MCLR at same time any way to sort it out I have to use the on board clock

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


    Did you find this post helpful? Yes | No

    Default

    I'm a sucker for simplicity.

    Try this;
    Code:
    GPIO.4 ----/\/\/\---|<|----+5V.
                        LED
    
                 10K
    GPIO.0 --|--/\/\/\---+5V
             |--switch---GND.
    When you press the switch it grounds GPIO.0.
    Code:
    @ device  pic12F629, intrc_osc_noclkout, wdt_on, mclr_off, protect_off
    
        DEFINE OSCCAL_1K 1
        DEFINE OSC 4
        
        RELAY VAR GPIO.4   ' relay output
        Pswitch VAR GPIO.0 ' switch input
    
        TRISIO = %00000001 ' GPIO.0 input, rest outputs
        WPU = 0            ' input pull-ups disabled
        CMCON = 7          ' disable comparators
        PAUSE 10           ' POR delay
        
    MAIN:
        RELAY = ! Pswitch ' Relay pin = the opposite of Psiwtch pin    
        GOTO MAIN
        END
    Does this work?
    Regards,

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

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Switch to ground. Definately the better way to go.

    I might suggest a different Main loop though.
    Code:
    MAIN:
        IF RELAY = Pswitch THEN
            RELAY = ! Pswitch ' Relay pin = the opposite of Pswitch pin    
        ENDIF
        PAUSE 20
        GOTO MAIN
    
        END
    Those pesky R-M-W's
    <br>
    DT

  12. #12
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Hi all out there
    The last time I did a 8 pin pic was 10 years ago
    The problem was to do with the weak pull up
    I really want to thank all out there
    Bye for now

  13. #13
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Switch to ground. Definately the better way to go.

    I might suggest a different Main loop though.
    Code:
    MAIN:
        IF RELAY = Pswitch THEN
            RELAY = ! Pswitch ' Relay pin = the opposite of Pswitch pin    
        ENDIF
        PAUSE 20
        GOTO MAIN
    
        END
    Those pesky R-M-W's
    <br>


    Darrel,

    I just want to learn;

    Is it really a safe way to read the status of an output pin?

    Thanks
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yes, in fact, from my understanding, it reads the content of the output-latch.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #15
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    Is it really a safe way to read the status of an output pin?
    Is it safe?

    Well, as far as doing damage, it's perfectly "Safe".
    In fact the chip "reads" the state of the OUTPUT pin, everytime you you change the state of any pin on the same port.

    The only un-safe part, is if you don't take the R-M-W problems into account.
    Can really mess with the program.
    <br>
    DT

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  3. program a pic 12f629
    By cancan in forum General
    Replies: 3
    Last Post: - 28th April 2008, 15:15
  4. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14
  5. Problem Pic 12f629
    By diegover in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 19th July 2004, 11:51

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