ST7920.H
The user function is C51.
Copyright (c) 1988-2004 Keil Elektronik GmbH sum zhaojun
All rights reserved.
---------------------------- --------------------------------------------------*/
// Serial mode
#ifndef __ST7920_H__
#define __ST7920_H__
#define uint unsigned int
#define uchar unsigned char
//Pin definition
#define LCD_CS P3_2 // Chip select high level is valid. When using a single-chip LCD, the high level can be fixed.
#define LCD_SID P3_3 // Data
#define LCD_CLK P3_4 // Clock
#define LCD_PSB P3_5 // Low level indicates that it is driven by the serial port. The low level can be fixed.
#define LCD_RST P3_6 // LCD reset. The LCD module has its own reset circuit. It can be left unconnected.
//#define LCD_BACK P2_6 // LCD backlight control
/********************************************************
Function name: void Delay_LCD(uint Number)
Function: LCD delayDescription
: If the BF flag is not checked before sending an instruction, a longer delay must be made between the previous instruction and this instructionEntry
parameter: NumberReturn
value: None
****************************************************/
void Delay_LCD(uint Number)
{
uint i,j;
for (i=0; i
for(j=0; j<10; j++)
{
;
}
}
}
/********************************************************
Function name: void Send_byte(uchar Byte)
Function: Send a byte
Input parameter: Byte
Return value: None
********************************************************/
void Send_byte(uchar Byte)
{
uchar i;
for (i=0; i<8; i++)
{
LCD_SID = Byte&0x80; // Take out the highest bit and write serial data
LCD_CLK = 1; // Serial synchronous clock signal
LCD_CLK = 0;
Byte <<= 1; // Shift left
}
}
/*********************************************************
Function name: void WriteCommandLCM()
Function: Write command
entry to LCMParameter: WCLCMReturn
value: None
****************************************************/
void WriteCommandLCM(uchar WCLCM)
{
uchar Start_data,Hdata,Ldata;
Start_data = 0xf8; // write instruction 11111000
Hdata = WCLCM&0xf0; // take the upper four bits DDDD0000
Ldata = (WCLCM << 4) & 0xf0; // take the lower four bits 0000DDDD
Send_byte(Start_data); // Send the first byte of the start signal - format: 1111ABC
Delay_LCD(5); // Delay is required
Send_byte(Hdata); // Send the upper four bits of the second byte - format: DDDD0000
Delay_LCD(1); // Delay is required
Send_byte(Ldata); // Send the third byte of the lower four bits - format: 0000DDDD
Delay_LCD(1); // Delay is required
}
/********************************************************
Function name: void WriteDataLCM()
Function: Write data to LCM1602Description
: Write the data in the parameter WDLCM to LCMEntry
parameter: WDLCMReturn
value: None
****************************************************/
void WriteDataLCM(uchar WDLCM)
{
uchar Start_data,Hdata,Ldata;
Start_data = 0xfa; // write data 11111010
Hdata = WDLCM & 0xf0; // Take the upper four bits DDDD0000
Ldata = (WDLCM << 4) & 0xf0; // Take the lower four bits 0000DDDD
Send_byte(Start_data); // Send the first byte of the start signal - format: 1111ABC
Delay_LCD(5); // Delay is required
Send_byte(Hdata); // Send the upper four bits of the second byte - format: DDDD0000
Delay_LCD(1); // Delay is required
Send_byte(Ldata); // Send the lower four bits 3rd byte - format: 0000DDDD
Delay_LCD(1); // Delay is required
}
/********************************************************
Function name: void Lcdinit(void)
Function: LCD initialization
entry Parameter: NoneReturn
value: None
********************************************************/
void Lcdinit(void)
{
Delay_LCD(10); // Start waiting, wait for LCM to enter working status
LCD_PSB = 0; // Serial port drive mode
LCD_RST = 0;
Delay_LCD(1);
LCD_RST = 1; // Reset LCD
LCD_CS = 1; // Chip select
WriteCommandLCM(0x30); // 8-bit interface, basic command set
WriteCommandLCM(0x0c); // Display on, cursor off, reverse white off
WriteCommandLCM(0x01); // Clear the screen, reset the DDRAM address counter to zero
}
/********************************************************
Function name: void DisplayListChar()
Function: write string to the pointed address
Entry parameter: x- horizontal coordinate, y- vertical coordinate, s- string
Return value: None
****************************************************/
void DisplayListChar(uchar x, uchar y, uchar code *s)
{
uchar add; // display address
switch (y) // Display address count
{
case 0: add = x + 0x80; break; // Address of the first line
case 1: add = x + 0x90; break; // Address of the second line
case 2: add = x + 0x88; break; // Address of the third line
case 3: add = x + 0x98; break; // Address of the fourth line
default: break;
}
WriteCommandLCM(0x30); // 8-bit interface, basic command set
WriteCommandLCM(add); // write address
while (*s > 0) // Write string
{
WriteDataLCM(*s);
s++;
Delay_LCD(50);
}
}
/********************************************************
Function name: void DisplayPicture(uint code *img)
Function: Display graphics on LCDDescription
: When displaying graphics on LCD, due to the particularity of ST7920, two screens should be usedControl
entry parameter: *imgReturn
value: None
********************************************************/
//Graphics modevoid
DisplayPicture(uint code *img)
{
uchar Line,Row; // Line is the row address; Row is the column addressuint
regist = 0; // Graphics address register
WriteCommandLCM(0x36); // Graphics mode, extended command
// -------------- Upper half screen----------------
for (Line=0; Line<32; Line++)
{
WriteCommandLCM(0x80 + Line); // Write row address
WriteCommandLCM(0x80); // Write column
for (Row=0; Row<16; Row++)
{
WriteDataLCM(img[regist++]); // Write image data
}
}
// --------------- Lower half screen---------------
regist=512; // Lower half screen starting data
for (Line=0; Line<32; Line++)
{
WriteCommandLCM(0x80 + Line); // Write row address
WriteCommandLCM(0x88); // Write column
for (Row=0; Row<16; Row++)
{
WriteDataLCM(img[regist++]); // Write image data
}
}
WriteCommandLCM(0x30); // Basic instructions
}
/********************************************************
Function name: void main(void)
Function: main function
entry parameter: noneReturn
value: none
****************************************************/
void main(void)
{
Lcdinit(); // Initialize LCD
while(1)
{
DisplayListChar(0,0,"zhaojun");
}
}
#endif
Previous article:Homemade 51 MCU common header files (DS18B20)
Next article:Homemade 51 MCU common header files (st7920 parallel mode)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Introduction to the mobile station development board: ultra-low power python board
- USB to JTAG
- DSP28335 SCI communication problem summary and problem summary
- Beetle ESP32-C3 test (IV) IDF method to provide AP connection
- Several questions about 7S3P battery pack circuit
- MSP430G2553 clock system configuration
- Award-winning live broadcast: Microchip&avnet series live broadcast third collection
- [Vicor White Paper Recommendation] Power Averaging Design Method with Voltage Regulation: Ideal Power Supply Solution for Pulse Loads
- Bear Pie Huawei IoT Operating System LiteOS Kernel Tutorial - IoT-Studio Introduction and Installation
- How to use C language to find the corresponding value in the table in the microcontroller