S3C2440-UART
這個(gè)程序可以通過串口調(diào)試助手發(fā)送一個(gè)字符,然后在接受的地方顯示出來。
#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;
}
這是通過向串口發(fā)送數(shù)據(jù),根據(jù)發(fā)送的數(shù)據(jù)控制led哪個(gè)燈亮的程序。注意事項(xiàng)是:我使用的是串口調(diào)試助手,發(fā)送數(shù)據(jù)前首先要設(shè)置波特率為115200,否則沒有任何顯示。void Delay(unsigned int x);這句話要在Main函數(shù)內(nèi)聲明,在外面聲明就不好使,不知為什么。
#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++)
;
}
評(píng)論