STC51单片机串口发送程序

news/2024/8/26 14:22:56

#include<reg52.h>   
#define uchar unsigned char   
unsigned char rtemp,sflag;
unsigned char code Buffer[] = "Welcome To The MCU World."; //所要发送的数据
unsigned char *p;  


unsigned char TestBuff[3];


unsigned char mode=0;


unsigned char ArrayIndex=0;


void SerialInit()   //11.0592M晶振,波特率19200   
{  
    TMOD=0x20;  //设置定时器1工作方式为方式2   
    TH1=0xfd;  
    TL1=0xfd;  
    TR1=1;      //启动定时器1   
  
    SM0=0;      //串口方式1   
    SM1=1;  
    REN=1;      //允许接收   
    PCON=0x80;  //关倍频   
    ES=1;       //开串口中断   
    EA=1;       //开总中断   



void SerialSend(unsigned char temp)
{  
ES=0;   //发送期间关闭串口中断     
    SBUF=temp;  
    while(!TI);  
    TI=0;  
    ES=1;   //发送完成开串口中断   

 
void SerialService() interrupt 4  
{  
    if(RI==1)  
    {  
        RI=0;  
if(mode==0)
{//如果处于通的测试模式
        TestBuff[ArrayIndex]=SBUF; //读缓冲区 
ArrayIndex++;
}  
      if(ArrayIndex==3)
{
sflag=1; 
}
    }  
}  


void main(void)  
{  
    SerialInit();  
p = Buffer;
while(*p != '\0')
{
SerialSend(*p); 
p++;
}


ArrayIndex=0;


    while(sflag)  
    {  
p = TestBuff;
while(*p != '\0')
{
SerialSend(*p); 
p++;
}
sflag=0;
    }     
}


http://www.niftyadmin.cn/n/2610683.html

相关文章

ZooKeeper源码分析-Jute-第二部分

数据类型和流 本部分描述支持Hadoop的基础数据类型以及复合类型。我们的目的是支持一系列的类型&#xff0c;可以用于在不同的编程语言中简化和有效表达一定范围的记录类型. 基础类型 大部分情况下&#xff0c;Hadoop的大部分基础类型直接映射到高级编程语言的基础类型。特殊的…

python写spark_使用Python的Spark:将RDD输出保存到文本文件中

我正在使用 python尝试使用spark计算单词计数问题.但是当我尝试使用.saveAsTextFile命令将输出RDD保存在文本文件中时,我遇到了问题.这是我的代码.请帮我.我被卡住了.感谢您的时间. import re from pyspark import SparkConf , SparkContext def normalizewords(text): return …

mysql中使用limit 分页

&#xfeff;&#xfeff;一、mysql中limit语法 SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset 二、mysql中limit分页说明 1、LIMIT接受一个或两个数字参数。 2、参数必须是一个整数常量 3、如果给定两个参数&#xff0c;第一个参数指定返回记录行的偏移量…

还叫你爸爸

一家人去云南丽江 大理 在回旅馆楼梯上 儿子忧伤的说 等我长大了 你就变老了 爸爸 到时候 我还叫你爸爸

python程序片段编程题_基本编程题 --python

基本编程题 --python 1、让Python帮你随机选一个饮品吧&#xff01; import random ​ listC [加多宝, 雪碧, 可乐, 勇闯天涯, 椰子汁] print(random.choices(listC), type(random.choices(listC))) # choices函数返回列表类型数据 print(random.choice(listC), type(random.c…

jQuery中height()、innerheight()、outerheight()有什么不同

&#xfeff;&#xfeff;一、jQuery 中 height() 获取匹配元素集合中的第一个元素的当前计算高度值&#xff0c;总是返回内容宽度 二、jQuery 中 innerheight() 包括padding&#xff0c;但是不包括border&#xff0c;即&#xff1a; height padding 三、jQuery 中 outerhei…

jquery如何遍历json字符串

对JSON字符串的遍历 var json [{"id":"1","tagName":"apple"},{"id":"2","tagName":"orange"}, {"id":"3","tagName":"banana"},{"id":…

python 3.6 + numpy + matplotlib + opencv + scipy 安装

首先&#xff0c;下载并安装 python3.6&#xff1b; 然后&#xff0c;在网址http://www.lfd.uci.edu/~gohlke/pythonlibs/ 上 分别下载 numpy、scipy、matplotlib、opencv 的安装包&#xff0c;可以看到包与包之间的依赖关系&#xff0c;以matplotlib为例&#xff0c;matplotli…