Current location - Education and Training Encyclopedia - Graduation thesis - How to display Chinese character test paper by single chip microcomputer
How to display Chinese character test paper by single chip microcomputer
System analysis of LED display control system

According to the application of LED display control system, the architecture and workflow of LED graphic display are designed. Among them, the software system and the wireless transmission control hardware main system use serial communication to download programs to realize the transmission of text information.

2. 1 Overall analysis

LED display system composition

The LED graphic display system consists of software control system, wireless transmission system, equipment master controller, LED display lattice, power supply and other parts. The basic structure is as follows:

Figure 4-1Overall framework of LED display screen

System workflow:

The main tasks of the software control system are graphic editing, font extraction and storage, image preview and file transmission. The wireless transmission system mainly completes the file information transmission from PC to LED display screen. The main task of the LED dot matrix in the hardware control system is to display information through current control, and to drive the LED dot matrix to be arranged in rows and columns through the control of scanning drive mode of single chip microcomputer, so as to drive the equipment and finally realize the received graphic display function.

2.2 Computer software module analysis and design

The software module is divided into editing part and control communication part. The editing part realizes the editing function of graphic files, and the communication part completes the transmission of files to the memory module of single chip microcomputer through RS-232C serial communication. The communication part will be introduced in detail in chapter 3.

The system design uses Windows operating system to open the text editing window. The pixels in the client area are the same as the actual LED dot matrix display screen, and the functions are similar to Word document editing tools, including editing module, drawing module, text editing module, color control module, display effect loading module, preview module and information download module.

1, editing module

1) In addition to the functions of cutting, copying and pasting generated by Windows, the system also adds the functions of cancellation and repetition.

(1) Select the Undo function to gradually cancel the previous editing work.

(2) Select the repeat function to realize the latest operation command of previous editing work.

2) Drawing: Drawing functions include straight line, rectangle, ellipse and circle.

3) Text editing: including editing of various fonts, glyphs, font sizes, effects and colors, and adding editing of characters at designated positions according to special applications.

(1) Select the text function, and the font selection box pops up, where you can select various fonts for editing.

(2) Bring up the dialog box for editing the specific text position, and enter the abscissa and ordinate of the text and the required display position.

4) Color control module: Due to the specific characteristics of the application field, red, green and Huang San are mainly used to realize color control.

2. Adding effect module: By adding display effect and single screen transmission of multi-screen files in transmission communication, the function of the control system is improved.

1) normal effect, static display information on the screen.

2) Scrolling effect, which can realize the scrolling display of information from left to right, and can be interspersed with static information.

3) Single screen information transmission, which saves the information to be transmitted.

4) Multi-screen information transmission, which realizes that the edited and saved single-screen information is merged and saved into one file, greatly reducing the complexity of file transmission.

3. Image preview module: realize the preview function of font information before file transmission, preview any font information saved before transmission, and directly integrate it into the toolbar file to open the function key button.

1), and the arrangement order of static and scrolling display effects can be adjusted by previewing the file before transmission.

2) Display time, which shows the time interval between different screen display information.

The structure diagram of the software module is as follows:

Figure 3-2 Software Module Structure Diagram

Design and Implementation of Software Control System

In the software control system of LED display screen, the editing of text information, the saving of font information, the processing of display effect, image preview and device communication are the core tasks of design. The following four core functions are studied and designed in detail.

4. Design and implementation of1editing function

Editing is one of the most important links to display the content and effect on the LED display screen. This system is designed with VC 6. 0 development tools and VC++ to complete the whole design work.

Build a project based on MFC AppWizard, and open the text area in the form of single document view. The following is the analysis and design of the project:

1. Opening of text area:

Because the number of pixels of the applied LED display screen is fixed, and the resolution of the computer screen is obviously much higher than that of the display screen, the logical coordinates are different, that is, the displayed image will be distorted, elongated or even distorted. Therefore, the error can be reduced by selecting an appropriate ratio between the pixel points of the computer screen where the window is opened and the pixel numbers of the display screen.

There are many ways to solve this problem now. For example, the compression method of dot matrix data, because in the Windows environment, the system defaults to more than 4,000 points for each Chinese character, and the large screen of each Chinese character 16× 16 is 256 points, so according to the calculation, the method of taking points at intervals can be adopted, and one point is taken every 12 point horizontally and vertically, and each Chinese character consists of 256 points.

