📄 test_uart1.c
字号:
#include "def.h"
#include "2410addr.h"
#include "config.h"
#include "board.h"
#include "utils.h"
void Test_Uart1(void)
{
U16 m ;
U32 baud, rUBRDIV1_save ;
printf("UART1 test, please select baud rate\n1: 9600\n2: 19200\n3: 57600\n4: 115200\n");
while(1) {
m = getch();
if(m>='1'&&m<='4')
break;
if(m==ESC_KEY)
return;
}
switch(m) {
case '1':
baud = 9600;
break;
case '2':
baud = 19200;
break;
case '3':
baud = 57600;
break;
default:
baud = 115200;
}
printf("set UART1 baud rate to %d\n", baud);
rUBRDIV1_save = rUBRDIV1;
rUBRDIV1 = ((int)(GetMasterClock()/16./baud + 0.5) -1);
while(1)
{
m = getkey();
if(m==ESC_KEY)
break;
if(m) {
while(!(rUTRSTAT1 & 0x2)); //Wait until THR is empty.
WrUTXH1(m);
}
if((rUTRSTAT1 & 0x1)) //Receive data ready
putch(RdURXH1());
//while(!(rUTRSTAT1 & 0x2)); //Wait until THR is empty.
//WrUTXH1(0xaa);
//Delay(2);
}
rUBRDIV1 = rUBRDIV1_save;
}
static char title[] = "串口2通讯实验";
static char tip[] = "实验串口2(UART1)通讯功能,按ESC键返回";
//Test_Q2403A_Item在prog_entry.c里被引用
TEST_PROGRAM_ITEM Test_Uart1_Item = {
(TEST_PROGRAM)Test_Uart1, //入口地址
title, //显示名称
tip, //帮助或提示信息,可为NULL
1}; //使用printf,puts,putch等函数时在LCD上也显示输出字符(串)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -