www.pudn.com > uCOS+GUI.rar > UART0.C


/* 
********************************************************************************************************* 
* 文件: UART0.C 
* 描述: Uart 0 服务程序. 
* 编写: 深思 (001-12345@sohu.com). 
********************************************************************************************************* 
*/ 
#include "headers.h" 
#include "uc_os.h" 
 
/* 
********************************************************************************************************* 
* 描述: 初始化 UART0 . 
********************************************************************************************************* 
*/ 
#define  Baud  115200                                   // 设置当前 UART0 的波特率. 
 
void Init_UART0 (void) 
{ 
    ULCON0 = ((0<<6)+(0<<3)+(0<<2)+3);                  // Normal,No parity,1 stop,8 bit. 
    UCON0  = ((0<<9)+(0<<8)+(0<<7)+(0<<6)+(0<<5)+(0<<4)+(1<<2)+0); 
    UFCON0 = ((0<<6)+(0<<4)+(0<<2)+(0<<1)+1); 
    UMCON0 = ((0<<4) + 0); 
    UBRDIV0= ((int)(Fclk / (16 * Baud)) - 1);  
 
    INTMSK &= ~(1 << 3);                                // 开 UART0 发送中断屏蔽位. 
 
    Uart0.Wr  = 0; 
    Uart0.Rd  = 0; 
    Uart0.Sem = OSSemCreate (1);                        /* 建立一个信号量,避免冲突.*/ 
} 
 
/* 
******************************************************************************************************** 
* 函数: void __irq ISR_UTXD0 (void). 
* 描述: UART0 发送中断服务程序. 
******************************************************************************************************** 
*/ 
void __irq ISR_UTXD0 (void) 
{ 
    OSIntEnter(); 
 
    while ((UFSTAT0 & (1<<9)) == 0) { 
        if (Uart0.Rd != Uart0.Wr) { 
            UTXH0 = Uart0.Buffer[Uart0.Rd++]; 
            if (Uart0.Rd >= Uart0BufSize) { 
                Uart0.Rd = 0x00; 
            } 
        } else    break; 
    } 
 
    OSIntExit(); 
    I_ISPC |= (1 << 3);                            /* clear the pending bit. */ 
} 
 
/* 
******************************************************************************************************** 
* End. 
******************************************************************************************************** 
*/