uart4.h:
#ifndef __UART4_H__
#define __UART4_H__
#include"stm32mp1xx_gpio.h"
#include"stm32mp1xx_uart.h"
#include"stm32mp1xx_rcc.h"
void uart4_config();
void putchar(char dat);
char getchar();
void puts(char *s);
void gets(char *s);
#endif
uart4.c:
#include "uart4.h"
void uart4_config()
{
//使能GPIOBGPIOGUART4的外设时钟
RCC->MP_APB4ENSETR |= (0X1MP_APB4ENSETR |= (0X1MP_APB1ENSETR |= (0X1MODER &= (~(0X3MODER |= (0X2MODER &= (~(0X3MODER |= (0X2AFRH &= (~(0XfAFRH |= (0X6AFRL &= (~(0XfAFRL |= (0X8CR1 &= (~0x1);
//设置八位数据位
USART4->CR1 &= (~(0X1CR1 &= (~(0X1CR1 &服务器托管amp;= (~(0服务器托管X1PRESC &= (~0Xf);
//设置十六倍过采样
USART4->CR1 &= (~(0X1CR2 &= (~(0X3BRR = 0X22B;
//使能发射器
USART4->CR1 |= (0X1CR1 |= (0X1CR1 |= 0X1;
}
//发送单个字符
void putchar(char dat)
{
while (!(USART4->ISR & (0x1TDR = dat;
while(!(USART4->ISR & (0x1ISR & (0x1RDR;
}
//发送字符串
void puts(char *s)
{
while(1)
{
if(*s == '')
{
break;
}
putchar(*s);
s++;
}
putchar('n');
putchar('r');
}
//接受单个字符串
void gets(char *s)
{
while(1)
{
*s=getchar();
putchar(*s);
if(*s == 'r')
{
break;
}
s++;
}
*s='';
putchar('n');
}
main.c:
#include "gpio.h"
#include"uart4.h"
void delay(int s)
{
int i,j;
for(i=0;i
效果:
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
对象 Object Object 是一个特殊的对象,它本身是一个顶级对象,同时还是一个构造函数,还可以使用字面量的方式声明一个对象 本质上是键值对的集合,但是健只能是字符串 或 Symbol 使用 . [] 去获取object 的属性,不存在则返回 undef…