'******************************
'Portb 4-7 as inputs for interrupt
'using hserout to do debug
'using portc for output to see if there is anything happening
'I can read the port and send the values to hserout and works ok
'But interrupt don't work ??
'******************************
INCLUDE "MODEDEFS.BAS" '
@ DEVICE PIC16F886
@ DEVICE HS_OSC
define LOADER_USED 1 ' using a loader, OK to leave in if a loader is not used
define OSC 20 ' this example uses a 20MHz clock
DEFINE HSER_RCSTA 90h 'rx enable
DEFINE HSER_TXSTA 20h 'tx enable
DEFINE HSER_BAUD 9600 ' set baud rate to 19200
DEFINE HSER_CLOERR 1 ' automatic clear overrun error
TRISC = %10000000 ' PORTC.7 is the RX input, PORTC.6 is the TX output
Old_Bits VAR BYTE
New_Bits VAR BYTE
Minute var byte ' Define minute variable
Second var byte ' Define second variable
Ticks var byte ' Define pieces of seconds variable
DoUpdate var byte ' Define variable to indicate update
intPortb var BYTE 'THE PORTB REGISTER STORE
DoUpdate = 1 ' Force first display
'OPTION_REG RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0
OPTION_REG = %01010111
ADCON1 = 7 ' 00000111
CM1CON0 = 0 'DISABLE COMPARITORS
CM2CON0 = 0 'DISABLE COMPARITORS
ANSELH = %00000000 '0= DIGITAL 1= ANALOG PORTB -,-,ANS13,ANS12,ANS11,ANS10,ANS9,ANS8
ANSEL = %00000000 '0= DIGITAL 1= ANALOG PORTB -,-,ANS13,ANS12,ANS11,ANS10,ANS9,ANS8
'Addr Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on POR, BOR Page
'0Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF(1) 0000 000x 31,217
INTCON = %10001000 '%10001000 port b int on change and global interrupt enable
'bit 7 = GIE: Global Interrupt Enable bit
'bit 6 = PEIE: Peripheral Interrupt Enable bit
'bit 5 = T0IE: Timer0 Overflow Interrupt Enable bit
'bit 4 = INTE: INT External Interrupt Enable bit
'bit 3 = RBIE: PORTB Change Interrupt Enable bit(1)
'bit 2 = T0IF: Timer0 Overflow Interrupt Flag bit(2)
'bit 1 = INTF: INT External Interrupt Flag bit
'bit 0 = RBIF: PORTB Change Interrupt Flag bit
IOCB.0=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (W3)
IOCB.4=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (W1)
IOCB.5=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E3)
IOCB.6=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E2)
IOCB.7=0 'ENABLE INERRUPT ON CHANGE PIN ON PORT B (E1)
TRISB = %11111001 'PORT B INPUT OUTPUT SETTINGS 1=INPUT 0=OUTPUT
CM1CON0 = 0
CM2CON0 = 0
WPUB = %111110001 '1=PULL UP O=PULL UP DISABLE PORTB WEAK PULL-UP
LOW PORTC.4 'BATTERY CHARGE ON
'Interrupt Source Enabled by Completion Status
'RB4–RB7 state change RBIE = 1 RBIF =1
B0 VAR BYTE
B0 =PORTB
intPortb = PORTB
On Interrupt Goto TickInterrupt
' Main program loop
MainLoop:
B0=PORTB
HSEROUT ["PORTB ",#B0,13,10]
pause 500
if DoUpdate then
B0=PORTB
HSEROUT ["PORTB INTERUPT ",#PORTB ,13,10]
TOGGLE PORTC.0
DoUpdate = 0
endif
Goto MainLoop
' Interrupt routine to handle each timer tick
' Disable interrupts during interrupt handler
disable
TickInterrupt:
DoUpdate = 1 ' Set update
TOGGLE PORTC.0
ExitInterrupt:
INTCON.2 = 0 ' TOIF Reset timer interrupt flag
INTCON.0 = 0 ' RBIF Clear interrupt flag portb
Resume
Bookmarks