📄 serial.c
字号:
#include <s3c2410.h>
#include <serial.h>
#define TXD0READY (1<<2)
#define RXD0READY (1)
void init_uart(void)
{//初始化UART
int i = 0;
GPHCON |= 0xa0; //GPH2,GPH3 used as TXD0,RXD0
GPHUP = 0x0c; //GPH2,GPH3内部上拉
ULCON0 = 0x03; //8N1
UCON0 = 0x245; //查询方式
UFCON0 = 0x00; //不使用FIFO
UMCON0 = 0x00; //不使用流控
UBRDIV0 = 53; //波特率为57600(PCLK=50MHz)
//UBRDIV0=(int)(PCLK/(bps*16))-1
for(; i < 10000; i++);
}
void putc(unsigned char c)
{
while( ! (UTRSTAT0 & TXD0READY) );
UTXH0 = c;
}
unsigned char getc(void)
{
while( ! (UTRSTAT0 & RXD0READY) );
return URXH0;
}
int printk(unsigned char* str)
{
int i = 0;
while( str[i] ){
putc( (unsigned char) str[i++] );
}
return i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -