Design of LCD display system based on VB 6.0

Publisher:LuckyDaisyLatest update time:2012-11-14 Source: 维库电子Keywords:6.0 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Liquid crystal display has become the mainstream display technology in the display system of pocket electronic products due to its advantages of low power consumption, light weight, small size and ultra-thinness. It is widely used in communication, home entertainment, advertising, instrumentation and other fields. This paper designs a system that directly controls the liquid crystal display through communication between the computer and the single-chip microcomputer. Using VB software programming, an intuitive human-computer interface is designed. Characters and character movement methods are directly input through the computer keyboard, and transmitted to the single-chip microcomputer through serial communication. The single-chip microcomputer system then controls the liquid crystal display module, so that characters can be moved and displayed on the LCD screen.

1. Selection of main control chip and LCD screen

In this system, the main control chip is AT89S51 produced by Atmel. This chip has 4k bytes of programmable FLASH memory, supports serial and parallel download programs ISP online programming, and is low-priced and fast in execution. The LCD screen uses a dot matrix character LCD display module LCD162. LCD162 uses a standard 16-pin interface, can display 2 lines of 32 words, 16 ASCII characters per line, and can customize graphics. You only need to write the ASCII code of the corresponding character to display it.

2 Hardware Circuit Design

The system hardware circuit mainly consists of two parts: LCD display module and communication module. The circuit is shown in Figure 1.

Figure 1 System hardware circuit

In Figure 1, the LCD display part, the microcontroller and LCD162 use a parallel interface. The P0 port of the microcontroller is connected to the data lines D0~D7 of the LCD display, and is pulled up through 8 10 kΩ pull-up resistors. P1.5 is connected to the RS end of LCD162. When P1.5 is high, the data register is selected, and when it is low, the instruction register is selected. P1.6 is connected to RW, which is used to control the read and write operations of the LCD display. When P1.6 is high, the read operation is performed, and when it is low, the write operation is performed. P1.7 is connected to the enable end of LCD162. When E jumps from high level to low level, the LCD module executes the command.

V0 is the contrast adjustment terminal of the LCD display. A 10 kΩ potentiometer R9 provides an adjustable LCD drive voltage for V0 to adjust the display contrast.

This system needs to display the characters typed on the microcomputer keyboard on the LCD screen, so the asynchronous serial communication interface of the 51 single-chip microcomputer is used to communicate with the computer in serial, and then the single-chip microcomputer controls the LCD display module. The computer has a serial communication port RS-232, whose logic level is represented by positive and negative voltages, and the signal uses negative logic. The voltage range of logic 0 is +5~+15V, and the voltage range of logic 1 is -5~-15V. However, the output signal of the 51 single-chip microcomputer does not actually meet the RS-232 standard. The voltage on its serial communication pin is the TTL standard, that is, two states between 0~5V. Therefore, when the 51 single-chip microcomputer is connected to the MODEM, a level and logic conversion link must be inserted in the middle. Here, the MAX232 chip is used to realize the conversion task between the TTL level and the RS-232 level.

3 Software Design and Development

The software part includes the LCD display subroutine controlled by the single-chip microcomputer, the communication subroutine between the single-chip microcomputer and the PC, and the VB programming part.

3.1 LCD Display

The LCD162 liquid crystal module has a character generator CGRAM inside, which stores 160 different dot matrix character graphics. Each character has a fixed code, and its corresponding code can be found through the standard character library table. When displaying characters, you need to send the address (write command) first, and then send the character (write data). If you want to display characters outside the character library, you need to use CGRAM to compile the display. The liquid crystal display module of this system includes LCD initialization, cursor positioning, character display and other modules. Its program flow chart is shown in Figure 2.

Figure 2 LCD display control main program

During initialization, it is necessary to set the initial state, display cursor, clear screen, display mode, etc. Here, LCD162 is set to 8-bit data, 5×7 character dot matrix, and two-line display, that is, write P0 port to 38H. LCD162 has four operations: write command, read status, write data, and read data. The four operations are determined by the status of P1.5, P1.6, and P1.7. Before performing the three operations of write command, write data, and read data, you need to perform the read status operation first, and query the busy flag through the query method. When the busy flag is 0, you can perform the other three types of operations. When sending display characters, the display data needs to be written in the corresponding DDRAM address to determine the display position of the display characters. The following is the busy status judgment subroutine and the write data subroutine, and its subroutine flow is shown in Figures 3 and 4.

RS BIT P1.5

RW BIT P1.6

E BIT P1.7

LCD EQU P0

; Determine whether the subroutine is busy:

CHECK_BF:

MOV LCD,#0FFH

CLR RS; When RS is low and RW is high, the status can be read

SETB RW ; RW=1, select read mode

CLR E

NOP

SETB E ;E=1, allows reading/writing LCD

NOP

JB LCD.7,CHECK_BF

RET

;Write data subroutine:

WR_DATA:

SETB RS; RS = 1, select data register

CLR R

CLR E

ACALL CHECK_BF

MOV LCD, A; send data to P0,

NOP; Give the hardware time to react

NOP

NOP

NOP

SETB E

NOP

NOP

NOP

NOP

CLR E ; When E changes from 1 to 0, the LCD module starts

Execute Command

RET

Figure 3 Busy judgment subroutine

Figure 4: Write data subroutine

3.2 Serial communication between MCU and PC

The serial data transmitting terminal TXD and the serial data receiving terminal RXD of the single-chip microcomputer are connected to T1 and R1 of MAX232 respectively. The settings should correspond to the serial port settings of the PC. The serial port of the single-chip microcomputer in this system adopts working mode 1, and the baud rate is set to 9600, which is generated by timer T1. At the beginning of communication, the PC sends a handshake signal. After receiving the handshake signal, the single-chip microcomputer sends a response signal back to the PC. After the PC receives the response signal and verifies that it is correct, it means that the serial port communication is successful.

3.3 PC Serial Communication

The computer communication is written in VB6.0 software. There is a MSComm communication control in VB, which can set the sending and receiving of serial communication data. By programming the properties and events of this control, serial communication can be easily realized. The MScomm control provides two communication methods: event-driven and query mode. This system uses the query mode to process communication. In order to ensure reliable communication between the computer and the single-chip microcomputer, both parties need to set the same data format and baud rate. This system uses binary to send and receive data. Before sending data, the sending buffer needs to be cleared, that is, the OutBufferCount property value of the MScomm control is 0. When initializing the communication port, select the serial communication port Com1, set its baud rate to 9600, no parity check, 8-bit data transmission, and 1 stop bit. After the character data is sent, use the Enter key as the end.

The following program is the code to realize communication, where Label1 control is used as the prompt label when serial communication is successful.

Private Sub MSComm1_OnComm()' Serial port settings

Dim Buffer As Variant

Dim Hexbuffer() As Byte

If MSComm1.PortOpen = True Then

Select Case MSComm1.CommEvent

Case comEvReceive 'A receive event occurs

MSComm1.InputLen = 0

MSComm1.InputMode = comInputModeBinary

'Data transmission and reception adopt binary

Buffer = MSComm1.Input

Label1.Caption = Buffer

Hexbuffer() = Buffer

Dim I As Integer

For I = 0 To UBound(Hexbuffer)

If Hex(Hexbuffer(I)) = 1 Then

Label1.Caption = Label1.Caption & "0" &Hex(Hexbuffer(I))

Else

Label1.Caption = Label1.Caption & Hex(Hexbuffer(I))

End If

Next I

End Select

End If

End Sub

Two buttons for moving left and right are also set in the VB form interface. By adding two timers, timer1 and timer2, and changing the position property of the control in the timer event, the characters can be moved on the form. Figure 5 shows the simulation effect through the virtual serial port and Proteus software. In Figure 5, the left picture is the VB form interface, and the right picture is the LCD display simulation picture. Enter characters in the form text box control, click the send button to display them on the LCD screen, and click the left and right buttons to move the contents of the LCD screen at the same time.

Figure 5 VB controlled LCD display simulation

4 Conclusion

This system uses a computer as the host and a single-chip microcomputer as the slave, realizing serial communication between the computer and the single-chip microcomputer, and can input characters into the computer through the keyboard and display them on the LCD screen. The system structure is simple and has certain practicality.

Keywords:6.0 Reference address:Design of LCD display system based on VB 6.0

Previous article:Photoelectric detection system with weak light signal preamplifier circuit
Next article:Implementation strategy of street lamp control and management system based on GIS

Recommended ReadingLatest update time:2024-11-17 01:41

WINCE6.0+S3C6410 watchdog restart
// File: watchdog_sw_rst.c // // Samsung SMDK6410 SW_RST using watchdog timer support code. // #include windows.h #include ceddk.h #include oal.h #include s3c6410.h // WTCON - control register, bit specifications #define WTCON_PRESCALE(x) (((x)&0xff) 8) // bit 15:8, prescale value, 0
[Microcontroller]
Latest Power Management 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号