Chinese Character Display in Single Chip Microcomputer System

Publisher:MysticalSoulLatest update time:2011-12-28 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

In modern industrial control and some intelligent instruments, more and more places need to use dot matrix graphic displays to display Chinese characters. The usual way to display Chinese characters is to first extract the Chinese character dot matrix (such as 16×16 dot matrix) according to the required Chinese characters, store the dot matrix file in ROM, and form a new Chinese character code; when using it, it is necessary to first compose a sentence according to the new Chinese character code, and then the MCU extracts the corresponding dot matrix according to the new code to display Chinese characters. In this display method, if the number of stream characters used is large or there are many sentences, it will be a very tedious and boring task to use the new code of Chinese characters to compose sentences. In response to this situation, this article proposes a very simple way-directly using the Chinese character internal code of the PC as the code of the single-chip microcomputer system. The following is an example of the 8051 single-chip microcomputer system as follows:

1. Hardware Composition

This system uses a 240128T dot matrix graphic LCD display with a built-in T6963 controller [1] from Hong Kong Varitronix. The display has 240 dots per row, can accommodate 15 Chinese characters in a 16×16 dot matrix, has a total of 128 dots, and can display 8 rows of Chinese characters. In order to use MCU operation, a 512KB memory (such as the 29F040 in this system) can be used to store all national standard 16×16 dot matrix Han Liao, 8×16 ASCII code dot matrix data and Chinese character sentence encoding data. In order to reduce costs and reduce size, large-capacity serial data storage, such as AT45DB041B, can also be used for occasions where speed requirements are not very high. The specific hardware control circuit is shown in Figure 1 (circuits not related to Chinese character display are omitted).

Since the capacity of 29F040 is 512KB, and the 5031 microcontroller can only manage 64KB of data space, the 29F040 can be divided into 16 pages, 32KB per page, occupying 8000H~0FFFFH of the microcontroller system data space (the remaining 32KB is other memory and peripherals of the microcontroller system). The page number is selected by P1.0~P1.3 of the microcontroller. The address of the LCD display is 7FF8H~7FF9H.

2. Chinese Character Display Principle and Software Design

The files HZK16 and ASC16 in the UCDOS software are 16×16 national standard Chinese character dot matrix files and 8×16 ASCII code dot matrix files, respectively, stored in binary format. In the file HZK16, all Chinese characters in the national standard area code table are stored in order from small to large according to the Chinese character area code. Each Chinese character occupies 32 bytes, and each area has 94 Chinese characters. In the file ASC16, 8×16 ASCII code dot matrix is ​​stored in order from small to large according to the ASCII code. Each ASCII code occupies 16 bytes.

In the text files of PC, Chinese characters are stored in the form of machine codes, and each Chinese character occupies two bytes: the first byte is the area code, which starts from hexadecimal 0A1H (less than 80H is ASCII code character) to distinguish it from ASCII code, corresponding to the first area of ​​the area code in the area code; the second byte is the bit code, which also starts from 0A1H and corresponds to the first bit code in a certain area. In this way, the area code of the Chinese character can be obtained by subtracting 0A0AH from the machine code of the Chinese character.

For example, the machine code of the Chinese character "房" is "B7BF" in hexadecimal, where "B7" indicates the area code and "BF" indicates the bit code. Therefore, the area code of "房" is 0B7BFH-0A0A0H=171FH. Converting the area code and bit code into decimal, the area code of the Chinese character "房" is "2331", that is, the dot matrix of "房" is located at the 31st word in the 23rd area, which is equivalent to the position of the 32nd×[(23-1) ×94+(31-1)]=67136B in the file HZK16. The 32 bytes after that are the display dot matrix of "房".

In this single-chip system, the high 4 bits of the starting address are the page number, which is sent to port P1, and the low 15 bits are the data area address, which is sent to pointer DPTR. By using the "MOVX" instruction to continuously fetch 32 bytes and send them to the corresponding position of the LCD, correct Chinese character display can be achieved.

The basic principle of displaying ASCII code is the same as that of displaying Chinese characters. There is no problem of machine code in the ASC16 file. The display dot matrix is ​​directly arranged in order from small to large according to the ASCII code, but each ASCII code only occupies 1 byte and is less than 80H in the text file, and the ASCII code is 8×16 dot matrix, so in the ASCII16 file, each ASCII code dot matrix also occupies only 16 bytes.

First, extract the 16×16 national standard Chinese character dot matrix and the 8×16 ASCII code dot matrix (such as HZK16 and ASC16 in UCDOS software) and write them directly into 29F040. HZK16 (256KB in total) is on pages 0 to 7. For the convenience of programming, ASC16, although only 4KB, also occupies page 8 separately. The remaining space is used to store the encoding of Chinese character sentences.

Since each 240×128 dot matrix LED display can only display 15 Chinese characters (16×16 dot matrix Chinese characters), that is, 30 bytes. Therefore, the statements to be displayed can be written as 30 bytes per line, and spaces are added if there are less than 30 characters. When entering on a PC, 30 characters per line plus the enter key and line feed character actually occupy 32 characters. The entered statements are saved in plain text form, and then the text file is written in binary form to page 9 of 29F040. Then, the line number of the statement that needs to be displayed can be displayed correctly in the future. Therefore, the author recommends using the "Edit non-document files" function of the DOS version of the WPS software, which can clearly show whether there are 30 characters in each line.

For the convenience of readers, the assembly subroutines that have been passed in actual applications are listed below (for the user method of LCD controller T6963, please see Reference 1).


LCDCOM EQU 7FF9H

LCDDAT EQU 7FF8H

; Display 1 line of Chinese characters subroutine

; Chinese character statement position number DPTR; line number: R6 PRHZ: MOV 24H, DPH

