Monday 2 September 2013

weather station code displaying temprature



sbit LCD_RS at RD3_bit;
sbit LCD_EN at RD2_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;

// Pin direction
sbit LCD_RS_Direction at TRISD3_bit;
sbit LCD_EN_Direction at TRISD2_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;

unsigned long result=0;
float volt=0;
float temp;
 int ch=0;
    char * txt[7];

void display()
{

floattostr(temp,txt);
     Lcd_out(1,1,txt);
     delay_ms(500);
     temp=0;
  if(ch==0)
  {
   ADCON0.CHS0=0;
      ADCON0.CHS1=0;
            ADCON0.CHS2=0;
             //        delay_ms(1000);
  }
  else if(ch==1)
  {
   ADCON0.CHS0=1;
         ADCON0.CHS1=0;
               ADCON0.CHS2=0;
     //  Lcd_out(1,1,"2nd Channel");
               // delay_ms(1000);
  }
   else
  {
      ADCON0.CHS0=1;
   ADCON0.CHS1=1;
    ADCON0.CHS2=0;
    // Lcd_out(1,1,"3rd channel");
               // delay_ms(1000);
          ch=0;
  }
   ADCON0.GO=1;
          delay_ms(500);
}
void interrupt ()
{
  if(PIR1.ADIF)
  {
    result=adresh;
    result=result<<8;
    temp=result+adresl;
    temp=temp*4.8828;
    temp=temp/10;
    pir1.adif=0;
    delay_ms(200);
    ch++;
  }
}
void main()
{
  intcon1.gie=1;
  intcon1.peie=1;
  ADCON0=0X41;// ADCON0.ADON=1; ADCON0.GO/DONE=1; ADCON0.ADCS0=1;
  ADCON1=0X80; // ADCON1.ADCS2=1; ADCON1.ADFM=1;
  PIE1.ADIE=1;
  PIR1.ADIF=0;
  ADRESH=0;
  ADRESL=0;
  TRISD=0X00;
  TRISA=0XFF;
  ADCON0.GO=1;
  LCD_INIT();
  while(1)
  {
  display();
  delay_ms(500);
    ADCON0.GO=1;
  }
}

No comments:

Post a Comment