文章目录
UART实验代码实践(lv9-day14.2)
1实现终端发送给4412一个字符,4412把字符+1返回
我们使用的是4412的UART2
1.1 UART寄存器封装
typedef struct {
unsigned int ULCON2;
unsigned int UCON2;
unsigned int UFCON2;
unsigned int UMCON2;
unsigned int UTRSTAT2;
unsigned int UERSTAT2;
unsigned int UFSTAT2;
unsigned int UMSTAT2;
unsigned int UTXH2;
unsigned int URXH2;
unsigned int UBRDIV2;
unsigned int UFRACVAL2;
unsigned int UINTP2;
unsigned int UINTSP2;
unsigned int UINTM2;
}uart2;
#define UART2 ( * (volatile uart2 *)0x13820000 )
1.2 UART2初始化
void UART_Init(void)
{
/*UART2连接在GPA1_1(TX)和GPA1_0(RX)上。*/
/*将GPA1_0和GPA1_1设置成UART的接收引脚和发送引脚*/
GPA1.CON=GPA1.CON &(~(0xFF<<0)) | (0x22<<0);
/*设置UART2的帧格式,8位数据位 1位停止位 无校验 正常模式 ULCON2[7:0]*/
UART2.ULCON2 =UART2.ULCON2 &