The modulo software to display Chinese characters into Chinese characters in keil5

To use the STM32 to do recently because of graduation, you need to display Chinese LCD, STM32 development board using a battleship STM32 development board atoms, to the LCD display routines in seemingly no Chinese display, you need to write their own Chinese display program.

Software written for me is not difficult, the key is a very wonderful experience problems in the process.

Modulo software I use is PCtoLCD2002.exe, which can be found in many places. After generating the font, the last Chinese translations of each font has a corresponding, but will generate a copy of the font program to discover a problem, Chinese show became a question mark is shown below:

 

I think this is very simple, nothing more than Chinese coding format is not the same thing, create a new text document, and then open with notepad ++, the resulting paste into the font, can be found displayed properly:

 

  

Then look at its encoding format, it found to be UTF-8 encoding:

 

 

 

 

 

 

This means using UTF-8 encoding in keil5 where you can display properly, and in keil5 the menu bar click Edit-> Configuration:

 

 

 In the box that pops up is keil5 found in ANSI decoding, and now we replaced decoding UTF-8, then click OK:

 

  Finished will find just copied the font, Chinese comment or a question mark how ah, do not worry, this is because, before copying the UTF-8 encoded content into the ANSI document decoding, keil5 will not be decoded part directly replaced with a question mark, that is to say, at this time keil5 in this question mark is not garbled, this is a really question mark ah. (Here it is necessary to mention, but why only Chinese garbled English and digital no distortion, it is because the English and the numbers are encoded with ASCLL, and ASCLL code is a subset of all codes, that is, whether you use What encoded, ASCLL part of the code that are not garbled.) OK, then have to solve this problem is very simple, delete the copied font, and then re-paste, because when keil5 is already in UTF-8 the decoding, it is possible to display normal UTF-8 encoding of the Chinese:

 

 

 Wait, I seem to find anything, though copied the font can be displayed as Chinese, but the Chinese before the comment seems garbled:

 

 

 好吧,因为我需要参考很多原子的例程,那么我们还是将keil5的解码方式改回ANSI。那么又如何能正常显示从字模软件里拷贝过来的中文注释呢,很简单,只要转换就好了啊,notepad++就有这个功能。我将拷贝的字模放在新建的文本文档中,然后用notepad++打开,这时可以看到notepad++中用的是UTF-8编码,并且能够正常显示。

 

 

 这时我将文件转为ANSI编码:

 

 

 然后再将转换过后的文字复制进keil5,这时迷惑的事情来了,keil5中显示的还是一个问号。经过核对之后能保证在notepad++中使用的已经是ANSI编码了,而且keil5中也是使用ANSI解码的,但为什么keil5中还是显示问号呢,肯定是某个环节有问题。这时我做了个实验,在keil5中将解码方式设置成了UTF-8,然后再将notepad++中以ANSI编码的汉字复制进keil5中,发现能正常显示,这能说明notepad++没有成功转码吗?既然如此,我们再在notepad++上以UTF-8解码,发现在notepad++上不能正常显示中文:

 

 这说明notepad++上的ANSI编码和keil5上的ANSI解码不一致???

经过查阅资料后发现尼玛ANSI真的不是一种统一标准,但他们都会对应一种真实编码,参考:

https://blog.csdn.net/weixin_30216561/article/details/99139847

而在网上搜“ANSI编码表”也确实找不到具体的编码表,这一点也可以佐证ANSI不是一种具体的编码。但还有一个疑问就是,即使ANSI不是一种具体编码,但在同一台电脑上那应该是同一种编码吧。干脆用最直接的方式来验证,notepadd++和keil5中使用的ANSI编码到底对应了哪一种真实编码。我们在notepad++和keil5中打开的文档中都使用ANSI编码,并且删掉所有的内容,只留下一个“拨”字,然后分别保存这两个文件,接下来用另一个强大的工具,winhex来打开他们,我们发现在keil5中编辑的“拨”字和notepad++中编辑的“拨”字,他们对应的编码:

 

 

 都是B2A6………………….(陷入沉思)

并且可以查到,B2A6如果代表的是汉字的“拨”,那么它对应的真实编码就是GBK编码:

 

 好吧,这让我很惆怅,想来想去,发现中间确实有一环是不严谨的,之前将notepad++和keil5都设置成ANSI编码的时候,我是将notepad++中的字复制到keil5中发现显示问号,这次我是直接在keil5中用键盘打出了“拨”这个字,因此我要将notepad++中的“拨”字复制到keil5中去。操作之后,发现在keil5中,真的就显示成了一个问号,保存keil5中的文件再用winhex查看的时候,发现编码已经变成3F了,而3F正是ASCLL码表中的问号。

OK,既然这样,我将keil5中的“拨”字拷贝到notepad++中会怎样呢。结果,它变成了这样:

 

 什么?????keil5中用ANSI编码的B2A6复制到notepad++中,notepad++也为ANSI编码,结果却变成了327C?那么B2A6和327C又有什么联系呢。为了进一步验证,我将keil5中的“寒武纪奥陶纪志留纪泥盆纪石炭纪侏罗纪”复制到notepad++中,发现它变成了这样:

 

 

 进一步验证发现keil5中的一个汉字复制到notepad++中并不一定是2个字节对应2个字节,而且变化后的字节以问号居多,而从notepad++中拷贝到keil5中的汉字则全部变成问号。

 总之一句话就是“你没问题,我也没问题,是复制粘贴这个操作有问题”,而且测试发现使用键盘复制和使用鼠标数字是一样的结果。

 

经过了半个小时的休息,我想问题仍然在ANSI这种特殊编码之上,如果我将编码改为GBK编码,是不是就好了呢,然鹅keil5中没有GBK编码的选项,只有GB2312编码(这里需要提一下的是,GBK编码比GB2312编码收录了更多的汉字,而且可以认为GB2312编码是GBK编码的子集,常用汉字用GB2312编码就够够的了)将keil5中的编码方式改为GB2312。发现原子的例程中文注释并没有乱码,然后在字模软件中将字模复制,在nodepad++中粘贴,注意这时notepad++中使用的是UTF-8编码,然后再转为ANSI编码,然后再复制,再到keil5中粘贴,这时,便不再乱码。

虽然问题解决了,但是用ANSI编码的文件中的汉字不能互相复制粘贴的原因还是没有找到。

 

Guess you like

Origin www.cnblogs.com/Suzkfly/p/12396489.html