freeze32
Newbie level 4
The problem I am facing is that; once the PIC takes an external interrupt on the pin RB1, it goes twice into the isr before coming out of it!
I am clueless as to why!
Thanks in advance for help
Nishant
I am clueless as to why!
Thanks in advance for help
Nishant
Code:
/** I N C L U D E S **********************************************************/
#include <p18f4550.h>
#include<adc.h>
#include<delays.h>
#include<timers.h>
#include<portb.h>
#include <lcd.h>
/** V A R I A B L E S ********************************************************/
#pragma udata
#pragma interrupt high_isr
int T1 = 0;
int T2 = 0;
int F = 0;
int TempF = 0;
int Energy = 0;
int ValidF = 0;
int WaterFlown = 0;
#define LED1 PORTDbits.RD1
#define Flow_int PORTBbits.RB1 //For interrupt check
#define Flow_bit PORTBbits.RB7 //For spike check
#define WSBridge_Power PORTAbits.RA1 //To power Wheat Stone Bridge circuit
/** V E C T O R R E M A P P I N G
*******************************************/
extern void _startup (void); // See c018i.c in your C18 compiler dir
#pragma code _RESET_INTERRUPT_VECTOR = 0x000800
void _reset (void)
{
_asm goto _startup _endasm
}
#pragma code
#pragma code _HIGH_INTERRUPT_VECTOR = 0x000808
void interrupt_at_high_vector(void)
{
_asm GOTO high_isr _endasm
}
#pragma code _LOW_INTERRUPT_VECTOR = 0x000818
void _low_ISR (void)
{
;
}
#pragma code /* return to the default code section */
#pragma interrupt high_isr
void high_isr(void)
{
INTCON3bits.INT1IF = 0; //CLEAR INT FLAG
WSBridge_Power = 1;
Delay_ms(10);
ConvertADC();
while(BusyADC());
T1 = ReadADC();
Delay_us(100);
WriteInt(T1,4);
Delay_ms(100);
F = ReadTimer1(); //New Reading
Delay_ms(100);
WriteInt(F,2);
Delay_ms(1000);
LED1 = 0;
}
/** D E C L A R A T I O N S **************************************************/
#pragma code
void initall(void);
/************Defined in LCD Header File**************/
/*******LCD************/
//#define RS PORTAbits.RA3
//#define E PORTAbits.RA4
//CONTROL PINS
//#define DAT4 PORTAbits.RA5
//#define DAT5 PORTEbits.RE0
//#define DAT6 PORTEbits.RE1
//#define DAT7 PORTEbits.RE2
//Test LEDs
void initall(void){
TRISAbits.TRISA0=1;
//For Wheat Stone Bridge
TRISAbits.TRISA1=0;
//LCD
TRISAbits.TRISA3=0;
TRISAbits.TRISA4=0;
TRISAbits.TRISA5=0;
TRISEbits.TRISE0=0;
TRISEbits.TRISE1=0;
TRISEbits.TRISE2=0;
//Flow Meter Input For Interrupt
TRISBbits.TRISB1=1;
//Flow Meter Input For Spike Check
TRISBbits.TRISB7=1;
//Test LED
TRISDbits.TRISD1=0;
}
void EnableExternalTimers(void)
{
T1CONbits.TMR1ON=0; // stop timer
T1CONbits.TMR1CS=1; // transition on T13CKI pin (Rising Edge)
T1CONbits.T1CKPS1=0; // prescalar 00
T1CONbits.T1CKPS0=0; // prescalar 00
T1CONbits.T1RUN=0; // device clock from another source
T1CONbits.T1OSCEN=0; // osc shut for power
T1CONbits.T1SYNC=0; // syncronisation
TMR1H = 0; // clear timer
TMR1L = 0; // clear timer
T1CONbits.TMR1ON=1; // start timer
PIE1bits.TMR1IE = 0; // interrupt disable
}
void main(void)
{
int a = 0;
int b=0;
int c=0;
char z[9] = "IIT Delhi";
char z1[7] = "BTP-SWH";
ADCON1 |= 0x0E; // Default all pins to digital, except 2
OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_16_TAD , ADC_CH0 & ADC_INT_OFF & ADC_REF_VDD_VSS , ADC_1ANA ); //robotics club
//OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_16_TAD , ADC_CH1 & ADC_INT_OFF & ADC_REF_VDD_VSS , ADC_2ANA );
EnableExternalTimers();
initall(); LCDinit(); ClearScreen();
WriteStringL(z,9);
Delay_ms(1000);
ClearScreen();
WriteStringL(z1,7);
Delay_ms(1000);
ClearScreen();
WDTCONbits.SWDTEN = 0; //WDT disabled
// //For external interrupt one
INTCON3bits.INT1IF =0; //External interrupt 1 Flag
INTCONbits.GIE = 1; //Global interrupt enable
INTCON3bits.INT1IE = 1; //External interrupt 1 enable
INTCON2bits.INTEDG1 = 1; //Rising edge interrupt
WSBridge_Power = 1;
while(1)
{
LED1 = 1;
ClearScreen();
Sleep();
ClearScreen();
WriteInt(99,2);
Delay_ms(1000);
ClearScreen();
}
}
//end
/** EOF Demo02.c *************************************************************/