View Single Post
Old 11-07-2008, 12:16 PM   #8
W.Rooney
Nhập môn đệ tử
 
W.Rooney's Avatar
 
Tham gia ngày: May 2008
Bài gửi: 5
:
Exclamation

Trích:
Nguyên văn bởi Encoder View Post
Các bác cho hỏi chương trình của tôi có chỗ nào sai mà khi mô phỏng trên protues thì port b các chân chỉ thấy ở mức 1, chẳng đúng gì cả.

//==============================================
#include <16F84A.h>
#device adc=8

#use delay(clock=10000000)

#use I2C(master, sda=PIN_A0, scl=PIN_A1, fast) // use the fast i2c specification

void main() {
byte data;

i2c_start();
i2c_write(0xa0); // device address // write mode
i2c_write(0x00); // data to device
i2c_write(0x05); // write 5 to 24c04
i2c_stop();

delay_ms(10);

i2c_start();
i2c_write(0xa0);
i2c_write(0x00); // data to device
i2c_start();
i2c_write(0xa1); // read mode
data = i2c_read(); // read a byte from 24c04
i2c_stop();

output_b(data); // display on port b
while(1){}
}
Chào bạn! Bạn thử xem lại con 16F84 có hỗ trợ phần cứng về I2C không?
W.Rooney vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn