#include <16F887.h>
#device ADC=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(crystal=20000000)
#include <bai1.h>
int8 giay,phut,gio,ngay,thang,nam;
int menu=0;
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
#include <LCD.C>
#define DS1307_SDA PIN_C4
#define DS1307_SCL PIN_C3
#include <DS1307.C>
void main()
{
lcd_init();
init_ds1307();
giay=read_ds1307(0);
write_ds1307(0,giay & 0x7F); // enable oscillator(bit 7 =0)
while(TRUE)
{
if(menu==0){
Giay=read_DS1307(0);
giay=(giay/16)*10+giay%16;
Phut=read_DS1307(1);
phut=(phut/16)*10+phut%16;
Gio=read_DS1307(2);
Gio=(Gio/16)*10+Gio%16;
lcd_gotoxy(1,1);
printf(lcd_putc,"%02d:%02d:%02d",gio,phut,giay);
ngay=read_DS1307(4);
ngay=(ngay/16)*10+ngay%16;
thang=read_DS1307(5);
thang=(thang/16)*10+thang%16;
nam=read_DS1307(6);
nam=(nam/16)*10+nam%16;
lcd_gotoxy(1,2);
printf(lcd_putc,"%02d-%02d-20%02d",ngay,thang,nam);
delay_ms(500);
if(input(PIN_B0)==1){
menu=1;
while(input(PIN_B0)==1);
}
}
if(menu==1){
lcd_gotoxy(1,1);
printf(lcd_putc,"Cai Phut ");
lcd_gotoxy(1,2);
printf(lcd_putc,"PHUT= %02d ",phut);
if(input(PIN_B0)==1){
menu=2;
while(input(PIN_B0)==1);
}
if(input(PIN_B1)==1){
phut++;
while(input(PIN_B1)==1);
}
if(input(PIN_B2)==1){
phut--;
while(input(PIN_B2)==1);
}
if(phut==60) phut=0;
if(phut==-1) phut=59;
}
if(menu==2){
lcd_gotoxy(1,1);
printf(lcd_putc,"CaiGio ");
lcd_gotoxy(1,2);
printf(lcd_putc,"Gio= %02d ",gio);
if(input(PIN_B0)==1){
menu=3;
while(input(PIN_B0)==1);
}
if(input(PIN_B1)==1){
gio++;
while(input(PIN_B1)==1);
}
if(input(PIN_B2)==1){
gio--;
while(input(PIN_B2)==1);
}
if(gio==24) gio=0;
if(gio==-1) gio=23;
}
if(menu==3)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"Cai Ngay ");
lcd_gotoxy(1,2);
printf(lcd_putc,"Ngay= %02d ",ngay);
if(input(PIN_B0)==1){
menu=4;
while(input(PIN_B0)==1);
}
if(input(PIN_B1)==1){
ngay++;
while(input(PIN_B1)==1);
}
if(input(PIN_B2)==1){
ngay--;
while(input(PIN_B2)==1);
}
if(ngay==32) ngay=1;
if(ngay==0) ngay=31;
}
if(menu==4)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"CaiThang ");
lcd_gotoxy(1,2);
printf(lcd_putc,"Thang= %02d ",thang);
if(input(PIN_B0)==1){
menu=5;
while(input(PIN_B0)==1);
}
if(input(PIN_B1)==1){
thang++;
while(input(PIN_B1)==1);
}
if(input(PIN_B2)==1){
thang--;
while(input(PIN_B2)==1);
}
if(thang==13) thang=1;
if(thang==0) thang=12;
}
if(menu==5){
lcd_gotoxy(1,1);
printf(lcd_putc,"CaiNam ");
lcd_gotoxy(1,2);
printf(lcd_putc,"Nam= %02d ",nam);
if(input(PIN_B0)==1){
menu=6;
while(input(PIN_B0)==1);
}
if(input(PIN_B1)==1)
{
nam++;
while(input(PIN_B1)==1);
}
if(input(PIN_B2)==1)
{
nam--;
while(input(PIN_B2)==1);
}
if(nam==-1) nam=99;
}
if(menu==6){ write_ds1307(1,(phut/10)*16+phut%10);
write_ds1307(2,(gio/10)*16+gio%10);
write_ds1307(4,(ngay/10)*16+ngay%10);
write_ds1307(5,(thang/10)*16+thang%10);
write_ds1307(6,(nam/10)*16+nam%10);
menu=0;
}
}
}
0 nhận xét:
Đăng nhận xét