UART 主要是串口通信。本实验就是通过UART0和PC通信。PC那边主要是利用建立一个超级终端实现。
下面的代码主要是实现在PC机的超级终端显示操作菜单。选择相应的菜单,实现对应的功能。
#define GLOBAL_CLK 1
#include "def.h"
#include "2440addr.h"
#include "option.h"
#include <stdarg.h>
#define LED1 (1<<5)// rGPB[5] =1 ;
#define LED2 (1<<6)// rGPB[6] =1 ;
#define LED3 (1<<7)// rGPB[7] =1 ;
#define LED4 (1<<8)// rGPB[8] =1 ;
char *CmdTip[] ={
"Please input 1-5 to select test",
"light led 1" ,
"light led 2" ,
"light led 3" ,
"light led 4"
};
void Delay_Time(int time)
{
unsigned int i,j;
for(i=1;i<100;i++)
for(j=1;j<time;j++)
;
}
void Uart_Initialize(int pclk,int baud)
{
if(pclk == 0)
pclk = PCLK;
rUFCON0 = 0x0; //UART channel 0 FIFO control register, FIFO disable
rUMCON0 = 0x0; //UART chaneel 0 MODEM control register, AFC disable
rULCON0 = 0x3; //Line control register : Normal,No parity,1 stop,8 bits
// [10] [9] [8] [7] [6] [5] [4]