Подключил к контроллеру PIC16F876A часы реального времени DS1904 и сделал тестовую программку. Проблема в том что ID часов читается, а контрольный регистр и текущее время ни в какую (вернее читаются FF). Может кто подскажет в чем дело? Код программы ниже.
Код
#include "touch.c"
void touch_reset()
{
output_low(TOUCH_PIN);
delay_us(500);
output_float(TOUCH_PIN);
}
void Set_Time(unsigned int32 Time)
{
touch_write_byte(0x99); //Write Clock register command
touch_write_byte(0x0C); //Set osc to run
touch_write_byte(MAKE8(time, 0)); //LSB
touch_write_byte(MAKE8(time, 1));
touch_write_byte(MAKE8(time, 2));
touch_write_byte(MAKE8(time, 3)); //MSB
touch_reset(); //Transfer data from R/W buffer to register
}
BYTE buffer_ID[8];
unsigned int32 Get_ID()
{
BYTE i;
touch_write_byte(0x33);
for(i=0;i<8;++i)
buffer_ID[i]=touch_read_byte();
touch_reset(); //According to datasheet flow chart it is needed
return (buffer_ID);
}
int8 TimeLSB, Time2, Time3, TimeMSB;
int8 control_reg;
unsigned int32 Get_Time()
{
touch_write_byte(0x66); //Read Clock register command
control_reg = touch_read_byte(); //Read control register
TimeLSB = touch_read_byte(); //LSB
Time2 = touch_read_byte();
Time3 = touch_read_byte();
TimeMSB = touch_read_byte(); //MSB
touch_reset(); //According to datasheet flow chart it is needed
return(make32(TimeMSB, Time3, Time2, TimeLSB));
}
int8 Get_Status()
{
int8 control_reg;
touch_write_byte(0x66); //Read Clock register
control_reg = touch_read_byte(); //Read control register
touch_reset(); //Stop reading
return(control_reg);
}
void main() {
BYTE buffer[8];
BYTE i;
printf("\r\nWaiting for a touch device...\r\n");
while (TRUE) {
if(touch_present()) {
Get_ID();
}
printf("\r\nID ok\r\n");
Get_Time();
printf("\r\ntime ok\r\n");
}
}
void touch_reset()
{
output_low(TOUCH_PIN);
delay_us(500);
output_float(TOUCH_PIN);
}
void Set_Time(unsigned int32 Time)
{
touch_write_byte(0x99); //Write Clock register command
touch_write_byte(0x0C); //Set osc to run
touch_write_byte(MAKE8(time, 0)); //LSB
touch_write_byte(MAKE8(time, 1));
touch_write_byte(MAKE8(time, 2));
touch_write_byte(MAKE8(time, 3)); //MSB
touch_reset(); //Transfer data from R/W buffer to register
}
BYTE buffer_ID[8];
unsigned int32 Get_ID()
{
BYTE i;
touch_write_byte(0x33);
for(i=0;i<8;++i)
buffer_ID[i]=touch_read_byte();
touch_reset(); //According to datasheet flow chart it is needed
return (buffer_ID);
}
int8 TimeLSB, Time2, Time3, TimeMSB;
int8 control_reg;
unsigned int32 Get_Time()
{
touch_write_byte(0x66); //Read Clock register command
control_reg = touch_read_byte(); //Read control register
TimeLSB = touch_read_byte(); //LSB
Time2 = touch_read_byte();
Time3 = touch_read_byte();
TimeMSB = touch_read_byte(); //MSB
touch_reset(); //According to datasheet flow chart it is needed
return(make32(TimeMSB, Time3, Time2, TimeLSB));
}
int8 Get_Status()
{
int8 control_reg;
touch_write_byte(0x66); //Read Clock register
control_reg = touch_read_byte(); //Read control register
touch_reset(); //Stop reading
return(control_reg);
}
void main() {
BYTE buffer[8];
BYTE i;
printf("\r\nWaiting for a touch device...\r\n");
while (TRUE) {
if(touch_present()) {
Get_ID();
}
printf("\r\nID ok\r\n");
Get_Time();
printf("\r\ntime ok\r\n");
}
}