服務熱線
為了在顯示器或印表機上輸出漢字,需要根據圖形符號將漢字設計成點陣,從而得到對應的點陣碼(字碼)。
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 2004H 2004H 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;
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室




粤公网安备44030002007346号