基于AT89C51单片机的串口通信
使用printf语句向虚拟终端发送字符串
第一步:增加基本输出库stdio.h
第二步:设置串口参数
第三步:直接在函数中使用printf进行打印
C51单片机如何使用printf
printf函数是调用putchar函数输入的,而putchar应该是先判TI断ti是否为1,不为1则等待为1。 如果为1则清0,然后送出一个字符。因此 你如果直接使用printf函数,你的程序就会在putchar函数中等待ti为1。这时你的程序就相当于直接死掉了。
方法一:删除stdio.h中的putchar函数,重定义putchar函数
#include <reg51.h>
#include <string.h>
#include <stdio.h>
#define uint unsigned int
#define uchar unsigned char
//毫秒级延时函数
void delay(uint x)
{
uchar i;
while(x--)
{
for(i = 0;i < 120;i++);
}
}
char * mystring()
{
static char str[20