首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

s3c2440的UART用法(4)

s3c2440的UART用法(4)

ADS下的串口配置


def.h 中的UART寄存器定义:


#define rULCON0     (*(volatile unsigned *)0x50000000) //UART 0 Line control


#define rUCON0      (*(volatile unsigned *)0x50000004) //UART 0 Control


#define rUFCON0     (*(volatile unsigned *)0x50000008) //UART 0 FIFO control


#define rUMCON0     (*(volatile unsigned *)0x5000000c) //UART 0 Modem control


#define rUTRSTAT0   (*(volatile unsigned *)0x50000010) //UART 0 Tx/Rx status


#define rUERSTAT0   (*(volatile unsigned *)0x50000014) //UART 0 Rx error status


#define rUFSTAT0    (*(volatile unsigned *)0x50000018) //UART 0 FIFO status


#define rUMSTAT0    (*(volatile unsigned *)0x5000001c) //UART 0 Modem status


#define rUBRDIV0    (*(volatile unsigned *)0x50000028) //UART 0 Baud rate divisor



#define rULCON1     (*(volatile unsigned *)0x50004000) //UART 1 Line control


#define rUCON1      (*(volatile unsigned *)0x50004004) //UART 1 Control


#define rUFCON1     (*(volatile unsigned *)0x50004008) //UART 1 FIFO control


#define rUMCON1     (*(volatile unsigned *)0x5000400c) //UART 1 Modem control


#define rUTRSTAT1   (*(volatile unsigned *)0x50004010) //UART 1 Tx/Rx status


#define rUERSTAT1   (*(volatile unsigned *)0x50004014) //UART 1 Rx error status


#define rUFSTAT1    (*(volatile unsigned *)0x50004018) //UART 1 FIFO status


#define rUMSTAT1    (*(volatile unsigned *)0x5000401c) //UART 1 Modem status


#define rUBRDIV1    (*(volatile unsigned *)0x50004028) //UART 1 Baud rate divisor



#define rULCON2     (*(volatile unsigned *)0x50008000) //UART 2 Line control


#define rUCON2      (*(volatile unsigned *)0x50008004) //UART 2 Control


#define rUFCON2     (*(volatile unsigned *)0x50008008) //UART 2 FIFO control


#define rUMCON2     (*(volatile unsigned *)0x5000800c) //UART 2 Modem control


#define rUTRSTAT2   (*(volatile unsigned *)0x50008010) //UART 2 Tx/Rx status


#define rUERSTAT2   (*(volatile unsigned *)0x50008014) //UART 2 Rx error status


#define rUFSTAT2    (*(volatile unsigned *)0x50008018) //UART 2 FIFO status


#define rUMSTAT2    (*(volatile unsigned *)0x5000801c) //UART 2 Modem status


#define rUBRDIV2    (*(volatile unsigned *)0x50008028) //UART 2 Baud rate divisor



#ifdef __BIG_ENDIAN


#define rUTXH0      (*(volatile unsigned char *)0x50000023) //UART 0 Transmission Hold


#define rURXH0      (*(volatile unsigned char *)0x50000027) //UART 0 Receive buffer


#define rUTXH1      (*(volatile unsigned char *)0x50004023) //UART 1 Transmission Hold


#define rURXH1      (*(volatile unsigned char *)0x50004027) //UART 1 Receive buffer


#define rUTXH2      (*(volatile unsigned char *)0x50008023) //UART 2 Transmission Hold


#define rURXH2      (*(volatile unsigned char *)0x50008027) //UART 2 Receive buffer



#define WrUTXH0(ch) (*(volatile unsigned char *)0x50000023)=(unsigned char)(ch)


#define RdURXH0()   (*(volatile unsigned char *)0x50000027)


#define WrUTXH1(ch) (*(volatile unsigned char *)0x50004023)=(unsigned char)(ch)


#define RdURXH1()   (*(volatile unsigned char *)0x50004027)


#define WrUTXH2(ch) (*(volatile unsigned char *)0x50008023)=(unsigned char)(ch)


#define RdURXH2()   (*(volatile unsigned char *)0x50008027)



#define UTXH0       (0x50000020+3)  //Byte_access address by DMA


#define URXH0       (0x50000024+3)


#define UTXH1       (0x50004020+3)


#define URXH1       (0x50004024+3)


#define UTXH2       (0x50008020+3)


