PDA

View Full Version : 16F767 Exteranl Interrupt with DT_INTS



exelanoz
- 29th May 2008, 21:46
Hello Hello,

I used Darrel's LCD anypin the other day on a 16F628, worked great, but I am not having any luck today with the interrupts on 16F767. I am probably doing something wrong.
I have checked settings, wiring, re-read darrel's website info, but I am still missing something.
Attached is a small test code. Using external interrupt, switch pins are connected to RB0,
so when interrupt triggered, it should read pins.
I assembled it on EasyPIC4 switches are indeed pulled to ground, I can verify with the LED and also doing a simple Port status display on the LCD, so it definitely the code or the configuration.
Any help, comments, suggestions much appreciated.




'*** SWITCH / INTERRUPT TEST ***

'Setup for PIC16F767 @ 4Mhz

;Config Register 1
@ __CONFIG _CONFIG1, _CP_OFF & _CCP2_RC1 & _DEBUG_OFF & _HS_OSC &_VBOR_2_7 & _MCLR_ON & _PWRTE_OFF & _WDT_ON


;Config Register 2
@ __CONFIG _CONFIG2, _BORSEN_0 & _IESO_OFF & _FCMEN_OFF

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

DEFINE OSC 4

OPTION_REG.7 = 1 'Disable PORTB pull ups
ADCON0.0 = 0
ADCON1 = 15 'Disable ALL Analog inputs. ALL PORTS digital

TRISB = %00011111 'PortB 7,6,5 Outputs,

'Set LCD Data Port
DEFINE LCD_DREG PORTC
'Set starting Data Bit (0 or 4) if a 4-bit bus
DEFINE LCD_DBIT 4
'Set LCD Register Select Port
DEFINE LCD_RSREG PORTC
'Set LCD Register Select Bit
DEFINE LCD_RSBIT 0
'Set LCD Enable Port
DEFINE LCD_EREG PORTC
'Set LCD Enable Bit
DEFINE LCD_EBIT 3
'Set LCD Bus Size (4 or 8 bits)
DEFINE LCD_BITS 4
'Set number of lines on LCD
DEFINE LCD_LINES 2

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _Detect, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT_INT ; enable external (INT) interrupts


Switch_1 VAR PORTB.1
Switch_2 VAR PORTB.2
Switch_3 VAR PORTB.3
Switch_4 VAR PORTB.4


Main:
Pause 50
GOTO MAIN



'---[INT - interrupt handler]---------------------------------------------------
Detect:
If switch_1 = 1 THEN LCDOUT $FE,$80,"Switch 1"
If switch_2 = 0 THEN LCDOUT $FE,$80,"Switch 2"
If switch_3 = 0 THEN LCDOUT $FE,$80,"Switch 3"
If switch_4 = 0 THEN LCDOUT $FE,$80,"Switch 4"
@ INT_RETURN

mister_e
- 29th May 2008, 21:47
And the problem is....?

The interrupt should only happen when INT0 is triggered.

For multiple switch, you may need to use Int On change (RBC_INT) ... or poll them in a Timer Interrupt.

exelanoz
- 29th May 2008, 21:53
Hello Mister_E


And the problem is....?

The problem is that the existing code does not display anything on the LCD...

It does not seem want to 'interrupt'.

mister_e
- 29th May 2008, 22:02
i've edited my previous post. Also, let's say you want to use INT0 (RB0), you want to disable the multiplexed ADC on it (see ADCON1 register pdf page 155).

INT_INT will work only with RB0, while RBC_INT will work with PORTB<7:4> pins (see INTCON page 25, and section 5.2 page 58).

exelanoz
- 29th May 2008, 22:07
Wow that was quick reply Mister_E!


i've edited my previous post. Also, let's say you want to use INT0 (RB0), you want to disable the multiplexed ADC on it (see ADCON1 register pdf page 155).

INT_INT will work only with RB0, while RBC_INT will work with PORTB<7:4> pins (see INTCON page 25, and section 5.2 page 58).

Yes, checked the PDF pg 155, but isn't ADCON1 = 15 doing that?
That should make all ports digital?

I agree the port change 7:4 would be better, but I plan to use RB5 for CCP3...so that is not really possible. I think I should use the RB0 external interrupt.

mister_e
- 29th May 2008, 22:14
Nah... you can use whatever spare I/O you have, and poll them with a Timer Interrupt, let's say 10 times/seconds. Your main loop just check if you have a new keypress.

1 Timer interrupt will do everything,
1. scan the Key
2. say if there's a new key available,
3. and... why not using it also for the debouncing as well?

Think about it... 10 times a second is usually just fine.

<hr>
Yes ADCON1=15 will do.

exelanoz
- 31st May 2008, 04:20
Nah... you can use whatever spare I/O you have, and poll them with a Timer Interrupt, let's say 10 times/seconds. Your main loop just check if you have a new keypress.

1 Timer interrupt will do everything,
1. scan the Key
2. say if there's a new key available,
3. and... why not using it also for the debouncing as well?

Think about it... 10 times a second is usually just fine.

<hr>
Yes ADCON1=15 will do.

Many thanks Mister_E...after much hair tearing I successfully managed to use the external RB0 interrupt with the above code. My stupid mistake, bad home made connector wiring on the EasyPIC board.
I ended up using your suggestion with the 10Hz timer -your multi-calculator works great! - as you said at least i can also debounce easily.

Many thanks for your time.

mister_e
- 31st May 2008, 10:12
The advantage of the timer interrupt is that you have a Global key scan... all the time, you just need to poll few variables it here and there. Another great thing.. you can use the pin you want. For user Key, it's just perfect and really fast enough.

Timer interrupt are sooo handy.