Question

Design a digital temperature meter using one temperature sensor

Design a digital temperature meter using one temperature sensor

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Temperature Indicator

In the preented circuit diagram, Thermister is used to measure the temperature, Thje thermister is connected at connector (J3).

A LCD is also connected to show the temperature on LCD.

The design is around PIC16F877A microcontroller. This design also controls the heating and cooling using the two relays as Relay-1 and Relay-2.

The working code for the same is given below:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#define SET_POINT_WINTER_LOW_L   0x00

#define SET_POINT_WINTER_LOW_H   0x01

#define SET_POINT_WINTER_HIGH_L 0x02

#define SET_POINT_WINTER_HIGH_H 0x03

#define SET_POINT_SUMMER_LOW_L   0x04

#define SET_POINT_SUMMER_LOW_H   0x05

#define SET_POINT_SUMMER_HIGH_L 0x06

#define SET_POINT_SUMMER_HIGH_H 0x07

#define ADDRESS_SEASON           0x08

#define WINTER                 0

#define SUMMER                 1

#define DISPLAY_FREQ           25000

#define FLIP_DISP_FREQ         1000

#define BOUNCE_DELAY           200

#define LED_ON                 0

#define LED_OFF                1

#define EEPROM_DELAY           200

/* Time delay for LCD On time*/

#define LCD_ON_TIME            40

unsigned char SetPoint_Winter_Low_L=0,SetPoint_Winter_Low_H=0;

unsigned char SetPoint_Winter_High_L=0,SetPoint_Winter_High_H=0;

unsigned char SetPoint_Summer_Low_L=0,SetPoint_Summer_Low_H=0;

unsigned char SetPoint_Summer_High_L=0,SetPoint_Summer_High_H=0;

unsigned char Season=WINTER;

unsigned int CurrentTemp,SetPoint_High,SetPoint_Low;

unsigned int ADCVal=0;

unsigned int DisplayCount=0;

//sbit RL_CH_TEMP at RE0_bit;

//sbit RL_CH_TEMP_Direction at TRISE0_bit;

//sbit RL_CC at RA5_bit;

sbit RL_CH at RA5_bit;      //Heatin Relay

sbit RL_CH_Direction at TRISA5_bit;

sbit RL_CC at RE0_bit;     //Cooling Relay

sbit RL_CC_Direction at TRISE0_bit;

// Lcd pinout settings

sbit LCD_RS at RC5_bit;

//sbit LCD_CHECK at RD2_bit;

sbit LCD_EN at RC7_bit;

sbit LCD_D7 at RD7_bit;

sbit LCD_D6 at RD6_bit;

sbit LCD_D5 at RD5_bit;

sbit LCD_D4 at RD4_bit;

sbit LED_H at RB4_bit;

sbit LED_C at RB5_bit;

sbit LED_H_Direction at TRISB4_bit;

sbit LED_C_Direction at TRISB5_bit;

sbit SW_1 at RB0_bit;

sbit SW_2 at RB1_bit;

// Pin direction

sbit LCD_POWER at RB2_bit;

sbit LCD_POWER_Direction at TRISB2_bit;

sbit LCD_RS_Direction at TRISC5_bit;

//sbit LCD_CHECK_Direction at TRISD2_bit;

sbit LCD_EN_Direction at TRISC7_bit;

sbit LCD_D7_Direction at TRISD7_bit;

sbit LCD_D6_Direction at TRISD6_bit;

sbit LCD_D5_Direction at TRISD5_bit;

sbit LCD_D4_Direction at TRISD4_bit;

void DisplayWinterSetPoints(void);

void DisplaySummerSetPoints(void);

void FaultCondition(void);

void EditSeason(void);

