12.25
2023-12-26 00:39:21
led.c
#include "led.h"
void all_led_init()
{
RCC_GPIO |= (0X3<<4);//时钟使能
GPIOE_MODER &=(~(0X3<<20));//设置PE10输出
GPIOE_MODER |= (0X1<<20);
//设置PE10为推挽输出
GPIOE_OTYPER &=(~(0x1<<10));
//PE10为低速输出
GPIOE_OSPEEDR &= (~(0x3<<20));
//设置无上拉下拉
GPIOE_PUPDR &= (~(0x3<<20));
//LED2
GPIOF_MODER &=(~(0X3<<20));//设置Pf10输出
GPIOF_MODER |= (0X1<<20);
//设置Pf10为推挽输出
GPIOF_OTYPER &=(~(0x1<<10));
//Pf10为低速输出
GPIOF_OSPEEDR &= (~(0x3<<20));
//设置无上拉下拉
GPIOF_PUPDR &= (~(0x3<<20));
//LED3
GPIOE_MODER &=(~(0X3<<16));//设置PE8输出
GPIOE_MODER |= (0X1<<16);
//设置PE8为推挽输出
GPIOE_OTYPER &=(~(0x1<<8));
//PE8为低速输出
GPIOE_OSPEEDR &= (~(0x3<16));
//设置无上拉下拉
GPIOE_PUPDR &= (~(0x3<<16));
}
void led1_on()
{
GPIOE_ODR |= (0x1<<10);
}
void led1_off()
{
GPIOE_ODR &= (~(0x1<<10));
}
void led2_on()
{
GPIOF_ODR |= (0x1<<10);
}
void led2_off()
{
GPIOF_ODR &= (~(0x1<<10));
}
void led3_on()
{
GPIOE_ODR |= (0x1<<8);
}
void led3_off()
{
GPIOE_ODR &= (~(0x1<<8));
}
led.h
#ifndef __LED_H_
#define __LED_H_
#define RCC_GPIO (*(unsigned int *)0x50000a28)
#define GPIOE_MODER (*(unsigned int *)0x50006000)
#define GPIOF_MODER (*(unsigned int *)0x50007000)
#define GPIOE_OTYPER (*(unsigned int *)0x50006004)
#define GPIOF_OTYPER (*(unsigned int *)0x50007004)
#define GPIOF_OSPEEDR (*(unsigned int *)0x50007008)
#define GPIOE_OSPEEDR (*(unsigned int *)0x50006008)
#define GPIOF_PUPDR (*(unsigned int *)0x5000700C)
#define GPIOE_PUPDR (*(unsigned int *)0x5000600C)
#define GPIOE_ODR (*(unsigned int *)0x50007014)
#define GPIOF_ODR (*(unsigned int *)0x50006014)
void led1_on();
void led2_on();
void led3_on();
void led1_off();
void led2_off();
void led3_off();
void delay(int ms);
void all_led_init();
#endif
uart4.h
#ifndef __UART4_H_
#define __UART4_H_
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include"stm32mp1xx_uart.h"
void uart4_config();
void putchar(char a);
char getchar();
int cmp(char *s1,char *s2);
void puts(char *s);
void gets(char *s);
#endif
#include"uart4.h"
#include "led.h"
int main()
{
char st[100];
all_led_init();
uart4_config();
while(1)
{
gets(st);
puts(st);
if(cmp(st,"open")==0)
{
led1_on();
led2_on();
led3_on();
}
if(cmp(st,"close")==0)
{
led1_off();
led2_off();
led3_off();
}
}
return 0;
}
main.c
文章来源:https://blog.csdn.net/m0_61791148/article/details/135208019
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!