⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.c

📁 用单片机M8和传感器H10来测量温湿度
💻 C
字号:
/******************************************************************************
**Name: 	串口驱动程序
**note:		ATmega8@1.0Mhz
**compiler:	IccAVR
**Verson:	v1.0		
**Date:		2008.08.31
**By:		Eason

******************************************************************************/

#include	"main.h"


/**************************************************************************************************
//UART0 initialize
// desired baud rate: 4800	@1.0Mhz
// actual: baud rate:4808 (0.2%)@1.0Mhz
// char size: 8 bit
// parity: Disabled
**************************************************************************************************/
void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x00;
 UCSRC = BIT(URSEL) | 0x06;
 UBRRL = 0x0C; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0x18;
}

/**************************************************************************************************
**Name: 	
**Function:	串口发送一字节
**Input:	
**Output:	
**************************************************************************************************/
void uart_send_char(char data) // \arg pointer to a string ending by \0
{
  	unsigned int	i=0;
	 while ((!(UCSRA&(1<<UDRE)))&&(i++<10000)) ;
	 //if(i>9998) return 1;
	 UDR=data;
	 //return 0;
}
/**************************************************************************************************
**Name: 	
**Function:	串口发送字符串
**Input:		发送字符串首地址,检测到\0 停止发送
**Output:	
**************************************************************************************************/
void uart_send_string(char * s) // \arg pointer to a string ending by \0
{
	while(*s)
	{
		uart_send_char(*s);
		s++;
	}
	//uart_send_char(0x0a);
	//uart_send_char(0x0d);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -