STC单片机不同数据类型串口打印输出示例程序
- 串口监视器打印
程序代码
#include "STC15W4K.H"
#include <stdio.h>
void printf_char_int_long(void)
{
char a=-100;
int b=-2000;
long c=6553600;
printf ("char %bd int %d long %ld\n",a,b,c);
printf ("char_0x%bx int_0x%x long_0x%lx\n",a,b,c);
printf ("a_int %d\n",(int)(a));
printf ("char %bd,int %d,long %ld\n",a,b,c);
}
void printf_float(void)
{
float a= 3.14159265798932;
float f = 10.0,g = 22.95;
printf("Max is %f\n",a);
printf("%.4f\n",a);
printf("%.12f\n",a);
printf ("%f , %g\n", f, g);
}
void printf_String(void)
{
char buf [] = "Test String";
char *p = buf;
printf ("String %s is at address %p\n",buf,p);
}
void UART_init(void)
{
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = 1;
AUXR = 0x00;
SCON = 0x50;
TI=1;
}
void main()
{
UART_init();
printf_char_int_long();
printf_float() ;
printf_String() ;
while(1) ;
}
|