12f629 push button & LED


Closed Thread
Results 1 to 4 of 4
  1. #1
    yankee's Avatar
    yankee Guest

    Default 12f629 push button & LED

    OK, I'm stumped. I know I missed something stupid here and I need some insight.

    I have an N.O. switch on gpio5 with a pullup resistor which is supposed to toggle an LED on gpio0. Nothing happens, however when I configure the code for a 16f628a, it works fine. I also checked the IC by loading a simple blink program and that works fine.

    Oscillator is set to INTOSC
    Watchdog enabled
    Power-up enabled
    MCLR as input
    Brownout disabled

    Here's the code:

    cmcon = 7

    trisio.5 = 1 ' port5 is an input

    led1_status var bit
    button1 var gpio.5
    led1 var gpio.0

    main:
    sleep 1 ' sleep for about 1 second
    if button1 = 0 then ' if the button is pressed

    if led1_status = 1 then ' if its last state was 1

    led1_status = 0 ' make it 0
    low led1
    pause 500 'debounce

    else

    led1_status = 1 ' the last state was a 0 so now make it a 1
    high led1
    pause 500 'debounce

    endif

    endif

  2. #2
    Join Date
    Sep 2005
    Location
    Dayton, Ohio
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    Looks like it executes your code once, then it's done. There is no LOOP.

    Try putting a GOTO MAIN at the end of your program. That way it keeps checking the button.
    Jim Robertson
    "MilesTag" DIY Lasertag
    www.lasertagparts.com/mtdesign.htm
    Dayton, Ohio

  3. #3
    yankee's Avatar
    yankee Guest


    Did you find this post helpful? Yes | No

    Default

    I know I'm new at this, but I still can't believe that I missed that one. It works!

    Now, any idea why it would work on the 16f628a without the goto main and not on the 12f629?

    Many Thanks

  4. #4
    trying's Avatar
    trying Guest


    Did you find this post helpful? Yes | No

    Default

    "edit " I spoke with out thinking sorry
    Last edited by trying; - 10th February 2006 at 02:24.

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  3. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43

Members who have read this thread : 1

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