Advice on building a seminar timer

Status
Not open for further replies.

picboy

New Member
I am building a seminar timer and i need some design advice...

Firstly my seminar timer needs to be able to set the time duration reqd ie say 3:40 meaning 3 min and 40 sec..and then this time must be wirelessly transmitted to a slave clock..

To start off with the very basics, i have decided on 6 push buttons (1) min (2) sec (3)Reset (4)Start (5)Stop (6)Trasmit and i wanted to use a interrupt based approached to decide which button has been pressed, and then go to the subroutine, problem was i used the RBIE intrrupt, RB port change on RB4-7 only to realise that i can only cater this interrupt to 4 of my push buttons while i have 6 of it..i initially plan to have a interrupt service routine to cater to each of the push buttons but reading up on interrupts, i found out that isr starts at 0x04.. so does this mean that i can only have one isr and not many isr for diff cases?


i will put down what i have written as a skelthon, can give me advise me or correct if i am heading in the wrong dirn..Thanks a millon.


Code:
;*********************************************************************************************************************
;START OF CODE to initialize the processor****************************************************************************
;*********************************************************************************************************************			

;**********************************
;Bank0 initialization starts first*
;**********************************

	Start	movlw	0x07				;Turn comparators off 
			movwf	CMCON				

			bcf		STATUS,RPO			;Select bank0	
			bcf		STATUS,RP1

			clrf	PORTA				;Initialize PORTA by clearing the output latches
			clrf	PORTB				;Initialize PORTB by clearing the output latches
			
			clrf	delay1
			clrf 	delay2

; *************************************
;Most Bank 1 initializations come next*
; *************************************
		
 	 		bsf 	STATUS,RP0			;select bank 1
   			
			movlw 	b'11111100'			
			movwf	TRISB				;set PortB as 2 outputs and 6 inputs 
			
			bcf		STATUS,RP0			;REvert back to bank 0
			
			bsf		INTCON,GIE			;Global interrupts enabled
			bsf		INTCON,RBIE			;interrupt upon pin change enabled
			
loop		goto 	loop				;Wait for interrupt??


;****************************************************************************************************************************

;This routine checks for the 6 inputs if they have been pressed at all, if they are pressed that subroutine
;will be called, if the buttons are not pressed it will go back and check the state of the buttons.

chkpress	bcf		INTCON,RBIF			;Clears RB interrupt flag to enable for other interrupts to occur in main prg
			
			btfss	PORTB,MINbutton		;Chk which pin causes the interrupt and call the subroutine to handle the interrupt
			goto	MINpress
			;call	MINpress

			btfss	PORTB,SECbutton
			goto	SECpress
			;call	SECpress

			btfss	PORTB,START
			goto	STARTpress
			;call	STARTpress

			btfss	PORTB,STOP	
			goto	STOPpress
			;call	STOPpress

			btfss	PORTB,RESET	
			goto	RESETpress
			;call	RESETpress

			btfss	PORTB,TXbutton			
			goto	TXpress
			;call	TXpress
			
			;**********************************************************			
			;Shd i use a polling system or interrupt based approached?*
			;**********************************************************
			retfie						;Main pbm, i have 6 inputs which must be interrupted once pressed but rbie acts upon pins 4 to 7, how??
			;goto 	chkpress			;Loop back and wait for change of state in buttons

;Subroutines for cases when the buttons are pressed

MINpress	call 	SWdebounce			;Call delay to allow for debounce to settle
			btfss	PORTB,MINbutton		;Check if the button is still pressed
			retlw	0x000				;Return if it is not pressed
			goto	INC_DECmin			;If pressed, call subroutine
			retfie
			
SECpress	call	SWdebounce			;Call delay to allow for debounce to settle
			btfss	PORTB,SECbutton		;Check if the button is still pressed
			retlw	0x000				;Return if it is not pressed
			goto	INC_DECsec			;If pressed, call subroutine
			retfie

STARTpress	call	SWdebounce			;Call delay to allow for debounce to settle
			btfss	PORTB,START			;Check if the button is still pressed
			retlw	0x000				;Return if it is not pressed
			goto	START				;If pressed, call subroutine
			retfie

STOPpress	call	SWdebounce			;Call delay to allow for debounce to settle
			btfss	PORTB,STOP			;Check if the button is still pressed
			retlw	0x000				;Return if it is not pressed
			goto	STOP				;If pressed, call subroutine
			retfie

RESETpress	call	SWdebounce			;Call delay to allow for debounce to settle
			btfss	PORTB,RESET			;Check if the button is still pressed
			retlw	0x000				;Return if it is not pressed
			goto	RESET				;If pressed, call subroutine
			retfie

TXpress		call	SWdebounce			;Call delay to allow for debounce to settle
			btfss	PORTB,TXbutton		;Check if the button is still pressed
			retlw	0x000				;Return if it is not pressed
			goto	TX					;If pressed, call subroutine
			retfie

This is how i intend to approach my problem, being a first time programmer to pic, i will welcome all useful comments or advice from all of u..Thanks once again.
 
You can use small trick:
Connect each button to normal input of the PIC, and place diodes from every button to the PORTB,0 PIN. Therefore every time you press the button, it will cause an interrupt (Using INT pin), and then you can scan the butons in your interrupt routine.

PS: Don't forget to use pull up/down resistor on INT PIN, depending if you are using positive/negative logic.
 
Have a look at my PIC tutorials.

Personally I would probably poll the buttons, rather than interrupts.
 
Thanks nigel and jay,

i have some pbms that need clarification from both nigel and jay or just abt anybody who knows..

Connect each button to normal input of the PIC, and place diodes from every button to the PORTB,0 PIN. Therefore every time you press the button, it will cause an interrupt (Using INT pin), and then you can scan the butons in your interrupt routine.

So u meant that my six push buttons can be connected to any of the portA or portB pins as long as they are configured as an input..and connect all the diodes to pin 0,RB0/INT will enable them to interrupt as long as any of the 6 buttons are pushed..

PS: Don't forget to use pull up/down resistor on INT PIN, depending if you are using positive/negative logic.

Ok, i have no idea what u meant on this, how do u determine a positive or negative logic and is there a way to calculate what resistor values to use?



On interrupts and isr

coming back to my question, can i write seperate interrupt routines to handle each button when pressed or must they all belong to a big lump of code??i haven been able to find a eg to demostrate such a case..might take a look at nigel tutorials as suggested..thanks
 
OK here's the stuff

Exactly! If you do this, it will interrupt every time you press *any* button. In your isr you should check state of all buttons.
The value of pull up/down resistor is not critical, usually values from 4K7 to 20K are fine, I use 10k to lower the current consumption.
By meaning positive / negative logic:
Positive logic has 5V as LOG. 1 and 0V as LOG.0
Negative logic has 0V as LOG.1 and 5V as LOG.1
I prefer to use positive logics to negative. You can use PORTB's pull up resistors if you want, but for a biginner it's better to use external ones. If your button has a resistor to ground, it's positive logic. Here's an example of your problem using positive logic:
 

Attachments

  • positive.jpg
    26.9 KB · Views: 371
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…