VGA display and laser printing system based on AVR

Publisher:MysticalWhisperLatest update time:2011-02-18 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Abstract : The ATMEGA128 single-chip microcomputer combined with CPLD realizes the control of VGA display and laser printer, completes the function of real-time display of characters and graphics on the VGA display, and controls the laser printer to print out the screen information. This design overcomes the shortcomings of the single-chip microcomputer system's weak display and printing functions, lays a foundation for expanding its application range, and also provides a solution for information output of other embedded systems.
Keywords : VGA controller; PCL command language; laser printing; CPLD

With the continuous development of integrated circuit manufacturing technology, the performance of microcontrollers and microprocessors such as MCU, ARM, and DSP has increased dramatically, but the output function, especially the display and printing function, is still relatively weak , and there is a big gap compared with PCs. The disadvantage of weak output function limits the expansion of its application range. ATmega128 is a high-performance MCU chip with RISC structure produced by Atmel Corporation of the United States. It contains multiple resources such as ADC, I2C , SPI, PWM, etc. [1] . Taking ATMEGA128 microcontroller as an example, combined with CPLD and high-speed SRAM, this paper introduces the method of displaying characters and graphic information on a VGA display and controlling a laser printer to print out screen information. This design overcomes the disadvantage of weak information output function of the microcontroller system, and provides a solution for the information output of microcontrollers and other embedded systems, making its application range wider. The system structure is shown in Figure 1.

1 Implementation of VGA display controller

The information displayed by the PC on the VGA monitor (usually including CRT and LCD) is completed by the graphics card. The microcontroller also needs a similar module to assist in displaying information on the VGA monitor, so we designed a VGA display controller with similar functions to the graphics card to assist the ATMEGA128 microcontroller in displaying information on the VGA monitor. The following introduces the design method of a universal VGA display controller with a resolution of 640×480 and a refresh rate of 59.9HZ, and explains how the microcontroller and microprocessor display information on the monitor with the VGA interface.

1.1 Design of VGA timing generation module

To realize the function of VGA display controller, we first need to understand the parameters and timing of VGA signal. Figure 2 shows the VGA timing diagram of 640×480 resolution and 59.9HZ refresh rate [2] . Based on the VGA timing diagram, this paper studies and implements VGA display controller. The hardware used is Altera's EPM7128 CPLD and ISSI's high-speed SRAM. The role of EPM7128 is to generate the timing signals required for VGA display through programming and assist the microcontroller to realize the read and write operations of video memory. The role of high-speed SRAM is to store the data information to be displayed. Its read and write cycle is 8ns, which meets the time requirement of fast reading and writing of video memory when the display is refreshed. In the design, one bit represents one pixel. 640×480 resolution requires 37.5K bytes of video memory. The choice of pixel clock frequency is related to the refresh frequency and resolution of the VGA monitor. When the refresh rate is 59.9HZ, the pixel clock frequency is 25.175MHZ. The calculation formula is: Clock frequency = (number of pixels per line + number of blanking points per line) × (number of lines per field + number of blanking lines) × refresh rate.

According to the requirements of VGA signal, the VGA timing generation module is implemented by programming the EPM7128 chip with VHDL language. The VGA timing generation module includes: pixel number counter h_cnt for each line, line number counter v_cnt for each field, line synchronization signal hs generation module, field synchronization signal vs generation module, blanking signal blank generation module and parallel input serial output module, etc. Among them, the maximum count value of h_cnt is 799, and the maximum count value of v_cnt is 524. The line synchronization signal generation module generates the line synchronization signal hs according to the count value of h_cnt; the field synchronization signal generation module generates the field synchronization signal vs according to the count value of v_cnt. The blanking signal generating module sets the blanking signal blank to a low level during the line synchronization period, the line blanking front shoulder and the line blanking back shoulder according to the count value of h_cnt; sets the blanking signal blank to a low level during the field synchronization period, the field blanking front shoulder and the field blanking back shoulder of each field according to the count value of v_cnt; the blanking signal blank is high level at other times, indicating that this is the effective display period. The parallel input serial output module reads data from the sram display memory in parallel during the effective display period, and outputs it serially on the red, green and blue signal lines of the display. After the program is successfully compiled, use MaxplussII software to perform waveform simulation to verify the rationality of the design. The timing waveform simulation of the final design is shown in Figure 3.

