#include <16F877A.h>
#device adc=16
#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 NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#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
#use delay(clock=4000000)
#include <DS1302.C>
#include "lcd.c"
#use fast_io(a)
#use fast_io(c)
int16 bilgi,sicaklik=0;
int8 saniye,dakika,saat=1,gun=1,ay=1,yil=1,haftanin_gunu=1,durum=0,x=0;
void lcd(){
lcd_gotoxy(1,1);
printf(lcd_putc,"%02u/%02u/%02u",gun,ay,yil);
lcd_gotoxy(9,1);
lcd_send_byte(0x08,0x7e);
lcd_gotoxy(1,2);
printf(lcd_putc,"%02u:%02u:%02u %02lu",saat,dakika,saniye,sicaklik);
lcd_gotoxy(13,2);
lcd_send_byte(0x4a,0xdf);
lcd_gotoxy(14,2);
printf(lcd_putc,"C");
}
void haftagunu(){
lcd_gotoxy(10,1);
switch(haftanin_gunu)
{
case 1: printf(lcd_putc,"PAZAR "); break; // Eğer "1" ise LCD'ye PAZAR yaz
case 2: printf(lcd_putc,"P.TESI "); break; // Eğer "2" ise LCD'ye P.TESI yaz
case 3: printf(lcd_putc,"SALI "); break; // Eğer "3" ise LCD'ye SALI yaz
case 4: printf(lcd_putc,"CARS "); break; // Eğer "4" ise LCD'ye CARS yaz
case 5: printf(lcd_putc,"PERS "); break; // Eğer "5" ise LCD'ye PERS yaz
case 6: printf(lcd_putc,"CUMA "); break; // Eğer "6" ise LCD'ye CUMA yaz
case 7: printf(lcd_putc,"C.TESI "); break; // Eğer "7" ise LCD'ye C.TESI yaz
}
}
void ayar(){
if(input(pin_c1)){
durum++;
while(input(pin_c1));}
if(durum==1){
lcd_gotoxy(4,1);
lcd_send_byte(0x03,0x0d);
lcd_gotoxy(5,1);
lcd_send_byte(0x04,0x0d);}
if(input(pin_c0)&&durum==1){
ay++;
while(input(pin_c0));}
if(input(pin_c2)&&durum==1){
ay--;
while(input(pin_c2));}
if(durum==2){
lcd_gotoxy(1,1);
lcd_send_byte(0x01,0x0d);
lcd_gotoxy(2,1);
lcd_send_byte(0x01,0x0d);}
if(input(pin_c0)&&durum==2){
gun++;
while(input(pin_c0));}
if(input(pin_c2)&&durum==2){
gun--;
while(input(pin_c2));}
if(durum==3){
lcd_gotoxy(7,1);
lcd_send_byte(0x06,0x0d);
lcd_gotoxy(8,1);
lcd_send_byte(0x07,0x0d);}
if(input(pin_c0)&&durum==3){
yil++;
while(input(pin_c0));}
if(input(pin_c2)&&durum==3){
yil--;
while(input(pin_c2));}
if(durum==4){
lcd_gotoxy(9,1);
lcd_send_byte(0x08,0x0d);}
if(input(pin_c0)&&durum==4){
haftanin_gunu++;
while(input(pin_c0));}
if(input(pin_c2)&&durum==4){
haftanin_gunu--;
while(input(pin_c2));}
if(durum==5){
lcd_gotoxy(1,2);
lcd_send_byte(0x40,0x0d);
lcd_gotoxy(2,2);
lcd_send_byte(0x41,0x0d);}
if(input(pin_c0)&&durum==5){
saat++;
while(input(pin_c0));}
if(input(pin_c2)&&durum==5){
saat--;
while(input(pin_c2));}
if(durum==6){
lcd_gotoxy(4,2);
lcd_send_byte(0x43,0x0d);
lcd_gotoxy(5,2);
lcd_send_byte(0x44,0x0d);}
if(input(pin_c0)&&durum==6){
dakika++;
while(input(pin_c0));}
if(input(pin_c2)&&durum==6){
dakika--;
while(input(pin_c2));}
if(durum==8){
durum=0;
printf(lcd_putc,"\f");}
}
void main()
{
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
rtc_set_datetime(01,01,12,01,01,00);
delay_ms(10);
set_tris_a(0b00000001);
set_tris_c(0b00000111);
lcd_init();
rtc_init();
delay_ms(10);
while(1){
lcd();
ayar();
haftagunu();
set_adc_channel(0);
delay_us(10);
bilgi=read_adc();
sicaklik=bilgi/128;
if(durum==7){
rtc_set_datetime(gun,ay,yil,haftanin_gunu,saat,dakika);
delay_ms(10);
printf(lcd_putc,"\f AYARLAR\n YUKLENIYOR");
delay_ms(1000);
durum=8;}
if(durum==0){
rtc_get_time(saat,dakika,saniye);
rtc_get_date(gun,ay,yil,haftanin_gunu);}
if(saat==24)saat=0;
if(saat==255)saat=23;
if(dakika==60)dakika=0;
if(dakika==255)dakika=59;
if(ay==13)ay=1;
if(ay==0)ay=12;
if(yil==0)yil=0;
if(haftanin_gunu==8)haftanin_gunu=1;
if(haftanin_gunu==0)haftanin_gunu=7;
if(ay==4||ay==6||ay==9||ay==11){
if(gun==31)gun=1;
if(gun==0)gun=30;}
if(ay==1||ay==3||ay==5|ay==7||ay==8||ay==10||ay==12){
if(gun==32)gun=1;
if(gun==0)gun=31;}
x=yil/4;
if((x==1||x==2||x==3||x==4||x==5||x==6||x==7||x==8||x==9||x==10)&&ay==2){
if(gun==30)gun=1;
if(gun==0)gun=29;}
}
}