如果在中斷中監控,資料會有遺失的問題
****stm8 uart 字串接收副程式****
uint8_t IncrementVar_RxCounter1(void) { return RxCounter1++; }
u8 uart1_sync=0; //要設定全域變數,不然case1 進不去.
INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18)
{
u8 data,;
//RxBuffer[IncrementVar_RxCounter1()]
UART1_ClearITPendingBit(UART1_IT_RXNE_OR);
data=UART1_ReceiveData8();
switch(uart1_sync)
{
case 1:
RxBuffer[IncrementVar_RxCounter1()]= data;
//uart1_in_temp_index %= UART1_BUF_SIZE;
if(data==0x0d)
{
RxBuffer[IncrementVar_RxCounter1()] =data;
//uart1_in_temp_index %= UART1_BUF_SIZE;
RxCounter1 = 0x00;
uart1_sync = 0;
}
break;
default:
switch(data)
case '%':
uart1_sync = 1;
RxBuffer[IncrementVar_RxCounter1()] = data;
//uart1_in_temp_index %= UART1_BUF_SIZE;
break;
break;
}
}
****stm8 uart 字串傳輸副程式****
void UART1_SendByte(u8 Data)
{
UART1_SendData8((unsigned char)Data);
while (UART1_GetFlagStatus(UART1_FLAG_TXE)==RESET);
{
}
}
void UART1_SendString(u8* Data,u16 len)
{
u16 i=0;
for(;i
UART1_SendByte(Data[i]);
}
}