const code unsigned int Res_1[] = {

28160,

26920,

25760,

24650,

23600,

22600,

20740,

19870,

19050,

18270,

17510,

16800,

16120,

15470,

14850,

14260,

13700,

13160,

12640,

12160,

11680,

11230,

10800,

10390,

10000,

9624 ,

9265 ,

8921 ,

8591 ,

8276 ,

7973 ,

7684 ,

7406 ,

7140 ,

6885 ,

6641 ,

6406 ,

6181 ,

5965 ,

5758 ,

5559 ,

5368 ,

5185 ,

5008 ,

4839 ,

4676 ,

4520 ,

4370 ,

4225 ,

4086 ,

3953 ,

3824 ,

3700 ,

3581 ,

3467 ,

3356 ,

3250 ,

3147 ,

3049 ,

2954 ,

2862 ,

2774 ,

2689 ,

2607 ,

2528 ,

2451 ,

2378 ,

2306 ,

2238 ,

2172 ,

2108 ,

2046 ,

1986 ,

1929 ,

1873 ,

1820 ,

1768 ,

1717 ,

1669 ,

1622 ,

1577 ,

1533 ,

1490 ,

1449 ,

1410 ,

1371 ,

1334 ,

1298 ,

1263 ,

1229 ,

1197 ,

1165 ,

1134 ,

1105 ,

1076 ,

1048 ,

1021 ,

995 ,

969 ,

945 ,

};

unsigned char EditSetPoints(unsigned char EditData)

{

unsigned char FlagEdit=1,tempEditData;

tempEditData = EditData;

while(FlagEdit)

{

Lcd_Chr(2,8,0x30+(EditData/10));

Lcd_Chr(2,9,0x30+(EditData%10));

if(SW_1==0) {Delay_ms(BOUNCE_DELAY);tempEditData=tempEditData+1;if(tempEditData>50) tempEditData=0;}

if(SW_2==0) FlagEdit=0;

}

return(tempEditData);

}

void FaultCondition(void)

{

    Lcd_Out(1,1,"      FAULT     ");

    Lcd_Out(2,1,"   SENSOR OPEN ");

    RL_CH=0;

    RL_CC=0;

    LED_H=~LED_H;

    LED_C = LED_OFF;

    Delay_ms(500);

}

void EditSeason(void)

{

if(Season==WINTER) Season = SUMMER;

else               Season = WINTER;

                     Lcd_Out(1,1,"SEASON CHANGED..");

if(Season==WINTER) Lcd_Out(2,1,"NOW -> WINTER   ");

if(Season==SUMMER) Lcd_Out(2,1,"NOW -> SUMMER   ");

while(SW_1==0){} Delay_ms(500);

}

void MakeLCDOff(void)

{

Lcd_Cmd(_LCD_CLEAR);               // Clear display

LCD_POWER=0;

}

unsigned int LCDDisplayCount=0;

void MakeLCDON(void)

{

LCD_POWER=1;

LCDDisplayCount=0;

Lcd_Init();

Lcd_Cmd(_LCD_CLEAR);               // Clear display

Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

}

void main(void)

