久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2773|回復: 0
打印 上一主題 下一主題
收起左側

51單片機WIFI通信發(fā)射機源碼

[復制鏈接]
跳轉到指定樓層
樓主
ID:349440 發(fā)表于 2018-6-11 14:26 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式


單片機源程序如下:
  1. #include "reg51.h"
  2. #include "intrins.h"
  3. #include "timer0.h"

  4. typedef unsigned char BYTE;
  5. typedef unsigned int WORD;

  6. #define FOSC 11059200L      //System frequency  系統(tǒng)頻率
  7. #define BAUD 9600           //UART baudrate     UART波特率

  8. /*Define UART parity mode*/
  9. #define NONE_PARITY     0   //None parity       無奇偶校驗
  10. #define ODD_PARITY      1   //Odd parity        奇校驗
  11. #define EVEN_PARITY     2   //Even parity       偶校驗
  12. #define MARK_PARITY     3   //Mark parity       校驗位始終為1
  13. #define SPACE_PARITY    4   //Space parity      校驗位始終為0

  14. #define PARITYBIT NONE_PARITY   //Testing even parity      偶校驗測試
  15.         
  16. bit busy;

  17. void SendData(BYTE dat);
  18. void SendString(char *s);
  19. void Delay500ms()                //@11.0592MHz
  20. {
  21.         unsigned char i, j, k;

  22.         _nop_();
  23.         i = 4;
  24.         j = 129;
  25.         k = 119;
  26.         do
  27.         {
  28.                 do
  29.                 {
  30.                         while (--k);
  31.                 } while (--j);
  32.         } while (--i);
  33. }
  34. void main()
  35. {
  36. #if (PARITYBIT == NONE_PARITY)
  37.     SCON = 0x50;            //8-bit variable UART(8位變量的UART)
  38. #elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY)
  39.     SCON = 0xda;            //9-bit variable UART, parity bit initial to 1(9位變量的UART,奇偶位初始值為1)
  40. #elif (PARITYBIT == SPACE_PARITY)
  41.     SCON = 0xd2;            //9-bit variable UART, parity bit initial to 0(9位變量的UART,奇偶位初始值為0)
  42. #endif

  43.     TMOD = 0x20;            //Set Timer1 as 8-bit auto reload mode(設置定時器18位自動重載模式)
  44.     TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule(設置自動加載值)
  45.     TR1 = 1;                //Timer1 start run(打開定時器1)
  46.     ES = 1;                 //Enable UART interrupt(開UART中斷)
  47.     EA = 1;                 //Open master interrupt switch(開主中斷開關)

  48.     while(1)
  49.         {
  50.                 Delay500ms();
  51.                 SendString("1");  
  52.         }
  53. }

  54. /*----------------------------
  55. UART interrupt service routine(中斷服務程序)
  56. ----------------------------*/
  57. void Uart_Isr() interrupt 4 using 1
  58. {
  59.     if (RI)
  60.     {
  61.         RI = 0;             //Clear receive interrupt flag(清除接收中斷標志)
  62. //        P0 = SBUF;          //P0 show UART data
  63.     }
  64.     if (TI)
  65.     {
  66.         TI = 0;             //Clear transmit interrupt flag(清除傳輸中斷標志)
  67.         busy = 0;           //Clear transmit busy flag(清除傳輸繁忙標志)
  68.     }
  69. }

  70. /*----------------------------
  71. Send a byte data to UART     將字節(jié)數(shù)據(jù)發(fā)送到UATR
  72. Input: dat (data to be sent)   輸入:dat(要發(fā)送的數(shù)據(jù))
  73. Output:None                    輸出:無
  74. ----------------------------*/
  75. void SendData(BYTE dat)
  76. {
  77.     while (busy);           //Wait for the completion of the previous data is sent  等待前一個數(shù)據(jù)完成發(fā)送
  78.     ACC = dat;              //Calculate the even parity bit P (PSW.0)        計算奇偶校驗位P(PSW.0)
  79.     if (P)                  //Set the parity bit according to P              根據(jù)P設置奇偶校驗位
  80.     {
  81. #if (PARITYBIT == ODD_PARITY)
  82.         TB8 = 0;            //Set parity bit to 0               將奇偶校驗位設置為0
  83. #elif (PARITYBIT == EVEN_PARITY)
  84.         TB8 = 1;            //Set parity bit to 1               將奇偶校驗位設置為1
  85. #endif
  86.     }
  87.     else
  88.     {
  89. #if (PARITYBIT == ODD_PARITY)
  90.         TB8 = 1;            //Set parity bit to 1               將奇偶校驗位設置為1
  91. #elif (PARITYBIT == EVEN_PARITY)
  92.         TB8 = 0;            //Set parity bit to 0               將奇偶校驗位設置為0
  93. #endif
  94.     }
  95.     busy = 1;
  96.     SBUF = ACC;             //Send data to UART buffer          發(fā)送數(shù)據(jù)到UART緩沖區(qū)
  97. }

  98. /*----------------------------
  99. Send a string to UART            發(fā)送字符串到UART
  100. Input: s (address of string)     輸入:s(字符串抵地址)
  101. Output:None                      輸出:無
  102. ----------------------------*/
  103. void SendString(char *s)
  104. {
  105.     while (*s)              //Check the end of the string         檢查字符串結尾
  106.     {
  107.         SendData(*s++);     //Send current char and increment string ptr   發(fā)送當前字符和字符串指針增量
  108.     }
  109. }

復制代碼

所有資料51hei提供下載:
發(fā)射機.zip (29.7 KB, 下載次數(shù): 21)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 午夜视频一区二区三区 | 成人精品久久久 | 欧美一级免费看 | 精品国产一区二区三区免费 | 精品国产乱码久久久久久闺蜜 | h片在线看 | 欧美一级片| 日韩视频中文字幕 | www.青青草 | 亚洲精品在线观看视频 | 国产二区三区 | 国产在线一级片 | 午夜电影福利 | 国产精品久久久久久久久久久新郎 | 久久久www成人免费精品张筱雨 | 亚洲成人一区二区在线 | 欧美一级黄色免费 | 亚洲一区二区三区四区五区午夜 | 久久精品16 | 欧美日韩精品在线免费观看 | 老头搡老女人毛片视频在线看 | 日韩视频1 | 91精品国产综合久久久动漫日韩 | 亚洲免费精品 | 超碰在线亚洲 | 成人精品国产免费网站 | 亚洲小视频在线播放 | 日韩视频在线观看 | 97国产在线视频 | 精品中文字幕在线观看 | 久久精品99国产精品 | 在线观看日韩 | 91视频在线| 久久国产精品偷 | 中文字幕一区在线观看视频 | 亚洲欧美视频 | 日韩在线观看精品 | 午夜精品福利视频 | 久久精品日产第一区二区三区 | 开操网| 欧美久久一区二区 |