Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need help in interfacing sensors to PIC18F4550 using interrupts

Status
Not open for further replies.

ravindrareddy2131

Newbie level 4
Joined
Jul 12, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,370
hi everyone,
i am interfacing temperature sensor to AN0 and humidity sensor to AN1 inputs of P18F4550 microcontroller. i had written the program in MPLAB IDE. am getting only humidity value in hyperterminal but the temperature loop is not executing. Here is my program. could any one please help me..thank you
#include<p18f4550.h>
#include<usart.h>
#include<delays.h>


#pragma config FOSC=HS
#pragma config BOR=OFF
#pragma config PWRT=OFF
#pragma config WDT=OFF, DEBUG=OFF
#pragma config LVP=OFF
#pragma config MCLRE=ON
#pragma config PBADEN=OFF
#pragma config ICPRT=OFF


void sertx(unsigned int);
void MSDelay (unsigned int);
void chk_ISR(void);
void INT0_ISR(void);



#pragma interrupt chk_ISR
void chk_ISR(void)
{
if(INTCONbits.INT0IF==1)
INT0_ISR();
}

#pragma myhipri_int=0x08;
void myhipri_int(void)
{
_asm
goto chk_ISR
_endasm
}
#pragma code


void main(void)
{
unsigned char LB,HB,BT,T1,T2;
TRISC=0;
TRISD=0;
ADCON0=0x09;
ADCON1=0x45;
TRISBbits.TRISB0=1;
TRISCbits.TRISC6=0;
TXSTA=0x20;
SPBRG=31;
TXSTAbits.TXEN=1;
RCSTAbits.SPEN=1;
INTCONbits.INT0IF=0;
INTCONbits.INT0IE=1;
INTCONbits.GIE=1;
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1)
LB=ADRESL;
HB=ADRESH;
BT=HB;
H1=(BT/10)+48;
H2=(BT%10)+48;
sertx('H');
sertx('M');
sertx('D');
sertx('T');
sertx('Y');
sertx(H1);
sertx(H2);
MSDelay(250);
}
}
void INT0_ISR(void)
{
unsigned char LB,HB,HD,H1,H2;
ADCON0=0x01;
ADCON1=0x45;

while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1)
LB=ADRESL;
HB=ADRESH;
HD=HB;
T1=(HD/10)+48;
T2=(HD%10)+48;
sertx('T');
sertx('E');
sertx('M');
sertx('p');
sertx(T1);
sertx(T2);
INTCONbits.INT0IF=0;
}
}

void sertx(unsigned int C)
{
while(PIR1bits.TXIF==0);
TXREG=C;
}


void MSDelay (unsigned int itime)
{
unsigned int i;
unsigned int j;
for(i=0;i<itime;i++)
for(j=0;j<135;j++);
}
 

You never call the INT0_ISR function, which is inside the chk_ISR, which must be called from myhipri_int. Rewrite the program it's bad written. Also use comments it's free.
 

You never call the INT0_ISR function, which is inside the chk_ISR, which must be called from myhipri_int. Rewrite the program it's bad written. Also use comments it's free.

thanks for the reply..
i didnt get you,could you please explain what you intend to tell..thank you
 

#include<p18f4550.h>
#include<usart.h>
#include<delays.h>


#pragma config FOSC=HS
#pragma config BOR=OFF
#pragma config PWRT=OFF
#pragma config WDT=OFF, DEBUG=OFF
#pragma config LVP=OFF
#pragma config MCLRE=ON
#pragma config PBADEN=OFF
#pragma config ICPRT=OFF


void sertx(unsigned int);
void MSDelay (unsigned int);
void chk_ISR(void);
void INT0_ISR(void);



#pragma interrupt chk_ISR
void chk_ISR(void)
{
if(INTCONbits.INT0IF==1)
INT0_ISR();
}


#pragma myhipri_int=0x08;
void myhipri_int(void)
{
_asm
goto chk_ISR
_endasm
}

#pragma code


void main(void)
{
unsigned char LB,HB,BT,T1,T2;
TRISC=0;
TRISD=0;
ADCON0=0x09;
ADCON1=0x45;
TRISBbits.TRISB0=1;
TRISCbits.TRISC6=0;
TXSTA=0x20;
SPBRG=31;
TXSTAbits.TXEN=1;
RCSTAbits.SPEN=1;
INTCONbits.INT0IF=0;
INTCONbits.INT0IE=1;
INTCONbits.GIE=1;
while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1)
LB=ADRESL;
HB=ADRESH;
BT=HB;
H1=(BT/10)+48;
H2=(BT%10)+48;
sertx('H');
sertx('M');
sertx('D');
sertx('T');
sertx('Y');
sertx(H1);
sertx(H2);
MSDelay(250);
}
}


void INT0_ISR(void)
{
unsigned char LB,HB,HD,H1,H2;
ADCON0=0x01;
ADCON1=0x45;

while(1)
{
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1)
LB=ADRESL;
HB=ADRESH;
HD=HB;
T1=(HD/10)+48;
T2=(HD%10)+48;
sertx('T');
sertx('E');
sertx('M');
sertx('p');
sertx(T1);
sertx(T2);
INTCONbits.INT0IF=0;
}
}



void sertx(unsigned int C)
{
while(PIR1bits.TXIF==0);
TXREG=C;
}



void MSDelay (unsigned int itime)
{
unsigned int i;
unsigned int j;
for(i=0;i<itime;i++)
for(j=0;j<135;j++);
}


Now every function has a different color.
The main() function is the first function which run on start up. You only call the MSDelay() function within the main.
The chk_ISR(void), the myhipri_int(void), the INT0_ISR(void) and the sertx(unsigned int C)
are never going to run because you dont call them within the main. Did you write the code??

Using // inside your code it's comments and you can write whatever you want. The compiler will ignore everything after // untill the end of line.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top