sábado, 3 de junio de 2017

Thermostat With PIC16F887


Diagram:

Code:

#include <16f887.h>
#device ADC=10       
#FUSES XT,NOWDT
#use delay(clock = 4000000)
#define use_portb_lcd TRUE
#include 
#use fast_IO(C)      

#byte trisb=0x86
#byte portb=0x06
#byte trisc=0x87
#byte portc=0x07

void main()
{
   trisc=0b00000000; 
   bit_clear(TRISC,0);         // C0 as output
   bit_clear(TRISC,1);         // C1 as output   
   int16 q;
   float p;
   setup_adc_ports(sAN0);          //Channel 0 
   setup_adc(ADC_CLOCK_DIV_32);    //Clock RC
do
{
     set_adc_channel(0);           // Channel 0
      delay_us(20);
      q = read_adc();                 
      p = 5.0 * 100 * q / 1024.0;           //Conversion
      lcd_init(); // start LCD
      lcd_gotoxy(5,1);
      printf(lcd_putc, "\f      TEMPERATURE  ");
      printf(lcd_putc, "\n        %01.2f C", p);

      if (p >= 30)
      {
         output_high(PIN_C0);                            //turn on FAN
         output_high(PIN_C1);                            //turn on LED        
         delay_ms(500);
      }
      else          
      {
         output_low(PIN_C0);                             //turn off FAN
         output_low(PIN_C1);                             //turn off LED   
         delay_ms(500);
      }
}
while(true);
}


_______________________________________________________________________

 Projects With Microcontrollers And PICC

http://guillengap.blogspot.com/2016/07/ebook-projects-with-microcontrollers.html


https://www.amazon.com/dp/B01EZOMGZS

https://www.amazon.com/Guillermo%20Perez/e/B01EZOTUVQ/

guillengap@gmail.com

No hay comentarios:

Publicar un comentario