開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Ansi C
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
MCU 自訂的函數
問題(Question):
不想使用while在那裏不斷地等待,占用CPU的時間.
那段時間可以執行近萬行指令.
餵入的資料(Input):
同樣的參數
預期的正確結果(Expected Output):
同樣的結果
錯誤結果(Wrong Output):
現在測試出的結果有
1.程式亂飛(PC亂了)
2.不斷地持續傳送
程式碼(Code):(請善用置底文網頁, 記得排版)
好讀版
http://ideone.com/dz4HER
void UART1WriteString( char *string)
{
// P_Debug_O=1;
while(*string != '\0')
{
while(!UARTTransmitterIsReady(UART_MODULE_ID))
;
UARTSendDataByte(UART_MODULE_ID, *string);
string++;
while(!UARTTransmissionHasCompleted(UART_MODULE_ID))
;
}
// P_Debug_O=0;
}
補充說明(Supplement):
我試過下面這一種寫法還是不行
IO_FLAG是自己訂的Union,用來作流程控制的.
void UART1Trans_fail( void)
{
P_Debug_O=1;
if(UARTTransmitterIsReady(UART_MODULE_ID))
{
UARTSendDataByte(UART_MODULE_ID, U1TX_Buffer[U1TX_Index]);
// IO_FLAG.U1TXP=1; //Uart1 TX in processing flag hand up
IO_FLAG.U1TXReady=0;
}
// P_Debug_O=0;
if(UARTTransmissionHasCompleted(UART_MODULE_ID))
{
// IO_FLAG.U1TXP=0;
if(U1TX_CNT==0) //check need to send next byte
{
IO_FLAG.U1TXReady=1;
IO_FLAG.U1TXP=0;
}
U1TX_CNT