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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4236|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

為什么我在串口發(fā)送1,但是串口接收為82(都是HEX模式)或者為B2(發(fā)送為文本模式)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:71099 發(fā)表于 2016-6-24 09:57 | 只看該作者 回帖獎勵 |倒序?yàn)g覽 |閱讀模式
  1. /**********************************************************
  2. STC12C5204       
  3. 串口工作方式        :        方式1        8位UART
  4. 定時(shí)器的選取        :        T1
  5. 定時(shí)器工作方式        :        方式2
  6. 波特率選取                :        9600

  7. **********************************************************/

  8. #include "reg51.h"
  9. #include "intrins.h"

  10. typedef unsigned char BYTE;
  11. typedef unsigned int WORD;

  12. bit busy;
  13. BYTE        temp=0;
  14. BYTE        flag=0;

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

  17. void main()
  18. {
  19.         SCON = 0x50;                        //方式1
  20.     TMOD = 0x20;                        //8位自動重裝載定時(shí)/計(jì)數(shù)器
  21.     TH1 = TL1 = 0xfd;                //9600
  22.     TR1 = 1;               
  23.     ES = 1;                 
  24.     EA = 1;                 
  25.     while(1)
  26.         {
  27.                 if(flag)
  28.                 {
  29.                         flag=0;
  30.                         SendData(temp+1);
  31.                 }
  32.         }
  33. }

  34. /*----------------------------
  35. UART interrupt service routine
  36. ----------------------------*/
  37. void Uart_Isr() interrupt 4 using 1
  38. {
  39.     if (RI)
  40.     {
  41.         RI = 0;             //Clear receive interrupt flag
  42.         temp = SBUF;          //P0 show UART data
  43.                 flag=1;
  44.     }
  45.     if (TI)
  46.     {
  47.         TI = 0;             //Clear transmit interrupt flag
  48.         busy = 0;           //Clear transmit busy flag
  49.     }
  50. }

  51. /*----------------------------
  52. Send a byte data to UART
  53. Input: dat (data to be sent)
  54. Output:None
  55. ----------------------------*/
  56. void SendData(BYTE dat)
  57. {
  58.     while (busy);           //Wait for the completion of the previous data is sent
  59.     busy = 1;
  60.     SBUF = dat;             //Send data to UART buffer
  61. }

  62. /*----------------------------
  63. Send a string to UART
  64. Input: s (address of string)
  65. Output:None
  66. ----------------------------*/
  67. void SendString(char *s)
  68. {
  69.     while (*s)              //Check the end of the string
  70.     {
  71.         SendData(*s++);     //Send current char and increment string ptr
  72.     }
  73. }
復(fù)制代碼


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

使用道具 舉報(bào)

沙發(fā)
ID:118380 發(fā)表于 2016-6-24 19:27 | 只看該作者
  1. /**********************************************************
  2. STC12C5204        
  3. 串口工作方式        :        方式1        8位UART
  4. 定時(shí)器的選取        :        T1
  5. 定時(shí)器工作方式        :        方式2
  6. 波特率選取                :        9600

  7. **********************************************************/

  8. #include "reg51.h"
  9. #include "intrins.h"

  10. typedef unsigned char BYTE;
  11. typedef unsigned int WORD;

  12. bit busy;
  13. BYTE        temp=0;
  14. BYTE        flag=0;

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

  17. void main()
  18. {
  19.         SCON = 0x50;                        //方式1
  20.     TMOD = 0x20;                        //8位自動重裝載定時(shí)/計(jì)數(shù)器
  21.     TH1 = TL1 = 0xfd;                //9600
  22.     TR1 = 1;               
  23.     ES = 1;                 
  24.     EA = 1;                 
  25.     while(1)
  26.         {
  27.                 if(flag)
  28.                 {
  29.                         flag=0;
  30.                         SendData(temp+1);
  31.                 }
  32.         }
  33. }

  34. /*----------------------------
  35. UART interrupt service routine
  36. ----------------------------*/
  37. void Uart_Isr() interrupt 4 using 1
  38. {
  39.     if (RI)
  40.     {
  41.         RI = 0;             //Clear receive interrupt flag
  42.         temp = SBUF;          //P0 show UART data
  43.                 flag=1;
  44.     }
  45. //    if (TI)
  46. //    {
  47. //        TI = 0;             //Clear transmit interrupt flag
  48. //        busy = 0;           //Clear transmit busy flag
  49. //    }
  50. }

  51. /*----------------------------
  52. Send a byte data to UART
  53. Input: dat (data to be sent)
  54. Output:None
  55. ----------------------------*/
  56. void SendData(BYTE dat)
  57. {
  58.     while (flag);           //Wait for the completion of the previous data is sent
  59.    
  60.     SBUF = dat;  
  61. while(!TI);
  62. TI=0;        //Send data to UART buffer
  63. }

  64. /*----------------------------
  65. Send a string to UART
  66. Input: s (address of string)
  67. Output:None
  68. ----------------------------*/
  69. void SendString(char *s)
  70. {
  71.     while (*s)              //Check the end of the string
  72.     {
  73.         SendData(*s++);     //Send current char and increment string ptr
  74.     }
  75. }
復(fù)制代碼

改了一下,可以實(shí)現(xiàn)發(fā)送1,返回2
回復(fù)

使用道具 舉報(bào)

板凳
ID:101595 發(fā)表于 2016-6-25 23:32 來自觸屏版 | 只看該作者
dpj蝸牛 發(fā)表于 2016-6-24 19:27
改了一下,可以實(shí)現(xiàn)發(fā)送1,返回2

一個簡單的程序?yàn)槭裁匆獙戇@么復(fù)雜,
回復(fù)

使用道具 舉報(bào)

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

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 日日碰碰 | 91在线精品视频 | 国产成人精品一区二 | 国产免费av在线 | 视频1区| 欧美在线成人影院 | 亚洲精品自在在线观看 | 精品一区二区三区在线观看国产 | 亚洲国产一区二区三区四区 | 伊人伊人| 污视频免费在线观看 | 91在线精品秘密一区二区 | 一级看片免费视频囗交动图 | 久久综合久久久 | 在线视频国产一区 | 日韩视频一区二区三区 | 亚洲免费一区二区 | 一级黄色在线 | 日韩超碰在线 | 日韩欧美在线视频 | 精品一区二区三区在线观看国产 | 亚洲精品丝袜日韩 | 亚洲一区二区视频 | 色综合99 | 波多野结衣亚洲 | 在线观看中文字幕 | 成人在线中文 | 免费网站在线 | 亚洲国产一区二区三区 | 国产精品永久久久久久久www | 国产美女自拍视频 | 欧美日韩在线一区二区 | 国产精品久久久久不卡 | 一区二区三区精品在线 | 久久久一区二区 | 91免费视频 | 久久成人精品视频 | 成人免费区一区二区三区 | 91精品国产综合久久久久久丝袜 | 日韩欧美在线免费观看 | 日韩欧美在 |