Hi Gentlemen,
I have met an unexpected obstakle today when tried to use TIMER1 interrupt while have PORTA interrupts enabled. Will very apreciate it if someone could look:
@ DEVICE pic16F688, WDT_OFF, INTOSCIO, PWRT_ON, MCLR_ON, BOD_OFF
@ DEVICE CPD_OFF, PROTECT_OFF 'DATA AND CODE MEMORY PROTECTION
define OSC 4
REDLED VAR PORTC.4
GREENLED VAR PORTC.5
clear
CMCON0 = 7 'TURN COMPARATORS OFF
VRCON = 0 'VOLTAGE REFERENCE OFF TO SAVE POWER OPTION_REG.7 = 0
OPTION_REG = 0
ANSEL = %1000 'PORTA4/AN3 IS ANALOG
PORTC=0
TRISC = 0
LINE21: INTCON.3 = 1 'this is the problem!!!
INTCON.4 = 1
LINE23: OCA = %100100 'ENABLES INTERRUPTS ON CHANGE ON PORTA.2 'AND PORTA.5 - ANOTHER part of the PROBLEM
T1CON.0 = 1 'TIMER ON
T1CON.1 = 0 'INT CLOCK Fosc/4
T1CON.4 = 1 'PRESCALER
T1CON.5 = 1 'PRESCALER
T1CON.6 = 0
PIE1.0=1 'TIMER1 OVERFLOW INTERRUPT ENABLE BIT (TMR1IE)
INTCON.6 = 1 'PERIPHERAL INT ENABLE
INTCON.7 = 1 'GLOBAL INT ENABLE
ON INTERRUPT GOTO INT_CHECK
START:
GOTO START 'WAIT HERE TILL INTERRUPTED
DISABLE
INT_CHECK:
IF GREENLED = 0 THEN
GREENLED =1
REDLED=0
ELSE
GREENLED =0
REDLED =1
ENDIF
PIR1.0 = 0
RESUME
ENABLE
When I comment line 21 or line 23 (not necessary both), then my timer interrupt works. If those lines are uncommented, then I have both LEDs ON and nothing work. Interrupt on change (lines marked as line21: and line23: needed for a part of code removed from here to have this text smaller
Please look if I can use Timer1 in this situation at all or have to use Timer0 instead. The MCU is PIC16F688
Thank you very much
Alexey
Bookmarks