新聞中心

ARM11-S3C6410 UART

作者: 時間:2016-11-10 來源:網(wǎng)絡(luò) 收藏
我想串口程序應(yīng)該是ARM程序中最簡單的了吧。盡管如此,做個記錄吧 。
具體設(shè)置如下:

本文引用地址:http://butianyuan.cn/article/201611/317136.htm
#define ULCON0 (*((volatile unsigned long *)0x7F005000))
#define UCON0 (*((volatile unsigned long *)0x7F005004))
#define UFCON0 (*((volatile unsigned long *)0x7F005008))
#define UMCON0 (*((volatile unsigned long *)0x7F00500C))
#define UTRSTAT0 (*((volatile unsigned long *)0x7F005010))
#define UFSTAT0 (*((volatile unsigned long *)0x7F005018))
#define UTXH0 (*((volatile unsigned char *)0x7F005020))
#define URXH0 (*((volatile unsigned char *)0x7F005024))
#define UBRDIV0 (*((volatile unsigned short *)0x7F005028))
#define UDIVSLOT0 (*((volatile unsigned short *)0x7F00502C))
#define GPACON (*((volatile unsigned long *)0x7F008000))
void init_uart(void)
{
GPACON &= ~0xff;
GPACON |= 0x22;
/* ULCON0 */
ULCON0 = 0x3; /* 數(shù)據(jù)位:8, 無較驗, 停止位: 1, 8n1 */
UCON0 = 0x5; /* 使能UART發(fā)送、接收 */
UFCON0 = 0x01; /* FIFO ENABLE */
UMCON0 = 0;
/* 波特率 */
/* DIV_VAL = (PCLK / (bps x 16 ) ) - 1
*PCLK = 66.5MHz
* bps = 115200
* DIV_VAL = (66500000 / (115200 x 16 ) ) - 1
* = 35.08
*/
UBRDIV0 = 35;
/* x/16 = 0.08
* x = 1
*/
UDIVSLOT0 = 0x1;
}
char getchar(void)
{
while ((UFSTAT0& (1<<6)) == 0 && (UFSTAT0& 0x3f) == 0);
return URXH0;
}
void putchar(char c)
{
while ((UFSTAT0 & (1<<14)) );
UTXH0 = c;
}

在主函數(shù)中調(diào)用上面的串口初始化函數(shù),接收字符串函數(shù)和發(fā)送字符穿函數(shù),如下,通過鍵盤在串口助手中向串口發(fā)送字符,則會有“輸入字符+1”顯示在終端上。

int main()

{
char c;
init_uart();
while (1)
{
c = getchar();
putchar(c+1);
}
return 0;

}
更改主函數(shù)與Uart.c函數(shù),實現(xiàn)你想要的功能:

int main()
{
char c;
char* str = "---hello uart-arm-----rn";
char* addition ="---addition operation----rn";
char* of1 = "a. hellorn";
char* of2 = "b. what is your namern";
char* of3 = "c. beliefrn";
char a,b ; char sum;
char choice;
init_uart();
//print str
c = getchar();
putchar(c+1);
putstr(str);
//addition operation
putstr(addition);
putstr(of1);
putstr(of2);
putstr(of3);
while(1){
choice = getchar();
if(choice ==a)
putstr("hellorn");
else
if (choice ==b)
putstr("what is your namern");
else
if (choice ==c)
putstr("beliefrn");
else
putstr("no optionrn");
}}


上面函數(shù)相當于一個簡單的菜單選擇。 輸出如下,以下結(jié)果是依次從鍵盤輸入a,b,c,d,e之后的結(jié)果


關(guān)鍵詞: ARM11S3C6410UAR

評論


技術(shù)專區(qū)

關(guān)閉