51单片机使用串口printf
/*—————————————————————————-*/
/*—————————————————————————-*/
void Uart0_Init(unsigned int baud)
{
unsigned long tmp;
#if 0
P2CR &= ~BIT(0); //Input Mode
P2PCR |= BIT(0); //Enable pull-up resistor
P2 |= BIT(0);
P2CR |= BIT(1); //Output Mode
P2PCR &= ~(BIT(1)); //Disable pull-up resistor
P2 |= BIT(1);
#endif
/* Config Uart0:Mode 1, 8-bits asynchronous. */
SCON = 0x50;
PCON |=0x80; //Double baud rate
tmp = 16000000/16/baud; //16000000UL*2/2/16/baud;
tmp = 65536 – tmp;
RCLK = 0; //T4 create rxd baud rate
TCLK = 0; //T4 create txd baud rate
_push_(INSCON);
Select_Bank1();
T4CLKS = 0; //T4 Clock select = Sysclk = 16MHz;
T4PS1 = 0; //T4 Prescaler = 1/1;
T4PS0 = 0;
T4M1 = 0; //T4 mode select bits = 01, T4 as Baud rate generator.
T4M0 = 1;
TL4 = (unsigned char)tmp;
TH4 = (unsigned char)(tmp>>8);
TR4 = 1;
Select_Bank0();
_pop_(INSCON);
REN = 1; //Enable Receive
//ES0 = 1; //Enable Uart0 Interrupt
//TI = 1; //printf need
}
2024最新激活全家桶教程,稳定运行到2099年,请移步至置顶文章:https://sigusoft.com/99576.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。 文章由激活谷谷主-小谷整理,转载请注明出处:https://sigusoft.com/93932.html