counting switch events beginner


Closed Thread
Results 1 to 2 of 2
  1. #1
    mrpete's Avatar
    mrpete Guest

    Default counting switch events beginner

    I'm trying to get my pic16f690 to count every time a switch is pressed until it reaches a certain number. I've written a simple test program but it doesn´t work...Somehow the switch is being ignored, the if statement gets executed everytime. switch or no switch. what am i doing wrong?(I´m using the low pin count demo board)
    TRISA = %00100000
    TRISC.0 = 0
    TRISC.1 = 0
    led VAR PORTC.0
    led2 VAR PORTC.1
    butt1 VAR PORTA.5
    counter VAR word
    bcounter VAR word


    counter = 0
    bcounter = 0


    '************************************************* ****************
    loop:

    high led2
    pause 100
    low led2

    if butt1 = 0 then
    high led
    pause 100
    low led
    counter = counter + 1
    endIF
    if counter>5 then blink

    goto loop
    '************************************************* ****************
    blink:

    bcounter = bcounter + 1
    high led
    pause 500
    low led
    PAuse 500
    if bcounter<5 then goto blink
    counter = 0
    goto loop

    end

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


    Did you find this post helpful? Yes | No

    Default

    Have a look at the following, read all post there, this should give you some hints.
    http://www.picbasic.co.uk/forum/showthread.php?t=561

    You may also need to debounce your switch once you've discover why it doesn't work.

    There's another option, use an internal counter to do the job.
    Steve

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

Similar Threads

  1. Counting Events PIC18F8722
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2009, 02:17
  2. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Newbie - 16F628A and switch latching
    By malc-c in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 19th May 2006, 02:35
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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