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

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

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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > PIC196F877A串口通信程序

          PIC196F877A串口通信程序

          作者: 時間:2016-11-19 來源:網(wǎng)絡 收藏
          今天上午完成PIC16F877A與上位機的串口通信程序!

          注意:使用MPLAB IDE C語言編程時,自定義頭文件要使用""包含不能使用<>

          本文引用地址:http://yuyingmama.com.cn/article/201611/318568.htm

          串口與單片機的連線原理圖

          串口通信頭文件

          #ifndef T232_H
          #define T232_H

          #include "main.h"
          //定義一幀的開始和結束
          #define FRAME_BEGIN 0x28//開始幀標志
          #define FRAME_END 0x29//結束幀標志

          void init_232() ;
          void send_str(const char *str) ;
          char get_char() ;
          void get_string(char *temp) ;
          void put_char(char temp) ;
          #endif

          串行通信子程序


          //基于TPDEM1,通過串口調(diào)試助手等串口觀察軟件觀察程序,
          //將TPDEM1通過ICD2配送的串口延長線與PC的串口連接,設置PC的串口為默認設置,如波特率9600,數(shù)據(jù)位8,無校驗位,使用FIFO
          #include "t232.h"
          /*
          *Function:init seriel port
          */
          void init_232()
          {
          INTCON=0;
          TRISC7=1; //RX置輸入
          TRISC6=0; //TX清成輸出
          RCSTA=0x90;//連續(xù)接受多位數(shù)據(jù)
          TXSTA=0x24;
          SPBRG=25; //9600=4000000/(16*(X+1))->X=25,high speed mode
          // INTCON=0xC0;//開GIE,外圍中斷PEIE
          //RCIE=1; //開接收中斷
          }
          /*
          *Fuction :send const string to seriel port
          /

          void send_str(const char *p)
          {
          while((*p)!=/0)
          {
          put_char(*p++) ;
          }
          }
          /
          Function:get charactor from serial port
          */
          char get_char()
          {
          char temp ;
          while(!RCIF) ; /* set when register is not empty */
          temp = RCREG ;
          return RCREG; /* RXD9 and FERR are gone now */
          }

          /*
          *Function:send charactot to serial port
          /
          void put_char(char temp)
          {
          TXREG=temp ;
          while(TRMT==0) ;
          }

          /*
          *Function:get num bytes charactot
          /
          void get_string(char *t)
          {
          uchar i ;
          char temp ;

          //有可能接受一幀數(shù)據(jù)后因為去處理數(shù)據(jù),導致接受下一幀數(shù)據(jù)失敗
          SPEN=1 ;//必須注意在連續(xù)接受完一幀數(shù)據(jù)時,一定要把這兩位使能,
          CREN=1 ;//我就是因為沒有使能查了一上午的錯,在找出錯誤所在;
          while(1)
          {
          temp=get_char() ;
          if(temp==FRAME_BEGIN)
          {
          i=0 ;
          continue ;
          }
          if(temp==FRAME_END)
          {
          t[i]=/0 ;
          break ;
          }
          t[i++]=temp ;
          }
          }



          關鍵詞: PIC196F877A串口通

          評論


          技術專區(qū)

          關閉