日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

USART_GetITStatus和USART_GetFlagStatus的区别

發(fā)布時間:2024/4/14 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 USART_GetITStatus和USART_GetFlagStatus的区别 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

USART_GetITStatus()和USART_GetFlagStatus()的區(qū)別

  都是訪問串口的SR狀態(tài)寄存器,唯一不同是,USART_GetITStatus()會判斷中斷是否開啟,如果沒開啟,也會返回false。

?

    ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint32_t USART_IT)

  該函數(shù)不僅會判斷標(biāo)志位是否置1,同時還會判斷是否使能了相應(yīng)的中斷。所以在串口中斷函數(shù)中,如果要獲取中斷標(biāo)志位,通常使用該函數(shù)。------串口中斷函數(shù)中使用。

    

?    FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint32_t USART_FLAG)

  該函數(shù)只判斷標(biāo)志位。在沒有使能相應(yīng)的中斷時,通常使用該函數(shù)來判斷標(biāo)志位是否置1。------做串口輪詢時使用。

    

?

1 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG) 2 { 3 FlagStatus bitstatus = RESET; 4 /* Check the parameters */ 5 assert_param(IS_USART_ALL_PERIPH(USARTx)); 6 assert_param(IS_USART_FLAG(USART_FLAG)); 7 8 /* The CTS flag is not available for UART4 and UART5 */ 9 if (USART_FLAG == USART_FLAG_CTS) 10 { 11 assert_param(IS_USART_1236_PERIPH(USARTx)); 12 } 13 14 if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET) 15 { 16 bitstatus = SET; 17 } 18 else 19 { 20 bitstatus = RESET; 21 } 22 return bitstatus; 23 }

?

1 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT) 2 { 3 uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00; 4 ITStatus bitstatus = RESET; 5 /* Check the parameters */ 6 assert_param(IS_USART_ALL_PERIPH(USARTx)); 7 assert_param(IS_USART_GET_IT(USART_IT)); 8 9 /* The CTS interrupt is not available for UART4 and UART5 */ 10 if (USART_IT == USART_IT_CTS) 11 { 12 assert_param(IS_USART_1236_PERIPH(USARTx)); 13 } 14 15 /* Get the USART register index */ 16 usartreg = (((uint8_t)USART_IT) >> 0x05); 17 /* Get the interrupt position */ 18 itmask = USART_IT & IT_MASK; 19 itmask = (uint32_t)0x01 << itmask; 20 21 if (usartreg == 0x01) /* The IT is in CR1 register */ 22 { 23 itmask &= USARTx->CR1; 24 } 25 else if (usartreg == 0x02) /* The IT is in CR2 register */ 26 { 27 itmask &= USARTx->CR2; 28 } 29 else /* The IT is in CR3 register */ 30 { 31 itmask &= USARTx->CR3; 32 } 33 34 bitpos = USART_IT >> 0x08; 35 bitpos = (uint32_t)0x01 << bitpos; 36 bitpos &= USARTx->SR; 37 if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET)) 38 { 39 bitstatus = SET; 40 } 41 else 42 { 43 bitstatus = RESET; 44 } 45 46 return bitstatus; 47 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/leo0621/p/8709944.html

總結(jié)

以上是生活随笔為你收集整理的USART_GetITStatus和USART_GetFlagStatus的区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。