Help with pic 12f629


Closed Thread
Results 1 to 40 of 53

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Yes

    that pretty much does it for me today. Too many DOHS.
    you intended to right?

    I thought you were just giving us new folks a chance to help Better to teach than to do. that way we learn something.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Sep 2010
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    hi guys,

    thanks all for your help, but no luck so far, before the last suggested changes, the code will just stay on forever.
    Now, with the ANSEL part, just wont compile, it says "syntax error".

    Removing the ansel part, it compiles, i run it and after the boton is pressed it jumps direct to the last part of the code (off_led/off_mosfet)

    This is my actual code:

    Code:
    cnt VAR BYTE
    boton VAR GPIO.2
    mosfet VAR GPIO.1
    
    
    CMCON = 7
    
    'Ports
    Output mosfet
    Input boton
    
    cnt=0
    
    CHECK:
    high mosfet
    IF boton = 0 THEN TEST
    GOTO CHECK
    
    TEST:
    cnt = cnt + 1
    IF cnt = 3 THEN OFF_MOSFET
    GOTO CHECK
    
    OFF_MOSFET:
    cnt = 0
    low mosfet
    pause 1000
    GOTO CHECK
    end
    Any sugestions?
    Much appreciated, and thanks again.

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Having no idea what your circuit looks like, my first guess is your button is bouncing. So when you press it, the pic sees any number of presses during that short time between starting to make contact and fully pressed. To test, add a pause in the "test" :

    TEST:

    pause

    cnt = cnt + 1
    IF cnt = 3 THEN OFF_MOSFET
    GOTO CHECK

    I don't know the exact format of pause, but set it for something big like 100mS. That way for every button press, execution waits to allow your finger to catch up with the pic.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Sep 2010
    Posts
    23


    Did you find this post helpful? Yes | No

    Smile

    Thanks, My circuit is just real pic simulator, so no circuit yet.
    but it should be something like a push boton normaly open, and a led with the resistor.
    I think it is the ansel thing, to set things digital.

    Excuse my ignorance....but if there is a newbie, my level is the same as the pet, of the pet of the newbie.

    Well, thanks again for your help guys.
    I will keep doing as you say.
    Thanks.

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gutisie View Post
    Thanks, My circuit is just real pic simulator, so no circuit yet.
    but it should be something like a push boton normaly open, and a led with the resistor.
    I think it is the ansel thing, to set things digital.

    Excuse my ignorance....but if there is a newbie, my level is the same as the pet, of the pet of the newbie.

    Well, thanks again for your help guys.
    I will keep doing as you say.
    Thanks.
    I don't know if the simulator simulates switches as de-bounced or not. This is all the help I can be at this time, I too do not understand. It looks like it should be working to me. -Sorry

    I will keep watching to see what the "pro's" have to say.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEFINE OSC 4
       @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
        CMCON=7 
        
        cnt VAR BYTE
        boton VAR GPIO.2
        mosfet VAR GPIO.1
    
        cnt = 0
       
        CHECK:
        IF boton = 0 THEN TEST
        LOW mosfet
        GOTO CHECK   
        
        TEST:
        IF cnt < 3 THEN OFF_MOSFET
        IF cnt => 3 THEN ON_MOSFET
        GOTO CHECK
        
        OFF_MOSFET:
        PAUSE 100
        IF boton = 0 THEN
        low mosfet
        cnt = cnt + 1
        ENDIF
        GOTO CHECK
        
        On_MOSFET:
        HIGH mosfet
        pause 1000
        low mosfet
        cnt = 0
        GOTO CHECK
        end
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Sep 2010
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Code:
    DEFINE OSC 4
       @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
        CMCON=7 
        
        cnt VAR BYTE
        boton VAR GPIO.2
        mosfet VAR GPIO.1
    
        cnt = 0
       
        CHECK:
        IF boton = 0 THEN TEST
        LOW mosfet
        GOTO CHECK   
        
        TEST:
        IF cnt < 3 THEN OFF_MOSFET
        IF cnt => 3 THEN ON_MOSFET
        GOTO CHECK
        
        OFF_MOSFET:
        PAUSE 100
        IF boton = 0 THEN
        low mosfet
        cnt = cnt + 1
        ENDIF
        GOTO CHECK
        
        On_MOSFET:
        HIGH mosfet
        pause 1000
        low mosfet
        cnt = 0
        GOTO CHECK
        end
    Hi guys, thanks again, your are wonderfull!!.

    Unfortunately, this code gives me error 118.

    Thanks.
    Best regards.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by cncmachineguy View Post
    you intended to right?

    I thought you were just giving us new folks a chance to help Better to teach than to do. that way we learn something.
    Nope, I made one of my many mistakes. I was planning to give the OP a basic working code like I just did for something to "start" with. Then if needed try to do a little "teaching".

    Seems like a simple operation, but to make it work well some sort of de-bouncing and maybe an interrupt will be needed.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi,

    May be that one ???

    Code:
    '****************************************************************
    '*  Name    : Bôton.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 17/09/2010                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    DEFINE OSC 4
    DEFINE BUTTON_PAUSE 10    ' 10 is default value
       @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
     
        cnt VAR BYTE
        delay var byte
     
        boton VAR GPIO.2
        mosfet VAR GPIO.1
     
     
     '   ANSEL           = 0     '12F675 for test
        CMCON           = 7
        OPTION_REG.7    = 0    'Pullups  enabled
        WPU             = %00000100
     
        cnt             = 0
        GPIO            = %00000110                 ' Nosurprise startup ...
        TRISIO          = %00000100 
     
    '******************************************************************************
    Detect: 'Button presses W/Debounce
    '
    delay = 0
    BUTTON Boton ,0,255,0,delay,1,pressed
        Pause 20                                    ' Slow Things down
        GOTO Detect
     
    '******************************************************************************    
    Pressed:  ' Some > 10ms press detected
        IF cnt < 3  Then
     
            cnt = cnt + 1
     
        ELSE
     
            cnt = 0
            LOW mosfet
            PAUSE 1000
     
        ENDIF
     
    WHILE !Boton : WEND                                ' Wait Boton release !!!    
    goto detect
     
    END
    Alain
    Last edited by Acetronics2; - 18th September 2010 at 14:42. Reason: Inverted Mosfet on/Off
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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