您的位置:首页 > 科技 > IT业 > 360建筑网忘记登入密码了怎么办_深圳网络推广平台_上海哪家seo好_营销推广48个方法

360建筑网忘记登入密码了怎么办_深圳网络推广平台_上海哪家seo好_营销推广48个方法

2025/1/9 21:54:29 来源:https://blog.csdn.net/m0_71556251/article/details/144930813  浏览:    关键词:360建筑网忘记登入密码了怎么办_深圳网络推广平台_上海哪家seo好_营销推广48个方法
360建筑网忘记登入密码了怎么办_深圳网络推广平台_上海哪家seo好_营销推广48个方法

【单片机实现串口控制】
ex:LED1_ON->LED1开
LED1_OFF->LED1关

可以控制蜂鸣器风扇、灯......

编译工具:keil

开发板:stm32u5

void mystrcmp(char* buf)
{if(strcmp(buf,"LED1_ON")==0){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_4,GPIO_PIN_SET);}else if(strcmp(buf,"LED1_OFF")==0){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_4,GPIO_PIN_RESET);}else if(strcmp(buf,"LED3_ON")==0){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_SET);}else if(strcmp(buf,"LED3_OFF")==0){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_RESET);}else if(strcmp(buf,"FAN_ON")==0){printf("222%s\n\r",buf);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);}else if(strcmp(buf,"FAN_OFF")==0){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_RESET);}else if(strcmp(buf,"MOTOR_ON")==0){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);}else if(strcmp(buf,"MOTOR_OFF")==0){HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);}
}
int main(void)
{/* USER CODE BEGIN 1 *//* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* Configure the System Power */SystemPower_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_USART1_UART_Init();MX_ICACHE_Init();/* USER CODE BEGIN 2 *//* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */char buf[32];while (1){//printf("hello world\n\r");//HAL_Delay(1000);memset(buf,0,sizeof(buf));HAL_UART_Receive(&huart1,(uint8_t*)buf,sizeof(buf),10000);HAL_UART_Transmit(&huart1,buf,strlen(buf),5);printf("111%s\n\r",buf);mystrcmp(buf);/* USER CODE END WHILE *//* USER CODE BEGIN 3 */}/* USER CODE END 3 */
}

编译工具:vim

开发板:FS_MP1A

//主函数
#include "uart4.h"void led_ctl_main();
void uart4_ctl();
void usart_ctl(char* buf);int main()
{uart4_init();while(1){char buf[128];gets(buf);puts(buf);usart_ctl(buf);}return 0;
}void uart4_ctl()
{uart4_init();char ch;while(1){ch = getchar();putchar(ch);putchar('\n');putchar('\r');}
}void usart_ctl(char* buf)
{if(my_strcmp(buf,"LED1_ON") == 0){GPIOE->ODR |= (0X1 << 10);}else if(my_strcmp(buf,"LED1_OFF")==0){GPIOE->ODR &= (~(0X1 << 10));}else if(my_strcmp(buf,"LED2_ON")==0){GPIOF->ODR |= (0X1 << 10);}else if(my_strcmp(buf,"LED2_OFF")==0){GPIOF->ODR &= (~(0X1 << 10));}else if(my_strcmp(buf,"LED3_ON")==0){GPIOE->ODR |= (0X1 << 8);}else if(my_strcmp(buf,"LED3_OFF")==0){GPIOE->ODR &= (~(0X1 << 8));		}else if(my_strcmp(buf,"FAN_ON")==0){GPIOE->ODR |= (0X1 << 9);}else if(my_strcmp(buf,"FAN_OFF")==0){GPIOE->ODR &= (~(0X1 << 9));		}else if(my_strcmp(buf,"MOTOR_ON")==0){GPIOF->ODR |= (0X1 << 6);}else if(my_strcmp(buf,"MOTOR_OFF")==0){GPIOF->ODR &= (~(0X1 << 6));		}else if(my_strcmp(buf,"BEEP_ON")==0){GPIOB->ODR |= (0X1 << 6);}else if(my_strcmp(buf,"BEEP_OFF")==0){GPIOB->ODR &= (~(0X1 << 6));		}
}
#include "uart4.h"void uart4_init()
{// 外设时钟// RCCRCC->MP_APB1ENSETR |= (0X1 << 16);RCC->MP_AHB4ENSETR |= (0X1 << 1);RCC->MP_AHB4ENSETR |= (0X1 << 6);RCC->MP_AHB4ENSETR |= (0X1 << 4);RCC->MP_AHB4ENSETR |= (0X1 << 5);// GPIOBGPIOB->MODER &= (~(0X3 << 4));GPIOB->MODER |= (0X2 << 4);GPIOB->AFRL &= (~(0XF << 8));GPIOB->AFRL |= (0X8 << 8);// GPIOGGPIOG->MODER &= (~(0X3 << 22));GPIOG->MODER |= (0x2 << 22);GPIOG->AFRH &= (~(0XF << 12));GPIOG->AFRH |= (0X6 << 12);// 禁用串口UE=0USART4->CR1 &= (~(0X1 << 0));// 8位数据位USART4->CR1 &= (~(0X1 << 12));USART4->CR1 &= (~(0X1 << 28));USART4->CR1 &= (~(0X1 << 10));	// 没有校验位USART4->PRESC &= (~(0XF << 0)); // 不分频USART4->CR1 &= (~(0X1 << 15));	// 16倍过采样USART4->CR2 &= (~(0X3 << 12));	// 1位停止位USART4->BRR = 0X22B;			// 115200波特率USART4->CR1 |= (0X1 << 3);		// 使能发送USART4->CR1 |= (0X1 << 2);		// 使能接收USART4->CR1 |= 0X1;				// 使能串口// 设置输出模式// 清零输出模式位GPIOE->MODER &= (~(0X3 << 20));//LED1GPIOF->MODER &= (~(0X3 << 20));//LED2GPIOE->MODER &= (~(0X3 << 16));//LED3GPIOE->MODER &= (~(0X3 << 18)); //FANGPIOF->MODER &= (~(0X3 << 12)); //MOTORGPIOB->MODER &= (~(0X3 << 12)); //BEEP// 置位输出模式GPIOE->MODER |= (0X1 << 20);GPIOF->MODER |= (0X1 << 20);GPIOE->MODER |= (0X1 << 16);GPIOE->MODER |= (0X1 << 18); 	GPIOF->MODER |= (0X1 << 12);GPIOB->MODER |= (0X1 << 12);// 设置推挽输出GPIOE->OTYPER &= (~(0X3 << 10));GPIOF->OTYPER &= (~(0X3 << 10));GPIOE->OTYPER &= (~(0X3 << 8));GPIOE->OTYPER &= (~(0X3 << 9));GPIOF->OTYPER &= (~(0X3 << 6));GPIOB->OTYPER &= (~(0X3 << 6));// 设置低速输出GPIOE->OSPEEDR &= (~(0X3 << 20));GPIOF->OSPEEDR &= (~(0X3 << 20));GPIOE->OSPEEDR &= (~(0X3 << 16));GPIOE->OSPEEDR &= (~(0X3 << 18));GPIOF->OSPEEDR &= (~(0X3 << 12));GPIOB->OSPEEDR &= (~(0X3 << 12));// 设置无上拉下拉电阻GPIOE->PUPDR &= (~(0X3 << 20));GPIOF->PUPDR &= (~(0X3 << 20));GPIOE->PUPDR &= (~(0X3 << 16));GPIOE->PUPDR &= (~(0X3 << 18));GPIOF->PUPDR &= (~(0X3 << 12));GPIOB->PUPDR &= (~(0X3 << 12));
}void putchar(char ch)
{while (!(USART4->ISR & (0X1 << 7)));			  // 判断发送数据寄存器是否为空,不为空则等待USART4->TDR = ch; // 为空,向发送数据寄存器写入while (!(USART4->ISR & (0X1 << 6))); // 等待发送完成
}char getchar()
{while (!(USART4->ISR & (0x1 << 5)));return USART4->RDR;
}void gets(char *s)
{while (1){*s = getchar();if ((*s) == '\r'){*s = '\0';break;}putchar(*s);s++;}putchar('\n');putchar('\r');
}void puts(char *s)
{while (*s){putchar(*s);s++;}putchar('\0');putchar('\n');putchar('\r');
}int my_strcmp(const char* str,const char* ptr)
{while(*str != '\0' && *ptr != '\0'){if(*str != *ptr){return (unsigned char)*str - (unsigned char)*ptr;}str++;ptr++;	}return ((unsigned char)*str - (unsigned char)*ptr);
}
//头文件
#ifndef __UART_H__
#define __UART_H__#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_uart.h"void uart4_init();
void putchar(char ch);
char getchar();
void gets(char* s);
void puts(char *s);
int my_strcmp(const char* str,const char* ptr);#endif

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com