![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
And sorry to mention i am using the 16f628a chip
|
|
|
|
|
|
|
(permalink) |
|
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.
__________________
"I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! |
|
|
|
|
|
|
(permalink) |
|
Have a look at my PIC tutorials.
Personally I would probably poll the buttons, rather than interrupts. |
|
|
|
|
|
|
(permalink) | |||
|
Thanks nigel and jay,
i have some pbms that need clarification from both nigel and jay or just abt anybody who knows.. Quote:
Quote:
Quote:
|
||||
|
|
|
|
|
(permalink) | ||
|
OK here's the stuff
Quote:
Quote:
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:
__________________
"I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! |
|||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|