1 Attachment(s)
Re: How to create 6 buttons?
Here is example how to use 1 int to serve button on any input pin of PIC.
Attachment 6763
One button also can be attached to INTX pin.
In your ISR just look which pin is 0, then do whatever you want.
If all pin is 1, then button on INTX is pressed...
Re: How to create 6 buttons?
@Pedja089
Thanks so much for sharing...got to try it...feedback here my output later.
---------------------------------------
I have a follow up question, I've tried before to create a 4x4 keypad using Mr_e' s keypad routine...do you think the same concept can be applied to my 6 buttons?
regards,
tacbanon
Re: How to create 6 buttons?
It probably could...
Try to pull down all "drive line" And on the top of ISR scan whole keyboard... Then again pull down all "drive lines".
Re: How to create 6 buttons?
You could still read the I/O in a Timer based ISR... done fast enough it "give" the feeling of an interrupt. You can even use the Time base as debounce delay... you could even trick the PIC and generate a false INT0 interrupt by writing directly to the according bit.
No extra hardware needed, free up one I/O.
1 Attachment(s)
Re: How to create 6 buttons?
Hi..something not right, I'm trying to toggle led on PORTB.7 but no success....can you check my code what I'm doing bad?
Attachment 6766
Code:
asm
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
;__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
Define OSC 20
TRISB.7 = 0
PORTB.7 = 0
TRISD = %00000000
PORTD = %00000000
LedD Var POrtD.5
Led1 var PortB.7
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT_INT ;RB Port Change Interrupt
PORTB = %00000000
Main:
pause 500
Toggle LedD
GOTO Main
'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
'TOGGLE LED1
If PortB.1 = 0 then
Toggle Led1
else
If PortB.2 = 0 then
Toggle Led1
else
If PortB.3 = 0 then
Toggle Led1
else
If PortB.4 = 0 then
Toggle Led1
else
If PortB.5 = 0 then
Toggle Led1
else
If PortB.6 = 0 then
Toggle Led1
else
Endif:Endif:Endif:Endif:Endif:Endif
@ INT_RETURN
thanks in advance
tacbanon
Re: How to create 6 buttons?
Check the default interrupt edge....that's not what you need ;)
INTCON2
Re: How to create 6 buttons?
Hi mister_e,
Thanks for the time responding...I think the default is INTCON2.6 = 1 so I need to make INTCON2.6 = 0 'interupt on falling edge.
But either one for me is not working on my setup.
regards,
tacbanon
Re: How to create 6 buttons?
Have you tried with real hardware or your life depends on How proteus decide to work (assuming it works at all)
From your schematic you're using led instead of diode and i'm pretty confident proteus is not smart enough to understand this.
Re: How to create 6 buttons?
Maybe problem is in D1 - D6.
Check state of int pin when you press button...
It square on INT0 should be blue if button is pressed...
If that isn't case, replace D1 - D6 with 1N4148.
Re: How to create 6 buttons?(SOLVED)
Thank you pedja089 and mister_e...I got it now.
/tacbanon