{

unsigned int TempChar,FinalTemperature,TResistance,Tempt=0,FlipDispCount=0;

unsigned char Flag=1,dCnt,EditCount=0,Flip=1,Error=0,FlagUp=0,FlagDown=0,H=0,C=0,FlagIO=0,y_1=0,y_2=0;

unsigned long CountEditSeason=0,DisplayONCount=0;

unsigned char FlagDisplaySetPoints=1,FlagSeason=WINTER,FlagH=0,FlagC=0,FlipDisplay=1,FirstTimeFlag=1;

unsigned long Temp,Qt,Rem,Tr;

signed char TempDir=1,TempPrev=0,TempCurrent=0;

TRISE = 0x00;

TRISD=0x00;

TRISC=0x00;

TRISB = 0x03;

TRISA = 0x0F;

ADC_Init();

LCD_POWER=1;

Lcd_Init();

Lcd_Cmd(_LCD_CLEAR);               // Clear display

Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

RL_CH=0; RL_CC=0; //Both Relay OFF

DisplayCount=DISPLAY_FREQ;

SetPoint_Winter_Low_L = 17;// = EEPROM_Read(SET_POINT_WINTER_LOW); Delay_ms(EEPROM_DELAY);

SetPoint_Winter_Low_H = 19;//High = EEPROM_Read(SET_POINT_WINTER_HIGH); Delay_ms(EEPROM_DELAY);

SetPoint_Winter_High_L = 21;// = EEPROM_Read(SET_POINT_WINTER_LOW); Delay_ms(EEPROM_DELAY);

SetPoint_Winter_High_H = 23;//High = EEPROM_Read(SET_POINT_WINTER_HIGH); Delay_ms(EEPROM_DELAY);

SetPoint_Summer_Low_L = 19;// = EEPROM_Read(SET_POINT_WINTER_LOW); Delay_ms(EEPROM_DELAY);

SetPoint_Summer_Low_H = 21;//High = EEPROM_Read(SET_POINT_WINTER_HIGH); Delay_ms(EEPROM_DELAY);

SetPoint_Summer_High_L = 23;// = EEPROM_Read(SET_POINT_WINTER_LOW); Delay_ms(EEPROM_DELAY);

SetPoint_Summer_High_H = 25;//High = EEPROM_Read(SET_POINT_WINTER_HIGH); Delay_ms(EEPROM_DELAY);

Season = EEPROM_Read(ADDRESS_SEASON);                      Delay_ms(EEPROM_DELAY);

if(Season!=WINTER && Season!=SUMMER) {Season = WINTER;}

// Season = WINTER;

while(1)

{

if(DisplayCount>=DISPLAY_FREQ)

{

   TempPrev = TempCurrent;

   if(LCDDisplayCount < LCD_ON_TIME) LCDDisplayCount++;

   if(LCDDisplayCount >= LCD_ON_TIME) MakeLCDOff();//LCD_POWER=0;

   FlipDispCount++;

   if(FlipDispCount >= FLIP_DISP_FREQ) {FlipDisplay=1-FlipDisplay; FlipDispCount=0;}

   DisplayCount=0;

   Flag=1;

   Temp = ADC_Read(0);

   if(Temp < 950)

   {

    LED_H = LED_OFF;

    Error=0;

    Qt = ((Temp *10)/(1024 - Temp))*1000;

    Rem = (Temp *10)%(1024 - Temp);

    Tr = Qt + Rem;

    if(FlipDisplay)

    {

     if(Season==SUMMER) {Lcd_Out(1,1,"SUMMER (HIGH)");}

     else               {Lcd_Out(1,1,"WINTER (LOW) ");}

     Lcd_Out(2,1,"COACH TEMP=    C");

     y_1=2;

    }

    else

    {

     Lcd_Out(1,1,"COACH TEMP=    C");

     y_1=1;

    }

    for(dCnt=0;(dCnt < 99 && Flag==1);dCnt=dCnt+1)

    {

     if(Flag==1 && Tr > Res_1[dCnt+1] && Tr <= Res_1[dCnt])

     {

      Flag=0;

      FinalTemperature = dCnt+1;

     }

    }                                       

    if(TempDir!=0)

    {

     Lcd_Chr(y_1,15,0xDF);

     TempChar = 0x30 + (FinalTemperature/10); Lcd_Chr(y_1,13,TempChar);

     TempChar = 0x30 + (FinalTemperature%10); Lcd_Chr(y_1,14,TempChar);

    }

   

//    TempChar = 0x30 + (LCDDisplayCount/10); Lcd_Chr(1,15,TempChar);

//    TempChar = 0x30 + (LCDDisplayCount%10); Lcd_Chr(1,16,TempChar);

    TempCurrent = FinalTemperature;

    TempDir = TempCurrent - TempPrev;

   }

   else

   {

    MakeLCDON();

    FaultCondition();

    Error=1;

    LED_H=LED_OFF;

    Lcd_Cmd(_LCD_CLEAR);               // Clear display

    Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

   }

}

DisplayCount++;

if(Error==0)

{

if(Season==WINTER)

{

   if(FinalTemperature >= 23                                         )   C=1;

   if(FinalTemperature > 21 && FinalTemperature < 23 && TempDir < 0)   C=1;

   if(FinalTemperature <= 21                           && TempDir < 0)   C=0;

   if(FinalTemperature > 21 && FinalTemperature < 23 && TempDir > 0)   C=0;

   if(FinalTemperature <= 17                                         )   H=1;

   if(FinalTemperature > 17 && FinalTemperature < 19 && TempDir > 0)   H=1;

   if(FinalTemperature >= 19                                         )   H=0;

   if(FinalTemperature > 17 && FinalTemperature < 19 && TempDir < 0)   H=0;

   if(H) {RL_CH=1; RL_CC=0;}

   if(C) {RL_CH=0; RL_CC=1;}

   if(H==0 && C==0) {RL_CH=0; RL_CC=0;}

}

if(Season==SUMMER)

{

   if(FinalTemperature >= 25                                         )   C=1;

   if(FinalTemperature > 23 && FinalTemperature < 25 && TempDir < 0)   C=1;

   if(FinalTemperature <= 23                                         )   C=0;

   if(FinalTemperature <= 19                                         )   H=1;

   if(FinalTemperature > 19 && FinalTemperature < 21 && TempDir > 0)   H=1;

   if(FinalTemperature >= 21                                         )   H=0;

   if(FinalTemperature > 19 && FinalTemperature < 21 && TempDir < 0)   H=0;

   if(H) {RL_CH=1; RL_CC=0;}

   if(C) {RL_CH=0; RL_CC=1;}

   if(H==0 && C==0) {RL_CH=0; RL_CC=0;}

}

if(!FlipDisplay)

{

   if(H==1 && C==0) Lcd_Out(2,1,"Htr-ON   AC-OFF");

   if(H==0 && C==1) Lcd_Out(2,1,"Htr-OFF   AC-ON");

   if(H==0 && C==0) Lcd_Out(2,1,"Htr-OFF AC-OFF");

}

if(SW_1==0)

{

   MakeLCDON();

   FlagDisplaySetPoints=1;

   Delay_ms(BOUNCE_DELAY);

   Flip=1-Flip;

   Lcd_Cmd(_LCD_CLEAR);               // Clear display

   Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

   if(Flip==1)    DisplayWinterSetPoints();

   if(Flip==0)    DisplaySummerSetPoints();

   while(FlagDisplaySetPoints)

   {

   CountEditSeason=0;

   if(SW_1==0)

     {

      Delay_ms(BOUNCE_DELAY);

      while(SW_1==0)

      {

       CountEditSeason++;

       if(CountEditSeason>100000)

       {

        EditSeason();

        EEPROM_Write(ADDRESS_SEASON,Season); Delay_ms(EEPROM_DELAY);

       }

      }

      FlagDisplaySetPoints=0;

     }

     else

     {

     Delay_ms(1500);   FlagDisplaySetPoints=0;

     }

   }

   Lcd_Cmd(_LCD_CLEAR);               // Clear display

   Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

   DisplayCount=DISPLAY_FREQ;

}

/*

if(SW_2==0)

{

   Delay_ms(BOUNCE_DELAY);

   if(EditCount==0)

   {

    SetPoint_Winter_Low_L = EditSetPoints(SetPoint_Winter_Low_L);

    EEPROM_Write(SET_POINT_WINTER_LOW_L,SetPoint_Winter_Low_L); Delay_ms(EEPROM_DELAY);

   }

   if(EditCount==1)

   {

    SetPoint_Winter_Low_H = EditSetPoints(SetPoint_Winter_Low_H);

    EEPROM_Write(SET_POINT_WINTER_LOW_H,SetPoint_Winter_Low_H); Delay_ms(EEPROM_DELAY);

   }

   if(EditCount==2)

   {

    SetPoint_Winter_High_L = EditSetPoints(SetPoint_Winter_High_L);

    EEPROM_Write(SET_POINT_WINTER_HIGH_L,SetPoint_Winter_High_L); Delay_ms(EEPROM_DELAY);

   }

   if(EditCount==3)

   {

    SetPoint_Winter_High_H = EditSetPoints(SetPoint_Winter_High_H);

    EEPROM_Write(SET_POINT_WINTER_HIGH_H,SetPoint_Winter_High_H); Delay_ms(EEPROM_DELAY);

   }

   if(EditCount==4)

   {

    SetPoint_Summer_Low_L = EditSetPoints(SetPoint_Summer_Low_L);

  EEPROM_Write(SET_POINT_SUMMER_LOW_L,SetPoint_Summer_Low_L); Delay_ms(EEPROM_DELAY);

   }

   if(EditCount==5)

   {

    SetPoint_Summer_Low_H = EditSetPoints(SetPoint_Summer_Low_H);

    EEPROM_Write(SET_POINT_SUMMER_LOW_H,SetPoint_Summer_Low_H); Delay_ms(EEPROM_DELAY);

   }  

   if(EditCount==6)

   {

    SetPoint_Summer_High_L = EditSetPoints(SetPoint_Summer_High_L);

    EEPROM_Write(SET_POINT_SUMMER_HIGH_L,SetPoint_Summer_High_L); Delay_ms(EEPROM_DELAY);

   }

   if(EditCount==7)

   {

    SetPoint_Summer_High_H = EditSetPoints(SetPoint_Summer_High_H);

    EEPROM_Write(SET_POINT_SUMMER_HIGH_H,SetPoint_Summer_High_H); Delay_ms(EEPROM_DELAY);

   }

   EditCount=EditCount+1;

   if(EditCount>7) EditCount=0;

   DisplayCount=DISPLAY_FREQ;

}

*/

}

}

}

