Newbie - 16F628A and switch latching


Closed Thread
Results 1 to 40 of 46

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm. One suggestion is to make all unused ports as outputs. This helps in noisy environments as electric motors drive PIC's crazy even with a separate supply. Make sure portb.0 is held high with a resistor not too high in value. I once had a small hobby motor drive my PIC crazy until I went down to a 1K resistor as a pullup.

    CMCON = 7
    TRISA = 0
    TRISB = 0 'MAKE ALL OUTPUTS
    PORTA = 0
    PORTB = 0 'ALL OUTPUTS LOW
    INPUT PORTB.0 'RB0 SWITCH INPUT

    MAIN:
    NAP 0 'REDUCE CURRENT DRAIN ON BATTERY
    IF PORTB.0 = 0 THEN CHANGELED 'IF REED SWITCH CLOSED CHANGE LED STATE
    GOTO MAIN

    CHANGELED:
    TOGGLE PORTB.4 'CHANGE LED STATE

    WAITFORRELEASE:
    PAUSE 1000 'WAIT A SECOND
    IF PORTB.0 = 0 THEN WAITFORRELEASE 'WAIT HERE FOR REED TO OPEN
    GOTO MAIN

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Peter,

    Thanks for the advice and I'll make port A all output as I'm only using port B. Oh and yes the inputs on the switches are tied high via a 10K resistor.

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


    Did you find this post helpful? Yes | No

    Talking You ..... again !!!

    Hi,Malc

    Have a look to the " BUTTON " command ...it is really very powerful for such application.

    Add a DEFINE BUTTON_PAUSE 200 at the top of your program if you want a debounce time of 200 ms ( max 255 ms ...) ... that's all !

    read you soon !!!

    Alain

    PS; if not already done, download this : http://www.melabs.com/downloads/pbpm304.pdf
    THE reference manual !!!
    Microcode studio : http://www.melabs.com/downloads/mcs2300.zip
    Last edited by Acetronics2; - 14th May 2006 at 13:57.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Hee hee - fancy seeing you here

    Yes I have downloaded the manual, and had it open last night whilst I was developing the program, and as manuals go its really good to get newbies like myself up and running.

    Must admit, that I'm having more fun (and luck) with PBP than I did with JAL. PBP seems more logical in its commands and the structure of using them.

    Alain, let me into a secret, is that Melanie in her avitar... brains as well as beauty - wow !!

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


    Did you find this post helpful? Yes | No

    Wink The Forum' Highest secret ...

    Quote Originally Posted by malc-c
    Hee hee - fancy seeing you here

    Alain, let me into a secret, is that Melanie in her avitar... brains as well as beauty - wow !!
    In fact, Mel is some like Charly in the "Charly's girls" TV series ... I do not think anyone on this forum knows her real appearance ...

    We only know she says she likes to wear leather clothes at night, and is a bit bored about charming guys hoping to get something from her brain ...

    May be she'd love to find a bunch of red roses and some Champagne at her door rather than the New up to date Compiler ....

    Talk to her gently, and she'll give you the best from her ...

    That's part of what I understood here ... not to break the magic.

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    There are those that have sent boxes of red roses...

    ...and there are those that have sent boxes of chocolates...

    ...boxes of diamonds are a little slower in coming - but I'm working on it...

    ...and there are those that have seen a little more of me than others (I seldom refuse an invite to dinner - especially if you're buying - but can you afford a genuine up-town girl?) *smiles*

    ...and Yes, that's really me in the avatar... if you're real nice I just might change it for a while to something more sophisticated - but I'm always worried that I'll distract you from your work (or play)...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie
    ... if you're real nice I just might change it for a while to something more sophisticated -
    I have a feeling of what it could be Maybe i'm in the 3rd category ... LOL easy to start some rumor here

    BTW Melanie, if you change your Avatar to 'something more sophisticated', i feel that some end-of-class student here could be shocked OR spam your PM! May i bet on the second one
    Last edited by mister_e; - 15th May 2006 at 03:34.
    Steve

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

Similar Threads

  1. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  2. Addressing with Dip Switch or ???
    By tazntex in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th September 2008, 12:19
  3. 16f628a wont wake up
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th August 2008, 14:22
  4. SLEEP mode 16F628A
    By Michael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th April 2006, 17:26
  5. 16F628A using PORTA.4, and it works, but...
    By zx81 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th August 2005, 08:45

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