日本a√视频在线,久久青青亚洲国产,亚洲一区欧美二区,免费g片在线观看网站

        <style id="k3y6c"><u id="k3y6c"></u></style>
        <s id="k3y6c"></s>
        <mark id="k3y6c"></mark>
          
          

          <mark id="k3y6c"></mark>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Atmega32單片機(jī)串口驅(qū)動(dòng)程序

          Atmega32單片機(jī)串口驅(qū)動(dòng)程序

          作者: 時(shí)間:2013-12-12 來(lái)源:網(wǎng)絡(luò) 收藏

          /* ******************************************************************
          * Filename: uart.c
          * Author: lstzixing
          * Mail: blievethink@gmail.com
          * Date: 2009-5-26
          * Description: 串口數(shù)據(jù)收發(fā)接口. For
          * ****************************************************************** */

          #include "app.h"

          // 對(duì)發(fā)送緩沖,信號(hào)計(jì)數(shù)為空閑字符數(shù)
          // 對(duì)接收緩沖,計(jì)數(shù)為緩沖已有計(jì)數(shù)
          typedef struct _FIFO
          {
          INT8U * buf; // FIFO緩沖區(qū)
          INT8U * in, * out; // FIFO讀寫(xiě)指針
          OS_EVENT * sem; // FIFO讀寫(xiě)同步信號(hào)量
          }FIFO;

          static INT8U UartTxBuf[ UART_TX_LEN ]; // 發(fā)送緩沖
          static INT8U UartRxBuf[ UART_RX_LEN ]; // 接收緩沖
          static FIFO UartTxFifo, UartRxFifo; // 收發(fā)緩沖控制FIFO結(jié)構(gòu)

          OS_SEM_DATA SemData;

          static INT8U UartPutRxChar( INT8U c );
          static INT8U UartGetTxChar( INT8U * err );

          #define UartStartTx() { UCSRB |= 1UDRIE; }
          #define UartStopTx() { UCSRB = ~(1UDRIE); }
          #define UartStartRx() { UCSRB |= 1RXCIE; }
          #define UartStopRx() { UCSRB = ~( 1RXCIE ); }
          /* ****************************************************************
          * UartFlush()
          * 功能:緩沖清空
          * 參數(shù): isTxBuf ------ 是否為發(fā)送緩沖
          * 返回值:None
          * 說(shuō)明:清空收發(fā)緩沖
          * *************************************************************** */
          void UartFlush( INT8U isTxBuf )
          {
          #if OS_CRITICAL_METHOD == 3
          OS_CPU_SR cpu_sr;
          #endif
          INT8U cnt;

          OS_ENTER_CRITICAL();

          if( isTxBuf )
          {
          UartTxFifo.buf = UartTxBuf; // 復(fù)位發(fā)送緩沖讀寫(xiě)指針
          UartTxFifo.in = UartTxBuf;
          UartTxFifo.out = UartTxBuf;
          OSSemQuery( UartTxFifo.sem, SemData );
          cnt = UART_TX_LEN - SemData.OSCnt; // 在其它地方必須保證SemData.OSCnt UART_TX_LEN
          while( cnt-- )
          OSSemPost( UartTxFifo.sem ); // 復(fù)位發(fā)送信號(hào)量值為UART_TX_LEN
          }

          else
          {
          UartRxFifo.buf = UartRxBuf; // 復(fù)位接收緩沖讀寫(xiě)指針
          UartRxFifo.in = UartRxBuf;
          UartRxFifo.out = UartRxBuf;
          while( OSSemAccept( UartRxFifo.sem ) ); // 復(fù)位接收信號(hào)量值為0

          }

          OS_EXIT_CRITICAL();
          }

          void UartPutStr( char * str )
          {
          char * ptr;

          ptr = (char *)str;

          while(*ptr != '