欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 4679|回復(fù): 13
收起左側(cè)

單片機(jī)C語(yǔ)言printf中文字符串亂碼 求助

[復(fù)制鏈接]
ID:1025655 發(fā)表于 2022-5-17 16:00 | 顯示全部樓層 |閱讀模式
代碼部分
while(1)
        {
        printf("系統(tǒng)初始化正常 hello word : %u\r\n",Cnt++);


串口輸出部分
系統(tǒng)初始化粘?hello word : 1
系統(tǒng)初始化粘?hello word : 2
系統(tǒng)初始化粘?hello word : 3
系統(tǒng)初始化粘?hello word : 4
系統(tǒng)初始化粘?hello word : 5
系統(tǒng)初始化粘?hello word : 6
系統(tǒng)初始化粘?hello word : 7
?低吵跏薊常 hello word : 8
系?吵跏薊常 hello word : 9
系統(tǒng)初始化粘?hello word : 10
系統(tǒng)初始化粘?hello word : 11
系統(tǒng)初?薊常 hello word : 12
系統(tǒng)初始化粘?hello word : 13
系統(tǒng)初始?常 hello word : 14
系統(tǒng)初始化粘?hello word : 15
系統(tǒng)初始化?常 hello word : 16
系統(tǒng)初始化粘?hello word : 17
系統(tǒng)初始化粘? hello word : 18
系統(tǒng)初始化粘?hello word : 19
系統(tǒng)初始化粘?hello word : 20
系統(tǒng)初始化粘?hello word : 21
系統(tǒng)初始化粘?hello word : 22
系統(tǒng)初始化粘?hello word : 23
系統(tǒng)初始化粘?hello word : 24
系統(tǒng)初始化粘?hello word : 25
系統(tǒng)初始化粘?hello word : 26
系統(tǒng)初始化粘?hello word : 27
系統(tǒng)初始化粘?hello word : 28
系統(tǒng)初始化粘?hello word : 29
系統(tǒng)初始化粘?hello word : 30
系統(tǒng)初始化粘?hello word : 31
系統(tǒng)初始化粘?hello word : 32
系統(tǒng)初始化粘?hello word : 33
系統(tǒng)初始化粘?hello word : 34
系統(tǒng)初始化粘?hello word : 35
系統(tǒng)初始化粘?hello word : 36
系統(tǒng)初始化粘?hello word : 37
?低吵跏薊常 hello word : 38
系統(tǒng)初始化粘?hello word : 39
系統(tǒng)初始化粘?hello word : 40
系統(tǒng)初始化粘?hello word : 41
系統(tǒng)初始化粘?hello word : 42
系統(tǒng)初始化粘?hello word : 43
系統(tǒng)初始化粘?hello word : 44
系統(tǒng)初始化粘?hello word : 45
系統(tǒng)初始?常 hello word : 46
系統(tǒng)初始化粘?hello word : 47
系統(tǒng)初始化?常 hello word : 48
系統(tǒng)初始化粘?hello word : 49
系統(tǒng)初始化粘? hello word : 50
系統(tǒng)初始化粘?hello word : 51
系統(tǒng)初始化粘?hello word : 52
系統(tǒng)初始化粘?hello word : 53
系統(tǒng)初始化粘?hello word : 54
系統(tǒng)初始化粘?hello word : 55
系統(tǒng)初始化粘?hello word : 56
系統(tǒng)初始化粘?hello word : 57
系統(tǒng)初始化粘?hello word : 58
系統(tǒng)初始化粘?hello word : 59
系統(tǒng)初始化粘?hello word : 60
系統(tǒng)初始化粘?hello word : 61
系統(tǒng)初始化粘?hello word : 62
系統(tǒng)初始化粘?hello word : 63
系統(tǒng)初始化粘?hello word : 64
系統(tǒng)初始化粘?hello word : 65
系統(tǒng)初始化粘?hello word : 66
系統(tǒng)初始化粘?hello word : 67
系統(tǒng)初始化粘?hello word : 68
系統(tǒng)初始化粘?hello word : 69
?低吵跏薊常 hello word : 70
系統(tǒng)初始化粘?hello word : 71
系?吵跏薊常 hello word : 72
系統(tǒng)初始化粘?hello word : 73
系統(tǒng)初始化粘?hello word : 74
系統(tǒng)初始化粘?hello word : 75
系統(tǒng)初始化粘?hello word : 76
系統(tǒng)初始化粘?hello word : 77
系統(tǒng)初始?常 hello word : 78
系統(tǒng)初始化粘?hello word : 79
系統(tǒng)初始化?常 hello word : 80
系統(tǒng)初始化粘?hello word : 81
系統(tǒng)初始化粘? hello word : 82
系統(tǒng)初始化粘?hello word : 83
系統(tǒng)初始化粘?hello word : 84
系統(tǒng)初始化粘?hello word : 85
系統(tǒng)初始化粘?hello word : 86
系統(tǒng)初始化粘?hello word : 87
系統(tǒng)初始化粘?hello word : 88
系統(tǒng)初始化粘?hello word : 89
系統(tǒng)初始化粘?hello word : 90
系統(tǒng)初始化粘?hello word : 91
系統(tǒng)初始化粘?hello word : 92
系統(tǒng)初始化粘?hello word : 93
系統(tǒng)初始化粘?hello word : 94
系統(tǒng)初始化粘?hello word : 95
系統(tǒng)初始化粘?hello word : 96
系統(tǒng)初始化粘?hello word : 97
系統(tǒng)初始化粘?hello word : 98
系統(tǒng)初始化粘?hello word : 99
系統(tǒng)初始化粘?hello word : 100
系統(tǒng)初始化粘?hello word : 101

回復(fù)

使用道具 舉報(bào)

ID:883242 發(fā)表于 2022-5-17 16:41 | 顯示全部樓層
“正”漢字編碼0xd5、0xfd,你這是遇到了C51的0xfd問題,網(wǎng)上找個(gè)補(bǔ)丁修一下就行了。
回復(fù)

使用道具 舉報(bào)

ID:1026496 發(fā)表于 2022-5-17 21:38 | 顯示全部樓層
不建議printf 輸出中文如果要建議UTF8 的格式輸出。
回復(fù)

使用道具 舉報(bào)

ID:1027424 發(fā)表于 2022-5-17 22:04 | 顯示全部樓層
建議輸出英文或者換個(gè)串口助手,應(yīng)該是解析中文最后一位的時(shí)候有問題
回復(fù)

使用道具 舉報(bào)

ID:939553 發(fā)表于 2022-5-17 22:59 | 顯示全部樓層
printf("系統(tǒng)初始化正\xfd常 hello word : %u\r\n",Cnt++);就可以了
回復(fù)

使用道具 舉報(bào)

ID:123289 發(fā)表于 2022-5-19 11:12 | 顯示全部樓層
函數(shù)會(huì)到漢字庫(kù)中去取數(shù)據(jù),取到什么就顯示什么?
在取字模的過程序中,如果取字模的【索引】號(hào)錯(cuò)了,或索引到的地址中的點(diǎn)陣錯(cuò)了,就發(fā)生樓主遇到的問題了。
樓上的建議,或許有用。但希望你知道錯(cuò)在哪里。
回復(fù)

使用道具 舉報(bào)

ID:883242 發(fā)表于 2022-5-19 15:05 | 顯示全部樓層
yzwzfyz 發(fā)表于 2022-5-19 11:12
函數(shù)會(huì)到漢字庫(kù)中去取數(shù)據(jù),取到什么就顯示什么?
在取字模的過程序中,如果取字模的【索引】號(hào)錯(cuò)了,或索 ...

在網(wǎng)上搜“C51的0xfd問題”對(duì)你來(lái)說(shuō)就那么困難嗎?還要無(wú)理由的胡說(shuō)八道。

就是C51的字符串中如果有漢字,而且漢字內(nèi)碼有0xfd,C51編譯器會(huì)把0xfd吞掉,最后出來(lái)的代碼里面沒有0xfd自然就亂碼了。
回復(fù)

使用道具 舉報(bào)

ID:1004455 發(fā)表于 2022-5-19 23:14 | 顯示全部樓層
格式弄一下就可以了
回復(fù)

使用道具 舉報(bào)

ID:123289 發(fā)表于 2022-5-20 08:35 | 顯示全部樓層
打開printf看看,是不是用先用漢字是索引字庫(kù),而后去取字模。
如果【C51編譯器會(huì)把0xfd吞掉】是平臺(tái)錯(cuò)了,還是樓主錯(cuò)了。
你如何證明,C51編譯器會(huì)把0xfd吞掉了呢?亮出來(lái)給樓主看看,也算是幫樓主了。
回復(fù)

使用道具 舉報(bào)

ID:883242 發(fā)表于 2022-5-20 09:41 | 顯示全部樓層
yzwzfyz 發(fā)表于 2022-5-20 08:35
打開printf看看,是不是用先用漢字是索引字庫(kù),而后去取字模。
如果【C51編譯器會(huì)把0xfd吞掉】是平臺(tái)錯(cuò)了 ...

在網(wǎng)上搜“C51的0xfd問題”對(duì)你來(lái)說(shuō)就那么困難嗎?還要無(wú)理由的胡說(shuō)八道。
回復(fù)

使用道具 舉報(bào)

ID:624769 發(fā)表于 2022-5-20 14:03 | 顯示全部樓層
如果:
        printf("系統(tǒng)初始化正常 hello word : %u\r\n",Cnt++);

換成:
       SendString("\r\n系統(tǒng)初始化正常 hello word : ");
        printf("%u",Cnt++);

是不會(huì)出現(xiàn)亂碼的。
所以,問題不在字符串,不在漢字,也不在編譯器,而是:
在明知KEIL C51 的 printf 不支持漢字,還非要用printf 發(fā)送漢字,就算沒有現(xiàn)成的SendString,自己寫一個(gè)
void SendString(char *p)
{
          while(*p)        SendUart(*p++);
}
就那么一句話的函數(shù),很難么?
回復(fù)

使用道具 舉報(bào)

ID:883242 發(fā)表于 2022-5-20 15:01 | 顯示全部樓層
188610329 發(fā)表于 2022-5-20 14:03
如果:
        printf("系統(tǒng)初始化正常 hello word : %u\r\n",Cnt++);

大錯(cuò)特錯(cuò)了你!

SendString("\r\n系統(tǒng)初始化正常 hello word : ");
這句話也是不正常的。

問題的根源不是printf不支持漢字,而是Keil C51編譯器不支持字符串里面出現(xiàn)0xfd這個(gè)內(nèi)碼。你的字符串里面一樣有這個(gè)內(nèi)碼,一樣是不正常的,一樣會(huì)出現(xiàn)亂碼的。謙虛點(diǎn)兒吧你!
回復(fù)

使用道具 舉報(bào)

ID:1052053 發(fā)表于 2023-10-15 15:09 | 顯示全部樓層
printf支持漢字,Keil C51編譯器不支持字符串里面出現(xiàn)0xFD,剛開始遇到的時(shí)候也想不通,監(jiān)測(cè)后才發(fā)現(xiàn)是這個(gè)問題,這應(yīng)該算是keil的bug吧
回復(fù)

使用道具 舉報(bào)

ID:883242 發(fā)表于 2023-10-15 16:09 | 顯示全部樓層
spirit01 發(fā)表于 2023-10-15 15:09
printf支持漢字,Keil C51編譯器不支持字符串里面出現(xiàn)0xFD,剛開始遇到的時(shí)候也想不通,監(jiān)測(cè)后才發(fā)現(xiàn)是這個(gè) ...

這個(gè)0xfd問題我在1999年就發(fā)表在當(dāng)時(shí)最火的C51BBS網(wǎng)站上,過了24年還沒有變,顯然不是bug而是feature。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表