eureka89
01-06-2011, 10:52 PM
Mình mới học về pic. Đang dùng con TC74 để hiển thị nhiệt độ trên LCD. Nhưng mô phỏng trong proteus thì nó chỉ đọc là 0.
Ai có thể chỉ mình lỗi nào được không ?
Code của mình đây:
// TC74 7-bits address = 0b1001101 = 0x4D
#define SLAVE_ADD 0x4D
#define READ 1
#define WRITE 0
void main()
{
i2c_init();
char temp;
while(1){
i2c_start();
i2c_write((SLAVE_ADD<<1)|WRITE);
i2c_write(0x00);
i2c_stop();
i2c_start();
i2c_write((SLAVE_ADD<<1)|READ);
temp = i2c_read(1);
i2c_stop();
printf("\nCurrentTemp:%d C", t);
}
}
Ai có thể chỉ mình lỗi nào được không ?
Code của mình đây:
// TC74 7-bits address = 0b1001101 = 0x4D
#define SLAVE_ADD 0x4D
#define READ 1
#define WRITE 0
void main()
{
i2c_init();
char temp;
while(1){
i2c_start();
i2c_write((SLAVE_ADD<<1)|WRITE);
i2c_write(0x00);
i2c_stop();
i2c_start();
i2c_write((SLAVE_ADD<<1)|READ);
temp = i2c_read(1);
i2c_stop();
printf("\nCurrentTemp:%d C", t);
}
}