Design of VRAM Color LCD Module Based on Single Chip Microcomputer

Publisher:郑哥Latest update time:2011-10-24 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This paper introduces the design of a VRAM color LCD display module based on AVR single-chip microcomputer and hardware Chinese character library. The display principle of color LCD, hardware interface design block diagram, and the production and application of hardware Chinese character library are given. At the same time, a programming module based on C language is given to realize the modularization of VRAM type LCD, which is convenient for transplantation to other types of single-chip microcomputers.

1 Introduction

With the rapid development of electronic technology, more and more fields are applying digital devices with single-chip microcomputer as the control core and liquid crystal as the display terminal. As the crystallization product of contemporary high-tech, color LCD display not only has the characteristics of ultra-thin plane, rich display information and realistic colors, but also has the advantages of small size, low power consumption, long life, no radiation, shock resistance, explosion-proof and other incomparable advantages of other types of displays. Therefore, it is an ideal display device for the upgrading of industrial control instruments, electromechanical equipment and other industries. Therefore, the use of color LCD display modules based on single-chip microcomputer system is becoming more and more widespread. This article introduces a color LCD display module based on AVR single-chip microcomputer and hardware Chinese character library. The module realizes the display of Chinese, English, numbers and simple drawing functions of different colors on the color LCD display.

2 LCD display principle

The LCD display used in this module is the YD2502 color LCD VRAM display produced by Henan Youlihua High-tech Co., Ltd. Its dot matrix is ​​320 × 240, and the VRAM capacity is 64k × 8 bits. Since any point on the screen is composed of three colors: R (red), G (green), and B (blue), and the grayscale cannot be adjusted, the display color is 8 colors. The basic principle block diagram is shown in Figure 1. The DC/DC converter generates various driving voltages used by the liquid crystal, and the DC/AC inverter is used to light up the cold cathode backlight. The display drive logic circuit uses an optimized logic circuit, and uses time-sharing technology to allow display and data writing to be performed simultaneously, realizing high-speed image updates without interfering with each other. Its display principle is: there is a display buffer inside the display that corresponds to the screen display one by one. When using it, you only need to write the corresponding data into the buffer, and the corresponding color graphics or text can be displayed on the screen. That is to say, the display can be used as an external memory of the single-chip system to realize the display of color information.

Figure 1 YD2502 block diagram

3 Hardware System Design

3.1 Overall hardware design

The MCU used in this module is the most powerful ATmega128 in the AVR series of MCUs. This MCU has rich on-chip resources such as 128 kB online reprogrammable Flash, 4 kB E2 PROM, 4 kB internal SRAM, 48 I/O ports, 34 different interrupt sources, addressable 64 kB address space, ISP download and JTAG emulation. Please refer to its data sheet for detailed introduction.

Figure 2 is the overall design block diagram of the module hardware system. Since the content in the display buffer of YD2502 cannot be read out, in order to save the written content, a memory chip 61LV5128 with a storage capacity of 512 kB is also expanded in the module. In addition to saving the data in the display buffer of YD2502, it also provides extended applications for embedded systems using this module. Since the addressing range of A Tmega128 is only 64 KB, paging management technology is used to operate 512 kB of storage space. In the specific circuit design, PB3 ~ PB0 of A Tmega128 is connected to the high 4-bit address line of 61LV5128, and the 512 kB storage space is divided into 16 pages, 32 kB per page. The storage capacity of the hardware Chinese character library chip AT29C040A is also 512 kB, and the interface design with the CPU is similar to that of 61LV5128. It is only necessary to connect the chip select signal and the high 4-bit address line to different I/O ports.

Figure 2 Hardware design diagram

3.2 Interface design of YD2502

The interface of YD2502 adopts bus mode. The external leads include data bus (DB7~DB0), chip select signal (/CS), read/write input (/RD, /WR) and register select signal (RS). It can be directly connected to the bus of the microcontroller and used as a part of the memory of the microcontroller. The interface adopts 16-pin socket. Please refer to its manual for the pin definition.

According to the interface characteristics that YD2502 can be used as an external memory of a single-chip microcomputer, the read and write signal lines of A Tmega128 are directly connected to the read and write signal lines of YD2502. The specific interface design principle is shown in Figure 3.