Figure 3 VGA display controller timing simulation diagram


From the simulation waveform, we can see that the time for each display line is 800 pixel clock cycles, and each field includes 525 lines. The width of the line synchronization pulse is 96 pixel clock cycles, and the width of the field synchronization pulse is 2 lines. During the line synchronization period of the line synchronization signal hs and its front and back shoulders, the blanking signal blank is low, indicating the blanking period. During the field synchronization period of the field synchronization signal vs and its front and back shoulders, the blanking signal blank is also low, indicating the blanking period. The simulation results meet the VGA standard timing, and the actual application of the project also proves the correctness of this result.

1.2 Writing VGA display underlying functions

To display information on the screen, in addition to the VGA display controller, it is also necessary to design the underlying drawing functions and establish a character library on the ATMEGA128 microcontroller. Usually, when writing line and circle drawing functions, multiplication, division, and square root operations are required to determine whether a point is on a line or a circle. Line and circle drawing functions are called most frequently, so the amount of calculation will be unacceptably large, greatly reducing the performance of the system. In order to overcome the above shortcomings, the Bresenham method in graphics is used when writing the underlying drawing functions.

void circle(unsigned int x0,unsigned int y0,unsigned int r,unsigned char color)

{

register int x,y,deltax,deltay,d;

x=0;y=r;deltax=3;deltay=2-rr;d=1-r;

while(x<=y)

{ drawpixel(x0+x,y0+y,color);

drawpixel(x0-x,y0+y,color);

drawpixel(x0-x,y0-y,color);

drawpixel(x0+x,y0-y,color);

drawpixel(x0+y,y0+x,color);

drawpixel(x0-y,y0+x,color);

drawpixel(x0-y,y0-x,color);

drawpixel(x0+y,y0-x,color);

if(d<0){

d+=deltax; deltax+=2;

x++;

}

else {

d+=(deltax+deltay);

deltax+=2;deltay+=2;

x++;y--;

}

}

}

The line drawing algorithm and the midpoint circle drawing method [3] use pixel approximation and incremental calculation to turn the complex operation of determining whether a point is on a line or a circle into an addition operation, which is very suitable for the characteristics of microcontrollers and greatly improves the drawing speed. We extracted the 12×12 and 96×96 pixel 0-9 digital font library and the 16×16 pixel common ASCII character font library from the Windows system. With the underlying drawing functions and character library, the ATMEGA128 microcontroller can display graphics or text information at any position on the screen through the VGA display controller. The right side is a routine written by ICCAVR to implement the midpoint circle drawing method on the ATMEGA128 VGA display and its implementation diagram. It only needs to use the incremental method to find the points on 1/8 of the circle, and the other points are at the central symmetric position.

2 Laser Printer Control

Laser printer is one of the most commonly used output devices at present. Compared with thermal and inkjet printers, it has significant advantages. The following introduces how to use ATMEGA128 microcontroller to directly control laser printer to print the contents of VGA display screen. To control the printer, you must understand the printer command language. Printer language refers to the commands that control the operation of the printer. It controls how the printer organizes the documents to be printed. The printer processes the print data according to these commands and finally prints out text and images accurately.

2.1 PCL Printer Command Language

PCL printer command language is the most widely used standard printer command language in the world. It was developed by HP and supports the printing of text, dot matrix images and vector graphics. PCL commands consist of more than two characters and always start with the control character ESC. It is represented by E C and its ASCII code is 27, so PCL commands are also called

Figure 4 Schematic diagram of the midpoint circle method

It is called ESC sequence. When the printer receives the character E C , it indicates that it starts to receive a control command. PCL commands include two types of ESC sequences: "two-character" command sequence and "parameterized" command sequence.

The format of the "two-character" command sequence is as follows: E C X , where the symbol X represents the characters with ASCII codes 48 to 126, that is, the characters between "0" and "~" in the ASCII character table. The symbol X indicates the operation that the printer needs to perform. For example, the command " E C E " is a printer reset command, and the command " E C g " resets the left and top margins of the paper to the default values. The format of the "parameterized" command sequence is as follows: E C X y z1 # z2 # z3 ... # Zn[data] , where E C is the starting character, X is the parameterized character, representing characters between ASCII codes 33 and 47, and its function is to indicate that the sequence is a "parameterized" sequence; y is the group character, representing characters between ASCII codes 96 and 126, and is used to specify which group the operation to be executed belongs to; # is the numeric field, and its range is from -32767 to 65535; z i is the parameter of this command, representing characters between ASCII codes 96 and 126. This parameter is used for combined "parameterized" sequences, but not for non-combined sequences. Its function is to specify the parameters used by the previous numeric field; Zn is the end character, indicating the end of the "parameterized" command sequence; [data] is the data to be printed that is transmitted to the printer, represented by 8 bits, that is, any data between 0 and 255. The following two examples are respectively a non-combined "parameterized" command sequence and a combined "parameterized" command sequence:

