Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 22nd April 2003, 06:58 PM   (permalink)
Default PIC16F628 counter

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
andero is offline  
Old 22nd April 2003, 09:03 PM   (permalink)
Default

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.
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline  
Old 23rd April 2003, 11:14 AM   (permalink)
Default

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?
andero is offline  
Old 23rd April 2003, 05:42 PM   (permalink)
Default

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.
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline  
Old 28th April 2003, 08:04 PM   (permalink)
Default

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?
andero is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 03:20 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker