View Single Post
Old 20-05-2012, 04:23 PM   #4
boydtbk
Đệ tử 1 túi
 
Tham gia ngày: Jul 2010
Bài gửi: 11
:
các bạn ơi mình làm mạch đồn hồ số hiển thị LCD dùng pic6f887 ds1307
code:
#include <16F887.h>
#include <def_887.h>
#device *=16

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BORV40 //Brownout reset at 4.0V
#FUSES NOWRT //Program memory not write protected
#use delay(clock=8000000)
#include "lcd4bit.c"
#include "DS1307.c"

int8 gio,phut,giay,thu,ngay,thang,nam;
void read_time()
{ giay=read_DS1307(0x00);
phut= read_DS1307(0x01);
gio = read_DS1307(0x02);
thu = read_DS1307(0x03);
ngay= read_DS1307(0x04);
thang= read_DS1307(0x05);
nam = read_DS1307(0x06);
}
/*void read_time_sau()
{
tam_giay=read_DS1307(0x00);
tam_phut= read_DS1307(0x01);
tam_gio = read_DS1307(0x02);
tam_thu = read_DS1307(0x03);
tam_ngay= read_DS1307(0x04);
tam_thang= read_DS1307(0x05);
tam_nam = read_DS1307(0x06);
}*/
void Transform_Time() {
giay = ((giay & 0xF0) >> 4)*10 + (giay & 0x0F);
phut = ((phut & 0xF0) >> 4)*10 + (phut & 0x0F);
gio = ((gio & 0xF0) >> 4)*10 + (gio & 0x0F);
ngay = ((ngay & 0x30) >> 4)*10 + (ngay & 0x0F);
thang = ((thang & 0x10) >> 4)*10 + (thang & 0x0F);
nam = (nam & 0x0F);
}
void Hienthi()
{ lcd_gotoxy(1,1);
switch (thu)
{
case 1: lcd_putc("SUN"); break;
case 2: lcd_putc("MON"); break;
case 3: lcd_putc("TUE"); break;
case 4: lcd_putc("WEB"); break;
case 5: lcd_putc("THU"); break;
case 6: lcd_putc("FRI"); break;
case 7: lcd_putc("SAT"); break;
}
lcd_gotoxy(6,1);
lcd_putc(ngay/10+48);
lcd_putc(ngay%10+48);
lcd_putc('/');
lcd_gotoxy(9,1);
lcd_putc(thang/10+48);
lcd_putc(thang%10+48);
lcd_putc('/');
lcd_gotoxy(12,1);
lcd_putc("201");
lcd_putc(nam+48);
lcd_gotoxy(1,2);
lcd_putc(gio/10+48);
lcd_putc(gio%10+48);
lcd_putc(':');
lcd_gotoxy(4,2);
lcd_putc(phut/10+48);
lcd_putc(phut%10+48);
lcd_putc(':');
lcd_gotoxy(7,2);
lcd_putc(giay/10+48);
lcd_putc(giay%10+48);


}
void setup_time()
{
byte u;
u=read_ds1307(0);
giay=u & 0x0F;
write_ds1307(0,giay);

}

void main()
{ trisd=0x00;
lcd_init();
init_DS1307();
delay_ms(500);
setup_time();
delay_ms(500);
while(TRUE)
{
read_time();
Transform_Time();
Hienthi();
}

}
----------------------------------------------------------------

mình viết và mô phỏng trên protes mà nó ko chạy. chỉ hiển thị đc thời gian ban đầu
sau đó im lun đc hồi hắn hiện số loạn lên. thấy hiện ngày tháng của con ds1307 hiên 115 155 5151
ko hiểu tại sao nữa. thêm dòng delay 500 vào thì dồng hồ chạy đc lúc thì cũng loạn lên. mong mọi người giúp đỡ
boydtbk vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn