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--; } } } |
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 |
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
Previous article:ADC Button Design Techniques Based on AVR Microcontroller
Next article:CAN bus application based on AVR processor at90can128
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Domestic RISC-V Linux Board Fang·Starlight VisionFive Trial Report] Python output HELLOWORLD
- Solutions for control loop design
- Data size transferred after power failure
- About DMX dimming system
- What is UWB?
- Solution to blind area communication of intercom
- Xunwei i.MX8MM Development Board Linux Android 9.0 Crotex-M4 Data Update
- Commonly used algorithms for drones - Kalman filter (Part 3)
- GigaDevice has also entered the wireless field and released its first GD32W515 series Wi-Fi MCU. Do you want to try it?
- Which MSP430 is right for your LCD application?