#define URXH2       (0x50008024+3)



#else //Little Endian


#define rUTXH0 (*(volatile unsigned char *)0x50000020) //UART 0 Transmission Hold


#define rURXH0 (*(volatile unsigned char *)0x50000024) //UART 0 Receive buffer


#define rUTXH1 (*(volatile unsigned char *)0x50004020) //UART 1 Transmission Hold


#define rURXH1 (*(volatile unsigned char *)0x50004024) //UART 1 Receive buffer


#define rUTXH2 (*(volatile unsigned char *)0x50008020) //UART 2 Transmission Hold


#define rURXH2 (*(volatile unsigned char *)0x50008024) //UART 2 Receive buffer



#define WrUTXH0(ch) (*(volatile unsigned char *)0x50000020)=(unsigned char)(ch)


#define RdURXH0()   (*(volatile unsigned char *)0x50000024)


#define WrUTXH1(ch) (*(volatile unsigned char *)0x50004020)=(unsigned char)(ch)


#define RdURXH1()   (*(volatile unsigned char *)0x50004024)


#define WrUTXH2(ch) (*(volatile unsigned char *)0x50008020)=(unsigned char)(ch)


#define RdURXH2()   (*(volatile unsigned char *)0x50008024)



#define UTXH0       (0x50000020)    //Byte_access address by DMA


#define URXH0       (0x50000024)


#define UTXH1       (0x50004020)


#define URXH1       (0x50004024)


#define UTXH2       (0x50008020)


#define URXH2       (0x50008024)


#endif



Uart.c 文件中定义串口配置函数:


//====================================================


// 语法格式:void myUart_Init(int whichuart, int baud)


// 功能描述: 对Uart进行初始化,以所需要的波特率为输入参数


// 入口参数: UART端口号  波特率


// 出口参数: 无


//=====================================================================



void myUart_Init(int pclk, int baud)


{


if (pclk == 0)


    pclk = PCLK;


    if(UartNum == 0)        //判断是否使用UART0     


{         


/ /设置GPH端口为UART口


rGPHCON = rGPHCON & (~(0xffff));   //UART0: RXD0<==>GPH3  TXD0<==>GPH2


rGPHCON = rGPHCON | (0xaaa0) ;     


    rGPHUP  = 0x0;                     //使能上拉功能



rUFCON0=0x00;   // 不使用FIFO  


        rUMCON0=0x00;   //不使用自动流控制


        rULCON0=0x03;   //不采用红外线传输模式,无奇偶校验位,1个停止位,8个数据位


        rUCON0=0x245;   



                        


        rUBRDIV0=( (int)(pclk/16./baud+0.5) -1 );  //根据波特率计算UBRDIV0的值


  Delay(10);


     }


     else if(UartNum == 1)


     {


rGPHCON = rGPHCON & (~(0xffff)) ; //UART1: RXD1<==>GPH5  TXD1<==>GPH4


rGPHCON = rGPHCON | (0xaaa0) ;    //设置GPH端口为UART口


    rGPHUP  = 0x0;                    // 使能上拉功能



rUFCON1=0x0;   


        rUMCON1=0x0;   


        rULCON1=0x3;


        rUCON1=0x245;


        rUBRDIV1=( (int)(pclk/16./baud+0.5) -1 );


        Delay(10);


     }


}



//====================================================


// 语法格式:void myUart_SendByte(char ch)


// 功能描述: 发送字节数据


// 入口参数: 发送的字节数据      


// 出口参数: 无


//====================================================================



void myUart_SendByte(char ch)


{


if (UartNum ==0)


    {


if(ch=='\n')


{


    while(!(rUTRSTAT0 & 0x2));  //等待,直到发送缓冲区为空


//     Delay(10);            //超级中断的响应速度较慢


    WrUTXH0('\r');              //发送回车符


}


while(!(rUTRSTAT0 & 0x2));      //等待,直到发送缓冲区为空


// Delay(10);


WrUTXH0(ch);                    //发送字符


   }


else


    {


if(ch=='\n')


    {


    while(!(rUTRSTAT1 & 0x2));   //等待,直到发送缓冲区为空


//     Delay(10);                 //等待


    rUTXH1='\r';


    }


    while(!(rUTRSTAT1 & 0x2));  //Wait until THR is empty.


//     Delay(10);


    WrUTXH1(ch);


    }


}

继承事业,薪火相传
返回列表