本人在项目中用到了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;
}
合泰BS86D20 串口通讯源码 - 啊和的博客
单片机串口通信中换行的两种方法
编码器程序(定时扫描版本)
合泰单片机利用中端口接收串口数据
C语言枚举类型变量的作用
AD滤波程序
单片机和弦音程序
Android手机通过蓝牙模块与单片机通信单片机程序
基于STM8的TIM定时器操作