Các đại ca chỉ giúp em, em điên với nó lắm rồi.
Chả là em định làm cái lịch vạn niên,chương trình chính ngắn gọn thôi
while(true)
{
read();
for(i=1;i<=300;i++)
{
porta=0x01;
portd=phut;
delay_ms(10);
porta=0x02;
portd=gio;
delay_ms(10);
porta=0x04;
portd=thu;
delay_ms(10);
porta=0x08;
portd=ngay;
delay_ms(10);
porta=0x10;
portd=thang;
delay_ms(10);
porta=0x20;
portd=nam;
delay_ms(10);
}
}
Chương Trình Đọc
void read()
{
i2c_start();
i2c_write(0xD0);
i2c_write(0x00);
i2c_start();
i2c_write(0xD1);
giay=i2c_read();
phut=i2c_read();
gio=i2c_read();
thu=i2c_read();
ngay=i2c_read();
thang=i2c_read();
nam=i2c_read();
i2c_stop();
}
nhưng khi quét lần 1 thì hiển thị đúng, quét lần 2 porta chạy đúng nhưng portd toàn set mức cao,lần 3 lại bình thường,...
Không biết tại cái gì hay do mô phỏng bị trục trặc.
Và 1 điều nữa là portc chỉ sử dụng chan sda và scl giao tiếp với ds1307, vậy mấy chân còn lại của portc thì làm sao để sử dụng như là chân I/O đây (phần set_tris_c(????) )
Chả là em định làm cái lịch vạn niên,chương trình chính ngắn gọn thôi
while(true)
{
read();
for(i=1;i<=300;i++)
{
porta=0x01;
portd=phut;
delay_ms(10);
porta=0x02;
portd=gio;
delay_ms(10);
porta=0x04;
portd=thu;
delay_ms(10);
porta=0x08;
portd=ngay;
delay_ms(10);
porta=0x10;
portd=thang;
delay_ms(10);
porta=0x20;
portd=nam;
delay_ms(10);
}
}
Chương Trình Đọc
void read()
{
i2c_start();
i2c_write(0xD0);
i2c_write(0x00);
i2c_start();
i2c_write(0xD1);
giay=i2c_read();
phut=i2c_read();
gio=i2c_read();
thu=i2c_read();
ngay=i2c_read();
thang=i2c_read();
nam=i2c_read();
i2c_stop();
}
nhưng khi quét lần 1 thì hiển thị đúng, quét lần 2 porta chạy đúng nhưng portd toàn set mức cao,lần 3 lại bình thường,...
Không biết tại cái gì hay do mô phỏng bị trục trặc.
Và 1 điều nữa là portc chỉ sử dụng chan sda và scl giao tiếp với ds1307, vậy mấy chân còn lại của portc thì làm sao để sử dụng như là chân I/O đây (phần set_tris_c(????) )
Comment