Figure 3 Interface between AT128 and YD2502

3.3 Production of Hardware Chinese Character Library

This module uses a hardware Chinese character library, which saves the trouble of using Chinese character modeling software to obtain dot matrix data, and also avoids the need to open up a large amount of program storage space to save these data.

The dot matrix file to be burned in the Chinese character library is the file HZK16 in the UCDOS software. This file is a 16 × 16 international Chinese character dot matrix file. In the file, 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 is 94 Chinese characters. The Chinese character library chip uses AT29C040A, which is a 512 kB Flash ROM produced by ATMEL. When making it, the burning process is basically the same as the programming of ordinary program memory. Just pay attention to selecting the correct model and using the binary method when choosing the way to open HZK16. After the programming verification is successful, remove it for use, and the hardware Chinese character library chip is ready.

In fact, if the file attributes of HZK16 are displayed, its size is 262 kB, while the storage capacity of AT29C040A is 512 kB. The excess part can be used to store the user's fixed Chinese characters, letters and numbers, making the display content more flexible and rich.

4 Software System Design and Implementation

4.1 Programming of operating YD2502

The instruction code format of YD2502 is as follows:

Among them: CA1, CA0 combination function is the selection of internal register channel, the functions are as follows:

DISP: Display control bit.

When DISP is set to "1", the LCD display module is in the on display state.

When DISP is set to "0", the LCD display module is in the off display state.

X: indicates an unused bit, which can be set to "0".

The software design steps for ATmega128 to access external memory are: first declare an external variable with extern, then use map2ping_init function (external memory address allocation function) to assign an external memory address to this variable (because ATmega128 has 4 kB of SRAM inside, the external memory address range is 1000H~0FFFFH), then the operation on this variable realizes the CPU's access to the external memory space of the corresponding address.

According to this step, the specific functions of writing instructions and writing data to YD2502 are as follows:

extern unsigned char LCD_DA TA;

void mapping_init (void) {

asm(". area memory (abs) n"

".org 0x4000n" // The address assigned to LCD_DA TA is 4000H

"_LCD_DA TA : : . blkb 1 n" // Storage space is 1

".text/n");}

The write instruction function is as follows:

void LCD_writeinstr (unsigned char data) {

PORTD & = 0xFC ; // Set CS to low level and RS to low level, in the write instruction state

LCD_DA TA = data ; // send data

PORTD | = 0x03 ;} // Set CS and RS to high level

The write data function is as follows:

void LCD_writedata (unsigned char data) {

PORTD & = 0xFE ; // Set CS to low and RS to high level, in data writing state

LCD_DA TA = data ; // send data

PORTD | = 0x01 ;} // Set CS to high level In addition to the above two basic functions, the most basic operation for YD2502 is to write data to VRAM. According to the instruction code given above, the specific functions are as follows:

#define HREG 0x09 //Display address high 8 bits register instruction

#define L REG 0x08 //Display address lower 8 bits register instruction

#define DA TARW 0x0A //Display data read and write channel instructions

void LCD_filldata (unsigned int address,

unsigned char data) {

unsigned char addrh ,addrl ;

addrh = (char) (address >> 8); // Get the high 8 bits of the memory address

addrl = (char) (address &0xFF); // Get the lower 8 bits of the memory address

LCD_writeinst r (HREG); //Send the display address high 8 bits register instruction

LCD_writedata (addrh); // send the high 8 bits of the memory address

LCD_writeinst r (L REG); // Send the display address lower 8 bits register instruction

LCD_writedata (addrl); // send the lower 8 bits of the memory address

LCD_writeinst r (DA TARW); // Send display data read and write channel instructions

LCD_writedata (data);} // Send data

4.2 Implementation of the point drawing function

To realize functions such as displaying characters and drawing on LCD, displaying a dot on the screen is the basis for realizing these functions. The steps of the dot drawing function are: first determine the memory location in VRAM corresponding to the dot, find the data bit corresponding to the dot, fill in the data of the display color, and the dot will be displayed in the corresponding color.

4.2.1 Correspondence between display memory and screen dot matrix

The YD2502 screen matrix is ​​320 × 240, each dot corresponds to 3 pixels (RGB), 8 dots on the screen correspond to 3 bytes of memory, and one row corresponds to 320/8 ×3 = 120 bytes. The corresponding relationship is as follows:

