PIC 16f452’ye Yüklenen Program Kodları
PIC 16f452’ye Yüklenen Program Kodları;
#include <18F452.H>
#device adc=8
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PC,errors)
#include <sht75.c>
#include <flex_lcd.c>
#include <ds1307.c>
#define sicak PIN_B4
#define nem PIN_B5
#define artir PIN_B6
#define eksit PIN_B7
float restemp, truehumid;
int sckust,sckalt,nemust,nemalt;
BYTE sec;
BYTE min;
BYTE hrs;
BYTE day;
BYTE month;
BYTE yr;
BYTE dow;
int i;
//==========================
void main()
{
ds1307_init();
lcd_init(); // Always call this first.
sht_init();
ds1307_set_date_time(03,01,11,1,15,20,55);
sckust=20;
sckalt=18;
nemust=70;
nemalt=60;
while(1)
{
for(i=0;i<3;i++)
{
ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hrs,min,sec);
printf(lcd_putc,"f%02d/%02d/%02d",day,month,yr);
switch(dow)
{
case 1:printf(lcd_putc,"PAZARTESIn");break;
case 2:printf(lcd_putc,"SALIn");break;
case 3:printf(lcd_putc,"CARSAMBAn");break;
case 4:printf(lcd_putc,"PERSEMBEn");break;
case 5:printf(lcd_putc,"CUMAn");break;
case 6:printf(lcd_putc,"CUMARTESIn");break;
case 7:printf(lcd_putc,"PAZARn");break;
}
printf(lcd_putc," %02d:%02d:%02d",hrs,min,sec);
delay_ms(500);
sht_rd (restemp, truehumid);
if(restemp<sckalt)
{
output_high(pin_b0);
output_low(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
if(restemp>sckust)
{
output_low(pin_b0);
output_low(pin_b1);
output_high(pin_b2);
output_low(pin_b3);
}
if(restemp<sckust)
{
if(restemp>sckalt)
{
if(truehumid<nemust)
{
if(truehumid>nemalt)
{
output_low(pin_b0);
output_low(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
}
}
}
if(truehumid<nemalt)
{ output_low(pin_b0);
output_high(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
if(truehumid>nemust)
{ output_low(pin_b0);
output_low(pin_b1);
output_high(pin_b2);
output_high(pin_b3);
printf(lcd_putc,"fILACLAMA");
printf(lcd_putc,"nYAPILIYOR");
delay_ms(5000);
output_low(pin_b2);
output_low(pin_b3);
}
}
for(i=0;i<3;i++)
{
sht_rd (restemp, truehumid);
lcd_gotoxy(1,1);
printf(lcd_putc, "fTemp : %3.1f %cC ", restemp, 223);
printf(lcd_putc, "nRH : %3.1f %% ", truehumid);
delay_ms(400); //delay 500 ms between reading to prevent self heating of sensor
sht_rd (restemp, truehumid);
if(restemp<sckust)
{
if(restemp>sckalt)
{
if(truehumid<nemust)
{
if(truehumid>nemalt)
{
output_low(pin_b0);
output_low(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
}
}
}
if(restemp<sckalt)
{
output_high(pin_b0);
output_low(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
if(restemp>sckust)
{
output_low(pin_b0);
output_low(pin_b1);
output_high(pin_b2);
output_low(pin_b3);
}
if(truehumid<nemalt)
{ output_low(pin_b0);
output_high(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
if(truehumid>nemust)
{ output_low(pin_b0);
output_low(pin_b1);
output_high(pin_b2);
output_high(pin_b3);
printf(lcd_putc,"fILACLAMA");
printf(lcd_putc,"nYAPILIYOR");
delay_ms(5000);
output_low(pin_b2);
output_low(pin_b3);
}
}
printf(lcd_putc,"fSICAKLIK USTn");
printf(lcd_putc, "DEGERI : %d ",sckust);
delay_ms(1000);
printf(lcd_putc,"fSICAKLIK Altn");
printf(lcd_putc, "DEGERI : %d ",sckalt);
delay_ms(1000);
printf(lcd_putc,"fNEM USTn");
printf(lcd_putc, "DEGERI : %d %% ",nemust);
delay_ms(1000);
printf(lcd_putc,"fNEM ALTn");
printf(lcd_putc, "DEGERI : %d %% ",nemalt);
delay_ms(1000);
sht_rd (restemp, truehumid);
if(restemp<sckust)
{
if(restemp>sckalt)
{
if(truehumid<nemust)
{
if(truehumid>nemalt)
{
output_low(pin_b0);
output_low(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
}
}
}
if(restemp<sckalt)
{
output_high(pin_b0);
output_low(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
if(restemp>sckust)
{
output_low(pin_b0);
output_low(pin_b1);
output_high(pin_b2);
output_low(pin_b3);
}
if(truehumid<nemalt)
{ output_low(pin_b0);
output_high(pin_b1);
output_low(pin_b2);
output_low(pin_b3);
}
if(truehumid>nemust)
{ output_low(pin_b0);
output_low(pin_b1);
output_high(pin_b2);
output_high(pin_b3);
delay_ms(5000);
output_low(pin_b2);
output_low(pin_b3);
}
printf(lcd_putc,"f AYARLAMA");
delay_ms(1000);
port_b_pullups(TRUE);
if(input(pin_b4)==1)
{
printf(lcd_putc,"f SICAKLIK");
delay_ms(1000);
if(input(pin_b6)==1)
{
sckalt++;
printf(lcd_putc, "n DEGERI : %d ",sckalt);
delay_ms(1000);
}
if(input(pin_b7)==1)
{
sckalt--;
printf(lcd_putc, "n DEGERI : %d ",sckalt);
delay_ms(1000);
}
}
port_b_pullups(FALSE);
}
}