#define GPC0CON *((volatile unsigned int *)0xE0200060) #define GPC0DAT *((volatile unsigned int *)0xE0200064) int main() __attribute__((section(".main"))); int main() { unsigned char c; uart_init(); GPC0CON &= ~(0xFF << 12); GPC0CON |= 0x11 << 12; // 配置GPC0_3和GPC0_4为输出 GPC0DAT |= (0x3 << 3); // 熄灭LED1和LED2 puts("UART Test in S5PV210"); puts("1.LED1 Toggle"); puts("2.LED2 Toggle"); puts("Please select 1 or 2 to Toggle the LED"); // putchar('1'); while (1) { c = getchar(); // 从串口终端获取一个字符 putchar(c); // 回显 putchar('\r'); if (c == '1') GPC0DAT ^= 1 << 3; // 改变LED1的状态 else if (c == '2') GPC0DAT ^= 1 << 4; // 改变LED2的状态 } return 0; }复制#define GPA0CON *((volatile unsigned int *)0xE0200000) #define ULCON0 *((volatile unsigned int *)0xE2900000) #define UCON0 *((volatile unsigned int *)0xE2900004) #define UFCON0 *((volatile unsigned int *)0xE2900008) #define UTRSTAT0 *((volatile unsigned int *)0xE2900010) #define UTXH0 *((volatile unsigned int *)0xE2900020) #define URXH0 *((volatile unsigned int *)0xE2900024) #define UBRDIV0 *((volatile unsigned int *)0xE2900028) #define UDIVSLOT0 *((volatile unsigned int *)0xE290002C) // #define GPA0CON *((volatile unsigned int *)0xE0200000) // #define ULCON0 *((volatile unsigned int *)0xE2900400) // #define UCON0 *((volatile unsigned int *)0xE2900404) // #define UFCON0 *((volatile unsigned int *)0xE2900408) // #define UTRSTAT0 *((volatile unsigned int *)0xE2900410) // #define UTXH0 *((volatile unsigned int *)0xE2900420) // #define URXH0 *((volatile unsigned int *)0xE2900424) // #define UBRDIV0 *((volatile unsigned int *)0xE2900428) // #define UDIVSLOT0 *((volatile unsigned int *)0xE290042C) /* UART0初始化 */ void uart_init() { /* ** 配置GPA0_0为UART_0_RXD ** 配置GPA0_1为UART_0_TXD */ GPA0CON &= ~0xFF; GPA0CON |= 0x22; GPA0CON &= ~(0xFF<<16); GPA0CON |= (0x22<<16); /* 8-bits/One stop bit/No parity/Normal mode operation */ ULCON0 = 0x3; /* Interrupt request or polling mode/Normal transmit/Normal operation/PCLK/*/ UCON0 = 0x5;//1 | (1 << 2) ;//| (1<<5); /* 静止FIFO */ UFCON0 = 0; /* ** 波特率计算:115200bps ** PCLK = 66MHz ** DIV_VAL = (66000000/(115200 x 16))-1 = 35.8 - 1 = 34.8 ** UBRDIV0 = 34(DIV_VAL的整数部分) ** (num of 1's in UDIVSLOTn)/16 = 0.8 ** (num of 1's in UDIVSLOTn) = 12 ** UDIVSLOT0 = 0xDDDD (查表) */ UBRDIV0 = 34; UDIVSLOT0 = 0xDDDD; } void putchar(unsigned char c); static void uart_send_byte(unsigned char byte) { while (!(UTRSTAT0 & (1 << 2))); /* 等待发送缓冲区为空 */ UTXH0 = byte; /* 发送一字节数据 */ } static unsigned char uart_recv_byte() { while (!(UTRSTAT0 & 1)); /* 等待接收缓冲区有数据可读 */ return URXH0; /* 接收一字节数据 */ } void putchar(unsigned char c) { uart_send_byte(c); /* 如果只写'\n',只是换行,而不会跳到下一行开头 */ if (c == '\n') uart_send_byte('\r'); } unsigned char getchar() { unsigned char c; c = uart_recv_byte(); return c; } void puts(char *str) { char *p = str; while (*p) putchar(*p++); putchar('\n'); }
#define GPA0CON *((volatile unsigned int *)0xE0200000) #define ULCON0 *((volatile unsigned int *)0xE2900000) #define UCON0 *((volatile unsigned int *)0xE2900004) #define UFCON0 *((volatile unsigned int *)0xE2900008) #define UTRSTAT0 *((volatile unsigned int *)0xE2900010) #define UTXH0 *((volatile unsigned int *)0xE2900020) #define URXH0 *((volatile unsigned int *)0xE2900024) #define UBRDIV0 *((volatile unsigned int *)0xE2900028) #define UDIVSLOT0 *((volatile unsigned int *)0xE290002C) // #define GPA0CON *((volatile unsigned int *)0xE0200000) // #define ULCON0 *((volatile unsigned int *)0xE2900400) // #define UCON0 *((volatile unsigned int *)0xE2900404) // #define UFCON0 *((volatile unsigned int *)0xE2900408) // #define UTRSTAT0 *((volatile unsigned int *)0xE2900410) // #define UTXH0 *((volatile unsigned int *)0xE2900420) // #define URXH0 *((volatile unsigned int *)0xE2900424) // #define UBRDIV0 *((volatile unsigned int *)0xE2900428) // #define UDIVSLOT0 *((volatile unsigned int *)0xE290042C) /* UART0初始化 */ void uart_init() { /* ** 配置GPA0_0为UART_0_RXD ** 配置GPA0_1为UART_0_TXD */ GPA0CON &= ~0xFF; GPA0CON |= 0x22; GPA0CON &= ~(0xFF<<16); GPA0CON |= (0x22<<16); /* 8-bits/One stop bit/No parity/Normal mode operation */ ULCON0 = 0x3; /* Interrupt request or polling mode/Normal transmit/Normal operation/PCLK/*/ UCON0 = 0x5;//1 | (1 << 2) ;//| (1<<5); /* 静止FIFO */ UFCON0 = 0; /* ** 波特率计算:115200bps ** PCLK = 66MHz ** DIV_VAL = (66000000/(115200 x 16))-1 = 35.8 - 1 = 34.8 ** UBRDIV0 = 34(DIV_VAL的整数部分) ** (num of 1's in UDIVSLOTn)/16 = 0.8 ** (num of 1's in UDIVSLOTn) = 12 ** UDIVSLOT0 = 0xDDDD (查表) */ UBRDIV0 = 34; UDIVSLOT0 = 0xDDDD; } void putchar(unsigned char c); static void uart_send_byte(unsigned char byte) { while (!(UTRSTAT0 & (1 << 2))); /* 等待发送缓冲区为空 */ UTXH0 = byte; /* 发送一字节数据 */ } static unsigned char uart_recv_byte() { while (!(UTRSTAT0 & 1)); /* 等待接收缓冲区有数据可读 */ return URXH0; /* 接收一字节数据 */ } void putchar(unsigned char c) { uart_send_byte(c); /* 如果只写'\n',只是换行,而不会跳到下一行开头 */ if (c == '\n') uart_send_byte('\r'); } unsigned char getchar() { unsigned char c; c = uart_recv_byte(); return c; } void puts(char *str) { char *p = str; while (*p) putchar(*p++); putchar('\n'); }
您需要 登录 才可以下载或查看,没有账号?注册
收藏0 举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
2
5
0
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号