View Single Post
Old 20-10-2009, 01:24 PM   #7
nguyen nam hung
Đệ tử 2 túi
 
Tham gia ngày: Jun 2008
Bài gửi: 26
:
giao tiep ds1307

mình đang viết chương trình giao tiếp với realtimer ds1307 dung driver thầy đưa nhưng vẩn chưa chạy. các cao thủ xem dùm còn thiếu sót ở đâu không:
////////////////////////////////////////////////
1.khởi đông:
//khoi tao i2c
i2c_init();

//KHOI DONG DS1307
khoi_dong_dong_ho:
i2c_start();
if(i2c_write(write_ds1307)==0)
{
i2c_write(0x00);
i2c_stop();

i2c_start();
if(i2c_write(read_ds1307)==0)
{
luutam=i2c_read(0);
luutam=luutam & 0b01111111;
}
}
else if(i2c_write(write_ds1307)==1)
{
lcd_gotoxy(0,0);
lcd_puts("\Haven't realtime");
i2c_stop();
//while(1);
goto khoi_dong_dong_ho;
}
else if(i2c_write(write_ds1307)==2)
{
lcd_gotoxy(0,0);
lcd_puts("\loi xung dot he thong");
goto khoi_dong_dong_ho;
}

i2c_stop();

i2c_start();
if(i2c_write(write_ds1307)==0)
{
i2c_write(0x00);
i2c_write(luutam);
i2c_stop();
}
else
{
lcd_puts("\fRead DS1307 error");
while(1);
}
///////////////////////////////////
2.đọc data:
i2c_start();
if(i2c_write(write_ds1307)==0)
{
i2c_write(0x00);
i2c_stop();

i2c_start();
if(i2c_write(read_ds1307)==0);
{
sec_realtimer=i2c_read(0);
min_realtimer=i2c_read(0);
hour_realtimer=i2c_read(1);
}
}
i2c_stop();

tại hạ xin cảm ơn trước
File Kèm Theo
File Type: rar thuvien va chuongtrinh.rar (7.5 KB, 271 lần tải)
nguyen nam hung vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn