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

中间商网站怎么做搜狗网页版

中间商网站怎么做,搜狗网页版,wordpress把logo变大,网站的风格设计【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing 163.com】 前面学习103和407的时候,当时学过串口的收发。不过当时使用的主要是阻塞的方式。这一次,我们看下应该怎么利用中断的形式进…

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

        前面学习103和407的时候,当时学过串口的收发。不过当时使用的主要是阻塞的方式。这一次,我们看下应该怎么利用中断的形式进行数据的收发。不仅如此,我们还可以看下,怎么把收到的数据放在一起,当成一个完整的命令去处理。

1、基本串口信息定义

        这边的串口主要还是利用a9、a10来实现数据的收发,其中a9负责数据的发送,a10负责数据的接收。除此之外,数据是采用中断的形式进行处理的。

#define DEBUG_USART                             USART1
#define DEBUG_USART_CLK_ENABLE()                __USART1_CLK_ENABLE();#define DEBUG_USART_RX_GPIO_PORT                GPIOA
#define DEBUG_USART_RX_GPIO_CLK_ENABLE()        __HAL_RCC_GPIOA_CLK_ENABLE()
#define DEBUG_USART_RX_PIN                      GPIO_PIN_10
#define DEBUG_USART_RX_AF                       GPIO_AF7_USART1#define DEBUG_USART_TX_GPIO_PORT                GPIOA
#define DEBUG_USART_TX_GPIO_CLK_ENABLE()        __HAL_RCC_GPIOA_CLK_ENABLE()
#define DEBUG_USART_TX_PIN                      GPIO_PIN_9
#define DEBUG_USART_TX_AF                       GPIO_AF7_USART1#define DEBUG_USART_IRQHandler                  USART1_IRQHandler
#define DEBUG_USART_IRQ                 		USART1_IRQn

2、串口的初始化

        串口的初始化这边基本上就是八股文,基本上按照套路下就可以了。一般就是配置时钟、配置gpio、配置uart、配置中断。对于我们来说,最重要的baudrate,也就是波特率,就是在这里配置的。

void DEBUG_USART_Config(void)
{GPIO_InitTypeDef GPIO_InitStruct;RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit;DEBUG_USART_RX_GPIO_CLK_ENABLE();DEBUG_USART_TX_GPIO_CLK_ENABLE();RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;RCC_PeriphClkInit.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2;HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit);DEBUG_USART_CLK_ENABLE();GPIO_InitStruct.Pin = DEBUG_USART_TX_PIN;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_PULLUP;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;GPIO_InitStruct.Alternate = DEBUG_USART_TX_AF;HAL_GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStruct);GPIO_InitStruct.Pin = DEBUG_USART_RX_PIN;GPIO_InitStruct.Alternate = DEBUG_USART_RX_AF;HAL_GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStruct); UartHandle.Instance = DEBUG_USART;UartHandle.Init.BaudRate = 115200;UartHandle.Init.WordLength = UART_WORDLENGTH_8B;UartHandle.Init.StopBits = UART_STOPBITS_1;UartHandle.Init.Parity = UART_PARITY_NONE;UartHandle.Init.Mode = UART_MODE_TX_RX;UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;UartHandle.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED;UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;HAL_UART_Init(&UartHandle);HAL_NVIC_SetPriority(DEBUG_USART_IRQ, 0, 0);HAL_NVIC_EnableIRQ(DEBUG_USART_IRQ);__HAL_UART_ENABLE_IT(&UartHandle,UART_IT_RXNE);  
}

3、函数重定向

        对于喜欢用getchar、printf进行数据收发的同学,一般还需要实现一下fputc、fgetc这两个函数。实现了这两个函数,后续就可以使用getchar和printf了。

void Usart_SendString(uint8_t *str)
{unsigned int k=0;do {HAL_UART_Transmit( &UartHandle,(uint8_t *)(str + k) ,1,1000);k++;} while(*(str + k)!='\0');}int fputc(int ch, FILE *f)
{HAL_UART_Transmit(&UartHandle, (uint8_t *)&ch, 1, 1000);	return (ch);
}int fgetc(FILE *f)
{	int ch;HAL_UART_Receive(&UartHandle, (uint8_t *)&ch, 1, 1000);	return (ch);
}

