Help with example button program


Results 1 to 9 of 9

Threaded View

  1. #5


    Did you find this post helpful? Yes | No

    Default Re: Help with example button program

    Any ideas how I can improve this code? I'm trying to use a push button switch to toggle between 2 LEDs. For the most part it works, but the switch does not debounce very well. I'm actually trying to toggle between turning an LED on and turning a relay off, which is why one of the variables is named LATCH1, but for testing purposes I'm just using 2 LEDs.



    ' Name : BUTTONTEST.pbp
    ' Compiler : PICBASIC PRO Compiler 3.0
    ' Assembler : PM
    ' Target PIC : 8-pin PIC12F675 or similar type
    ' Hardware : Kee
    ' Oscillator : 4MHz internal
    ' Keywords : HIGH, LOW
    ' Description : PICBASIC PRO program to show button press on LED.

    #config
    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
    #endconfig

    Define OSCCAL_1K 1 ' PIC12F675, Calibrate internal oscillatordefine MCLRE_OFF
    define BUTTON_PAUSE 65

    LED1 Con 0 ' Alias GPIO.0 to LED1
    LATCH1 con 1 'Alias GPIO.1 to LATCH1
    PB1 Var GPIO.2 ' Alias GPIO.2 to push button
    B1 var byte 'Working buffer for switch1 button command

    ANSEL = 0 ' Set all digital
    CMCON = 7 ' Analog comparators off
    clear
    low LED1 'Begin program with LED1 off
    high LATCH1 'Begin program with relay1 in bypass

    main:
    switch1:

    button PB1, 0, 40, 5, B1, 0, main
    toggle LATCH1
    toggle LED1

    Goto main ' Do it forever

    End
    Last edited by keithv; - 23rd March 2014 at 15:24.

Similar Threads

  1. [Help] PIC 16F886 with 9 button program with CCS
    By keviltran in forum General
    Replies: 1
    Last Post: - 8th October 2013, 21:40
  2. Toggle program branch ussing interrupot by button?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 14th September 2013, 09:58
  3. Replies: 1
    Last Post: - 23rd May 2009, 09:22
  4. button help
    By Kalind in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 14th October 2008, 13:12
  5. Program Code and Program Memory
    By DenFrod in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2007, 14: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