一.系统概述
系统使用STM32单片机进行主控,系统内使用按键和串口模拟红外无线遥控,设置了5个按键来模拟不同的按键指令,从而实现不同的指令控制,两个显示屏上都会显示发送的数据,数据之间都是相互对应的。
二.仿真概述
1. 右侧遥控端通过按键进行控制,按键按下的序号会在本地显示屏上进行显示 ,
2. 按下对应的按键,对应的LED灯会亮并且在被控制端会显示对应的序号。
三.程序设计
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"
#include "Serial.h"
#include "key.h"
uint8_t KeyNum;
int main(void)
{
/*模块初始化*/
OLED_Init(); //OLED初始化
Key_Init();
Serial_Init(); //串口初始化
OLED_ShowString(1, 1, "RxData:");
while (1)
{
KeyNum = Key_GetNum(); //获取按键键码
OLED_ShowNum(2, 1,KeyNum, 2);
if (KeyNum == 1) //按键1按下
{
Serial_SendByte(0x41);
}
if (KeyNum == 2) //按键2按下
{
Serial_SendByte(0x42);
}
if (KeyNum == 3) //按键1按下
{
Serial_SendByte(0x43);
}
if (KeyNum == 4) //按键2按下
{
Serial_SendByte(0x44);
}
if (KeyNum == 5) //按键1按下
{
Serial_SendByte(0x45);
}
}
}