51 MCU_1602 LCD custom heart-shaped pattern

Publisher:WhisperingGlowLatest update time:2015-06-24 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
# include

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************************************************/

Reference address:51 MCU_1602 LCD custom heart-shaped pattern

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

Typical interface circuit of 8051 single chip microcomputer -- parallel expansion static display circuit diagram
The figure below is a parallel extended static display circuit diagram (3-digit LED static display circuit). Compile a display subroutine according to the figure below. The display number (≤255) is stored in the internal RAM 30H.       The corresponding program is:   DIR1: MOV A,30H; read the displayed number   
[Analog Electronics]
Typical interface circuit of 8051 single chip microcomputer -- parallel expansion static display circuit diagram
51 MCU User Experience
  8051 microcontroller is the most common microcontroller. I have been using 8051 for a long time and have taught microcontroller courses for a period of time. Here I would like to share my experience with you.   1. Hardware part   1. Remember to connect the crystal oscillator and reset circuit. After many students s
[Microcontroller]
C51 single chip microcomputer uses 74hc138 to expand the simulation circuit diagram + program of the water lamp
The C51 microcontroller uses 74hc138 to expand the water lamp program, which includes source code. The simulation circuit can be expanded to multiple LED circuits at will. The schematic diagram is as follows: The microcontroller source program is as follows: #define uint unsigned int #define uchar unsigned char vo
[Microcontroller]
C51 single chip microcomputer uses 74hc138 to expand the simulation circuit diagram + program of the water lamp
Simulation of Four-way Answering Machine Based on 51 Single-chip Microcomputer
When the host presses the start button, a 60-second countdown begins and the contestants begin to answer. Once a contestant answers, the answers of other contestants will be invalid. And the countdown stops after the contestant answers. Since I did not set a new round button, if you need to use a new round of answ
[Microcontroller]
Simulation of Four-way Answering Machine Based on 51 Single-chip Microcomputer
51 MCU ~ DS1302 clock, SPI bus principle
1. Description: (II) SPI bus principle: (III) Calendar clock register: Slow charging: BCD code: temp.h #ifndef __TEMP_H_ #define __TEMP_H_ #include reg52.h //---Redefine keywords---// #ifndef uchar #define uchar unsigned char #endif #ifndef uint  #define uint unsigned int #endif //--
[Microcontroller]
51 MCU ~ DS1302 clock, SPI bus principle
STC15W4K48S4's direct USB-ISP function! The most convenient download for 51 MCU
Detecting target MCU...   MCU model: STC15W4K48S4Firmware   version: 7.3.1TThe current chip hardware options are:   . After the next cold start, the system clock source is the internal IRC oscillator   . The frequency of the internal oscillator is not adjusted   . The frequency of the power-down wake-up timer: 37.133K
[Microcontroller]
STC15W4K48S4's direct USB-ISP function! The most convenient download for 51 MCU
8051 MCU Pin Function Introduction
Introduction to the pin functions of 8051 microcontroller First, let's connect the pin diagram of the microcontroller. If, the specific functions are introduced below. The 40 pins of a microcontroller can be roughly divided into four categories: power, clock, control, and I/O pins. ⒈ Power supply: ⑴ VCC - chip pow
[Microcontroller]
8051 MCU Pin Function Introduction
51 single chip microcomputer plus CPLD makes the system more efficient
I. Introduction The single-chip microcomputer market can be described as a giant, and the 51 single-chip microcomputer has more users. There is no need to introduce the 51 single-chip microcomputer more. One point must be emphasized here. As long as you are proficient in the 51 single-chip microcomputer, it will be
[Embedded]
51 single chip microcomputer plus CPLD makes the system more efficient
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号