MOV 25H,DPL

PUSH DPH

PUSH DPL

MOV A, DPH ; calculate page number

R R

R R

ADD A, #9; store the machine code of each line of characters starting from the 9th area

ORL A, #0F0H

MOV P1, A

LCALL RL245 ; line number multiplied by 32 (32 characters per line)

SETB 24H, 7; data address is located at 8000H~0FFFFH

MOV DPH, 24H

MOV DPL, 25H

MOV R0, #0E0H

MOV R7, #30; continuously fetch 30 characters to the internal data memory at 0E0H

PRHZ3:MOVX A,@DPTR

MOV @R0, A

INC R0

INC DPTR

DJNZ R7, PRHZ3

MOV 1DH, #30; Display a line of characters after 0E0H (30 in total)

MOV R5, #0; current column R5

MOV R0, #0E0H

MOV A, #7FH; Is it ASCII code?

CLR C

SUBB A, @R0

JC DPHZ1

MOV 26H, @R0

INC R0

MOV 24H, R6; ASCII code display

MOV 25H, R5

LCALL PRASCII

SJMP PRHZ4

DPHZ1: MOV 24H, @R0; if it is Chinese characters, the internal code will be sent to 24H25H

INC R0

MOV 25H, @R0

INC R0

MOV A, 25H

CLR C

SUBB A, #0A1H; machine code converted to binary area code and bit code

MOV 25H, A

MOV A, 24H

CLR C

SUBB A, #0A1H

LCALLDPONHZ; Display 1 Chinese character

DEC 1DH

INC R5

PRHZ4:INC R5

DJNZ 1DH,PRHZ5

POP DPL

POP DPH

RET

PR0: MOV DPTR, #LCDCOM; read status

MOVX A, @DPTR

RET

PR01: LCALLPR0; before reading or writing a data

JNB ACC.0,PR01

JNB ACC.1,PR01

RET

PR02: LCALL PR0; before continuous reading

JNB ACC.2,PR02

RET

PR03: LCALL PR0; before continuous writing

JNB ACC.3,PR02

RET

PR1: LCALL PR01; double-byte parameters R2, R3

MOV A, R2

LCALL PR14

PR11: LCALL PR01; single-byte parameter R3

MOV A, R3

LCALL PR14

PR12: LCALL PR01; instruction R4 without parameters

MOV A, R4

SJMP PR15

PR14: MOV DPTR, #LCDDAT

PR15: MOVX @DPTR, A

RET

RL245: MOV R7, #5; 24H25H shift left by 5

RLL1:CLR C

MOV A, 25H

RLC A

MOV 25H, A

MOV A, 24H

RLC A

MOV 24H, A

DJNZ R7, RLL1

RET

; Row position R6 (0-7), column position R5 (0-29), Chinese character distinction 24H, bit code 25H

DPONHZ: MOV A, 24H; display 1 Chinese character

MOV B, #94; 94 Chinese characters per area

MUL AB

ADD A,25H

MOV 25H, A

CLR A

ADDC A, B

MOV 24H, A

RR A; Get the page number of 32KB as 1 page

R R

ORL A, #0F0H

MOV P1, A; send page number to port P1

LCALL RL245; Chinese character serial number multiplied by 32

SETB 24H, 7; because the memory is located at 7FFFH ~ 0FFFFH of the microcontroller system

MOV DPH, 24H

MOV DPL, 25H

MOV R2, #32; take out 32 bytes in succession at this position

MOV R1, #0C0H

DPHZ2:MOVX A,@DPTR

INC DPTR

MOV @R1, A

INC R1

DJNZ R2, DPHZ2

MOV R1, #0C0H

MOV A, R6; Calculate LCD pointer according to row and column position

MOV B, #16

MUL AB

MUL B, #30

MUL AB

ADD A,R5

MOV 25H, A

MOV R2, A

CLR A

ADDC A, B

MOV 24H, A

MOV R3, A

MOV 26H, #16; send the extracted dot matrix to LCD display

PRHZ6: MOV R4, #24H

LCALL PR1; double-byte parameters R2, R3

MOV A, @R1

MOV R3, A

INC R1

MOV R4, #0C0H

LCALL PR11; Single-byte parameter R3

MOV A, @R1

MOV R3, A

INC R1

MOV R4, #0C0H

LCALL PR11

MOV A, #30

ADD A,25H

MOV R2, A

CLR A

ADDC A,24H

MOV R3, A

MOV 24H, A

DJNZ 26H,PRHZ6

RET

Note: Since the above program is directly quoted from the following application example, please make the register group located in the second area when calling the above program, that is, R0 corresponds to 10H.

3. Application Examples

We successfully designed a medical instrument using the method introduced in this article. The design requires complete Chinese and English character prompts and Chinese prescription display, and leaves room for future function expansion and prescription modification as much as possible. At present, there are about 1,200 Chinese characters used in the instrument, and about 1,300 lines of statements. In addition, the user believes that the cost of using industrial control PCs is too high and requires that the cost be reduced as much as possible. Obviously, although the traditional Chinese character processing method can save a certain amount of storage space for the system, the huge amount of Chinese characters and sentence re-encoding work is daunting, and it is quite troublesome when the prescription modification requires the use of new Chinese characters. We used the 8051 single-chip microcomputer system and the method introduced in this article for design. The entire hardware circuit and underlying program design took only one week, greatly shortening the development cycle. Moreover, since this system can call all ASCII codes and all Chinese character libraries, it is very convenient for function expansion and prescription modification.

Reference address:Chinese Character Display in Single Chip Microcomputer System

Previous article:The Application and Implementation of Time-Sharing Operating System Idea in Single-Chip Microcomputer Programming
Next article:Compensation method based on high-precision temperature measurement of single-chip microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号