实验一
键盘输入一个字符’a’,串口工具显示’b’
uart4.h
#ifndef __UART4_H__
#define __UART4_H__
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_uart.h"
//初始化UART4
void hal_uart4_init();
//发送一个字符
void hal_put_char(const char str);
//发送一个字符串
void hal_put_string(const char * str);
//接收一个字符
char hal_get_char();
//接收一个字符串
char* hal_get_string();
#endif
uart4.c
#include "uart4.h"
//初始化UART4
void hal_uart4_init()
{
/*************RCC*************/
//1.GPIOB使能 MP_AHB4ENSETR[1] = 1
RCC->MP_AHB4ENSETR |= (0x1 MP_AHB4ENSETR |= (0x1 MP_APB1ENSETR |= (0x1 MODER &= (~(0X3 MODER |= (0x2 AFRL &= (~(0xf AFRL |= (0x8 MODER &= (~(0X3 MODER |= (0X2 AFRL &= (~(0XF AFRL |= (0X6 CR1 &= (~0x1);
//1.设置1位起始位,8位数据位
USART4->CR1 &= (~(0x1 CR1 &= (~(0x1 CR1 &= (~(0x1 CR2 &= (~(0x3 CR1 &= (~(0x1 PRESC &= (~0xF);
//6.设置串口波特率为115200
USART4->BRR &= (~0xFFFF);
USART4->BRR |= (0x22B);
//7.设置串口发送器使能
USART4->CR1 |= (0x1 CR1 |= (0x1 CR1 |= 0x1;
}
//发送一个字符
void hal_put_char(const char str)
{
//1.判断是否为空 ISR[7]
//0为满(堵塞),1为空(发送)
while(!(USART4->ISR & (0x1 TDR = str;
//3.判断一帧数据是否发送完成ISR[6]
//0未完成,1已完成
while(!(USART4->ISR & (0x1 ISR & (0x1 RDR;
}
main.c
#include "uart4.h"
extern void printf(const char *fmt, ...);
void delay_ms(int ms)
{
int i,j;
for(i = 0; i
实现二
键盘输入一个字符串,串口工具回显输入的字符串
uart4.h
#ifndef __UART4_H__
#define __UART4_H__
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_uart.h"
//初始化UART4
void hal_uart4_init();
//发送一个字符
void hal_put_char(const char str);
//发送一个字符串
void hal_put_string(const char * str);
//接收一个字符
char hal_get_char();
//接收一个字符串
char* hal_get_string();
#endif
uart4.c
#include "uart4.h"
//初始化UART4
void hal_uart4_init()
{
/*************RCC*************/
//1.GPIOB使能 MP_AHB4ENSETR[1] = 1
RCC->MP_AHB4ENSETR |= (0x1 MP_AHB4ENSETR |= (0x1 MP_APB1ENSETR |= (0x1 MODER &= (~(0X3 MODER |= (0x2 AFRL &= (~(0xf AFRL |= (0x8 MODER &= (~(0X3 MODER |= (0X2 AFRL &= (~(0XF AFRL |= (0X6 CR1 &= (~0x1);
//1.设置1位起始位,8位数据位
USART4->CR1 &= (~(0x1 CR1 &= (~(0x1 CR1 &= (~(0x1 CR2 &= (~(0x3 CR1 &= (~(0x1 PRESC &= (~0xF);
//6.设置串口波特率为115200
USART4->BRR &= (~0xFFFF);
USART4->BRR |= (0x22B);
//7.设置串口发送器使能
USART4->CR1 |= (0x1 CR1 |= (0x1 CR1 |= 0x1;
}
//发送一个字符
void hal_put_char(const char str)
{
//1.判断是否为空 ISR[7]
//0为满(堵塞),1为空(发送)
while(!(USART4->ISR & (0x1 TDR = str;
//3.判断一帧数据是否发送完成ISR[6]
//0未完成,1已完成
while(!(USART4->ISR & (0x1 ISR & (0x1 RDR;
}
//接收一个字符串
char* hal_get_string()
{
//循环接收
char* arr='';
int i=0;
while(1)
{
//'n'回车表示接收完成
*(arr+i) = hal_get_char();
hal_put_char(*(arr+i));
if(*(arr+i) != 'n') break;
i++;
}
return arr;
}
main.c
#include "uart4.h"
extern void printf(const char *fmt, ...);
void delay_ms(int ms)
{
int i,j;
for(i = 0; i
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
文章和代码已经归档至【Github仓库:https://github.com/timerring/java-tutorial 】或者公众号【AIShareLab】回复 java 也可获取。 JDBC 概述 基本介绍 JDBC为访问不同的数据库提供了统一的接口,…