However, in order not to distort the image, this system adopts the way that the number of pixels in the opened text area is exactly the same as that in the display screen, which avoids the circle becoming an ellipse, the square becoming a rectangle, and even the slope will not change when drawing diagonal lines.

The CMainFrame::PreCreateWindow function is used to set the size of the whole window, but the window frame also includes menu, toolbar, status bar and client area. The system-defined text area needs an accurate client area to store font information. Therefore, the height of the status bar and toolbar should be added to the ordinate indicating the size of the client area, and even the edge of the menu and window border should be deducted [1].

SetClientSize() // Function for setting the client area size

{ CRect rect

CSize winSize

int cx,cy = 0;

CControlBar * pBar

PBar = GetControlBar(AFX _ IDW _ status bar);

If ((pBar! = NULL)& amp; & amp(pBar->; IsWindowVisible())){

pBar->; GetWindowRect(rect);

winSize = rect。 size();

cy+=(winSize。 cy); }

PBar=GetControlBar(AFX_IDW_ toolbar);

If ((pBar! = NULL)& amp; & amp(pBar->; IsWindowVisible())){

pBar->; GetWindowRect(rect);

winSize = rect。 size();

cy+=(winSize。 cy * 2); }

cx = 384+(384-m_clientSize。 CX);

cy+=( 192+( 192-m _ clientSize。 cy));

GetWindowRect(rect);

SetWindowPos(this,rect。 Left, rect.top, cx, cy, SWP_ zod); }

OnViewStatusBar(){

CFrameWnd::OnBarCheck(ID _ VIEW _ STATUS _ BAR);

SetClientSize(); }

Through the precise control of the client area, the number of pixels in the text area can really correspond to the number of plane luminous points on the display screen, and in order not to change the pixels in the text area due to mistakes during editing operations, the system limits the table maximization control [3] [9].

cs。 Style & amp= ~ WS _ MAXIMIZEBOX// Cancel maximization and make the form size fixed.

2. Edit function design:

In the control system, the input of words and graphics is imagined as the editing of images, so that the editing work can be completed on the drawing board at will.

MFC drawings are always output to devices through device context (device context is the medium between devices and data, which can be abbreviated as DC). DC stores the properties of the device and outputs drawing data. To output drawing data to a device in MFC, a DC object must be prepared for the device, which is an object of a class inherited from CDC. This DC object can use some drawing functions of CDC class (such as drawing straight lines, circles, squares, etc. ). Every DC should attach some so-called GDI objects (GD objects, such as brushes, painting brushes, glyphs, bitmaps and other common drawing tools. ) to cooperate with the drawing function of DC.

The system compiles Line () function to draw straight lines, Rectangle () function to draw rectangles, Ellipse () function to draw ellipses, and Circle () function to complete graphic editing [2] [3].

It should be pointed out that newPen is destructed: newPen. Call the DeleteObject method. The destruction of GDI objects is very important, especially those created by ourselves, and must be removed at an appropriate time (when GDI objects are no longer attached to DC). The only way to remove attachments is to use the SelectObject function to select another new object (the old object will be automatically deleted). You can choose MFC pre-stored objects to remove the dependence of objects, because MFC pre-stored objects will be automatically destructed when they are not used. DeleteObject is a member function exposed by CGdiObject class, so it can be used by all its subclasses.

Text input: generate a dialog box for selecting font type through CFontDialog class.

CDC * pDC = GetDC();

LOGFONT m _ lFont

COLORREF m _ cTextColor

CFont myFont

CFont * pOldFont

CFontDialog FontDlg

FontDlg。 lpLogFont = & ampm _ lFont

font DLG . m _ cf . RGB colors = m _ ctext color;

FontDlg。 M _ cf. flag! = CF _ INITTOLOGFONTSTRUCT

if ( FontDlg。 DoModal() = =IDOK)

{

FontDlg。 GetCurrentFont(& amp; m _ 1 font);

m_cTextColor = FontDlg。 GetColor();

}

Call the system's own input method, including font, font, color, effect, etc.

The system loads the TextDialog dialog box, and establishes a logical coordinate system with the upper left corner of the text editing area as the coordinate origin, the right direction as the positive direction of the X axis, and the downward direction as the positive direction of the Y axis, so as to realize the editing of the specified position of the text:

CString string;

CTextDlg TextDlg

//CRect rect (TextDlg。 m_ctrEdit。 GetClientRect());

if ( TextDlg。 DoModal)==IDOK)