Among them, R, G, B represent the three primary colors of red, green and blue, and D7~D0 represent the corresponding data bits.

For a point on the screen with coordinates (X, Y), the corresponding memory address is calculated as follows:

When Y = 0, SRAM = 0EFH × 100H + [INT (X/8)] × 3

When Y > 0, SRAM = (Y - 1) × 100H + [INT (X/8)] × 3

The specific memory location is obtained by the remainder of (X/8):

When the remainder is 0, RAM = SRAM [ 1110 ,0000 ]

When the remainder is 1, RAM = SRAM [ 0001 ,1100 ]

When the remainder is 2, RAM1 = SRAM [ 0000 ,0011 ]

RAM2 = SRAM + 1[1000 ,0000 ]

When the remainder is 3, RAM = SRAM + 1[0111 ,0000 ]

When the remainder is 4, RAM = SRAM + 1[0000 ,1110 ]

When the remainder is 5, RAM1 = SRAM + 1[0000, 0001]

RAM2 = SRAM + 2[1100 ,0000 ]

When the remainder is 6, RAM = SRAM + 2[0011, 1000]

When the remainder is 7, RAM = SRAM + 2[0000 ,0111 ]

The bit with "1" in [ ] indicates the position that should be filled with color, SRAM indicates the base address corresponding to the point, and RAM, RAM1 and RAM2 indicate the actual memory address corresponding to the point.

When the data bit is "1", the corresponding color point is bright; when it is "0", the corresponding color point is dark. The 8 color codes obtained by combining the three primary colors of RGB are as follows:

Example 1: If the X and Y coordinates are (7, 0)

SRAM = 0EFH ×100H + 0 = 0EF00H

The remainder is 7, then RAM = 0EF00H + 2 = 0EF02H

If this point is red, the data sent to the memory unit 0EF02H is [0EF02H] &11111000B + 00000100B

Example 2: If the X and Y coordinates are (15, 5)

SRAM = (5 - 1) ×100H + 1 ×3 = 403H

The remainder is 5, then RAM1 = 403H + 1 = 404H

RAM2 = 403H + 2 = 405H

If this point is white, the data sent to these two units is

[404H] &11111110B + 00000001B

[405H] &00111111B + 11000000B

4.2.2 Specific implementation of the point drawing function

From Example 1 and Example 2, we can see that to display only one color point, we must know the data in the memory corresponding to the point. As mentioned earlier, the data in the memory cannot be read out, so the data written into the memory must be saved first, that is, before writing data to the display buffer of YD2502, the data should be written to 61LV5128 first. If a point with color color is drawn at the coordinate (X, Y), the specific function is as follows:

void LCD_ disppixel (unsigned int X, unsigned int Y, unsigned char color) {

unsigned int address ;

unsigned char data ;

address = LCD_pixeladdr (X, Y);

// Calculate the memory address corresponding to this point

switch ( X %8 ) {

case 0: data = read_exram (ad2

dress) ; //Read the data in the corresponding SRAM

data & = 0x1F; // [1110 ,

0000] Save data of other points

data |= (color << 5);

//Fill with the corresponding color

write_exram(data,ad2

dress) ; //Write the modified data back to SRAM

LCD_filldata (address, da2

ta) ; //Write data to the LCD display buffer

break ;

case 7 : …; break ;}}

The above only gives the case where the remainder is 0, and the other cases can be deduced in the same way. The LCD_pixeladdr function for calculating the memory address can be written according to the given memory address calculation method, and the read_exram function and write_exram function for reading and writing 61LV5128 can be written according to the specific hardware design, which will not be given here.

4.3 Display of Chinese characters and implementation of other functions

The basic steps to display 16 × 16 dot matrix Chinese characters on the screen are: first obtain the 32 bytes of dot matrix data of the Chinese character, then determine the display position on the screen, and use the dot drawing function to display the Chinese character. Because this module uses hardware Chinese character library technology, the dot matrix data of the Chinese character is obtained from the Chinese character library.

