0
다음 코드에서는 다른 기능을 사용하여 시계 시간을 표시하려고합니다. main에서이 함수를 호출하는 동안이 함수에 16 진수 형식의 주소를 전달하고 시간을 인쇄하려고하지만 올바르게 인쇄되지 않습니다.포인터를 사용하여 시간을 표시해야합니다.
void DS1307_GetTime(unsigned char *h_ptr, unsigned char *m_ptr, unsigned char *s_ptr)
{
I2C_Start(); // Start I2C communication
DS1307_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
DS1307_Write(SEC_ADDRESS); // Request Sec RAM address at 00H
I2C_Stop(); // Stop I2C communication after selecting Sec Register
I2C_Start(); // Start I2C communication
DS1307_Write(0xD1); // connect to DS1307(under Read mode) by sending its ID on I2c Bus
*s_ptr = DS1307_Read(); I2C_Ack(); // read second and return Positive ACK
*m_ptr = DS1307_Read(); I2C_Ack(); // read minute and return Positive ACK
*h_ptr = DS1307_Read(); I2C_NoAck(); // read hour and return Negative/No ACK
*s_ptr = bcd_to_dec(*s_ptr);
*m_ptr = bcd_to_dec(*m_ptr);
*h_ptr = bcd_to_dec(*h_ptr);
printf("Time is in ss:mm:hh = %u:%u:%u\n", s_ptr, m_ptr, h_ptr);
I2C_Stop(); // Stop I2C communication after reading the Time
}
내 문제는 내 포인터 선언 또는 printf 문에 있다고 생각하지만 문제가 무엇인지 정확히 알 수 없습니다.
는 I도의 printf 시도했다 (이 다른 내부 시각 생성 함수가 의도 한대로 작동 가정 물론,() "시간은 SS에 : mm : HH = %의 P : % p : % p \ n ", * s_ptr, * m_ptr, * h_ptr); 그래도 여전히 정답을 얻지는 못합니다 .. – Jay
그렇다면 문제가 다른 곳에 있다고 가정합니다. 장치와 통신 중이거나 bcd_to_dec에 있음 – LinearZoetrope