2017-04-13 27 views
-1

在這裏輸入的代碼LPC2148 RTC打印問題

void DateTimeConversion (void) 
{ 
    unsigned char TempDay,TempMonth,TempYear,i; 
    unsigned char TempHour,TempMinute,TempSecond; 
    TempDay=0;TempMonth=0;TempYear=0;TempHour=0;TempHour=0;TempSecond=0; 
    col=1; 
    for(i=0;i<10;i++) 
    { 
    sprintf(MyStr,"%c",(unsigned int)StoreUserID[i]); 
    ClcdGoto(col,2);ClcdPutS_P(MyStr); 
    col++; 
    } 

    TempDay=((unsigned int)(StoreUserID[6] * 10) + (unsigned int)(StoreUserID[7] * 1)); 
    TempMonth=((unsigned int)(StoreUserID[8] * 10) + (unsigned int)(StoreUserID[9] * 1)); 
    TempYear=((unsigned int)(StoreUserID[4] * 10) + (unsigned int)(StoreUserID[5] * 1)); 
    TempHour = ((unsigned int)(StoreUserID[0] *10) + (unsigned int)(StoreUserID[1] * 1)); 
    TempMinute = ((unsigned int)(StoreUserID[2] *10) + (unsigned int)(StoreUserID[3] * 1)); 
    TempSecond = ((unsigned int)(StoreUserID[4] *10) + (unsigned int)(StoreUserID[5] * 1)); 
} 

我使用LPC 2148爲RTC。
描述:

  1. 我已經使用singlekey以讀取同一列的多個值(0-9)(使用2個行LCD顯示器)。

  2. 讀取值被存儲在StoreUserId陣列(如COL ++陣列還增大)

  3. 以上函數被調用,以節省值用於SEC,分鐘,小時。

  4. StoreUserid是打印以交叉檢查值正確輸入。

  5. 但轉換後(檢查乘以* 10)TempSecond,TempMinute,TempHour顯示轉換後的隨機值沒有得到哪裏是問題?

+0

我不明白。最後六行不做任何事情。 – ThingyWotsit

+0

最後六行是我用來存儲值的實際變量。 for循環僅用於交叉檢查數組中存儲的值是否正確,僅用於測試目的(不會用實際代碼) – Tushar

+0

固定代碼縮進 – rlandster

回答

0

您的問題,幾乎可以肯定是在這裏:

{sprintf(MyStr,"%c",(unsigned int)StoreUserID[i]); 

我不能知道你是怎麼聲明的StoreUserID陣列和爲什麼你一直轉換爲unsigned int(如charint?) (對於小的正數yearseconds它沒有意義),但有這2個最可能的更正:

{sprintf(MyStr,"%c", StoreUserID[i]);  // for character representation in StoreUserID[] 

或 - 我認爲這是你的情況 -

{sprintf(MyStr,"%c",StoreUserID[i] + '0'); // for numerical one - the conversion is needed 

說明:

0具有字符表示'0',這是一些數字(ASCII是48)。
編號1具有字符表示'1',這是下一個數字(ASCII碼是49)。
...等等。
因此,您需要添加值'0'以從裸號獲得字符表示

+0

for循環僅用於交叉檢查數組中存儲的值是否正確(不會在實際的代碼中)。實際問題是使用for循環我已經確認我正在讀取的值是正確顯示的,但是在轉換之後(乘以10並添加下一個數組值)TempHour ,秒和分鐘顯示錯誤的值。請參閱我已使用ClcdPutNum(TempHour)顯示在LCD上。它顯示隨機值 – Tushar

+0

「TempDay」,「TempMonth」和「TempYear」是否正確顯示?如果是這樣,問題出在'StoreUserID'的聲明(使用)上。你如何宣佈它? – MarianD