{

CRect rect (TextDlg。 m_iPosX,TextDlg。 m_iPosY,

TextDlg.m_iPosX+ 1000,text DLG . m _ iPosY+ 1000);

Str=TextDlg。 m _ sText

My abundant. createfont indirect(& amp; m lFont);

pold font = pDC-& gt; Select object (& ampmyfont);

pDC->; settext color(m _ ctext color);

pDC->; DrawText (str,rect,0);

pDC->; select object(pold font);

save instack(); }

Embedding the TextDialog () function in the OnFont () function,

DDX_ Text(pDX,IDC_ POS-X,m _ iPosX); //Enter X-axis text in the text area.

DDX_ Text(pDX,IDC_ POS_ Y,m _ iPosY); //Y axis of text input in the text area

Color control:

In Windows system, color is defined by ture color, that is, COLORREF is a four-byte word, in which three bytes represent three basic monochromatic colors, that is, each basic monochromatic color is represented by one byte, that is, each basic monochromatic color has 256 levels. Therefore, true colors have 167772 16 color variations. Although there are so many colors defined in the computer, LED display screen is not necessary and impossible in application and real life. Because human eyes are sensitive to different colors of light, and red, green and yellow are the most sensitive to human visual cells, these three colors become primary colors, and various colors from white to black can be realized by mixing them in different proportions. So it is also the most commonly used color for traffic police.

LED display screen is used for legal publicity in traffic command hall to deliver information and services to the public. Based on the special application field, there are only three color changes in the graphic display screen. Therefore, the control system only adds the above three colors to the upper column to meet the requirements of future expansion.

4.2 font extraction

4.2. Brief Introduction of1Die

The font of a character is a set of numbers, but its meaning and the meaning of numbers have fundamental changes. It records the shapes of English or Chinese characters with the information of each number [1].

In computer hardware, there is no concept of Chinese characters at all, and there is no concept of English. The only concept it knows is that the rarely used value of the high-order 128 in the ASCII table is represented by two groups, that is, the internal code of Chinese characters. The remaining low bits 128 are reserved for English characters, that is, the internal code of English). If you start the system with the startup disk and use the DIR command, you may get a string of inexplicable characters, but they are really Chinese characters. If you start UCDOS or other Chinese character systems, you will see that they are familiar Chinese characters. In the hardware system, English font information is generally solidified in ROM, and English characters can be seen even in CMOS without entering the system. Under DOS, Chinese font information is generally recorded in a Chinese font file (the prepared font is put into a standard library, which is a dot matrix font file).

4.2.2 Implementation technology of fonts in the field of LED display

In the technology of software implementation, there are many font generation software at present. After the software is opened, enter Chinese characters and click "Search", and the Chinese character code of hexadecimal data can be automatically generated, and the vertical data we need can be copied into our program. In the technology of font extraction by hardware, one method is to add a tough guy font library in the single chip microcomputer system. The Chinese character sent by the main controller is its internal code, and two bytes are used to represent a Chinese character. The control module of the display unit searches the display font from the Chinese character library according to the built-in code to realize the display of Chinese characters. Because of the tough font, when displaying dynamic characters, the general intelligent display unit only accepts the internal codes of Chinese characters, so the data communication volume is greatly reduced. So "dynamic text display speed is fast".

4.2.3 Analysis and Design of Font Extraction in Software Control System

How to extract font information is the core of design under Windows operating system and the concrete application of LED display control system. In the actual editing process, the software control system requires that all kinds of fonts and sizes can be edited and saved. Therefore, when designing the system, the text area is understood to be composed of many pixels, and characters with different fonts and sizes are understood as an image. Since the size of the opened text area corresponds to the size of the LED display screen, each pixel in the text area is regarded as a two-dimensional array in the unit of 16× 16 dot matrix. Because all colors in the system have corresponding values, each pixel with different colors is given a different corresponding value, and then each point is given an int value, so the saved information is binary data. Through this design, we can not only save any font and any size of text, but also display any graphics with 256 pixel dot matrix units. Realizing font extraction in software control system also avoids loading tough guy font module in single chip microcomputer, thus simplifying the design of hardware module.

Taking monochrome screen as an example, this paper introduces the algorithm design of font saving in the system:

COLORREF Mozi _ color is defined as the color of a pixel, and the color value of a certain point is judged. If the value is Oxffffff, this point is white, and this point is given a value of 0. Since the monochrome screen has only two colors, red and colorless, except white, it can be simply assigned as 1.

CClientDC dc (this);

CFile myfile

Unsigned integer Mozi [192] [384] = {0};

Unsigned character Mozi _ data [192] [48] = {0};

COLORREF Mozi _ color;

int row,col

This-> hide caret();

for(row = 0; row & lt 192; row++){

for(col = 0; col & lt384; col++){

Mozi color = do. GetPixel (col,row);

If (Mozi color = = Oxffffff)

{Mozi [row] [column] = 0; } Otherwise,

{Mozi [row] [column] =1; }}}

Define unsigned integer ink [192] [384] = {0}; //pixels in the text area

Take 8 bits as a byte (because in the subsequent serial communication, the transmitted data is 8-bit binary data).

Define unsigned charzimo _ data [192] [48] = {0};

This-> show caret();

int i,j,k;

for(I = 0; I< 192; i++){

for(j = 0; j & lt48; j++){

for(k = 0; k & lt8; k++){

Mozi _ Data [I][j]+= Mozi [i] [8=}j+k]*((int) pow (2, (7-k))); }}}

4.3 Design and Implementation of Effect Adding and Preview Function

In today's highly information-based society, the proportion of graphic information such as graphics and images is increasing day by day, and computers play an important role in various information processing. Due to the intervention of digital technology and computer technology, the traditional TV industry based on analog images began to enter the era of digital broadcasting. From the microscopic world under the electron microscope to the vast field of satellite images, image processing is widely used in real life: processing office images such as documents and graphics; Medical image processing represented by medical X-ray CT (computed tomography) machine; Remote sensing image processing for satellite shooting and image processing for broadcasting, television and film industries.

In order to enhance the display effect, the LED display screen can also have multiple display modes.

1, hardware module processing display mode technology

LED graphic display screen can add a variety of display modes, thus enhancing the display effect. The main method to generate different display modes is to control and refresh the display data continuously with the change of time. However, refreshing the display data does not mean that the display data must be rewritten, and it can be generated directly from the original display data through a certain algorithm. The number of rows can be adjusted in turn to make the displayed pictures and texts translate up and down; By adjusting the position of column display data in turn, the purpose of left and right translation is achieved; By adjusting the order of rows and columns at the same time, you can get the effect of diagonal translation.

2. Software module direct loading effect technology

If the refresh algorithm of information data is too complicated, we can consider using display mode to generate data directly. After systematic analysis and design, text and graphics are edited in the text area, fonts are extracted and saved, and scrolling display mode is added through algorithm design.

Design and implementation of 1) scrolling display mode

Screen display scrolling effect In PreviewDialog, the button option is added, that is, when saving multi-screen information, the common effect and scrolling effect are alternately selected as needed to achieve the final purpose of saving:

For (unsigned character I = 0;; I< file number; i++)

CString temporary field 1, temporary field 2 and temporary field 3;

Unsigned characters file_length, file_ distype, file _ distime

tempFieldl = m_listCtrl。 GetItemText(i,0);

tempField2 = m_listCtrl。 GetItemText(i, 1);

tempField3 = m_listCtrl。 GetItemText(i,2);

File_length= (unsigned character) tempfield 1. GetLength();

My papers. Write (& ampfile_length,1); //Store file name length

My papers. Write (& ampfile_distype,1); //storage file display mode

My papers. Write (& file _ distime,1); //Storage file display time}

2) Design and implementation of image preview function.

After editing, the control system saves the font information, and the image preview function is mainly used to preview the font saved file to be transmitted. Due to the effect of multi-screen transmission and scrolling display, the information to be displayed transmitted to the big screen needs to be saved in advance, and previewing the saved information is conducive to the accurate and efficient completion of editing and transmission.

Research and design:

Define the unsigned character dis _ type _ pre = 0;; //means ordinary way.

Define unsigned chardis _ type _ pre =1; //Indicates the scrolling mode.

When the setting mode is scrolling:

if (roll_number! = 399){

for(row = 0; row & lt 192; row++){

for(col = 0; Col<= number of volumes; col++){

If (Mozi [row] [383-roll _ number+col]; = = 1){

Washington. SetPixel (col,row,0);

}}}

Otherwise {

dis _ type _ pre = 0;

roll _ number =- 1;

kill timer( 1);

for(row = 0; row & lt 192; row++){

for(col = 0; col & lt383; col++){

If (Mozi [row] [column] =1) {

Washington. SetPixel (col,row,0);

}}}