Μcgui three text display and numerical display of learning notes

Source: Internet
Author: User
Tags control characters
Μc/gui Three text display and numerical display of learning notes 3.1 Text Display 3.1.1 Display support control characters

The text display supports ASCII characters as shown in Figure 3.1.

Figure 3.1 shows the supported ASCII control characters

Character

C character

Function

LF

\ n

Line break. Changes the current text display position to the next line. Similar to line breaks in the C language

CR

\ r

A carriage return similar to the C language. No line break, carriage return only, X coordinate set to 0

3.1.2 Text Display API

The main text display API is as follows:

l void Gui_dispchar (U16 c): Displays a character using the current font in the current text position of the current window, and does not appear if the font is not supported;

l void Gui_dispcharat (U16 C, i16p x, i16p y): Displays one character using the current font at the specified text position in the current window, or not if the font is not supported. The coordinates specified for the upper-left corner of the displayed character;

l void Gui_dispchars (U16 c, int Cnt): uses the current font to display Cnt characters in the current text position of the current window, and does not appear if the font is not supported;

l void Gui_dispnextline (void): Moves the cursor to the beginning of the next line, equivalent to line break;

l void gui_dispstring (const char Gui_far *s): Displays a string using the current font in the current text position of the current window, which supports ' \ n ' control characters, and is not displayed if the font is not supported;

l void Gui_dispstringlen (const char gui_far *s, int Len); Displays a character using the current font in the current text position of the current window, or not if the font is not supported. If the string length is shorter, it is filled with spaces, otherwise it will only show part;

l void Gui_dispstringat (const char Gui_far *s, int x, int y): Displays a string using the current font at the specified text position in the current window, supports ' \ n ' control characters, and is not displayed if the font is not supported;

L Gui_dispstringatceol (): Displays the string, and clears the display to the end of the corresponding line;

l void Gui_dispstringhcenterat (const char Gui_far *s, int x, int y): Displays a string with the current font in the current window centered in (x, y) (text centered), or not if the font is not supported will be displayed;

l void Gui_dispstringinrect (const char Gui_far *s, const gui_rect *prect, int Align): Displays a string in the current font in the rectangle specified in the current window ... The datum of the coordinate is the middle position of the string. The alignment align optional values are:

U gui_ta_top, Gui_ta_bottom, gui_ta_vcenter for vertical alignment.;

U gui_ta_left, Gui_ta_right, gui_ta_hcenter for horizontal alignment.

Select the alignment within the rectangle box. If the rectangle is too small, you may not be able to display all of the content.

l void Gui_dispstringinrectex (const char gui_uni_ptr *s,gui_rect* prect,int textalign,int maxlen,const GUI_ROTATION * PLC D_API); Displays a string in the current font in the rectangle specified in the current window. maxlen-the maximum string length. Plcd_api value GUI_ROTATE_0,GUI_ROTATE_CCW rotates 90 degrees clockwise.

Note: The above API functions can be divided into several categories: single character display, line wrapping, normal display of string, string display in Rectangle box. The additional feature is the design display alignment, Text style. 3.1.3 Selection of text mode   1. Supports four types of text modes

L Gui_textmode_normal: Normal text mode, the writing text will overwrite the point on the original LCD;

L Gui_textmode_reverse: Invert mode, display text color will be reversed; foreground color and background color invert;

Note: This is not clear how the function.

L Gui_textmode_trans: Transparent mode, writing text will be displayed at the top of the original graph;

L Gui_textmode_xor: XOR mode.

Note: This is not clear how the function.   2. Text-mode-related APIs

l int Gui_gettextmode (void): Gets the displayed text pattern;

l int gui_settextmode (int textmode): Sets the text mode of the display;

L Char Gui_settextstyle (char style): Sets the text style of the display, the main styles are:

n Gui_ts_normal;

n Gui_ts_underline;

n Gui_ts_strikethru;

N Gui_ts_overline.

Note: Text style, interesting. 3.1.4 Text alignment:

l int gui_gettextalign (void): Gets the text alignment;

l int gui_settextalign (int TextAlign): Sets the alignment of text, main alignment:

n Gui_ta_left-gui_ta_hcenter-gui_ta_right;

N Gui_ta_top-gui_ta_vcenter-gui_ta_bottom.

l void Gui_setlborder (int x): Sets the left margin of the display.

Note: This should be a variable that is set and then used when the display function is called. The alignment should be a function that shows that the function parameter contains the specified coordinates, such as Gui_dispstringat (). The corresponding coordinates specify the datum coordinates to display for alignment. See left-aligned and Center-aligned effects in listing 3.1. 3.1.5 Current text position:

Each task corresponds to a text position relative to the window's (0,0) coordinates. Used to determine the current position of the output text.

L char gui_gotoxy (int x, int y);

L char Gui_gotox (int x);

L char gui_gotoy (int y);

l int gui_getdispposx (void);

l int gui_getdispposy (void).

Note: I think the text shown here should be relative to the active window, not to the entire LCD screen. When you enter a character, the starting position of the display corresponds to the coordinates of the upper-left corner of the font image. 3.1.6 Full and partial cleanup of Windows

l void Gui_clear (void): Clears the current window. If the current window is not specified, the entire screen is cleared;

l void Gui_dispceol (void): Clears the text from the current position of the current window to the end of the current line at the height of the current font.

Program Listing 3.1 Text display test program

#include "gui.h"

void Maintask (void)

