PDA

View Full Version : Interrupt on Change with 16F886



Ioannis
- 1st April 2022, 23:55
Hi. I got a problem with DT-INTS14 on a 16F886 chip.

I can't seem to make it work. It is a simple test code on port b change, to trigger interrupts with DT-INTS14.



#config
Line1 = _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF
Line2 = _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG1, Line1 & Line2
__CONFIG _CONFIG2, _WRT_HALF & _BOR40V
#endconfig

OSCCON = %01110001 '8MHz Clock

DEFINE OSC 8


DEFINE LCD_DREG PORTC
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 100

OPTION_REG.0=1 'PSA0 PRESCALER SELECT 1:1 TO 1:256
OPTION_REG.1=1 'PSA1
OPTION_REG.2=1 'PSA2
OPTION_REG.3=1 'PRESCALER TO: 1->WDT, 0->TMR0
OPTION_REG.4=0 'T0SE SOURCE EDGE 1->H TO L, 0->L TO H
OPTION_REG.5=0 'T0CS 1->FROM RA4, 0->FROM INT. CLOCK
OPTION_REG.6=0 'INT EDGE SELECT 0->H TO L, 1->L TO H
OPTION_REG.7=0 'PULL UP 1->DISABLE, 0->ENABLE

adcon0=%11000001
adcon1=%10000000
ansel=$01
anselh=$00

DEFINE ADC_BITS 10 ; Set-up ADC for fast 10-bit results
DEFINE ADC_SAMPLEUS 5

ccp1con=0

PORTA=%00000001
PORTB=%01110000 'RB0-RB3 row outputs to 3x4 keyboard
'RB4-RB6 col inputs from 3x4 keyboard

PORTC=0'%10000001

TRISC=0'$80:'TRISD=0:TRISE=0

TRISA = %00010001

TRISB = %01110000 'PB0: row 1
'PB1: row 2
'PB2: row 3
'PB3: row 4
'PB4: column 1
'PB5: column 2
'PB6: column 3
'PB7: No Con.

IOCB = %01110000 'interupt on change enable on RB4-RB6
INTCON = %10001000 'Enable global and Int. on change
RBIF var INTCON.0 'alias to RBIF bit of INTCON
wsave var byte $70 system
wsave1 var byte $a0 system
wsave2 var byte $120 system
wsave3 var byte $1a0 system

adc_t var word

temp var word
i var byte
a var byte
pressed var byte


clear

Lcdout $fe,1,"IOC test"

INCLUDE "D:\Dropbox\Projects\PICDEM2\Interrupt\DT_INTS-14.bas"
INCLUDE "D:\Dropbox\Projects\PICDEM2\Interrupt\ReEnterPBP.b as"


'------------- INTERRUPTS SETUP ---------------------
ASM
INT_LIST macro; IntSource, Label, Type, ResetFlag?
INT_Handler RBC_INT, _IOC2, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE RBC_INT ; Enable Port B on change

'------------- INTERRUPTS SETUP ---------------------

portb=$7F
goto main

'************************************************* **********************
'*
'* Interrupt on Change
'*
'************************************************* **********************

IOC2:
pressed=1
lcdout $fe,$80,"interrupt"
i=portb
RBIF=0
@ INT_RETURN


main:

while 1
if pressed then
lcdout $fe,$c0,#i," "
pressed=0
portb=$0f
endif
wend

End


It must be something stupid but do not see it...
Thanks,

Ioannis

richard
- 2nd April 2022, 01:14
what makes the pins change state ?

Ioannis
- 2nd April 2022, 08:26
You are right. I forgot to note that col and rows are connected to a keyboard matrix 3x4.

Ioannis

richard
- 2nd April 2022, 08:37
You are right. I forgot to note that col and rows are connected to a keyboard matrix 3x4.

but how is it wired , what will make the columns change state the rows are set to all 1's the initial col port pins are set to all 1's
where can a o come from ?

usually a zero or a one is walked down a row or col

Ioannis
- 2nd April 2022, 09:23
Well, I have to work the project on the morning and not late at night...

I missed that portb=0 obviously and just focused on the Interrupt itself and the settings...

Ioannis