S3C2440 UART串口驱动
/* xmain.c */
/* GPIO registers */
#defineGPHCON(*(volatile unsigned long *)0x56000070)
#defineGPHDAT(*(volatile unsigned long *)0x56000074)
#defineGPHUP(*(volatile unsigned long *)0x56000078)
/*UART registers*/
#defineULCON0(*(volatile unsigned long *)0x50000000)
#defineUCON0(*(volatile unsigned long *)0x50000004)
#defineUFCON0(*(volatile unsigned long *)0x50000008)
#defineUMCON0(*(volatile unsigned long *)0x5000000c)
#defineUTRSTAT0(*(volatile unsigned long *)0x50000010)
#defineUTXH0(*(volatile unsigned char *)0x50000020)
#defineURXH0(*(volatile unsigned char *)0x50000024)
#defineUBRdiv0(*(volatile unsigned long *)0x50000028)
#defineTXD0READY(1<2)//发送数据状态OK
#defineRXD0READY(1)//接收数据状态OK
/* UART串口初始化*/
void uart_init( )
{
GPHCON |= 0xa0;//GPH2,GPH3 used as TXD0,RXD0
GPHUP= 0x0;//GPH2,GPH3内部上拉
ULCON0= 0x03;//8N1
UCON0= 0x05;//查询方式为轮询或中断;时钟选择为PCLK
UFCON0 = 0x00;//不使用FIFO
UMCON0 = 0x00;//不使用流控
UBRdiv0 = 12;//波特率为57600,PCLK=12Mhz
}
/* UART串口单个字符打印函数*/
extern void putc(unsigned char c)
{
while( ! (UTRSTAT0 & TXD0READY) );
UTXH0 = c;
}
/* UART串口接受单个字符函数*/
extern unsigned char getc(void)
{
while( ! (UTRSTAT0 & RXD0READY) );
return URXH0;
}
/* UART串口字符串打印函数*/
extern int printk(const char* str)
{
int i = 0;
while( str[i] ){
putc( (unsigned char) str[i++] );
}
return i;
}
__inline void delay(int msec)
{
int i, j;
for(i = 1000; i > 0; i--)
for(j = msec*10; j > 0; j--)
/* do nothing */;
}
/* xmain通过UART串口打印字符串*/
int xmain()
{
uart_init();
while(1) {
delay(10);
printk("Uart串口打印试验/r/n");
}
return 0;
}
S3C2440UART串口驱 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)