{

Gui_rect RECT = {0, 50, 10, 250};

Gui_init ();

                Gui_dispchars ( ' C ',;                      /* Displays 20 characters c                                                 */

                Gui_ Dispnextline ();                                              /* Line break                                                        */

Gui_dispchars (' D ', 10); /* Display 10 characters D */

Gui_dispstring ("Hello, uc/gui\n");

Gui_dispstringlen ("hello,uc/gui\n", 7); /* Displays characters of the specified length */

Gui_dispstringhcenterat ("hello,uc/gui!", 0, 0); /* Text centered position display */

Gui_settextstyle (Gui_ts_underline | Gui_ts_overline);/* Set Text style */

Gui_dispstringinrect ("hello,uc/gui!", &rect, Gui_ta_hcenter);

/*------------------------text string display------------------------------*/

Gui_settextalign (Gui_ta_hcenter); /* Center Alignment */

Gui_dispstringat ("Gui_ta_hcenter!!!", 10, 100);

Gui_settextalign (Gui_ta_left); /* Left Justified */

Gui_dispstringat ("Gui_ta_left!!!", 0, 200);

Gui_setcolor (gui_red);

Gui_drawline (80, 10, 240, 90);

Gui_drawline (80, 90, 240, 10);

Gui_setbkcolor (Gui_black);

Gui_setcolor (gui_red);

Gui_settextmode (Gui_tm_normal); /* Normal display */

Gui_dispstringhcenterat ("Gui_tm_normal", 160, 10);

Gui_settextmode (Gui_tm_rev);

Gui_dispstringhcenterat ("Gui_tm_rev", 160, 26);

Gui_settextmode (Gui_tm_trans); /* Transparent display */

Gui_dispstringhcenterat ("Gui_tm_trans", 160, 42);

Gui_settextmode (Gui_tm_xor);

Gui_dispstringhcenterat ("Gui_tm_xor", 160, 58);

Gui_settextmode (Gui_tm_trans | Gui_tm_rev);

Gui_dispstringhcenterat ("Gui_tm_trans | Gui_tm_rev ", 160, 74);

while (1)

{

Gui_delay (100);

}

3.2 Numeric Display API 3.2.1 Decimal number Display Support

l void Gui_dispdec (I32 V, U8 Len): Displays the decimal number, the maximum length is 9, and if the number is negative, a minus sign is added when displayed. If the actual length is less than Len, the display will fill 0 filled;

l void Gui_dispdecat (I32 V, i16p x, i16p y, U8 Len): Displays the decimal number in the specified position, with the Gui_dispdec ();

l void Gui_dispdecmin (I32 v); Displays a decimal number in a string with a minimum length;

l void Gui_dispdecshift (I32 V, U8 Len, U8 Shift): Specifies how many bits represent the fractional part from the right. LEN Specifies the length of the displayed string;

l void Dispdecspace (I32 V, U8 maxdigits);

l void Gui_dispsdec (I32 V, U8 Len): Displays signed decimal numbers, same as Gui_dispdec (), but always contains +/-symbols;

l void Gui_dispsdecshift (I32 V, U8 Len, U8 Shift).

Note: If you need to specify Len, if Len is longer, the display will be empty with a space or character 0, and if Len is smaller, the display may appear incorrect. Use Gui_dispdecmin () to automatically determine how long to display. Shift is used to shift, which would have been to display integers, but now displays decimals. Maximum support displays 9 character lengths. Supports sign and sign display. 3.2.2 Floating point display support:

l void Gui_dispfloat (float V, char Len): Displays the number of symbols, the decimal point symbol counts into the displayed symbol;

l void Gui_dispfloatfix (float V, Char Len, char Decs): Displays floating-point numbers, len-total length, number of bits in Decs decimal parts;

l void Gui_dispfloatmin (float f, char Fract): If the Fract value is negative, the minus sign is added. Fract Displays the minimum length of the characters, is not required, the actual display will be selected according to the minimum value;

l void Gui_dispsfloatfix (float V, Char Len, char Decs):

l void Gui_dispsfloatmin (float f, char Fract); Specifies the number of decimal points to display; the +/-symbol is always displayed before the displayed value.

Note: Part ibid. However, the display is followed by 0. 3.2.32 binary number display support:

l void Gui_dispbin (U32 V, U8 Len):

l void Dispbinat (U32 V, i16p y, i16p x, U8 Len). 3.2.46 Binary Number Display support

l void Gui_disphex (U32 V, U8 Len):

l void Gui_disphexat (U32 V, i16p x, i16p y, U8 Len).

Note: There is no additional "0x" string display, and no sign symbol display is supported. 3.2.5 Test Procedure

Program Listing 3.2 Numerical display test program

#include "gui.h"

void Maintask (void)

{

Gui_rect RECT = {0, 50, 10, 250};

Gui_init ();

/*----------Decimal Display Support---------------*/

Gui_dispstring ("Disp dec:\n");

Gui_dispdec (-32, 9); /* Displays the minus sign with zero fill */

Gui_dispnextline ();

Gui_dispdec (56, 9); /* Do not display a positive sign, zero fill empty */

Gui_dispnextline ();

Gui_dispdec (51, 1); /* Do not display a positive sign, zero fill empty */

Gui_dispnextline ();

Gui_dispdecmin (-32); /* Minimum quantity display */

Gui_dispnextline ();

Gui_dispdecmin (54);

Gui_dispnextline ();

Gui_dispdecshift (-3212, 8, 1); /* 1 Decimal places */

Gui_dispnextline ();

Gui_dispdecshift (-3212, 8, 2); /* 2 decimal places */

Gui_dispnextline ();

Gui_dispdecspace (-3212, 9); /* Fill empty with space */

/*----------floating point Display support---------------*/

Gui_dispnextline ();

Gui_dispfloat (-3.1232, 9); /* Normal floating point display support */

Gui_dispnextline ();

Gui_dispfloatfix (-3.14159, 9, 2); /* Maximum 9 characters, 2 decimal parts */

Gui_dispnextline ();

/*----------binary number Display Support---------------*/

Gui_dispbin (0xFE, 8);

Gui_dispnextline ();

/*----------hexadecimal number Display Support---------------*/

Gui_disphex (0xFE, 4);

Gui_dispnextline ();

while (1)

{

Gui_delay (100);

}

}

By:lstzixing

Mail:blievethink@gmail.com

Blog:http://blog.ednchina.com/lstzixing

2010-5-7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.