This is very strange. I have the interrupt working with a toggle on RB1 while main is generating in a loop a pulse on RB0.
During power up both ports are putting out a toggle, but about 5 to 10 seconds after power on the interrupt generated toggle stops. Main still is toggling away. I went through and made sure other peripheral interrupt sources are off...
what am I missing? Would someone please load this code and verify that the interrupt is stopping for some reason?
Code:' This code is for 16F1827 MCU with built in oscillator (Max Osc 32Mhz) ' Code requires PicBasic Pro 2.60 along with MPASM assembler ASM __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _LVP_OFF & _STVREN_OFF ENDASM DEFINE OSC 8 ' Define ADCIN parameters DEFINE ADC_BITS 8 ' Set number of bits in result DEFINE ADC_CLOCK 4 ' Set clock source, look on data sheet for chart DEFINE ADC_SAMPLEUS 500 ' Set sampling time in uS DEFINE INTHAND myint ' Setup interrupt handler ;******************************************************************************* ;******************************************************************************* ; System hardware configuration ;******************************************************************************* ;******************************************************************************* OSCCON = %01110000 ' 8MHz internal ANSELA = %00000001 ' all digital. A/D disabled ANSELB = %00000000 TRISB = %00000000 ' set port directions 0 = output, 1 = input TRISA = %00000001 ADCON0 = %00000111 ' Set PORTA digital 1, analog 0 APFCON0.0 = 1 ' CCP1 PWM output on RB0 APFCON0.3 = 1 ' CCP2 PWM output on RA7 APFCON1 = 1 CCPR1L = 64 ' Set PWM Duty-Cycle to 50% CCPR2L = 64 PR2 = 49 ' Set PWM frequency CCP1CON = %00000000 ' Mode select = PWM off , to turn on %00001100 CCP2CON = %00000000 ' Mode select = PWM off, to turn on %00001100 T2CON = %00000110 ' %00000100 = TMR2 ON 1:1 pre-scale ' %00000101 = TMR2 ON 1:4 pre-scale ' %00000110 = TMR2 ON 1:16 pre-scale ' %00000111 = TMR2 ON 1:64 pre-scale ;******************************************************************************* ; Program variables ;******************************************************************************* ADCVAL var byte ;******************************************************************************* ; Program constants ;******************************************************************************* ;******************************************************************************* ; Power on initialization to known port states ;******************************************************************************* PowerOn_init: PortA = 0 ' force low to avoid glitches POrtB = 0 PIR1 = 0 ' clear TMR1 int flag PIE1 = %00000001 ' TMR1 int enabled INTCON = %11000000 ' global & peripheral ints enabled T1CON = %00010001 ' TMR1 1:2 prescale, timer1 on ;******************************************************************************* ;******************************************************************************* goto mainloop asm ; Save W, STATUS and PCLATH registers, if not done previously myint ; retfie auto-restores w, status, bsr, fsr and pclath bcf T1CON,TMR1ON ; stop timer 1 bcf PIR1,TMR1IF ; clear over flow flag movlw 0xEF ; load timer for 16,535 * 2 prescaler interrupt on 16 bit timer movwf TMR1H ; load high byte movlw 0xEF movwf TMR1L ; load low byte bsf T1CON,TMR1ON ; re-enable timer 1 movlw 0x02 xorwf PORTB,f ; toggle RB1 retfie ; Return from interrupt retfie ; Return from interrupt endasm mainloop: adcin 0, adcval LATB.0 = 1 pauseus (4*adcval) + 1000 LATB.0 = 0 pause 15 goto mainloop




Bookmarks