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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

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

[復制鏈接]
跳轉到指定樓層
樓主
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. }
復制代碼



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

評分

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

查看全部評分

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

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久精品视频一区二区 | 91.xxx.高清在线 | 亚洲精品免费视频 | 久草精品视频 | 欧美在线高清 | 日韩三级在线 | 黄色毛片在线看 | 国产成人一区二区三区电影 | 午夜极品 | 欧美日一区二区 | 国产福利在线 | 99热视| 免费在线观看黄视频 | 超碰地址 | 欧美精品一区免费 | 91精品国产综合久久小仙女图片 | 亚洲a视| 国产精品久久久久久av公交车 | 国产精品视频免费看 | 成年人视频在线免费观看 | 中文字幕99 | 盗摄精品av一区二区三区 | 91亚洲国产成人久久精品网站 | 久久久一二三区 | 天天操夜夜操 | 日韩精品一区二区三区视频播放 | 成人av网站在线观看 | 4hu最新网址 | 欧美一区二区三区大片 | 男人的天堂在线视频 | 97超碰成人 | 国产精品一二三区 | 久久久免费在线观看 | 日日操视频 | 日韩精品免费视频 | 91天堂网| 婷婷桃色网 | 三级成人在线 | 国产成人精品一区二区三区 | 日韩欧美成人一区二区三区 | 国产精品日韩欧美 |