S3C2440-UART
这个程序可以通过串口调试助手发送一个字符,然后在接受的地方显示出来。
#define rULCON0 (*(volatile unsigned*) 0x50000000)
#define rUCON0 (*(volatile unsigned*) 0x50000004)
#define rUTRSTAT0 (*(volatile unsigned*) 0x50000010)
#define rUTXH0 (*(volatile unsigned*) 0x50000020)
#define rURXH0 (*(volatile unsigned*) 0x50000024)
#define rUBRDIV0 (*(volatile unsigned*) 0x50000028)
int Main(){
char buf;
rULCON0 = 0xfff00;
rULCON0 |= 0x3;
rUCON0 = 0x0805;
rUBRDIV0 = 26;
while(1){
if(rUTRSTAT0&0x1){
buf = rURXH0;
while(!(rUTRSTAT0&0x04));
rUTXH0 = buf;
}
}
return 0;
}
这是通过向串口发送数据,根据发送的数据控制led哪个灯亮的程序。注意事项是:我使用的是串口调试助手,发送数据前首先要设置波特率为115200,否则没有任何显示。void Delay(unsigned int x);这句话要在Main函数内声明,在外面声明就不好使,不知为什么。
#define GPFCON (*(volatile unsigned*) 0x56000050)
#define GPFDAT (*(volatile unsigned*) 0x56000054)
#define GPFUP (*(volatile unsigned*) 0x56000058)
#define ULCON0 (*(volatile unsigned*) 0x50000000)
#define UCON0 (*(volatile unsigned*) 0x50000004)
#define UTRSTAT0 (*(volatile unsigned*) 0x50000010)
#define UTXH0 (*(volatile unsigned*) 0x50000020)
#define URXH0 (*(volatile unsigned*) 0x50000024)
#define UBRDIV0 (*(volatile unsigned*) 0x50000028)
int Main(){
void Delay(unsigned int x);
char buf;
GPFCON &= 0xc03f;
GPFCON |= 0x1540;
GPFUP &= 0x87;
ULCON0 |= 0x3;
UCON0 &= 0x0800;
UCON0 |= 0x05;
while(1){
if(UTRSTAT0 & 0x1){
buf = URXH0;
while(!(UTRSTAT0 & 0x4));
UTXH0 = buf;
switch(buf){
case 0x11:
GPFDAT = 0xf7;
Delay(100);
break;
case 0x22:
GPFDAT = 0xef;
Delay(100);
break;
case 0x33:
GPFDAT = 0xdf;
Delay(100);
break;
case 0x44:
GPFDAT = 0xbf;
Delay(100);
break;
}
}
}
}
void Delay(unsigned int x){
int i,j,k;
for(i = 0; i <= x; i++)
for(j = 0; j <= 0xff; j++)
for(k = 0; k <= 0xff; k++)
;
}
评论