当前位置:网站首页>Stc8a8k64d4 (51 Series MCU) printf printing data abnormal problem
Stc8a8k64d4 (51 Series MCU) printf printing data abnormal problem
2022-04-22 03:43:00 【Diye】
Problem phenomenon
I am using STC8A8K64D4 MCU to do a project , Use printf An exception occurred while the function was printing debugging information with parameters ( Redirected correctly printf function ), The specific performance defines 8 Bit variables use %X The value printed out in the format becomes 16 position , And the assignment is 0 Then print out 16 Random value of bit ; And then define a 16 Bit variables , Use %d Format printing , Nor can the value of the variable be printed correctly , And print the values of other exceptions , Use the serial port to send a single byte function , Send the upper eight bits and the lower eight bits respectively , And print out the value of the variable correctly ; And format the data into a string Use %s You can print data normally
Problem solving
Access to information ,51 Single chip microcomputer adopt printf When printing formatted data , Out of commission %d Placeholders like that , Instead, use the following placeholders :
| Size of data to be printed | Formatted symbols | remarks |
|---|---|---|
| Place holder 8 position | bd/bu | bd: A signed 8 Bit data bu: Unsigned 8 Bit data |
| Place holder 16 position | hd/hu | hd: A signed 16 Bit data hu: Unsigned 16 Bit data |
| Place holder 32 position | ld/lu | ld: A signed 32 Bit data lu: Unsigned 32 Bit data |
- The first thing to do is to determine printf Has been correctly redirected to the specified serial port
/********************* Printf Redirection function ************************/
#if(PRINTF_SEL == 1)
char putchar(char c)
{
TX1_write2buff(c);
return c;
}
#elif(PRINTF_SEL == 2)
char putchar(char c)
{
TX2_write2buff(c);
return c;
}
#elif(PRINTF_SEL == 3)
char putchar(char c)
{
TX3_write2buff(c);
return c;
}
#elif(PRINTF_SEL == 4)
char putchar(char c)
{
TX4_write2buff(c);
return c;
}
#endif
- 51 Use of single chip microcomputer printf when , Formatted data is , Use the formatting symbols in the above table , The specific tests are as follows :
/* Put the function in mian Function Check the printed value */
void test51printf(void)
{
unsigned char a = 128;
char b = -15 ;
unsigned short c = 256;
short d = -25;
unsigned int e = 65535;
int f = -32765;
printf("a=%bu b=%bd c=%hu d=%hd e=%hu f=%hd \r\n",a,b,c,d,e,f);
printf("\r\n size(a)=%bu,size(c)=%bu,size(e)=%bu \r\n" ,sizeof(a),sizeof(c),sizeof(e));
}
The results are as follows :
a=128 b=-15 c=256 d=-25 e=65535 f=-32765
size(a)=1,size(c)=2,size(e)=2
Data can be printed normally , Problem solving !
PS:51 In the single chip microcomputer int = short int = 2 Bytes
版权声明
本文为[Diye]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211119010477.html
边栏推荐
- 安装node环境
- MNIST recognition through back propagation
- DR/AP4029 outdoor IPQ-4019/4029 Outdoor directional-antennas
- What is the future direction of GPU?
- TP5 uses phpoffice / phpexcel package to operate excel (export)
- Machine learning theory (6): from logistic regression (logarithmic probability) method to SVM; Why is SVM the maximum interval classifier
- 2021-10-19 performance test
- Une solution pour enregistrer l'échec de la connexion à distance MySQL dans la configuration du serveur Cloud
- Use and principle of atomic class
- Five methods of not displaying line number in history command in UNIX like system
猜你喜欢

Implementation of small cases

Knowledge of power system

AI video cloud vs narrowband HD, who is the darling of the video era

【C】 Guess the number, shut down the applet, and practice some branch loops

Deep learning and image recognition: principle and practice notes day_ fifteen

Deep learning and image recognition: principle and practice notes day_ 18 (target detection) continued

The third year after the epidemic: technical management and teamwork under the changing times!

机器学习理论之(6):由逻辑回归(对数几率)方法到 SVM;为什么 SVM 是最大间隔分类器

There is no input method after win11 system starts up - the solution is effective through personal test

Im instant messaging development technology: 1-10 million high concurrency architecture evolution
随机推荐
Deep learning and image recognition: principle and practice notes day_ thirteen
The third year after the epidemic: technical management and teamwork under the changing times!
View application memory usage
The WiFi button of win11 is missing and cannot be connected to the Internet
[knowledge atlas] catalogue of financial securities knowledge atlas projects
隊列使用問題總結 queue:work和queue:listen的區別
Record the solution to the failure of configuring MySQL remote connection for ECS once
Xampp configuration Xdebug extension, php7 Version 2.2
Computer wechat built-in browser turns on debugging mode
win11系统开机后没有输入法——解决方法亲测有效
Zabbix5 series - making topology map (XIII)
Collection thread safety
类unix系统中history命令不显示行号的5种方法
Deep learning and image recognition: principle and practice notes day_ 18 (target detection) continued
2021-10-19 performance test
wangEditor富文本编辑器使用、编辑器内容转json格式
ForkJoin
Xiaomi and zhiting's smart cameras protect your family privacy
税法18个税种全总结附记忆小口诀
【C】猜数字,关机小程序,一些分支循环的练手题