串口函数总结
串口的初始化
void UART0_Init(int mclk,int baud) {
if(mclk==0) mclk=MCLK; rPCONE = 0x28; rULCON0=0x3; rUCON0=0x245;
rUBRDIV0=( (int)(mclk/16./baud + -1 ); }
void UART1_Init(int mclk,int baud) {
if(mclk==0) mclk=MCLK; rPCONE = 0x28; rULCON0=0x3; rUCON0=0x245;
rUBRDIV0=( (int)(mclk/16./baud + -1 ); }
查询方式发送数据
void UART0_SendByte(uint8 data) {
rUTXH0 = data;
while((rUTRSTAT0 & 0x2) == 0); }
查询方式接收
Void UART0_RcvByte((uint8 data) {
uint8 rcv_data;
while((rUTRSTAT0 & 0x01) == 0); rcv_data = rURXH0; return(rcv_data); }
使用外部中断发送和接收字符的函数:
#include \"\" #include \"\" #include \"\" void Main(void);
extern void Eint4567Isr(void) __attribute__ ((interrupt (\"IRQ\"))); void init_Eint(void); void Main(void)
1
-
{
sys_init(); /* 初始化s3c44B0XInterrupt,Port and UART */ _Link();
init_Eint() ; }
#include \"\" #include \"\"
void Eint4567Isr(void) __attribute__ ((interrupt (\"IRQ\"))); void init_Eint(void); extern void Delay(int time); void init_Eint(void) {
rI_ISPC = 0x3ffffff;
if(which_int == 4) {
Uart_Printf(\"发送:\\n\"); Uart_SendByte('*'); }
else if(which_int == 8) i=Uart_Getch(); Uart_Printf(\" %c \\n\ } }
// SB3
{ Uart_Printf(\"接收:\\n\");
// SB2
rEXTINTPND = 0xf;
//clear pending_bit
rI_ISPC=BIT_EINT4567;
Uart_Printf(\"\\n\\rEmbest 44B0X Evaluation Board(S3CEV40)\");
Uart_Printf(\"\\n\\r8-segment Digit LED Test Example(Please look at LED)\\n\"); for( ; ; ) { ; }
2
因篇幅问题不能全部显示,请点此查看更多更全内容