butonlamı istiyorsun
#include <16F877.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES PROTECT //Code protected from reads
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#use delay(clock=4000000)
#include <
Lcd.c>
#define RTC_SCLK PIN_c6 //DS1302 için pin tanımlamaları
#define RTC_IO PIN_c7
#define RTC_RST PIN_c5
#include <ds1302.c>
#define sht_data_pin PIN_b1//(Data pin veya input)
#define sht_clk_pin PIN_b0
//***** SHT11 Başlatma *****
void comstart (void)
{
output_float(sht_data_pin); //data high
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
output_bit(sht_data_pin, 0); //data low
delay_us(1);
output_bit(sht_clk_pin, 0); //clk low
delay_us(2);
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
output_float(sht_data_pin); //data high
delay_us(1);
output_bit(sht_clk_pin, 0); //clk low
}
//***** SHT11 yazma fonksiyonu*****
int1 comwrite (int8 iobyte)
{
int8 i, mask = 0x80;
int1 ack;
//Komut gönderilir
delay_us(4);
for(i=0; i<8; i++)
{
output_bit(sht_clk_pin, 0);
if((iobyte & mask) > 0) output_float(sht_data_pin);
else output_bit(sht_data_pin, 0);
delay_us(1);
output_bit(sht_clk_pin, 1);
delay_us(1);ask = mask >> 1;
}
//Shift in ack
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
ack = input(sht_data_pin); //get ack bit
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
output_bit(sht_clk_pin, 0); //clk low
return(ack);
}
int16 comread (void)
{
int8 i;
int16 iobyte = 0;
const int16 mask0 = 0x0000;
const int16 mask1 = 0x0001;
//shift in MSB data
for(i=0; i<8; i++)
{
iobyte = iobyte << 1;
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
if (input(sht_data_pin)) iobyte |= mask1; //shift in data bit
else iobyte |= mask0;
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
}
//send ack 0 bit
output_bit(sht_data_pin, 0); //data low
delay_us(1);
output_bit(sht_clk_pin, 1); //clk high
delay_us(2);
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
output_float(sht_data_pin); //data high
//shift in LSB data
for(i=0; i<8; i++)
{
iobyte = iobyte << 1;
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
if (input(sht_data_pin)) iobyte |= mask1; //shift in data bit
else iobyte |= mask0;
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
}
//send ack 1 bit
output_float(sht_data_pin); //data high
delay_us(1);
output_bit(sht_clk_pin, 1); //clk high
delay_us(2);
output_bit(sht_clk_pin, 0); //clk low
return(iobyte);
}
void comwait (void)
{
int16 sht_delay;
output_float(sht_data_pin); //data high
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
for(sht_delay=0; sht_delay<30000; sht_delay++) // wait for max 300ms
{
if (!input(sht_data_pin)) break; //if sht_data_pin low, SHT75 ready
delay_us(10);
}
}
void comreset (void)
{
int8 i;
output_float(sht_data_pin); //data high
output_bit(sht_clk_pin, 0); //clk low
delay_us(2);
for(i=0; i<9; i++)
{
output_bit(sht_clk_pin, 1); //toggle clk 9 times
delay_us(2);
output_bit(sht_clk_pin, 0);
delay_us(2);
}
comstart();
}
void sht_soft_reset (void)
{
comreset(); //SHT75 communication reset
comwrite(0x1e); //send SHT75 reset command
delay_ms(15); //pause 15 ms
}
int16 measuretemp (void)
{
int1 ack;
int16 iobyte;
comstart(); //alert SHT75
ack = comwrite(0x03); //send measure temp command and read ack status
if(ack == 1) return;
comwait(); //wait for SHT75 measurement to complete
iobyte = comread(); //read SHT75 temp data
return(iobyte);
}
int16 measurehumid (void)
{
int1 ack;
int16 iobyte;
comstart(); //alert SHT75
ack = comwrite(0x05); //send measure RH command and read ack status
if(ack == 1) return;
comwait(); //wait for SHT75 measurement to complete
iobyte = comread(); //read SHT75 temp data
return(iobyte);
}
void calculate_data (int16 temp, int16 humid, float & tc, float & rhlin, float & rhtrue)
{
float truehumid1, rh;
//calculate temperature reading
tc = ((float) temp * 0.01) - 40.0;
//calculate Real RH reading
rh = (float) humid;
rhlin = (rh * 0.0405) - (rh * rh * 0.0000028) - 4.0;
//calculate True RH reading
rhtrue = ((tc - 25.0) * (0.01 + (0.00008 * rh))) + rhlin;
}
void sht_rd (float & temp, float & truehumid)
{
int16 restemp, reshumid;
float realhumid;
restemp = 0; truehumid = 0;
restemp = measuretemp(); //measure temp
reshumid = measurehumid(); //measure RH
calculate_data (restemp, reshumid, temp, realhumid, truehumid); //calculate temp & RH
}
void sht_init (void)
{
comreset(); //reset SHT75
delay_ms(20); //delay for power-up
}
int saniye,dakika,saat,gun,ay,yil,haftanin_gunu,x; //ds1302 değişkenleri
void main()
{
float restemp, truehumid;
lcd_init();
sht_init();
rtc_init(); // DS1302 başlangıç ayarları yapılıyor
rtc_set_datetime(6,5,8,2,22,52); // Tarih ve Saat ayarları yapılıyor
while(1)
{
comreset();
printf(lcd_putc,"\f");
sht_rd (restemp, truehumid);
printf(lcd_putc,"%3.1f%cC", restemp, 223);
rtc_get_time(saat,dakika,saniye); // DS1302'den saat,dakika,saniye bilgileri alınıyor
rtc_get_date(gun,ay,yil,haftanin_gunu); // DS1302'den gün,ay,yil ve günün isim bilgisi alınıyor
printf(lcd_putc," %02d.%02d.%02d",gun,ay,yil);
printf(lcd_putc,"\nN:%3.1f%%",truehumid);
printf(lcd_putc," %02d:%02d:%02d",saat,dakika,saniye);
delay_ms(1000); //delay 500 ms between reading to prevent self heating of sensor
}
}
bu çalışan kod tarafımca denendi ve bir müh fak.abimize proje olarak yapmıştık internet derlemesi kendi bilgimizden harmanlayarak oluşturduk.