背景图片
合泰BS86D20 串口通讯源码 - 啊和的博客

合泰BS86D20 串口通讯源码 - 啊和的博客 合泰BS86D20 串口通讯源码 - 啊和的博客

合泰BS86D20 串口通讯源码

本人在项目中用到了BS86D20的串口通讯,现在发出例程给各大网友参考下

void uart_init()  //串口初始化
{
	_ucr1	= 0x80;                 /* 1000 0000 */
	_ucr2	= 0xc4;                 /* 1100 0000 */
 //_hircs1=0;_hircs0=1;//HIRC 时钟频率选择位 12MHZ选这个
 //_hircs1=0;_hircs0=0;//HIRC 时钟频率选择位 8MHZ选这个
	_hircs1 = 1; _hircs0 = 0;       /* HIRC 时钟频率选择位 16MHZ选这个 */
	_brg	= 25;                   /* 9600波特率 */
	_uarte	= 1;                    /* 使能UART中断 */
	_emi	= 1;                    /* 使能全局中断 */
}


void Send_Uart( unsigned char dat ) //发一个字节的数据
{
	while ( _txif == 0 )
	{
		_clrwdt();
	}
	_txr_rxr = dat;
}

void Send_String(unsigned char  *s)//发送字符串
{
	while(*s != '\0')
    { 
			Send_Uart(*s);
			s++;
    }
}

}
void __attribute( (interrupt( 0x2C ) ) ) Interrupt_Uart( void ) /* 串口接收中断 */
{
	if ( RxCount > 25 )
	{
		RxCount = 0;
	}
	UartRxBuf[RxCount] = _txr_rxr;

	RxCount++;


	while ( _txif == 0 )
	{
		_clrwdt();
	}

	_uartf = 0;
}

 

 

评论 0

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论