![]() |
|
Tài trợ cho PIC Vietnam |
dsPIC - Bộ điều khiển tín hiệu số 16-bit Theo dự kiến của Microchip, vào khoảng năm 2011 dsPIC sẽ có doanh số lớn hơn PIC |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#7 |
Đệ 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 |
![]() |
![]() |
|
|