unsigned char table1[]={0x03,0x07,0x0f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x18,0x1E,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f, 0x07,0x1f
,0x1f,0x1f,0x1f,0x1f ,0x1f,0x1f,
0x10,0x18,0x1c,0x1E,0x1E,0x1E,0x1E,0x1E, 0x0f
,0x07,0x03,0x01,0x00,0x00,0x00,0x00,
0x1f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x01,
0x1f,0x1f,0x1f,0x1f,0x1f,0x1c,0x18,0x00,
0x1c,0x18,0x10,0x00,0x00,0x00,0x00,0x00} ;/ /Heart pattern
#define CLEARSCREEN LCD_write_command(0x01)
/**************Define interface****************************/
#define LCDIO P0
sbit LCD1602_RS=P2^2;
sbit LCD1602_RW=P2^1;
sbit LCD1602_EN=P2^0;
/**************Define function****************************/
void LCD_write_command(unsigned char command);//write command function
void LCD_write_dat(unsigned char dat);//write data function
void LCD_set_xy( unsigned char x, unsigned char y );//set display position function
void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat);//display a character function
void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s);//display string function
void LCD_init(void);//initialization function
void delay_nms(unsigned int n);//delay function
/************************************************/
/************Initialization function******************/
void LCD_init(void)
{
CLEARSCREEN;//clear screen
LCD_write_command(0x38);/ /set 8 bit data transmission mode
LCD_write_command(0x0c);//open display (enable lcd display)
LCD_write_command(0x80);//set lcd first display address
CLEARSCREEN;//clear screen
}
/********* *******************************************/
/**************Write command function************************************/
void LCD_write_command(unsigned char command)
{
LCDIO=command;
LCD1602_RS=0;
LCD1602_RW=0;
LCD1602_EN=0;
LCD1602_EN=1;
delay_nms(10);
}
/***************************************************/
/****************Write data function****************************/
void LCD_write_dat(unsigned char dat)
{
LCDIO=dat;
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
delay_nms(1);
LCD1602_EN=1;
}
/********************************************************/
/******************Set display position****************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y == 1)
address = 0x80 + x;
else
address =0xc0+ x;
LCD_write_command(address);
}
/************ ***************************************/
/****************Display a character**********************/
void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat)
{
LCD_set_xy( x, y );
LCD_write_dat(dat);
}
/**************************************************/
/***************Display string function***************/
void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y );
while (*s)
{
LCD_write_dat(*s);
s ++;
}
}
/***************************************************/
/********** Delay************************/
void delay_nms(unsigned int n)
{
unsigned int i=0, j=0;
for (i=n;i>0;i--)
for (j=0;j<10;j++);
}
/************************ *********************/
/***********Main function**************/
void main(void)
{
unsigned char i,j,k,tmp;
LCD_init();
delay_nms(100);
tmp=0x40;//Set the format word of CGRAM address
k=0;
for(j=0;j<8;j++)
{
for(i=0;i<8;i++)
{
LCD_write_command(tmp+i); // Set the CGRAM address of custom character
delay_nms(2);
LCD_write_dat(table1[k]); // Write the data of custom character table to CGRAM
k++;
delay_nms(2);
}
tmp=tmp+8;
}
LCD_dsp_string(1,1,"heart: ");//Display "heart" in the first row and first column
for (i=0;i<4;i++)
{
LCD_dsp_char( 10+i,1,i);//Display the upper half of the heart pattern at the 10th column of the first row
delay_nms(1);
}
for (i=4;i<8;i++)
{
LCD_dsp_char( 10+i-4,2,i);//Display the lower half of the heart pattern at the 10th column of the second row
delay_nms(1);
}
while (1);
}
/************************ Thanks to Mr. Chen Qinghua for his help************************************************/
Previous article:51 MCU Learning 2-Flowing Light
Next article:80C51 microcontroller drives UZZ9001 read and write operations by simulating SPI port
Recommended ReadingLatest update time:2024-11-16 14:40
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Single-chip microcomputer C language programming and simulation
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
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
- 2. Main knowledge points of previous "power supply" competition questions
- PCB Design Issues
- Professor Yang's book is here, a five-volume collection of "New Concept Analog Circuits" series by Yang Jianguo of Xi'an Jiaotong University
- 2019, what is your New Year's resolution?
- How does MCU implement part of the code running in RAM?
- STM32SPI interrupt can only accept the first two bytes each time
- BlueNrg-1 and Raspberry Pi communication abnormality
- 28335 Sampling Problems
- Common problems and causes of switching power supplies
- DM6467T calls TI's C6Accel library