1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PIC16F628 counter

Discussion in 'Microcontrollers' started by andero, Apr 22, 2003.

  1. andero

    andero New Member

    Joined:
    Apr 22, 2003
    Messages:
    3
    Likes:
    0
    Im having trouble creating PIC based counter system :(
    i want to count how many button presses (push and release increases counter by 1) was on RA0 and RA1.

    i can write code that counts one push at a time, but there may be cases where one button is pressed down, then second button is pressed down, then button one or two is released (counter goes +1 here) if other button is released then (counter goes +1)

    can anyone help me with that
    and sorry for my bad english

    msn: andero@cma.ee
     
  2. kinjalgp

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA
    Use 2 diffenrent counter variables in your PIC's RAM. If one switch is released its corresponding variable will be incremented and similar for other.
     
  3. andero

    andero New Member

    Joined:
    Apr 22, 2003
    Messages:
    3
    Likes:
    0
    i thaught about it, but i cant seem to generate code that can monitor those pushes/releases :(
    im new with pic risc assembler

    those pushes come in randomly and have random duration so i need a code that scans for pushes paralelly not serialy

    can anyone give an example or even send me that code?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. kinjalgp

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA

    What do you mean by parallel and serial scanning? I think you are talking about bit-scanning and scanning the entire port in one shot.
    To solve your problem, you can use Internal Timer to periodically scan the swithces. Store the data of previous scan in some variable say 'old' and then store the newly scanned data into 'new'. Compare both of them and if they are not equal, that means there was a push, or release of button. If the bit changed from 0 to 1 it was push (this depends on your switch logic) and vice-versa.
     
  6. andero

    andero New Member

    Joined:
    Apr 22, 2003
    Messages:
    3
    Likes:
    0
    i use that code for counter
    loop
    movf TRISA
    bcf STATUS,Z
    xorwf stat
    btfss STATUS,Z
    call changed

    goto loop

    changed movf TRISA
    movwf stat
    call add
    ; movlw 'x'
    ; call snd
    retlw 0x00

    what is wrong?
     

Share This Page