0
在下面的代碼中,我試圖顯示時鐘時間,我使用其他函數。 從main調用此函數時,我以十六進制形式將地址傳遞給此函數,並且我想要打印時間,但打印不正確。需要使用指針顯示時間
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語句,但我無法弄清楚到底是什麼問題。
我也嘗試的printf(「時間是在SS:MM:HH =%P: %p:%p \ n「,* s_ptr,* m_ptr,* h_ptr);但仍然沒有得到正確的答案.. – Jay
然後我假設你的問題是在別處。無論是與設備通信還是在bcd_to_dec中 – LinearZoetrope