www.pudn.com > EFA.rar > Uart.c


/***************************************************************************** 
描述:UART异步串行通讯程序。使用USART0。 
      晶体振荡器 XT2:8MHz  LFXT1:32.768kHz 
      波特率:9600bit/s,8位数据位,1位停止位,奇校验 
版本:1.0	2006-03-20 
*****************************************************************************/ 
#include  
#include "define.h" 
#include "Global.h" 
 
/***************************************************************************** 
发送函数。采用查询方式。 
p:指向发送数据缓冲区的指针 
******************************************************************************/ 
void Send_Uart(unsigned char *p) 
{ 
    unsigned char i; 
    unsigned char *pBuffer; 
    if(Send_Uart_En != 0x01) return; 
    Send_Uart_En = 0x00; 
     
    pBuffer = p; 
    for(i = 0;i < 14;i++) 
    { 
	while(IFG1&UTXIFG0 == 0);           // 查询是否发送完毕 
	TXBUF0 = *pBuffer; 
	pBuffer ++; 
    } 
} 
 
/********************************************************************* 
// 函数功能: 扫描键盘 
// 全局变量: key---键值 
// 返回值:   无 
**********************************************************************/ 
void Read_Key(void) 
{ 
    unsigned char temp1 = 0; 
    unsigned char temp2 = 0; 
 
    temp1 = P1IN & BIT2; 
    if(temp1 == BIT2) return;       	// 没有检测到有键按下,返回值为0 
    Delayms(20); 
    temp2 = P1IN & BIT2; 
    if(temp2 == BIT2 || temp2 != temp1) return;           									// 没有检测到有键按下,说明是抖动             
    key = ON;                           
    while((P1IN & BIT2) != BIT2); 
    Delayms(100); 
}