51单片机 串口用 printf输出 ,当输出的数据类型是unsigned char的时候 电脑收到的数自动乘上了256

比如我unsigned char a=111; printf("%d" ,a); 电脑串口收到的字符是 a=28416.为啥???其他类型却不是,比如我用u int又正常,这是为啥

楼主你好。
51单片机与标准C有区别:
KEIL里扩展出了b,h,l来对输入字节宽的设置:
(1)b八位
(2)h十六位
(3)l三十二位

在Keil C51中用printf输出一个单字节变量时要使用%bd,如
unsigned char counter;
printf("Current count: %bd\n", counter);

而在标准C语言中都是使用%d:
printf("Current count: %d\n", counter);
希望对你有帮助。
温馨提示:答案为网友推荐,仅供参考
相似回答