void DisplayWinterSetPoints(void)

{

    Lcd_Out(1,1,"WINTER:");

    Lcd_Chr(1,9, 0x30+(SetPoint_Winter_Low_L/10));

    Lcd_Chr(1,10,0x30+(SetPoint_Winter_Low_L%10));

    Lcd_Chr(1,14,0x30+(SetPoint_Winter_Low_H/10));

    Lcd_Chr(1,15,0x30+(SetPoint_Winter_Low_H%10));

    Lcd_Chr(2,9, 0x30+(SetPoint_Winter_High_L/10));

    Lcd_Chr(2,10,0x30+(SetPoint_Winter_High_L%10));

    Lcd_Chr(2,14,0x30+(SetPoint_Winter_High_H/10));

    Lcd_Chr(2,15,0x30+(SetPoint_Winter_High_H%10));

}

void DisplaySummerSetPoints(void)

{

    Lcd_Out(1,1,"SUMMER:");

    Lcd_Chr(1,9, 0x30+(SetPoint_Summer_Low_L/10));

    Lcd_Chr(1,10,0x30+(SetPoint_Summer_Low_L%10));

    Lcd_Chr(1,14,0x30+(SetPoint_Summer_Low_H/10));

    Lcd_Chr(1,15,0x30+(SetPoint_Summer_Low_H%10));

    Lcd_Chr(2,9, 0x30+(SetPoint_Summer_High_L/10));

    Lcd_Chr(2,10,0x30+(SetPoint_Summer_High_L%10));

    Lcd_Chr(2,14,0x30+(SetPoint_Summer_High_H/10));

    Lcd_Chr(2,15,0x30+(SetPoint_Summer_High_H%10));

}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

R1 LED CTANCE R4 R3 10K GHD TD YEE UT RAD LCD RD LD RW MCLRAVp RAI 4 RA2 MCLR RAB LED DD DBCVLK 104 RATCLK GHD PGD PaC ICn n1

Add a comment
Know the answer?
Add Answer to:
Design a digital temperature meter using one temperature sensor
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT