![]() |
![]() |
#4 |
Đệ tử 3 túi
Tham gia ngày: Jul 2007
Bài gửi: 48
: |
chuong trinh minh viet co j sai ko ha cac ban? sao minh viet mai ma` no' chi thuc hien duoc 1 lan ghi, sau cau lenh i2c_stop() thi no' khong the doc ghi duoc nua?
----------------------------------------------------------------------------------- #include <16f877a.h> #include <def_16f877a.h> #device *=16 ADC=8 #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #use delay(clock=20000000) #use I2C(master,sda=PIN_C4,scl=PIN_C3) // dung i2c = phan cung #include <lcd_lib_4bit.c> // Thu vien ham cho LCD void write(int8 value, int8 add) { i2c_start(); i2c_write(0xD0); i2c_write(add); i2c_write(value); i2c_stop(); delay_us(3); } int8 read(int8 add) { int8 value_re; i2c_start(); i2c_write(0xD0); i2c_write(add); i2c_start(); i2c_write(0xD1); value_re = i2c_read(); i2c_stop(); delay_us(3); return(value_re); } void khoitao(){ i2c_start(); i2c_write(0xD0); //den dia chi ds1307. i2c_write(0x00); //den dia chi thanh ghi 00H. i2c_write(0x00); //s i2c_write(0x00); //m i2c_write(0x52); //h i2c_write(0x02); //day i2c_write(0x03); //date i2c_write(0x04); //mth i2c_write(0x05); //y i2c_write(0x10); //tao xung vuong 1Hz. i2c_stop(); delay_us(3); } int h,m,s,day,date,month,year,con; void main() { int value; set_tris_b(0x00); write(0x90,0x07);// o day tao xung 1hz delay_ms(2000); // write(0x00,0x07);// ket thuc qua trinh tao xung. nhung mo phong thi no khong the tat chan SWQ duoc????? } ----------------------------------------------------------------------------- o tren, minh chi ghi duoc giu lieu duoc 1 lan, sau cau lenh i2c_stop() thi minh khong the dung cac ham write() va read() duoc, co' phai do chuong trinh dich bi loi hay sao? minh dung CCS 4.057. thay đổi nội dung bởi: nguyenhung1811, 21-07-2009 lúc 01:30 AM. |
![]() |
![]() |
|
|