In the computer Chinese character system, Chinese characters are stored in the form of machine codes. Subtracting 0A0A0H from the machine code of a Chinese character will give the area code of the Chinese character. The location of the Chinese character dot matrix data in the Chinese character library can be found through the area code. For example, the machine code of the Chinese character "中" is "D6D0" in hexadecimal, where the first two digits "D6" represent the area code of the machine code, and the last two digits "D0" represent the bit code of the machine code. Therefore, the area code of "中" is 0D6D0H - 0A0A0H = 3630H. Convert the area code and bit code to decimal respectively, and the area code of the Chinese character "中" is "5448". That is, the dot matrix of "中" is located at the 48th word of the 54th area, and the position in the file HZK16 is the 32nd × [(54 - 1) × 94 + (48 - 1)] = 160928D. The 32 bytes after are the dot matrix data of "中". After reading the file HZK16 with the SUPER2PRO25 programmer, use the buffer editing in its editing function to find the 32 bytes starting with 274A0H (the hexadecimal representation of 160928D): 01H, 00H, 01H, 00H, 01H, 04H, 7FH, FEH, 41H, 04H, 41H, 04H, 41H, 04H, 41H, 04H, 7FH, FCH, 41H , 04H , 01H , 00H , 01H , 00H , 01H , 00H ,01H , 00H ,01H ,00H ,01H ,00H ,01H ,00H ,00H. The corresponding relationship between these data and their dot matrix graphics is shown in Figure 4. The black squares in the figure represent the binary bit "1", that is, the points that should be displayed, and the white squares represent the binary bit "0", that is, the points that should not be displayed. Therefore, in order to display Chinese characters with 16 × 16 dot matrix on the LCD screen, you should first find the position of the Chinese character in the hardware Chinese character library and take out the 32 bytes of data behind it. The function to take these 32 bytes of data is as follows:

Figure 4 The dot pattern of the Chinese character “中”

unsigned char chinese[ ] [ 2 ] = {"中"",国"};

unsigned char buffer [32];

void LCD_ readdata (unsigned char num2

ber) {

unsigned char temp1,temp2,k;

unsigned long address , i ;

temp1 = chinese [ number ] [ 0 ] - 0xA0 ; // Convert the machine code to the area code

temp2 = chinese [number] [1] - 0xA0;

address = 32 3 ( ( (long) temp1 - 1) 3 94 + ( (long) temp2 - 1) ) ; // Calculate the first address of the Chinese character in the Chinese character library

k = 0 ;

for ( i = address ; i < address + 32 ; i + + ) {

data = read_exrom(i);

buffer[k] = data;

k++; }}

The read_exrom function for reading A T29C040A can be written according to the hardware design and will not be given here.

After obtaining the 32 bytes of data, the following program design is relatively easy. Here we only give the program flow (as shown in Figure 5), and the specific function can be written according to this flow. Among them, (X, Y) is the starting point of the Chinese character display, color is the display color of the Chinese character, and number is the position of the Chinese character in the Chinese array. The function of displaying English and numbers can be obtained by slightly modifying the function of displaying Chinese characters, so it will not be analyzed in detail here.

Figure 5 shows a Chinese character program flow chart

This module also implements functions such as drawing oblique lines and circles on the screen. The specific implementation process is to write these functions through corresponding algorithms based on the point drawing function. There are many algorithms for drawing lines and circles. Here, the line drawing algorithm uses the integer digital differential analysis method, and the circle drawing algorithm uses the Besenheim algorithm.

Due to the limited space, we will not analyze it in detail here. Since YD2502 is a dot matrix LCD display, it can also display multiple curves and various window objects such as buttons, edit boxes, sliders, etc. by transplanting embedded GUI (such as μC/GUI) software to form a richer and more flexible graphical interface.

5 Conclusion

The above programs have been debugged in the ICCAVR compiler and have achieved the normal display of Chinese characters, English, numbers and simple graphics in various colors on the LCD screen. In the oil field detection blaster equipment developed by the author, this LCD module was used to achieve a relatively ideal display effect with stable display, rich display colors and friendly human-computer interface.

Reference address:Design of VRAM Color LCD Module Based on Single Chip Microcomputer

Previous article:Indoor formaldehyde testing system based on 51 single chip microcomputer
Next article:Working Principle of DDS Chip AD9850 and Analysis of Its Interface with Single Chip Microcomputer

Latest Industrial Control Articles
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号