S3C2440 Uart (miniARM 2440 )
S3C2440 Uart (miniARM 2440 )
- #ifndef UART_H
- #define UART_H
- #include "2440addr.h"
- void UartInit(u32 baud);
- void UartSendChar(u8 c);
- void UartSendStr(char *str);
- char UartGetChar(void);
- void UartPrintf(char *fmt,...);
- #endif
uart.c
[cpp]
- #include "uart.h"
- void UartInit(u32 baud)
- {
- rUBRDIV0 = (int)(PCLK/baud/16.0)-1;
- // rULCON0:
- //bit7 Reserved
- //bit6 Infrared Mode
- // 0 = Normal
- // 1 = Infrared
- //bit5:3 Parity Mode
- // 0xx = No Parity
- // 100 = ODD Parity
- // 101 = EVEN Parity
- // 110 = Parity Forced / Checked as 1
- // 111 = Parity Forced / Checked as 0
- //bit2 number Of Stop bit
- // 0 = one stop bit per frame
- // 1 = two stop bit per frame
- //bit1:0 Word Length
- // 00 = 5bits 01 = 6bits
- // 10 = 7bits 11 = 8bits
- rULCON0 = 0x03;
- rUCON0 = 0x245;
- }
- void UartSendChar(u8 c)
- {
- while(! (rUTRSTAT0 &0x02));
- rUTXH0 = c;
- }
- void UartSendStr(char *str)
- {
- while(*str !='/0')
- UartSendChar(*str++);
- }
- char UartGetChar(void)
- {
- while(!(rUTRSTAT0 & 0x01));
- return rURXH0;
- }
- void UartPrintf(char *fmt,...)
- {
- va_list ap;
- char string[256];
- va_start(ap,fmt);
- vsprintf(string,fmt,ap);
- UartSendStr(string);
- va_end(ap);
- }
评论暂时关闭