Button problem.


Closed Thread
Results 1 to 3 of 3

Thread: Button problem.

  1. #1
    Modena's Avatar
    Modena Guest

    Default Button problem.

    I'm using the K8084 development board to learn how to use picbasic. The board uses the 16F627 chip with the LED's on port b and buttons on porta. The input from a button is high when pressed.

    The following is the code I'm using to try and get the buttons working, but it doesn't work.


    B6 var byte
    button1 con 1
    TRISA = 0

    loop:

    B6 = 0
    button button1, 1, 10, 5, B6, 1, pressed
    pause 100
    goto loop

    pressed:

    TRISB = 0 ' PORTB is output
    PORTB = %11111111 ' Turn ON diodes on PORTB
    PAUSE 1000 ' Wait for 1 second
    PORTB = $00000000 ' Turn OFF diodes on PORTB
    pause 1000

    goto loop

    Can anyone see what is wrong.

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


    Did you find this post helpful? Yes | No

    Default

    in your case i see few mistake.

    1. Is your PushButton is connected to PORTA. In case you set TRISA=0... PORTA is now output... so you cannot get from PORTA.

    2. PIC16F627 have internal analog comparator that must be turn off when you don't using them CMCON=7

    3. i've never use BUTTON statement. I think this fuction eat too much code space for an simple task. i post you my way to handle pushbutton

    Code:
    CMCON=7 ;Disable analog comparator
    TRISB=0 ;set PORTB to output
    TRISA=255 ;set PORTA to input
    PushButton VAR PORTA.0 ;push button connected to RA0
    
    PORTB=0 ;turn off PORTB... in case only
    
    start:
         While Pushbutton=0 ;wait for Push button action
         ;you can also use While NOT PushButton
         Wend
    
         While PushButton ; wait for push button release
         Wend
    
         pause 50 ; debounce time...cheap but work
    
         ;once the debounce time is finish... use your code
    
         PORTB = 255 ' Turn ON diodes on PORTB
         PAUSE 1000 ' Wait for 1 second
         PORTB = 0 ' Turn OFF diodes on PORTB
         pause 1000
         GOTO Start
    I hope this help you. Sorry if i didn't use BUTTON statement
    Last edited by mister_e; - 5th November 2004 at 15:34.
    Steve

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

  3. #3
    Modena's Avatar
    Modena Guest


    Did you find this post helpful? Yes | No

    Talking Re: buttons

    Buttons now work, thanks.

Similar Threads

  1. Button problem driving me crazy!! Please help!
    By bearpawz in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th November 2007, 14:46
  2. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  3. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  4. Button subfunction 16F628
    By Jųan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2005, 16:44
  5. push button problem
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd June 2005, 19:44

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