Professional Documents
Culture Documents
Code Giao Tiep DS1307
Code Giao Tiep DS1307
Code Giao Tiep DS1307
{ SDA=0; SCL=0; delay_i2c(); SCL=1; delay_i2c(); SDA=1; delay_i2c(); } unsigned char rx_i2c(unsigned char ACK) { unsigned char d=0,x; SDA=1;// tha noi cong // qua trinh doc du lieu tu ngoai vao for (x=0;x<8;x++) { d<<=1; SCL=1; while(SCL==0); // khi da co canh len thi doc du lieu tu ngoai vao delay_i2c(); if (SDA) d|=1; SCL=0; } // // tao xung ACK luu y la co xet xem la co can tao xung ACK khong if (ACK) SDA=0; else SDA=1; SCL=1; delay_i2c(); SCL=0; SDA=1;//release the SDA line return d; } bit tx_i2c(unsigned char trans) { unsigned char x; bit ACK; SCL=0; for (x=0;x<8;x++) { if(trans&0x80) SDA=1; else SDA=0;