[STM8] memcpy函数问题

[复制链接]
1430|9
 楼主| zwll 发表于 2021-8-6 21:30 | 显示全部楼层 |阅读模式
stm8接收串口数据后显示到lcd1602上,串口数据格式是1+16位数据+16位数据,例如接收到的数据是"1    16:07:21     2019-08-22 Thu ",
我是用memcpy函数把接收到的数据拷贝到2个数据里面
dengdc 发表于 2021-8-6 21:34 | 显示全部楼层

楼主程序可以公开吗?贴程序看下吧,这么说看不出什么原因
 楼主| zwll 发表于 2021-8-6 21:38 | 显示全部楼层
u8 bluetooth_date;
u8 bluetooth_date_str0[17],bluetooth_date_str1[17];
int main(void)
{
  
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
  USART_Configuration();//串口初始化
  GPIO_Configuration();
  LCD1602_Init();
  LCD1602_ClearScreen();
  

  while(1)
  {
   
    if (bluetooth_date[0]=='1')
    {
      
      memcpy(bluetooth_date_str0, bluetooth_date + 1, 16);
      memcpy(bluetooth_date_str1, bluetooth_date + 17, 32);
      bluetooth_date_str0[16]='\0';
      bluetooth_date_str1[16]='\0';
      
    }
   
    LCD1602_Show_Str(0, 0, bluetooth_date_str0);
    LCD1602_Show_Str(0, 1, bluetooth_date_str1);
   
  }
然后发现有一个问题,如果只写memcpy(bluetooth_date_str0, bluetooth_date + 1, 16);程序能正常接收到数据并显示出来,但如果加上 memcpy(bluetooth_date_str1, bluetooth_date + 17, 32);程序就没办法接收到串口数据。
这个到底是哪里的问题。
wuhany 发表于 2021-8-6 21:40 | 显示全部楼层
bluetooth_date_str1[17];

memcpy(bluetooth_date_str1, bluetooth_date + 17, 32);

越界了
 楼主| zwll 发表于 2021-8-6 21:43 | 显示全部楼层
恩,看到了。没仔细看函数说明犯了低级错误。
 楼主| zwll 发表于 2021-8-6 21:45 | 显示全部楼层
再想请教一下,memcry的用法,memcry只能复制静态数组里面的内容吗?
bluetooth_date是uart1接收到的内容,调试的时候没发现有问题,但是
memcpy(bluetooth_date_str0, bluetooth_date + 1, 16);
memcpy(bluetooth_date_str1, bluetooth_date + 17, 32);
之后,bluetooth_date_str0和bluetooth_date_str1的内容就对不上了
 楼主| zwll 发表于 2021-8-6 21:47 | 显示全部楼层
要保证更新之后 及时copy!
 楼主| zwll 发表于 2021-8-6 21:50 | 显示全部楼层
说出来你可能不信,这个问题折腾我好几天了,在改了无数次之后,昨天某次剪切粘贴最早的代码后就没问题了。。。。
chuxh 发表于 2021-8-6 21:57 | 显示全部楼层
具体的这个问题,分析不处理。可能是哪里有一个小bug.调试程序的时候,往往会出现这种问题。但是往往最后都不了了之了。。。
 楼主| zwll 发表于 2021-8-6 22:08 | 显示全部楼层

哦,那我就知道怎么回事了,多谢大家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

885

主题

11314

帖子

5

粉丝
快速回复 在线客服 返回列表 返回顶部