当前位置: 首页 > wzjs >正文

贵阳做网站找哪家好抖音seo怎么做

贵阳做网站找哪家好,抖音seo怎么做,成立公司的条件,公司网站管理串口通信像是蓝桥杯单片机组国赛中一个若隐若现的秘境,总在不经意间为勇者们敞开大门。然而,初次探索这片领域的冒险者,常常会被其神秘莫测的特性所震慑,黯然退场(编不下去了,直接进入正题)。 附…

串口通信像是蓝桥杯单片机组国赛中一个若隐若现的秘境,总在不经意间为勇者们敞开大门。然而,初次探索这片领域的冒险者,常常会被其神秘莫测的特性所震慑,黯然退场(编不下去了,直接进入正题)。

附件:第十五届蓝桥杯单片机组国赛(串口部分)(

一、串口三部曲

1.串口初始化

相关原理:速通串口通信

在STC-ISP中按照以下步骤操作即可

在这里插入图片描述

在keil中新建uart.c和uart.h

  • uart.c
#include "uart.h"void Uart1_Init(void)	//9600bps@12.000MHz
{SCON = 0x50;		//8位数据,可变波特率AUXR |= 0x01;		//串口1选择定时器2为波特率发生器AUXR &= 0xFB;		//定时器时钟12T模式T2L = 0xE6;			//设置定时初始值T2H = 0xFF;			//设置定时初始值AUXR |= 0x10;		//定时器2开始计时ES = 1;				//使能串口1中断EA = 1;
}extern char putchar(char ch)
{SBUF = ch;while(!TI);TI = 0;return ch;
}

uart.h

#include <STC15F2K60S2.H>
#include <stdio.h>void Uart1_Init();

2.串口中断

  • main.c
typedef unsigned char u8;pdata u8 uartBuf[10] = {0,0,0,0,0,0,0,0,0,0};
idata u8 uartBufIndex;
idata u8 uartTick;
idata bit uartFlag;void Uart1_Isr(void) interrupt 4
{if(RI){uartFlag = 1;uartTick = 0;uartBuf[uartBufIndex++] = SBUF;RI = 0;}if(uartBufIndex > 10){uartTick = uartFlag = 0;uartBufIndex = 0;memset(uartBuf,0,10);}
}	

3.串口数据处理函数

#include <string.h>
#include <stdio.h>
#include <math.h>void uartProc()
{if(!uartBufIndex) return;if(uartTick >= 10){uartTick = uartFlag = 0;//数据解析memset(uartBuf,0,uartBufIndex);uartBufIndex = 0;}
}void Timer1_Isr(void) interrupt 3
{if(uartFlag) uartTick++;
}

二、串口功能-查询设备状态

在这里插入图片描述

1.memcmpstrcmp

对比接收数据存放数组可以使用memcmp或者strcmp

  • int memcmp(const void *s1, const void *s2, size_t n)
    比较两个内存区域的前 n 个字节。

  • int strcmp(const char *s1, const char *s2)
    比较两个以\0 结尾的字符串,直到遇到第一个不匹配字符或结束符。

2.运动状态设计

定义idata u8 moveState;表示运动状态:
0-空闲 1-等待 2-运行
在这里插入图片描述

3.串口解析"?"

void uartProc()
{if(!uartBufIndex) return;if(uartTick >= 10){uartTick = uartFlag = 0;//串口解析if(strcmp(uartBuf, "?") == 0){if(!moveState)			//空闲状态printf("Idle");else if(moveState == 1) //等待状态printf("Wait");else					//运行状态printf("Busy");}memset(uartBuf,0,uartBufIndex);uartBufIndex = 0;}
}
  • 空闲状态
    在这里插入图片描述
  • 运行状态
    在这里插入图片描述

三、串口功能-查询设备位置

在这里插入图片描述
定义idata u16 currentPoint[2]表示当前位置坐标

void uartProc()
{if(!uartBufIndex) return;if(uartTick >= 10){uartTick = uartFlag = 0;if(strcmp(uartBuf, "?") == 0){if(!moveState)					//空闲状态printf("Idle");else if(moveState == 1) //等待状态printf("Wait");else									  //运行状态printf("Busy");}else if(strcmp(uartBuf, "#") == 0)printf("(%u,%u)",currentPoint[0],currentPoint[1]);memset(uartBuf,0,uartBufIndex);uartBufIndex = 0;}
}

在这里插入图片描述

四、串口功能-设置目的地坐标

在这里插入图片描述
接收坐标,例如(30,40)

数据数组位置uartBufIndex
(uartBuf[0]1
3uartBuf[1]2
0uartBuf[2]3
,uartBuf[3]4
4uartBuf[4]5
0uartBuf[5]6
)uartBuf[6]7
  • 所以判断两个括号只需判断uartBuf[0]uartBuf[uartBufIndex-1]是否为()即可。
  • 然后再将uartBuf[1]uartBuf[uartBufIndex-2]依次取出(用循环,每次循环取出一位),判断是否为数字(0~9),未碰到时,取出的数据是终点坐标的横坐标,用临时变量x保存,碰到,后,取出的数据是终点坐标的纵坐标,用临时变量y保存。
pdata u16 pointOver[2] = {0,0};  //终点坐标
idata bit dateFlag; //串口接收坐标标志位void uartProc()
{if(!uartBufIndex) return;if(uartTick >= 10){uartTick = uartFlag = 0;/*if(strcmp(uartBuf, "#") == 0)printf("(%u,%u)",currentPoint[0],currentPoint[1]);else if(strcmp(uartBuf, "?") == 0){if(!moveState)					//空闲状态printf("Idle");else if(moveState == 1) //等待状态printf("Wait");else									  //运行状态printf("Busy");}*/else if(uartBuf[0] == '(' && uartBuf[uartBufIndex-1] == ')'){idata u16 x = 0, y = 0;idata bit parse = 0; //解析标志位 0-解析x 1-解析yidata bit useful = 0;//收到的坐标是否有效 0-有效 1-无效idata u8 i;for(i = 1; i < uartBufIndex - 1; i++){u8 ch = uartBuf[i];if(ch >= '0' && ch <= '9')!parse ? (x = x * 10 + ch - '0') : (y = y * 10 + ch - '0');else if(ch == ',')parse = 1;else//接收到无效数据{useful = 1;//收到的坐标无效break;//直接退出循环}}if(!useful)//数据有效时才保存坐标{pointOver[0] = x;pointOver[1] = y;dateFlag = 1; //收到目的地坐标if(!moveState)printf("Got it");elseprintf("Busy");}}elseprintf("Error");memset(uartBuf,0,uartBufIndex);uartBufIndex = 0;}
}
http://www.dtcms.com/wzjs/334439.html

相关文章:

  • b2b电子商务购物网站网络广告电话
  • 对于网站建设的提问云南百度推广开户
  • 开封做网站公司汉狮网站收录网
  • 上海做网站公司有哪些app推广是做什么的
  • 网站开发进度控制计划表百度网址提交
  • 做采购应该关注的网站网站推广搜索
  • 做mla网站网站建站在线制作
  • 上海十大网站建设世界球队最新排名榜
  • 怎么在建筑网站做翻译兼职磁力搜索引擎
  • wordpress 自学郑州seo技术
  • php网站开发淮安招聘郑州网站推广
  • wordpress网站速度慢seo推广岗位职责
  • 网站建设惠州网站策划书
  • 网站优化排名易下拉系统百度seo网站优化 网络服务
  • 网站建设的结论做网站
  • 新冠疫苗最新官方消息seo专员很难吗
  • 怎么做快递网站的分点产品市场推广方案
  • 域名注册好了怎么了做网站google chrome浏览器
  • 国际购物网站网站优化推广
  • 网站keyword如何排列最近的新闻大事
  • 网站维护兼职关键词查询工具哪个好
  • 建设直销团队网站网络营销岗位有哪些
  • 好的做淘宝详情页的网站有哪些内容上海sem
  • 成都医院手机网站建设哪里有网页设计公司
  • 做系统前怎么保存网站上的收藏百度全网营销
  • 1688黄页网济南seo排名优化推广
  • 日照网站优化搜索关键词的工具
  • 做有网被视频网站吗有哪些网络推广平台
  • 网站安全评估怎么做山东企业网站建设
  • 百度网盟 网站定向百度不收录网站怎么办