1 2

1 is a non-combined sequence without parameters. 2 is a combined sequence, which is composed of the sequences E C & l 1O and E C & l 2A , where the lowercase character "o" is the parameter of the sequence [4] . For a detailed description of various command sequences, see reference [4] .

2.2 Print Screen

The IO port of the ATMEGA128 microcontroller and the parallel port of the laser printer are connected by the following signals: Strobe, Busy, GND, D0~D7, a total of 11 signal lines. Among them, D0~D7 are data lines, and the microcontroller transmits the PCL command for controlling the printer and the data to be printed to the printer through the data line; the Busy signal line indicates whether the printer is busy; the Strobe signal line is the selection control line, and the microcontroller outputs a low-level pulse on the Strobe signal line to write the data on D0~D7 to the printer. It was mentioned in the first part of the paper that the content displayed by the VGA monitor is stored in the SRAM video memory, and each bit represents a pixel, so printing the screen is to print out the data in the video memory. The ATMEGA128 microcontroller first sends the printer setting command in PCL language to set up the printing, and then transmits the print data. The steps are as follows: 1. Send a printer reset command; 2. Send a command to set the paper size; 3. Send a command to set the starting position of printing; 4. Send a command to set the resolution; 5. Send a command to set the printer to dot-matrix graphics mode; 5. Send the data to be printed; 6. Send a command to end the graphics mode; 7. Send a page change command to print the current page. The following is a routine of ATMEGA128 microcontroller sending PCL commands to HP LASERJET6L laser printer and controlling the printer to print out VGA screen information:

void print()

{unsigned int M; unsigned char i;

unsigned char xdata *p;p=NVRS;

out(27);out('E');//printer reset

out(27); pprint("&l26A"); // Set the paper size to A4

out(27); pprint("*p210X"); // 'Set the X coordinate starting position of this page print

out(27); pprint("*p400Y"); // 'Set the Y coordinate starting position of this page print

out(27); pprint("*t100R"); // 'Set the resolution

out(27); pprint("*r1A"); // 'Set graphics mode to start

for(M=0;M<480;M++) //Transmit the graphic data to be printed

{ out(27); pprint("*b80W");

…………

out(27); pprint("*rC"); // 'Graphics mode ends

out(255); out(12); //'End of this page, execute printing

}

in conclusion:

The innovation of this paper is to use the ATMEGA128 microcontroller combined with CPLD to realize the control of VGA display and laser printer, so that the microcontroller can display graphics and text information on the VGA interface display, and control the laser printer to print out the information on the VGA screen. This design overcomes the shortcomings of the weak information display and printing functions of the microcontroller control system, so that it has practical display and printing functions on the basis of giving full play to the advantages of control functions, laying a foundation for expanding its application scope. In addition, the interface of ATMEGA128 used in this design is GPIO port and Intel format standard bus, so it can be easily transplanted to other types of chips, providing a reference solution for information display and printing of other systems. This design has been successfully transplanted to the TMS320C6713 DSP chip [5] .

References
[1] Atmel. 8-bit AVR Microcontroller with 128K Bytes In-System Programmable Flash 2001
[2] Cao Yun. VGA timing color bar signal implementation method based on FPGA and its application. Electronic Technology Application. Vol.28 No.7 2002
[3] Sun Jiaguang et al. Computer Graphics. Tsinghua University Press, 2002
[4] Hewlett-Packard. PCL5 Printer Language Technical Reference Manual First Edition. 1992
[5] He Mingxing et al. Application of Max7000 series programmable devices in DSP system design Microcomputer Information 2003 Vol.19 No.6 pp.25-26

Reference address:VGA display and laser printing system based on AVR

Previous article:ADC Button Design Techniques Based on AVR Microcontroller
Next article:CAN bus application based on AVR processor at90can128

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号