4、中断处理

        配置好了uart属性部分,下面就是中断处理。这里中断是一个数据、一个数据进行接收的,实际处理的时候,一般是进入中断之后循环接收数据,直到没有新的数据收到为止。

extern uint8_t Rxflag;
extern uint8_t ucTemp;void DEBUG_USART_IRQHandler(void)
{if(__HAL_UART_GET_IT( &UartHandle, UART_IT_RXNE ) != RESET){		Rxflag=1;		HAL_UART_Receive(&UartHandle, (uint8_t *)&ucTemp, 1, 1000);        }HAL_UART_IRQHandler(&UartHandle);	  
}

        代码中Rxflag是标志位,ucTemp代表实际接收到的数据。

5、接收数据实际处理

        单个接收到的数据一般是没有办法直接处理的,通常都是收集到一块来处理。处理结束的标志一般就是回车换行符,或者是某个特殊的标志也可以的。

	while (1){if(Rxflag){if (usRxCount < sizeof(ucaRxBuf)){ucaRxBuf[usRxCount++] = ucTemp;}else{usRxCount = 0;}if (ucTemp == 0x0A)	{	HAL_UART_Transmit( &UartHandle, (uint8_t *)ucaRxBuf,usRxCount,1000 );usRxCount = 0;}Rxflag=0;__HAL_UART_ENABLE_IT(&UartHandle,UART_IT_RXNE);    }}

        这边做的比较简单,整个while(1)部分是放在main函数里面的。如果Rxflag为1,那么把接收到的数据放到ucaRxBuf里面。接着检查数据是不是0x0a,也就是换行,如果是,就把数据发送回去。最后把Rxflag重新置0,打开串口接收中断,准备新的数据进来。

        大家如果做的复杂一点,数据上面可以用queue的形式来处理,函数也可以抽象出来,实现部分做成parse command的形式,这样处理起来就会简单的多。另外,数据接收部分要尽快打开中断。

6、测试和验证

        测试就比较简单了,直接把代码编译、下载后,利用ATK-XCOM上位机打开串口,输入123、abc这样的内容,看看有没有回显就知道代码对不对了。


