The Godfather talking
This is god damn my place! Capisci?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 23, 2024, 04:25:32 04:25


Login with username, password and session length


Pages: [1]
Print
Author Topic: using p/button switch to count input (16F876A)  (Read 5133 times)
0 Members and 1 Guest are viewing this topic.
sebaloq
Guest
« on: July 10, 2007, 03:17:25 03:17 »

hello... i really need ur help and guidance.. i was trying to develop a program by using Proton Basic to count an input switch (push button). As an example if the same p/button (assume portd.0) been pressed 3 times an LED (assume portb.0) will be light on. Pls help me... thanks a lot Smiley
Logged
raraavis
Newbie
*
Offline Offline

Posts: 13

Thank You
-Given: 7
-Receive: 12

Buenos Aires - Argentina


« Reply #1 on: July 10, 2007, 01:00:23 13:00 »

Check This:  Wink

COUNTER
 
Syntax

Variable = COUNTER Pin , Period
 
Overview

Count the number of pulses that appear on pin during period, and store the result in variable.
 
Operators
Variable - a user-defined variable.
Pin - a Port.Pin constant declaration i.e. PORTA.0.
Period - a constant, variable, or expression.
Example

Code:
 ' Count the pulses that occur on PORTA.0 within a 100ms period and displays the results. 
 DIM WRD as WORD          ' Declare a word size variable
 SYMBOL Pin = PORTA.0     ' Assign the input pin to PORTA.0
 CLS
Loop:
 WRD = COUNTER Pin , 100  ' Variable WRD now contains the Count
 CURSOR 1 , 1
 PRINT DEC WRD , " "      ' Display the decimal result on the LCD
 GOTO Loop                ' Do it indefinitely

Notes

The resolution of period is in milliseconds (ms). It obtains its scaling from the oscillator declaration, Declare XTAL.  Counter checks the state of the pin in a concise loop, and counts the rising edge of a transition (low to high).
 
With a 4MHz oscillator, the pin is checked every 20us, and every 4us with a 20MHz oscillator. From this we can determine that the highest frequency of pulses that may be counted is: -
25KHz using a 4MHz oscillator.
125KHz using a 20MHz oscillator.


« Last Edit: July 10, 2007, 01:04:48 13:04 by raraavis » Logged
kalpakchiev
Active Member
***
Offline Offline

Posts: 137

Thank You
-Given: 34
-Receive: 68



« Reply #2 on: September 03, 2007, 09:41:37 21:41 »

It will look like this in PicBasic

Count VAR Byte
Buton VAR PortD.0
Tris PortD.0=1' make it an input
Led VAR PortB.0
Tris PortB.0=0' make it an output

Count=0
led=0

Start:
If buton=0 then
   pause 50
     if buton=0 then
        count=count+1
     endif
endif

if count=3 then
  led=1
endif

goto start
 
You have to add also some code to turn off the led. It depends on condition You want.

Logged

A known mistake is better than an unknown truth.
Wizpic
Global Moderator
Hero Member
*****
Offline Offline

Posts: 1203

Thank You
-Given: 553
-Receive: 409



« Reply #3 on: September 03, 2007, 09:57:19 21:57 »

hello... i really need ur help and guidance.. i was trying to develop a program by using Proton Basic to count an input switch (push button). As an example if the same p/button (assume portd.0) been pressed 3 times an LED (assume portb.0) will be light on. Pls help me... thanks a lot Smiley


Your lucky to get the replies like you haev your first post and you ask someone to write code for you, there are plenty of ways to do it

some advise:
1. Read up on what you want to do
2.seearch the PDS forums for code
3. WE will help all that come here for help if you show us your code you have already wrote that don't work we then can give you giudance in the right direction and get your code working. You should not expect ohters to write code for you that way you will never learn.

Please note it's not my intention to start a war these are my thoughts and opinion's

welcomne to our community

wizpic
Logged

When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
iphone
Active Member
***
Offline Offline

Posts: 168

Thank You
-Given: 115
-Receive: 10


« Reply #4 on: September 04, 2007, 11:35:43 11:35 »


With a 4MHz oscillator, the pin is checked every 20us, and every 4us with a 20MHz oscillator. From this we can determine that the highest frequency of pulses that may be counted is: -
25KHz using a 4MHz oscillator.
125KHz using a 20MHz oscillator.


raraavis,

Thanks for the sample.

BTW, how you calculate max freq as you said ... Fmax = 25khz for 4Mhz Osc and Fmax = 125kHz for 20Mhx Osc ?

Actually this code what I'm looking for ... I need the PIC response when the push button being push ( maybe for rising edge transition) in very manner.

Thanks friend.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC