Continue to Site

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.

  • 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.

PIC16F628 counter

Status
Not open for further replies.

andero

New Member
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
 
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.
 
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?
 
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.
 
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?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top