12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi Joe,everyone. Sorry for the slow reply, it's been one of those days today.
    Before I forget I loved the line: "I think I smell what you are cooking" It's had me smiling all day.

    Joe, the program you wrote. I was happy with all of it except line four.I see you've made GPIO.0 an input
    but the 'THEN' label hasn't been given a HIGH or LOW statement for the pin

    Code:
    If GPIO.0 then unlock
    To my mind (please be gentle with me I'm really green at this) it should be something like:

    Code:
    IF GPIO.0 = HIGH THEN  UNLOCK ' GPIO.O goes HIGH (button pressed) jump to
    label UNLOCK.
    
    
    ELSE  GOTO MAIN ' button not pressed do the loop again 
    (not sure if I needed the GOTO here).
    
    Or maybe:
    
    IF GPIO.O = LOW THEN MAIN ' button not pressed,  do the loop again
    Am I on the right lines here?

    * Silly but important question here*: I'm confusing myself, can an INPUT be either HIGH or LOW?
    I know an OUTPUT can be.

    So your program is maybe a timed latching relay circuit or locking solenoid?

    As for my program, I was thinking more along the lines that if GPIO.X goes high (a button is pressed +5v on that input pin) that would make an output on GPIO.Y go high. In other words the pressing of a button makes the program jump to some specified section of code making an output.

    Then moving this idea on, if the button was pressed twice (within a certain time period say) you could 'jump' to another section of code and make a different output..

    I hope you're all having a pleasant evening,

    David
    Last edited by LEDave; - 27th February 2010 at 22:16.

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


    Did you find this post helpful? Yes | No

    Default

    Now you will want to look at the COUNT command. Might be what you need for the button presses.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Cheers mackrackit, will do.

    Reading the manual for me isn't such a bad idea after all....lol.

    Can you help me with my:

    * Silly but important question here*: I'm confusing myself, can an INPUT be either HIGH or LOW? I know an OUTPUT can be.

    For the record I think it can be active HIGH or Low (but I'm not 100% sure).

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    When a pin is an INPUT it will read the pin's state. Either HIGH or LOW.
    Yes, active H/L.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Cheers mackrackit.

    Another question (I know but I am trying hard) In my PICkit1 there is a button attached, now I'm thinking that it goes onto pin GPIO.3 is that right.

    So I could use that button to try out some programs using IF THEN and COUNT.

    David

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


    Did you find this post helpful? Yes | No

    Default

    I do not have the PicKit1's docs with me, but yes. What ever pin it goes to you can use it that way.
    Also, check the data sheet to see it the pin has anything "special" about it. MCLR??
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by LEDave View Post
    Hi Joe,everyone. Sorry for the slow reply, it's been one of those days today.
    Before I forget I loved the line: "I think I smell what you are cooking" It's had me smiling all day.

    Joe, the program you wrote. I was happy with all of it except line four.I see you've made GPIO.0 an input
    but the 'THEN' label hasn't been given a HIGH or LOW statement for the pin

    Code:
    If GPIO.0 then unlock
    To my mind (please be gentle with me I'm really green at this) it should be something like:

    Code:
    IF GPIO.0 = HIGH THEN  UNLOCK ' GPIO.O goes HIGH (button pressed) jump to
    label UNLOCK.
    
    
    ELSE  GOTO MAIN ' button not pressed do the loop again 
    (not sure if I needed the GOTO here).
    
    Or maybe:
    
    IF GPIO.O = LOW THEN MAIN ' button not pressed,  do the loop again
    Am I on the right lines here?

    * Silly but important question here*: I'm confusing myself, can an INPUT be either HIGH or LOW?
    I know an OUTPUT can be.

    So your program is maybe a timed latching relay circuit or locking solenoid?

    As for my program, I was thinking more along the lines that if GPIO.X goes high (a button is pressed +5v on that input pin) that would make an output on GPIO.Y go high. In other words the pressing of a button makes the program jump to some specified section of code making an output.

    Then moving this idea on, if the button was pressed twice (within a certain time period say) you could 'jump' to another section of code and make a different output..

    I hope you're all having a pleasant evening,

    David
    I am always gentle
    It does seem unintuitive doesn't it?
    Got it straight from the manual though. If gpio.0 is set? goto unlock. As I understand it, it is a computed goto.
    Where zero and one are representing False and true.
    IF GPIO.0 is true, goto Label, without requiring endif or else statements.
    Melanie posted some things which will interest you using multiple button presses to do different things:
    try looking at these, open the links Melanie posted, especially the Olympic timer PDF:
    http://www.picbasic.co.uk/forum/showthread.php?t=3423
    http://www.picbasic.co.uk/forum/showthread.php?t=632

    Oh yeah, that was for a shotgun lock for a police car, officer would turn a keyswitch, and it would stay energized long enough to access his weapon.
    Last edited by Archangel; - 27th February 2010 at 23:23.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Cheers Joe, very interesting that regards the GPIO.0 computed GOTO. You can see why a newbie like me got a little confused, very handy piece of code though, thanks for the explanation.

    I had a look at Melanie's Olympic timer, very impressive. She's one very clever lady.

    I've always been an admirer of clever people.

    Right, I'm off to my bed to dream of COUNTER - IF-THEN- ELSE IF commands.

    Really enjoying this, I hope I'm not driving you all to mad?

    David

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


    Did you find this post helpful? Yes | No

    Default

    I hope I'm not driving you all to mad?
    Already been there. Had a lot of fun too!!!!
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Just in case this isn't clear already....
    Code:
    IF GPIO.0 = HIGH THEN  UNLOCK
    This is NOT how you you determine if an input is high or low. HIGH and LOW are commands that both sets the pin in question to "output mode" and then drives it either high or low. To check if a pin (or any bit in any register) is set you do either:
    Code:
    If GPIO.1 = 1 THEN GOTO Unlock
    Or
    Code:
    If GPIO.1 THEN GOTO Unlock
    Or
    Code:
    If GPIO.1 = 0 THEN
      GPIO.2 = 1
      Goto DoThis
    ELSE
       Goto Unlock
    ENDIF
    Right, back to HIGH and LOW... as have been said already the HIGH and LOW commands first sets the pin to "output mode" and then drives the pin high or low. It's nothing wrong with that except that it sets the pin to "output mode" each and every time either command is used. It doesn't matter if the pin already IS in "output mode" - it still writes to the TRIS register - every time and this wastes both time and codes space. It's much better to set the TRIS register manually and only change it if needed and then simply write to the Port or GPIO register directly.

    /Henrik.

  11. #11
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik, thanks for that. Being new to programming it's easy to get confused especially when many of the terms are so similar.

    I'm a relatively slow learner too which doesn't help I guess. When I finally get it though, it does stick.

    You've got to marvel the complexity contained within an eight pin microchip, staggering.

    I can't wait to actually build something either.

    Have a nice evening.

    David

  12. #12
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi everyone.

    I'm working on my first circuit using the12F683 and I'd like to add a push button as an input. Would I be right in assuming that:

    A pull-up resistor say 10k from the +5v line onto the chosen input GPIO.n and a push button connected from GPIO.n to ground should do the job?

    This to my mind would leave GPIO.n at +5v until pressed, momentarily dropping to 0v.

    David

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