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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2604|回復: 1
收起左側

STC89C52 UART程序

[復制鏈接]
ID:162993 發表于 2017-1-26 22:35 | 顯示全部樓層 |閱讀模式
STC89C52UART程序:
1.UartMCUtoPC.zip (24.96 KB, 下載次數: 7)

  1. /*------------------------------------------------------------------*/
  2. /* --- STC MCU Limited ---------------------------------------------*/
  3. /* --- STC89-90xx Series MCU UART (8-bit/9-bit)Demo ----------------*/
  4. /* --- Mobile: (86)13922805190 -------------------------------------*/
  5. /* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
  6. /* --- Tel: 86-0513-55012928,55012929,55012966----------------------*/
  7. /* If you want to use the program or the program referenced in the  */
  8. /* article, please specify in which data and procedures from STC    */
  9. /*------------------------------------------------------------------*/

  10. #include "reg51.h"
  11. #include "intrins.h"

  12. typedef unsigned char BYTE;
  13. typedef unsigned int WORD;

  14. #define FOSC 11059200L      //System frequency
  15. #define BAUD 9600           //UART baudrate

  16. /*Define UART parity mode*/
  17. #define NONE_PARITY     0   //None parity
  18. #define ODD_PARITY      1   //Odd parity
  19. #define EVEN_PARITY     2   //Even parity
  20. #define MARK_PARITY     3   //Mark parity
  21. #define SPACE_PARITY    4   //Space parity

  22. //在此更改模式!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  23. #define PARITYBIT NONE_PARITY   //Testing even parity

  24. sbit bit9 = P2^2;           //P2.2 show UART data bit9
  25. bit busy;

  26. void SendData(BYTE dat);
  27. void SendString(char *s);

  28. void main()
  29. {
  30. #if (PARITYBIT == NONE_PARITY)
  31.     SCON = 0x50;            //8-bit variable UART
  32. #elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY)
  33.     SCON = 0xda;            //9-bit variable UART, parity bit initial to 1
  34. #elif (PARITYBIT == SPACE_PARITY)
  35.     SCON = 0xd2;            //9-bit variable UART, parity bit initial to 0
  36. #endif

  37.     TMOD = 0x20;            //Set Timer1 as 8-bit auto reload mode
  38.     TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule
  39.     TR1 = 1;                //Timer1 start run
  40.     ES = 1;                 //Enable UART interrupt
  41.     EA = 1;                 //Open master interrupt switch

  42.     SendString("Hello 51\n");
  43.     while(1);
  44. }

  45. /*----------------------------
  46. UART interrupt service routine
  47. ----------------------------*/
  48. void Uart_Isr() interrupt 4 using 1
  49. {
  50.     if (RI)
  51.     {
  52.         RI = 0;             //Clear receive interrupt flag
  53.         P0 = SBUF;          //P0 show UART data
  54.         bit9 = RB8;         //P2.2 show parity bit
  55.     }
  56.     if (TI)
  57.     {
  58.         TI = 0;             //Clear transmit interrupt flag
  59.         busy = 0;           //Clear transmit busy flag
  60.     }
  61. }

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

  90. /*----------------------------
  91. Send a string to UART
  92. Input: s (address of string)
  93. Output:None
  94. ----------------------------*/
  95. void SendString(char *s)
  96. {
  97.     while (*s)              //Check the end of the string
  98.     {
  99.         SendData(*s++);     //Send current char and increment string ptr
  100.     }
  101. }

復制代碼


回復

使用道具 舉報

ID:1 發表于 2017-2-12 23:42 | 顯示全部樓層
好資料,51黑有你更精彩!!!
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品亚洲精品 | 羞羞视频在线网站观看 | 亚洲狠狠丁香婷婷综合久久久 | 亚洲一区二区三区欧美 | 国产91在线播放精品91 | 亚洲资源在线 | 免费不卡视频 | 在线播放国产一区二区三区 | 久久国产成人 | 最近日韩中文字幕 | 人干人操 | 日韩一区二区三区在线观看 | 成人av片在线观看 | 欧美日韩综合一区 | 亚洲国产二区 | 韩日一区二区 | 国产精品久久久久久影视 | 欧美一区视频 | 国产伦一区二区三区四区 | 久久九九99 | 欧美精品一区二区三区在线四季 | 伊人伊人伊人 | 国产精品毛片无码 | 99福利网 | 欧美性一区二区三区 | 免费一区在线观看 | 国产精品高潮呻吟久久久久 | 成人免费视频网站在线看 | 国产精品jizz在线观看老狼 | www.久久| 黄色片在线| 国产精品中文字幕在线观看 | 午夜免费视频观看 | 成人欧美一区二区 | 91免费电影 | 久久久综合精品 | 极品电影院 | 亚洲欧美日韩精品久久亚洲区 | 超碰精品在线 | 亚洲精品片 | 亚洲精品国产偷自在线观看 |