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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3244|回復: 0
收起左側

51單片機串口庫文件com.h頭文件,使用方便,添加即用

[復制鏈接]
ID:254411 發表于 2021-10-2 12:19 | 顯示全部樓層 |閱讀模式
c51串口庫文件,使用方便,添加即用。
單片機源程序如下:
  1. #include "reg51.h"
  2. #include "intrins.h"

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

  5. #define FOSC 11059200L      //System frequency
  6. #define BAUD 9600           //UART baudrate

  7. /*Define UART parity mode*/
  8. #define NONE_PARITY     0   //None parity
  9. #define ODD_PARITY      1   //Odd parity
  10. #define EVEN_PARITY     2   //Even parity
  11. #define MARK_PARITY     3   //Mark parity
  12. #define SPACE_PARITY    4   //Space parity

  13. #define PARITYBIT NONE_PARITY //EVEN_PARITY   //Testing even parity

  14. //yy sbit bit9 = P2^2;           //P2.2 show UART data bit9
  15. bit busy;

  16. void SendData(BYTE dat);
  17. void SendString(char *s);

  18. void InitCom()
  19. {
  20. #if (PARITYBIT ==NONE_PARITY )
  21.     SCON = 0x50;            //8-bit variable UART
  22. #elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY)
  23.     SCON = 0xda;            //9-bit variable UART, parity bit initial to 1
  24. #elif (PARITYBIT == SPACE_PARITY)
  25.     SCON = 0xd2;            //9-bit variable UART, parity bit initial to 0
  26. #endif

  27.     TMOD = 0x20;            //Set Timer1 as 8-bit auto reload mode
  28.     TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule
  29.     TR1 = 1;                //Timer1 start run
  30.     ES = 1;                 //Enable UART interrupt
  31.     EA = 1;                 //Open master interrupt switch

  32.     SendString("yySTC12C5A60S2\r\nUart Test !\r\n");
  33.            SendData(0x31);
  34.     while(1);
  35. }

  36. /*----------------------------
  37. UART interrupt service routine
  38. ----------------------------*/
  39. void Uart_Isr() interrupt 4 using 1
  40. {
  41.     if (RI)
  42.     {
  43.         RI = 0;             //Clear receive interrupt flag
  44.         P0 = SBUF;          //P0 show UART data
  45. //yy        bit9 = RB8;         //P2.2 show parity bit
  46.     }
  47.     if (TI)
  48.     {
  49.         TI = 0;             //Clear transmit interrupt flag
  50.         busy = 0;           //Clear transmit busy flag
  51.     }
  52. }

  53. /*----------------------------
  54. Send a byte data to UART
  55. Input: dat (data to be sent)
  56. Output:None
  57. ----------------------------*/
  58. void SendData(BYTE dat)
  59. {
  60.     while (busy);           //Wait for the completion of the previous data is sent
  61.     ACC = dat;              //Calculate the even parity bit P (PSW.0)
  62.     if (P)                  //Set the parity bit according to P
  63.     {
  64. #if (PARITYBIT == ODD_PARITY)
  65.         TB8 = 0;            //Set parity bit to 0
  66. #elif (PARITYBIT == EVEN_PARITY)
  67.         TB8 = 1;            //Set parity bit to 1
  68. #endif
  69.     }
  70.     else
  71.     {
  72. #if (PARITYBIT == ODD_PARITY)
  73.         TB8 = 1;            //Set parity bit to 1
  74. #elif (PARITYBIT == EVEN_PARITY)
  75.         TB8 = 0;            //Set parity bit to 0
  76. #endif
  77.     }
  78.     busy = 1;
  79.     SBUF = ACC;             //Send data to UART buffer
  80. }

  81. /*----------------------------
  82. Send a string to UART
  83. Input: s (address of string)
  84. Output:None
  85. ----------------------------*/
  86. void SendString(char *s)
  87. {
  88.     while (*s)              //Check the end of the string
  89.     {
  90.         SendData(*s++);     //Send current char and increment string ptr
  91.     }
  92. }
復制代碼

51hei.png

以上文件下載,.h格式文檔下載(內容和本網頁上的一模一樣,方便保存)::
Com.rar (1.34 KB, 下載次數: 18)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 7777久久 | 国产精品一区二区视频 | 日本一二三区电影 | 中文成人在线 | 福利社午夜影院 | 欧美成人激情 | 国产一区影院 | 中文字幕免费中文 | 国产午夜精品一区二区三区嫩草 | 国产亚洲精品久久久优势 | 日韩久久网 | 国产精品成av人在线视午夜片 | 欧美激情综合色综合啪啪五月 | 一级做a爰片性色毛片16美国 | 精品少妇一区二区三区日产乱码 | 久久一二| 爱草视频 | 色综合久久久 | 日韩专区中文字幕 | 男女羞羞视频在线看 | 国产精品一区二区三区久久 | av一二三区 | av手机免费在线观看 | 亚洲精品中文字幕在线观看 | 欧美日韩高清一区 | 久久成人国产精品 | 免费国产视频 | 黄网站在线观看 | 中文字幕 视频一区 | 久久精品国产a三级三级三级 | 国产不卡视频 | 国产一区在线免费观看视频 | 日韩色图在线观看 | 欧美日韩久久久久 | 亚洲视频一区 | 国产精品美女久久久久久久网站 | 99热最新| 亚洲一区二区视频 | 久久久国产精品入口麻豆 | 成人国产一区二区三区精品麻豆 | 亚洲欧美久久 |