• 串口发送字符串到串口软件


    /*发送函数*/
    #include <reg52.h>
    #define uchar unsigned char
    #define uint unsigned int
    uchar Mydata[10]={'q','w','e','r','t','y'};
    //sbit KEY=P1^0;
    void InitUART(void)
    {
        TMOD = 0x20;    //定时器
        SCON = 0x50;    //串口
        TH1 = 0xF3;
        TL1 = TH1;
        PCON = 0x80;
        EA = 1;
        ES = 1;
        TR1 = 1;
    }
     
    void SendOneByte(uchar Onedata)     //发送
    {
        SBUF = Onedata;
        while(TI==0);
        TI = 0;
    }
    void Delay()
    {
     uint i,j;
     for(i=0;i<10;i++)
      for(j=0;j<12500;j++);
    }
     
    void main(void)
    {
     uint i;
     P2=0xff;
        InitUART();
     Delay();      //延时一会,让硬件就位,如果不延时,不成功
     while(1)
     {
      for(i=0;i<sizeof(Mydata);i++)
      { 
       P2=0x00;
       SendOneByte(Mydata[i]);
      }
      Delay();
      P2=0xff;
      Delay();
     }
    }

    //注意,4800波特率

  • 相关阅读:
    java 常用
    面试题目总结
    前端自动化构建工具gulp记录
    js面向对象学习笔记
    sass,compass学习笔记总结
    JS核心知识点:DOMBOMEVENT
    boost atomic
    boost thread
    boost function bind ref
    boost phoenix
  • 原文地址:https://www.cnblogs.com/judes/p/5695778.html
Copyright © 2020-2023  润新知