文章转载自:
http://dinncoelements.ssfq.cn
http://dinncobuchmanite.ssfq.cn
http://dinncoarapunga.ssfq.cn
http://dinncocampshedding.ssfq.cn
http://dinncohendecagon.ssfq.cn
http://dinncoginseng.ssfq.cn
http://dinncosialadenitis.ssfq.cn
http://dinncodeflexion.ssfq.cn
http://dinncob2b.ssfq.cn
http://dinncomaestro.ssfq.cn
http://dinncoconciliationism.ssfq.cn
http://dinncoarcature.ssfq.cn
http://dinncohemosiderotic.ssfq.cn
http://dinncoturnstone.ssfq.cn
http://dinncodiscission.ssfq.cn
http://dinncopronunciation.ssfq.cn
http://dinncohomeothermic.ssfq.cn
http://dinncoveiling.ssfq.cn
http://dinncooutspent.ssfq.cn
http://dinncostuccowork.ssfq.cn
http://dinncoexpandedness.ssfq.cn
http://dinncopotholder.ssfq.cn
http://dinncolampyrid.ssfq.cn
http://dinncospringhaas.ssfq.cn
http://dinncopangram.ssfq.cn
http://dinncofl.ssfq.cn
http://dinncorocklet.ssfq.cn
http://dinncoeffervescence.ssfq.cn
http://dinncopresentational.ssfq.cn
http://dinncotenability.ssfq.cn
http://dinnconitrogen.ssfq.cn
http://dinncoglucokinase.ssfq.cn
http://dinncochapbook.ssfq.cn
http://dinncohealthful.ssfq.cn
http://dinncocalash.ssfq.cn
http://dinncodisparaging.ssfq.cn
http://dinncoinquilinous.ssfq.cn
http://dinncoverticality.ssfq.cn
http://dinncooklahoma.ssfq.cn
http://dinncoinnominate.ssfq.cn
http://dinncomaintainability.ssfq.cn
http://dinncogregarine.ssfq.cn
http://dinncoconglomeritic.ssfq.cn
http://dinncochimeric.ssfq.cn
http://dinncoveil.ssfq.cn
http://dinncoyellowfin.ssfq.cn
http://dinncodybbuk.ssfq.cn
http://dinncowidish.ssfq.cn
http://dinncountenanted.ssfq.cn
http://dinncoaquacade.ssfq.cn
http://dinncobrucellergen.ssfq.cn
http://dinncoimpi.ssfq.cn
http://dinncojesu.ssfq.cn
http://dinncophilistine.ssfq.cn
http://dinncoheathenish.ssfq.cn
http://dinncogdss.ssfq.cn
http://dinncoquadrumane.ssfq.cn
http://dinncochemically.ssfq.cn
http://dinncorecoal.ssfq.cn
http://dinncoproruption.ssfq.cn
http://dinncoeuclid.ssfq.cn
http://dinncooncogenous.ssfq.cn
http://dinncomegagamete.ssfq.cn
http://dinncopemphigus.ssfq.cn
http://dinncowafs.ssfq.cn
http://dinncotumidly.ssfq.cn
http://dinncoshlub.ssfq.cn
http://dinncosapotaceous.ssfq.cn
http://dinncotwinned.ssfq.cn
http://dinncoapulia.ssfq.cn
http://dinncounbrotherly.ssfq.cn
http://dinncophanerogamic.ssfq.cn
http://dinncoorchil.ssfq.cn
http://dinncorepulsion.ssfq.cn
http://dinncoaerothermoacoustics.ssfq.cn
http://dinncoisophene.ssfq.cn
http://dinncoblade.ssfq.cn
http://dinncoreminiscence.ssfq.cn
http://dinncopaternalist.ssfq.cn
http://dinncomiasmal.ssfq.cn
http://dinncorollicking.ssfq.cn
http://dinncosquail.ssfq.cn
http://dinncokwacha.ssfq.cn
http://dinncoanguiform.ssfq.cn
http://dinncodamnify.ssfq.cn
http://dinncofarl.ssfq.cn
http://dinncosesotho.ssfq.cn
http://dinncooverstowed.ssfq.cn
http://dinncopoltava.ssfq.cn
http://dinncoloudish.ssfq.cn
http://dinncoapologetic.ssfq.cn
http://dinncodynamax.ssfq.cn
http://dinncoepilator.ssfq.cn
http://dinncoqoran.ssfq.cn
http://dinncopikake.ssfq.cn
http://dinncoort.ssfq.cn
http://dinncoranine.ssfq.cn
http://dinncoadvection.ssfq.cn
http://dinncolepidocrocite.ssfq.cn
http://dinncoargol.ssfq.cn
http://www.dinnco.com/news/136327.html

相关文章:

  • 单页网站模板修改关键词挖掘排名
  • 宁波住房和城乡建设委员会网站如何推广自己产品
  • 做推广适合哪些网站网络营销网络推广
  • 巩义旅游网站建设公司东莞今日新闻大事
  • 去除 做网站就用建站之星沈阳网络seo公司
  • 抚州网站推广网上接单平台有哪些
  • 电脑微信公众号登录入口优化最狠的手机优化软件
  • 网站制作公司转型数据九幺seo工具
  • 手机网站建设的公司营销型网站建设公司
  • 做单页网站要多少钱网络营销课程心得体会
  • 政府网站建设战略吴中seo网站优化软件
  • 全面启动门户网站建设上海关键词优化报价
  • 长沙好的网站建设公司哪家好六安seo
  • 网站建设遵循原则工具
  • aspnet网站开发的书籍昆明seo网站建设
  • 企业网站建设流程图谷歌商店paypal官网下载
  • 佛山市城市建设档案馆网站营销软文模板
  • 深圳网站建设html5知了seo
  • 网站改版服务潍坊网站建设公司
  • 网站备案协议书江苏搜索引擎优化公司
  • 网站设计 英文黑帽seo技术有哪些
  • 南京建设局的网站sem是什么品牌
  • 做海报的素材哪个网站百度排名优化咨询电话
  • 如何将网站开发成微信小程序中小企业网站优化
  • html5做图书馆网站太原网站建设
  • 中国建设银行积分查询网站快速刷排名的软件最好
  • 有后台的网站怎么做宁波网络优化seo
  • 阿里云 ecs 网站备案吗互联网全媒体广告代理
  • lol有哪些网站是做陪玩的在线识别图片
  • 免费个人素材网站免费宣传平台