九鼎创展论坛
标题:
UART_x6818裸板编程
[打印本页]
作者:
laohu360
时间:
2017-11-19 20:06
标题:
UART_x6818裸板编程
#define UART0CLKENB *((volatile unsigned int *)0xC00A9000)
#define UART0CLKGEN0L *((volatile unsigned int *)0xC00A9004)
#define GPIOD_ALTFN0 *((volatile unsigned int *)0xC001D020)
#define GPIOD_ALTFN1 *((volatile unsigned int *)0xC001D024)
#define GPIOD_PULLENB *((volatile unsigned int *)0xC001D060)
#define ULCON0 *((volatile unsigned int *)0xC00A1000)
#define UCON0 *((volatile unsigned int *)0xC00A1004)
#define UFCON0 *((volatile unsigned int *)0xC00A1008)
#define UTRSTAT0 *((volatile unsigned int *)0xC00A1010)
#define UTXH0 *((volatile unsigned int *)0xC00A1020)
#define URXH0 *((volatile unsigned int *)0xC00A1024)
#define UBRDIV0 *((volatile unsigned int *)0xC00A1028)
#define UFRACVAL0 *((volatile unsigned int *)0xC00A102C)
void uart_init(void)
{
//先禁止时钟
UART0CLKENB &= ~(1<<2);
//选择时钟源为PPL1=800MHZ
//[4:2]=001 先请零
UART0CLKGEN0L &= ~(7<<2);
UART0CLKGEN0L |= (1<<2);
//设置分频系数
//[12:5] = 1111 1111,先请零
UART0CLKGEN0L &= ~(0xff<<5);
//UART0CLKGEN0L |= (0x0f<<5); //800/(0xof+1)=50MHz
UART0CLKGEN0L |= (0x13<<5); //800/(0x13+1)=40MHz
//配置管脚的功能 功能1
GPIOD_ALTFN0 &= ~(3<<28);
GPIOD_ALTFN0 |= (1<<28);
GPIOD_ALTFN1 &= ~(3<<4);
GPIOD_ALTFN1 |= (1<<4);
//uart控制器的配置
ULCON0 = 0x03; //7-bit/1-bit停止位
UCON0 = 0x05; //[3:0]=0101
//UBRDIV0 = 26; //uart 50MHz
//UFRACVAL0 = 2;
UBRDIV0 = 20; //uart 40MHz
UFRACVAL0 = 11;
//使能时钟
UART0CLKENB |= (1<<2);
}
void uart_putc(char c)
{
/*轮询发送缓冲区是否为空,
UARTSTATO[1]=1 空*/
while( !(UTRSTAT0 & (1<<1)) ) ;
UTXH0 = c;//发送一个字符
if(c == '\n')
uart_putc('\r');
}
void uart_puts(char *str)
{
while(*str)
{
uart_putc(*str);
str++;
}
}
UART_x6818裸板编程.rar
2017-11-19 20:01 上传
点击文件名下载附件
160.69 KB, 下载次数: 6
作者:
FuZhenYu163
时间:
2020-9-6 16:08
学习一下
欢迎光临 九鼎创展论坛 (http://bbs.9tripod.com/)
Powered by Discuz! X3.2