|
這個(gè)嵌套函數(shù)我看不懂,哪位大佬講一下?
單片機(jī)源程序如下:
- /************************************************************
- 程序功能:串口4發(fā)送一個(gè)字符
- ************************************************************/
- void Usart4_SendByte( USART_TypeDef * pUSARTx, u8 ch)
- {
- /* 發(fā)送一個(gè)字節(jié)數(shù)據(jù)到USART */
- USART_SendData(pUSARTx,ch);
- /* 等待發(fā)送數(shù)據(jù)寄存器為空 */
- while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET)
- {
- ;
- }
- }
- /************************************************************
- 程序功能:串口4發(fā)送字符串
- ************************************************************/
- void Usart4_SendString( USART_TypeDef * pUSARTx, char *str)
- {
- unsigned int k=0;
- do
- {
- Usart4_SendByte( pUSARTx, *(str + k) );
- k++;
- }
- while(*(str + k)!='\0');
- /* 等待發(fā)送完成 */
- while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
- {}
- }
- /************************************************************
- 程序功能:串口4發(fā)送一個(gè)16位數(shù)
- ************************************************************/
- void Usart4_SendHalfWord( USART_TypeDef * pUSARTx, u16 ch)
- {
- uint8_t temp_h, temp_l;
- /* 取出高八位 */
- temp_h = (ch&0XFF00)>>8;
- /* 取出低八位 */
- temp_l = ch&0XFF;
- /* 發(fā)送高八位 */
- USART_SendData(pUSARTx,temp_h);
- while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET)
- {
- ;
- }
- /* 發(fā)送低八位 */
- USART_SendData(pUSARTx,temp_l);
- while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET)
- {
- ;
- }
- }
- /************************************************************
- 程序功能:重定向c庫函數(shù)printf到串口,重定向后可使用printf函數(shù)
- ************************************************************/
- int fputc(int ch, FILE *f)
- {
- /* 發(fā)送一個(gè)字節(jié)數(shù)據(jù)到串口 */
- USART_SendData(DEBUG_USART4, (uint8_t) ch);
- /* 等待發(fā)送完畢 */
- while (USART_GetFlagStatus(DEBUG_USART4, USART_FLAG_TXE) == RESET)
- {
- ;
- }
- return (ch);
- }
- /************************************************************
- 程序功能:重定向c庫函數(shù)scanf到串口,重寫向后可使用scanf、getchar等函數(shù)
- ************************************************************/
- int fgetc(FILE *f)
- {
- /* 等待串口輸入數(shù)據(jù) */
- while (USART_GetFlagStatus(DEBUG_USART4, USART_FLAG_RXNE) == RESET)
- {
- ;
- }
- return (int)USART_ReceiveData(DEBUG_USART4);
- }
復(fù)制代碼
所有資料51hei提供下載:
新建文本文檔.rar
(754 Bytes, 下載次數(shù): 8)
2019-3-26 23:01 上傳
點(diǎn)擊文件名下載附件
串口通信嵌套
|
|