IAR For AVR USART 应用

 

#include
#define uchar unsigned char
#define uint unsigned int

//###########################################################
/*串口初始化函数*/
void Uart_Init(void)
{                        
   UCSRB = (1< UCSRC = (1<

UBRRH=0x00;                                              //设置波特率寄存器低位字节
        UBRRL=47;                                //9600    //设置波特率寄存器高位字节

DDRD_Bit1=1;                            //配置TX为输出(很重要)
}
//###########################################################
/*发送一个字符数据,查询方式*/
void Uart_Transmit(uchar data)
{
     while(!(UCSRA&(1<    //while(UCSRA_UDRE==0);   /* 等待发送缓冲器为空*/
UDR = data;                         /* 发送数据*/
}
//###########################################################
//发送一串数据 带回车符
void Uart_Puts(uchar *str)
{
while(*str)
         {
    Uart_Transmit(*(str++));
}
Uart_Transmit(0x0a);//回车换行
Uart_Transmit(0x0d);
}
//###########################################################
//发送一串数据 不带回车符
void Uart_Put(uchar *str)
{
while(*str)
         {
    Uart_Transmit(*(str++));
}
}
//###########################################################
/*数据接收,查询方式*/
unsigned char Uart_Receive( void ) {

while (!(UCSRA & (1< return UDR;    
}
//###########################################################

你可能感兴趣的:(AVR-IAR)