標(biāo)題: 單片機(jī)串口通信,上位機(jī)一直接受不到數(shù)據(jù) 求幫助 [打印本頁(yè)]

作者: 51_users    時(shí)間: 2020-11-10 22:37
標(biāo)題: 單片機(jī)串口通信,上位機(jī)一直接受不到數(shù)據(jù) 求幫助
  1. #include <reg52.h>
  2. #include <string.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. void Init()
  6. {
  7.         TMOD=0x20;
  8.         TH1=0xfd;
  9.         TL1=0xfd;
  10.         SCON=0x50;
  11.         EA=1;
  12.         ES=1;
  13.         TR1=1;
  14. }

  15. void delayms(int z)
  16. {
  17.         int i,j;
  18.         for(i=z;i>0;i--)
  19.         for(j=114;j>0;j--);
  20. }

  21. void SendByte(uchar transdata)//發(fā)送字符
  22. {
  23.         SBUF=transdata;        
  24.         while(!TI)
  25.   TI=0;
  26. }

  27. void SendStr(uchar *p)//處理字符串
  28. {
  29.         int i=0;
  30.         while(p[i]!='\0')//運(yùn)用將字符串處理成字符
  31.         {
  32.                 SendByte(p[i]);
  33.                 i++;
  34.         }
  35. }

  36. void SendEnd()
  37. {
  38.         SendByte(0xFF);
  39.         SendByte(0xFF);
  40.         SendByte(0xFF);        
  41. }

  42. void main()
  43. {
  44.                 Init();
  45.         while(1)
  46.         {
  47.                 delayms(500);
  48.                 SendStr("t1.txt=\"Welcome!\"");
  49.                 SendEnd();
  50.         }
  51. }
復(fù)制代碼


這是用于淘晶馳串口屏的接受代碼,上位機(jī)一直接受不到數(shù)據(jù),請(qǐng)教一下大家這個(gè)代碼中存在問(wèn)題嗎???在此謝過(guò)。


作者: wulin    時(shí)間: 2020-11-11 07:36
while(!TI)后面少分號(hào)
void SendByte(uchar transdata)//發(fā)送字符
{
        SBUF=transdata;
        while(!TI);
        TI=0;
}
作者: 51_users    時(shí)間: 2020-11-11 13:59
wulin 發(fā)表于 2020-11-11 07:36
while(!TI)后面少分號(hào)
void SendByte(uchar transdata)//發(fā)送字符
{

十分感謝!。
作者: 壓著我頭發(fā)啦    時(shí)間: 2020-11-11 14:39
編譯時(shí)候沒(méi)報(bào)錯(cuò)么




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1