C Language Embedded system programming cultivation of screen operation

Source: Internet
Author: User
Tags current time

Chinese character processing

Now to solve the problem is that embedded systems often need to use not a complete Chinese character library, often just need to provide a limited number of Chinese characters for the necessary display function. For example, there is no need for an LCD on a microwave to provide the ability to display "e-mail"; a "short message" is not required for an air-conditioner that provides Chinese character display, and so on. But a mobile phone, PHS usually need to include a more complete Chinese character library.

If the included Chinese character library is complete, then, it is very simple to calculate the deviation of Chinese fonts in the library from the inner code: The Chinese character library is arranged in the order of location, the first byte is the area code of the Chinese character, and the last byte is the digit of the word. Each section records 94 characters, and the bit number is the position of the word in the area. Therefore, the specific position of Chinese characters in the Chinese font is calculated as follows: 94* (area code 1) + bit number-1. Minus 1 is because the array starts with 0 and the area code number is 1. Just multiply the number of bytes in the last Chinese font, that is: (94* (area code-1) + bit-1) * A Chinese character font occupies the number of bytes, taking 16*16 lattice font as an example, the formula is: (94* (area code-1) + (bit number 1)) *32. The 32-byte information from this location in the Chinese character Library records the font information of the word.

For systems containing more complete Chinese character libraries, we can calculate the position of the font with the above rules. But what if it only provides a small number of Chinese characters? Dozens of to hundreds of, for example? The best way to do this is to:

To define a macro:

# define EX_FONT_CHAR(value)
# define EX_FONT_UNICODE_VAL(value) (value),
# define EX_FONT_ANSI_VAL(value) (value),

Define structure Body:

typedef struct _wide_unicode_font16x16
  WORD value; /* 内码 */
  BYTE data[32]; /* 字模点阵 */
#define CHINESE_CHAR_NUM … /* 汉字数量 */

Array of storage for the font:

Unicode Chinese[chinese_char_num] =
Ex_font_char ("Industry")
Ex_font_unicode_val (0X4E1A)
{0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x04, 0x44, 0x44, 0x46, 0x24, 0x4c, 0x24, 0x48, 0x14, 0x50, 0x1c, 0x50, 0x14, 0x60, 0 x04, 0x40, 0x04, 0x40, 0x04, 0x44, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00}
Ex_font_char ("Medium")
Ex_font_unicode_val (0x4e2d)
{0x01, 0x00, 0x01, 0x00, 0x21, 0x08, 0x3f, 0XFC, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x21, 0x08,
0x3f, 0xf8, 0x21, 0x08, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00}
Ex_font_char ("cloud")
Ex_font_unicode_val (0x4e91)
{0x00, 0x00, 0x00, 0x30, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xFF, 0xFE, 0x03, 0x00, 0x07, 0x00,
0x06, 0x40, 0x0c, 0x20, 0x18, 0x10, 0x31, 0xf8, 0x7f, 0x0c, 0x20, 0x08, 0x00, 0x00}
Ex_font_char ("Pieces")
Ex_font_unicode_val (0X4EF6)
{0x10, 0x40, 0x1a, 0x40, 0x13, 0x40, 0x32, 0x40, 0x23, 0XFC, 0x64, 0x40, 0xa4, 0x40, 0x28, 0x40, 0x2f, 0xFE,
0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40, 0x20, 0x40}

To display a particular Chinese character, you only need to look up the inner code from the array and ask for the same font size. If the preceding Chinese characters are in the order of the code size in the array, then the binary search method can find the Chinese characters more efficiently.

This is a very effective way to organize the small Chinese character library, it can ensure that the program has a good structure.

System time Display

From the NVRAM can read the system time, the system generally by the NVRAM generated by the second interrupt per second read the current time and on the LCD display. There is an efficiency issue with regard to the display of time. Because time has its particularity, that is 60 seconds only one minute change, 60 minutes only one hour change, if we will read the time on the screen completely refreshed once, then wasted a lot of system time.

A better approach is to store hours, minutes, and seconds in a static variable in the time display function, and only update its display when its contents change.

extern void DisplayTime(…)
  static BYTE byHour,byMinute,bySecond;
  BYTE byNewHour, byNewMinute, byNewSecond;
  byNewHour = GetSysHour();
  byNewMinute = GetSysMinute();
  byNewSecond = GetSysSecond();
  if(byNewHour!= byHour)
   … /* 显示小时 */
   byHour = byNewHour;
  if(byNewMinute!= byMinute)
   … /* 显示分钟 */
   byMinute = byNewMinute;
  if(byNewSecond!= bySecond)
   … /* 显示秒钟 */
   bySecond = byNewSecond;

This example can also be used as a proof of the powerful power of the static keyword in C language. Of course, in C + + language, static has a more powerful power, it makes some data and functions out of "object" and become part of "class", it is this feature, the achievements of the numerous excellent software design.

Related Article

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.