一、通过操作Cortex-A7核,串口输入相应的命令,控制LED灯进行工作
1.例如在串口输入led1on,开饭led1灯点亮
2.例如在串口输入led1off,开饭led1灯熄灭
3.例如在串口输入led2on,开饭led2灯点亮
4.例如在串口输入led2off,开饭led2灯熄灭
5.例如在串口输入led3on,开饭led3灯点亮
6.例如在串口输入led3off,开饭led3灯熄灭
二、检测中断到来时,让LED灯状态取反,并且在串口工具上打印一句话
例如:当按键1按下之后,让LED1状态取反,并打印“LED1 down”
当按键2按下之后,让LED2状态取反,并打印“LED2 down”
当按键3按下之后,让LED3状态取反,并打印“LED3 down”
火焰传感器/人体红外/光电开关实验要求如上
作业一:
uart_led.h:
#ifndef __UART_LED_H__
#define __UART_LED_H__
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_uart.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"
//重写strcmp函数
int strcmp(const char *s1, const char *s2);
//对LED灯初始化
void hal_led_init();
//对GPIO引脚初始化函数
void hal_gpio_init(gpio_t* gpiox, gpio_init_t* init, unsigned int pin);
//对GPIO引脚写操作函数
void hal_led_gpio_write(gpio_t* gpiox, unsigned int pin, gpio_status_t state);
//初始化串口
void hal_uart_init();
//发送一个字节
void uart_put_char(const char str);
//发送一个字符串
void uart_put_string(const char* str);
//接受一个字符
char uart_get_char();
//接收一个字符串
char* uart_get_string();
#endif
uart_led.c:
#include "uart_led.h"
extern void printf(const char *fmt, ...);
extern void delay_ms(int ms);
//重写strcmp函数
int strcmp(const char *s1, const char *s2)
{
int t = 0;
while(*s1 || *s2)
{
if(*s1 != *s2)
{
t = *s1 - *s2;
return t;
}
*s1 ++;
*s2 ++;
}
return t;
}
//对LED灯初始化
void hal_led_init()
{
//RCC时钟初始化
RCC->MP_AHB4ENSETR |= (0x3 MODER &= (~(0x3 MODER |= (init->moder OTYPER &= (~(0x1 OTYPER |= (init->otyper OSPEEDR &= (~(0x3 OSPEEDR |= (init->ospeedr PUPDR &= (~(0x3 PUPDR |= (init->pupdr ODR &= (~(0x1 ODR |= (0x1 MP_AHB4ENSETR |= (0x1 MP_AHB4ENSETR |= (0x1 MP_APB1ENSETR |= (0x1 MODER |= (0x1 AFRL &= (~(0xF AFRL |= (0x1 MODER |= (0x1 AFRH &= (~(0xF AFRH |= (0x3 CR1 & (0x1 CR1 &= (~(0x1 CR1 &= (~(0x1 CR1 &= (~(0x1 CR1 &= (~(0x1 CR1 &= (~(0x1 CR2 &= (~(0x3 PRESC &= (~(0x3 BRR |= 0x22B; //设置串口波特率
USART4->CR1 |= (0x1 CR1 |= (0x1 CR1 |= (0x1 ISR & (0x1 TDR = str;
//3.判断发送数据是否完成 ISR[6]
while(!(USART4->ISR & (0x1 ISR & (0x1 RDR;
return ch;
}
char buff[50] = {0};
//接收一个字符串
char* uart_get_string()
{
int i = 0;
//for循环
//当键盘的回车键'r'按下之后,字符串输入完成
for(i = 0; i
main.c:
#include "uart_led.h"
extern void printf(const char *fmt, ...);
void delay_ms(int ms)
{
int i,j;
for(i = 0; i
测试结果如下:
作业二:
实验现象如下: