Tahmid
Advanced Member level 6
- Joined
- Jun 17, 2008
- Messages
- 4,764
- Helped
- 1,799
- Reputation
- 3,590
- Reaction score
- 1,662
- Trophy points
- 1,413
- Location
- Berkeley, California
- Activity points
- 30,713
while(1)
{
//......
//......
}
#include <p18f452.h>
#pragma config WDT=OFF //Turn watchdog timer off
#pragma config OSC=XT //For 4MHz oscillator
unsigned int temp1=102;
//25'C gives LM35 voltage of 0.25V, Reference voltage = 2.5V,
// so 0.25V gives ADC reading of (0.25/2.5)*1023 = 102
unsigned int temp2=27;
unsigned int itime;
unsigned char l_byte,h_byte;
unsigned int bin_temp;
void temperature(void);
void delay(void);
void main()
{
ADCON0=0X81;
ADCON1=0XC5;
TRISD=0;
TRISAbits.TRISA0=1;
TRISAbits.TRISA2=1;
while(1){
temperature();
if (bin_temp > temp1){ //If temperature > 25'C
PORTDbits.RD3 = 1;
}
else{
PORTDbits.RD3 = 0;
}
}
}
void temperature(void)
{
delay();
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);
l_byte=ADRESL;
h_byte=ADRESH;
bin_temp=(h_byte << 8)|l_byte;
//Results direct result of conversion without processing
}
void delay(void)
{
int i,j;
for(i=0;i<=250;i++)
for(j=0;j<=135;j++)
{
}
}
#include <p18f452.h>
#pragma config WDT=OFF //Turn watchdog timer off
#pragma config OSC=XT //For 4MHz oscillator
unsigned int temp1=102;
//25'C gives LM35 voltage of 0.25V, Reference voltage = 2.5V,
// so 0.25V gives ADC reading of (0.25/2.5)*1023 = 102
unsigned int temp2=110;
//27'C gives LM35 voltage of 0.27V, Reference voltage = 2.5V,
// so 0.27V gives ADC reading of (0.27/2.5)*1023 = 110
unsigned int itime;
unsigned char l_byte,h_byte;
unsigned int bin_temp;
void temperature(void);
void delay(void);
void main()
{
ADCON0=0X81;
ADCON1=0XC5;
TRISD=0;
TRISAbits.TRISA0=1;
TRISAbits.TRISA2=1;
while(1){
temperature();
if (bin_temp < temp1){ //If temperature < 25'C
PORTDbits.RD3 = 1;
}
else{
PORTDbits.RD3 = 0;
}
if (bin_temp > temp2){ //If temperature > 27'C
PORTDbits. RD2 = 1;
}
else{
PORTDbits.RD2 = 0;
}
}
}
void temperature(void)
{
delay();
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);
l_byte=ADRESL;
h_byte=ADRESH;
bin_temp=(h_byte << 8)|l_byte;
//Results direct result of conversion without processing
}
void delay(void)
{
int i,j;
for(i=0;i<=250;i++)
for(j=0;j<=135;j++)
{
}
}
#pragma config OSC=XT //For 4MHz oscillator
#pragma config OSC=HS
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?