Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC Push Button Routine

Status
Not open for further replies.

chevymn1964

Full Member level 2
Joined
Apr 1, 2006
Messages
120
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,296
Location
Santa Rosa, Ca.
Activity points
2,551
Hello Everyone, Just wondering if anyone has any ideas on a routine for push button that when you press the button once it would call a routine that would incriment a number just once and if you push and hold the button down it would keep on incrimenting the number very fast? Make any since??? thank you!
 

This is a rarther basic and easy thing to do.

Don't forget switch debouncing, though you may prefer to do that in hardware.

You have to choose a time period below above which you start repeatedly incrementing your number.

You can do timing in two ways

a) by having the PIC execute a loop that takes a suitable amount of time, somthing equivalent to FOR N=1 TO 100000:NEXT N: IF BUTTON=PRESSED THEN GOTO FAST-COUNT

With a clock frequency of a few megahertz you often end up needing to use several registers for the loop counter so if you are writing in assembly language you have to carry bits your self.

b) by using the hardware timers in your PIC. The available timers vary between different PIC's. I tend to use the hardware timers because I want the timing of different tasks to be the same each time while doing several things at once
and not stop doing other tasks when a button is pressed.
 

Thanks for youre help throwaway18, I have the basic idea about how to do it... I just need help with writing the code... Also I dont mind using delays because the pic will only be incrimenting a number and displaying it on an lcd so it wouldent hurt much....
 

hello chevymn1964,

you write in assembly or in C?

what do you want exactly?

the code or the logic diagram?

:p
 

Hello, Im writing in assembly and I am looking for code... I have the basic idea down just trying to get some hints...
 

chevymn1964 said:
Hello Everyone, Just wondering if anyone has any ideas on a routine for push button that when you press the button once it would call a routine that would incriment a number just once and if you push and hold the button down it would keep on incrimenting the number very fast? Make any since??? thank you!

here you are the complete solution :D
in assembly language using pic16f84 and simulated on Proteus 6 Professional

Code:
;***************************************************************************************************
;file type:		ASM.									   ;
;processor:		PIC16F84.								   ;
;program Description:	accelerated counting in response to push button 			   ;
;Author:		king_rero								   ;
;contact:		[email]king_rero@yahoo.co.uk[/email]	                                                   ;
;done date:		19-jan-2007  9:09 AM			               			   ;
;***************************************************************************************************
;tested on Proteus 6 Professional Release 6.9 SP4 with advanced Simulation			   ;
;***************************************************************************************************
list p=16f84
radix hex

#DEFINE BANK0 BCF STATUS,5
#DEFINE BANK1 BSF STATUS,5
                 
STATUS          EQU 3                   
TRISA           EQU 5                  
PORTA           EQU 5                   
TRISB           EQU 6                   
PORTB           EQU 6                   
COUNT           EQU H'20'               
DELA		EQU H'21'

                ORG 0                      
                BANK1                      
                movlw 	B'00000001'        
                movwf 	TRISA              
                clrf 	TRISB              
                BANK0                      
                 
BEGIN           clrf 	COUNT              
		btfss	PORTA,0
		goto	BEGIN		   
LOOP            
		btfss	PORTA,0
		call	DELAY
		incf	COUNT,1
		movf	COUNT,W		   
		movwf 	PORTB              
                goto 	LOOP               
DELAY		movlw	0x0f
		movwf	DELA
LOOP1		decfsz	DELA,1
		goto	LOOP1
		return
				 
                end

the following rar file contains the whole material
so enjoy :D
 

I don't know why you wanna complicate the issue mike it's so simple
 

Hey Everyone, I figured it out on my own, it turned out to be very simple to my suprise.... Thanks for all of the input though!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top