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

STM32 串口和I2C结合案例:

需求

1. 电脑通过串口 给单机 下发点灯计划  例如 13322  单片机上的灯 LED1 亮1秒 灭1秒 LED3 亮1秒 灭1秒 LED3 亮一秒 灭1秒 133221332213322->

mian.c

#include "usart1.h"
#include "M24C02.h"
#include "stdio.h"
#include "led.h"
#include "delay.h"
#include <string.h>uint8_t buffer[100] = {0};
extern uint8_t receive_complete_flag;
extern uint8_t receive_buffer[100];
extern uint8_t receive_len;
uint16_t leds[] = {LED1, LED2, LED3};
uint8_t current_led = 0;
int main(void)
{LED_Init();USART1_InitIt();M24C02_Init();while (1){for (uint8_t i = 0; i < 5; i++){if (receive_complete_flag){receive_complete_flag = 0;M24C02_Savebytes(receive_buffer, 0x00, 5);Delay_ms(10);M24C02_ReadBytes(buffer, 0x00, 5);printf("%s\n", buffer);receive_len = 0;}current_led = (buffer[i] + 2) % 3;LED_Toggle(leds[current_led]);Delay_ms(500);LED_Toggle(leds[current_led]);Delay_ms(500);printf("%d\n", current_led);}}
}

 

http://www.lryc.cn/news/498066.html

相关文章:

  • QT6_UI设计——设置表格
  • 游戏使用辅助工具修改器检测不到游戏进程应该如何解决?多种解决方法分享
  • Java JVM(内存结构,垃圾回收,类加载,内存模型)
  • C++设计模式(桥接、享元、外观、状态)
  • 鸿蒙 DevEco Studio 设置状态栏,调用setWindowSystemBarProperties不生效
  • Spring03——基于xml的Spring应用
  • 【AIGC半月报】AIGC大模型启元:2024.12(上)
  • 本etcd系列文章补充说明
  • 【新品发布】ESP32-P4开发板 —— 启明智显匠心之作,为物联网及HMI产品注入强劲动力
  • HTML 添加 文本水印
  • 软件无线电安全之GNU Radio基础(下)
  • windows基础
  • hhdb数据库介绍(10-43)
  • JMS和消息中间件:Kafka/RocketMQ
  • 【问题解决】ArcgisGP工具使用GIS模块自动发布图层报错:过渡失败
  • Yocto bitbake and codeSonar
  • gpt-computer-assistant - 极简的 GPT-4o 客户端
  • 中国移动量子云平台:算力并网590量子比特!
  • Vue 3 中的计算属性(Computed Properties)详解
  • AWS S3 权限配置与文件上传下载指南
  • 6. 一分钟读懂“抽象工厂模式”
  • CV(2)-插值和卷积
  • 学习threejs,通过设置纹理属性来修改纹理贴图的位置和大小
  • fastadmin 后台插件制作方法
  • 9. 一分钟读懂“策略模式”
  • 65页PDF | 企业IT信息化战略规划(限免下载)
  • Android 单元测试断言校验方法 org.junit.Assert
  • 亚马逊云(AWS)使用root用户登录
  • 用点云信息来进行监督目标检测
  • Navicat连接服务器MySQL