串口发送接收显示和sprintf

#include <STC15F2K60S2.H>
#include <stdio.h>
float fa[10]={0};
unsigned char jie[10]={0};
unsigned char i;
unsigned char date;
float t=22.36;
void fasong(unsigned char *dat);
unsigned char code Duan[22]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,
0xc6,0xc0,0x86,0x8e,0xbf,0x7f,0XC1,0X8C,0XC8,0xc3};
void UartInit(void)		//9600bps@12.000MHz
{
	SCON = 0x50;		//8???,?????
	AUXR |= 0x01;		//??1?????2???????
	AUXR |= 0x04;		//???2???Fosc,?1T
	T2L = 0xC7;		//??????
	T2H = 0xFE;		//??????
	AUXR |= 0x10;		//?????2
	EA=1;
	ES=1;
}
void send_Byte(unsigned char dat)
{
	SBUF = dat;
	while(TI==0);
	TI=0;
}
void fasong(unsigned char *dat)
{
	while(*dat!='\0')
			send_Byte(*dat++);
}
void un() interrupt 4
{
	if(RI==1)
	{
		jie[i]=SBUF;
		i++;
		RI=0;
	}
}
void caozuo()
{
	if(i==1)
	{
		date=jie[0];
		i=0;
	}
}
void suocun(unsigned char n)
{
	switch(n)
	{
		case 4:P2= (P2 & 0x1f)|0x80;break;
		case 5:P2= (P2 & 0x1f)|0xa0;break;
		case 6:P2= (P2 & 0x1f)|0xc0;break;
		case 7:P2= (P2 & 0x1f)|0xe0;break;
	}
}
void Delay(unsigned int t)
{
	while(t--);	
}
void smg(unsigned char wei,unsigned char shu)
{
	suocun(6);
	P0=0x01<<wei;
	suocun(7);
	P0=Duan[shu];
	Delay(500);
	P0=0xff;
}
void xs()
{
	smg(0,date/10);
	Delay(100);
	smg(1,date%10);
	Delay(100);

}
void main()
{
	UartInit();
	fasong("Hello!\r\n");
	sprintf(fa,"ζÈ=%.2f",t);
	fasong(fa);
	
	while(1)
	{
		caozuo();
		xs();
	}
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值