微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM11-S3C6410 UART

ARM11-S3C6410 UART

时间:11-10 来源:互联网 点击:
我想串口程序应该是ARM程序中最简单的了吧。尽管如此,做个记录吧 。

具体设置如下:

#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; /* 数据位:8, 无较验, 停止位: 1, 8n1 */

UCON0 = 0x5; /* 使能UART发送、接收 */

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;

}

在主函数中调用上面的串口初始化函数,接收字符串函数和发送字符穿函数,如下,通过键盘在串口助手中向串口发送字符,则会有“输入字符+1”显示在终端上。

int main()

{

char c;

init_uart();

while (1)

{

c = getchar();

putchar(c+1);

}

return 0;

}

更改主函数与Uart.c函数,实现你想要的功能:

int main()

{

char c;

char* str = "---hello uart-arm-----\r\n";

char* addition ="---addition operation----\r\n";

char* of1 = "a. hello\r\n";

char* of2 = "b. what is your name\r\n";

char* of3 = "c. belief\r\n";

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("hello\r\n");

else

if (choice ==b)

putstr("what is your name\r\n");

else

if (choice ==c)

putstr("belief\r\n");

else

putstr("no option\r\n");

}}


上面函数相当于一个简单的菜单选择。 输出如下,以下结果是依次从键盘输入a,b,c,d,e之后的结果

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top