|
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 |
16-04-2012, 05:05 PM | #1 |
Nhập môn đệ tử
Tham gia ngày: Mar 2011
Bài gửi: 3
: |
Help me! PIC24FJ256GB110 kết nối I2C với DS1307, xuất ra toàn FF.
Các bác xem giúp em chương trình thời gian thức của e với, khi đọc thời gian ra toàn là FF thôi.
EM dùng pic24fj256gb110 kết nối i2c với ds1307. đây là code của em: #include <24FJ256GB110.h> #use delay(clock=20000000) #fuses HS, NOWDT, NOPROTECT, PR #use rs232(UART1, baud=9600, xmit=PIN_B4,rcv=PIN_B5) #use I2C(master, sda=PIN_A15, scl=PIN_A14,FAST=100000, FORCE_HW) #include <input.c> #include <string.h> #include <math.h> #include "ds1307.c" //================================================== == void main() { int8 sec,min,hour,day,date,month,year; while(true) { sec=read_ds1307(0x00); // read second min=read_ds1307(0x01); // read minute hour=read_ds1307(0x02); // read hour printf("Time : %04X:%04X:%04X\r",hour,min,sec); } } //================================================ //================================================ //=============DS1307.c============================ #define DS1307_SDA PIN_G3 #define DS1307_SCL PIN_G2 //#use i2c(master,scl=DS1307_SCL,sda=DS1307_SDA) //Khoi tao DS1307 void init_DS1307() { output_float(DS1307_SDA); output_float(DS1307_SCL); } BYTE read_DS1307(byte address) { BYTE data; i2c_start(); delay_ms(100); i2c_write(0xd0); i2c_write(address); i2c_start(); i2c_write(0xd1); delay_ms(100); data=i2c_read(0); i2c_stop(); return(data); } //Ghi du lieu toi DS1307 Void write_DS1307(byte address, byte data) { int1 status; i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_write(data); i2c_stop(); i2c_start(); status=i2c_write(0xd0); while(status==1) { i2c_start(); status=i2c_write(0xd0); } } Các bác xem code cho em, xem có chỗ nào sai không ah? Nhờ các bác, thanks! |
|
|