MCU 最强科普摘要[推荐合集] (3)
2022-03-17 231
12、Overview of Chinese characters:
为了在显示器或打印机上输出汉字,需要根据图形符号将汉字设计成点阵,从而得到相应的点阵码(字形码)。  
The unified encoding method used to represent Chinese characters in computers is called internal code (such as national standard code), and the internal code is unique (equivalent to the ID number of the character). The Chinese character encoding formed to facilitate the input of Chinese characters is an input code, which is an external code of Chinese characters. The input code is different due to different encoding methods and is diverse. The Chinese character code formed for displaying and printing out Chinese characters is a glyph code. The computer finds the glyph code of the Chinese character in the font model library through the Chinese character internal code and realizes its conversion.  
  相机内代码  
According to the provisions of the national standard code, each Chinese character has a certain binary code, but this code will conflict with the ASCII code when processed internally by the computer. To solve this problem, add 1 to the first byte of each byte of the national standard code. Since the ASCII code only uses 7 bits, the "1" in the first place can be used as a mark to identify Chinese character codes. When the computer processes the code with "1" in the first place, it understands it as Chinese character information, and when it processes the code with "0" in the first place, it understands it as an ASCII code. The national standard code (internal code) processed in this way is the internal code.  
如果我们把这个“口”字形中的“.”替换成“0”,就能非常清晰地得到“口”字的字形代码:0000H 0004H 3FFAH 2004H 2004H 2004H 2004H 2004H 2004H 2004H 2004H 2004H 3FFAH 2004H 0000H 0000H。当计算机想要输出“口”字时,它首先找到显示字体库的第一个地址,根据“口”字的内部代码进行计算,然后找到“口”字的字形代码,再通过字符生成器的控制,按照字形代码(二进制)顺序扫描屏幕。当二进制代码为“0”时,扫描“0”所在的位置,扫描“1”所在的位置并高亮显示,从而得到“口”字的字符模式。  
汉字字体按照国家标准代码的顺序排列,并以二进制文件的形式存储在内存中,形成汉字字体库,也称为汉字字形库或汉字库。
两种编码方法,参见头文件
    GB1616.h//------------------ Data structure definition of Chinese character font ------------------------//struct typFNT_GB16 //Chinese character font data structure { unsignedchar Index[3]; //Chinese character internal code index unsignedchar Msk[32]; //Dot matrix code data }; ///////////////////////////////////////////////////////////////////////////// Chinese character font table //// Chinese character library: Song style 16.dot, horizontal modulo left high bit, data arrangement: left to right, top to bottom ///////////////////////////////////////////////////////////////////////////// conststruct typFNT_GB16 codeGB_16[]= //Data table {/*------------------------------------------------------------------------------------------------ Source file/text: Xu; Width×Height (pixels):16×16---------------------------------------------------------------------------------*/ "Xu",0x10,0x80,0x10,0x80,0x21,0x40,0x42,0x20,0x94,0x10,0x1B,0xEC,0x20,0x80,0x60,0x8 0,0xAF,0xF8,0x20,0x80,0x22,0xA0,0x24,0x90,0x2A,0x88,0x21,0x00,0x00,0x00,0x00,0x00,
     

    This structure is very simple:One is the internal code, a dot matrix sequence. The previous dot matrix library was placed in the order of the internal code, and no internal code index was needed. If only some Chinese characters were placed, the internal code index was needed. (The Chinese character "Xu" in the front is to find the dot matrix sequence of the word when outputting "Xu". This dot matrix sequence is written by myself. When displayed with 1602, because the chip has an English dot matrix sequence in the memory, there is no need to write it.) Generally, two bytes are enough for the internal code. If you use one more byte, you just add a trailing 0. In this way, the Chinese character string can be directly placed in the Chinese character internal code;


    codeGB_16[k].Index[0] 表示存在一个名为 codeGB_16 的结构体 typFNT_GB16 的数组。codeGB_16[k] 是该数组的第 k+1 个成员。index 是结构体 typFNT_GB16 的成员,因此可以用 codeGB_16[k].Index 来引用。同时,index 本身也是一个数组,所以可以用 indexed[0] 来访问。如果 ((codeGB_16[k].Index[0]==c[0])&&(codeGB_16[k].Index[1]==c[1])),&& 是一个逻辑与运算符,表示 && 符号两侧的值都为真。只有 && 的值是真,即 true && true = true。这句话的意思是:codeGB_16[k].Index[0]==c[0] 和 codeGB_16[k].Index[1]==c[1] 同时成立。如果执行以下语句,则 codeGB_16[] 是一个结构体数组,codeGB_16[k].Index[0] 表示该结构体数组中第 k 个结构体的索引成员的第 0 个元素的值。    

    13、12864 LCD:

    每个显示点对应一个二进制数,1 表示开,0 表示关。存储这些点阵信息的 RAM 称为显示数据存储器。要显示某个图形或汉字,就需要将相应的点阵信息写入相应的存储单元。


    图形内存的地址计数器 (AC) 只会自动将水平地址(X 轴)加一。当水平地址为 0FH 时,它将被重置为 00H。但是,它不会自动将垂直地址加一并带进位。因此,当连续写入多个数据时,程序需要判断是否需要重置垂直地址。


      14、Graphics RAM (GDRAM)

    The drawing display RAM provides 128×8 bytes of memory space. When changing the drawing RAM, first write the horizontal and vertical coordinate values ​​continuously, and then write two bytes of data to the drawing RAM. The address counter (AC) will automatically increase the horizontal address (X address) by one. When the horizontal address is 0XFH, it will be reset to 00H; the vertical address will not be automatically incremented by 1. The drawing display must be turned off during writing to drawing RAM.

     
      [cpp] view plain copy//Display Chinese characters voiddispString (uchar X, Y,uchar *msg) //Which row is X and which column is Y. msg is Chinese characters { if(X==0) X = 0x80; // First line, Chinese characters display coordinates else if(X==1) write_data(*msg++); //Display Chinese characters } } ////////////////////////////////// //////////////// //////////////// // Display image voiddisppicture(uchar code *adder) { uint i,j; //*******Display the upper half screen content setting for(i=0;i<32;i++) // 32 column addresses in the upper half of the screen { write_com(0x80 + i); //SET vertical address VERTICALADD write_com(0x80); //SET horizontal address HORIZONTAL ADD for(j=0;j<16;j++) { write_data(*adder); adder++; } } //************Display the content settings of the lower half of the screen for(i=0;i<32;i++) // { write_com(0x80 + i); //SET vertical address VERTICALADD write_com(0x88); //SET horizontal address HORIZONTAL ADD for(j=0;j<16;j++) { write_data(*adder); adder++; } } }
       
         

      For the C language, space is automatically allocated for a defined variable, and its address is the name of the variable. Through this name, the data can be retrieved in the memory and new data can be obtained through calculation. However, in assembly, the programmer needs to define the storage space and send the data to the accumulator for calculation. Every step requires the programmer's operation. In C language, these processes are completed by the compiler.


        15、Some useful FAQs

      ① 在微控制器C语言中,变量的内存分配是如何进行的?编译器是否会在编译过程中智能地添加分配和回收代码?关键在于,我编写的程序如何确保不会出现内存溢出错误?如果我进行递归操作,那么内存需求很难自行计算。  
      ②. 微控制器C语言在变量定义方面是否会受到限制?例如,浮点数据的乘除运算是用汇编语言编写的,代码相当复杂。如果直接用C语言编写,会不会过于简单?  
      ③ 在微控制器的 C 语言生成的 hex 文件中,指令 ROM 和数据 ROM 的地址分配是由编译器自动分配的吗?用户可以自行分配吗?  
      Answer 1: The microcontroller program written in C language is first compiled by a program (it seems to be c51.exe). After the compilation is completed, the storage space size of the variables has been arranged, but the specific address has not yet been allocated (the address is floating). Next, another program (it seems to be a51.exe) is connected. After the connection, the specific address is determined.  
      如果变量过多,编译器会提示数据段过大。为避免内存溢出错误,主要考虑的是栈溢出,而这取决于经验。
      微控制器的C语言通常禁止递归,递归操作也一般避免使用。毕竟,微控制器不是PC,递归会影响速度。如果需要递归,最好使用DSP芯片。总之,必须能够选择合适的芯片。
      答案 2:变量的大小(位数)通常与芯片累加器的位数相同。例如,数字 51 通常使用 8 位,因为它是 8 位微控制器。

      微控制器可以定义位变量,但不能定义位数组。用C语言编写代码看似简单,但实际上会生成大量的代码。用于控制的微控制器几乎不使用浮点运算,这不仅速度慢,而且繁琐并占用空间。如果是DSP芯片,拥有合适的硬件结构会更好。  
       

      答案 3:通常情况下,它是自动分配的。它可以用 C 语言和汇编语言混合编程,也可以使用 Keil C 在线汇编。芯片与外部之间的数据交换通过端口进行。


      免责声明:本文转载自《国际电子商业信息》。本文仅代表作者个人观点,不代表Sacco Micro及业界立场。仅供转载分享,支持知识产权保护。转载请注明原出处及作者。如有侵权,请联系我们删除。

      公司电话号码:+86-0755-83044319
      传真:+86-0755-83975897
      电子邮件:1615456225@qq.com
      QQ:3518641314 李经理

      QQ:332496225 邱经理

      地址:深圳市龙华新区民治大道1079号展涛科技大厦C座809室

      whatsapp

      WhatsApp

      Whatsapp:+8618073002950