STM8 LCD

Publisher:快乐之源Latest update time:2020-02-19 Source: eefocusKeywords:STM8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Sixiu Electronic Studio "Xiangyun Little Prince" development version


Define Pins

/**************************Port/pin definition area****************************/

#define LCDRS PF_ODR_ODR0 //LCD1602 data/command selection port

#define LCDRW PF_ODR_ODR3 //LCD1602 read and write control port

#define LCDEN PF_ODR_ODR4 //LCD1602 enable signal port

#define LCDDATA PB_ODR //LCD1602 data port D0 to D7


initialization

/****************************************************************/

//LCD1602 initialization function LCD1602_init(), no parameters or return values

/****************************************************************/

void LCD1602_init(void)

{

  LCD1602_Write(0x38,0); //Configure 16*2 display, 5*7 dot matrix, 8-bit data interface

  LCD1602_Write(0x0C,0); //Set to display, do not display cursor

  LCD1602_Write(0x06,0); //Address automatically increases by 1 after writing characters

  LCD1602_Write(0x01,0); //display cleared to 0, data pointer cleared to 0

}


Write LCD module command or data function

void LCD1602_Write(u8 cmdordata,u8 writetype)

{

  if(writetype==0)//Judge the write type

    LCDRS=0; //Write command information

  else

    LCDRS=1; //Write data information

  LCDDATA=cmdordata; //Write information to the data line port

  delay(5); //delay to wait for stabilization

  LCDEN=1; //module enable

  delay(5); //delay waiting for writing

  LCDEN=0; //Module is disabled

}


Display character function

void LCD1602_DIS(void)

{

  u8 i; //define control loop variable i

  LCD1602_Write(0x80,0); //Select the first line

  for(i=0;i<16;i++)

  {

      LCD1602_Write(table1[i],1); //Write the contents of table1[]

      delay(5);

  }

  LCD1602_Write(0xC0,0); //Select the second line

  for(i=0;i<16;i++)

  {

      LCD1602_Write(table2[i],1); //Write the contents of table2[]

      delay(5);

  }

}


Move screen

void LCD1602_MOV(void)

{

  u8 i;

  LCD1602_Write(0x01,0); //Clear screen

  LCD1602_Write(0x90,0); //Select the end of the first line (invisible)

  for(i=0;i<16;i++)

  {

      LCD1602_Write(table1[i],1); //Write the contents of table1[]

      delay(2);

  }

  LCD1602_Write(0xD0,0); //Select the end of the second line (invisible)

  for(i=0;i<16;i++)

  {

      LCD1602_Write(table2[i],1); //Write the contents of table2[]

      delay(2);

  }

  for(i=0;i<16;i++)

  {

      LCD1602_Write(0x18,0); //Loop 16 times and move the screen left one by one

      delay(100);

  }

}


Set address to write character

/****************************************************************/

//Set the address to write the character function LCD1602_DIS_CHAR(), with parameters x, y, z and no return value

//x represents the row of the 1602 LCD, y represents the column address, and z represents the character to be written

/****************************************************************/

void LCD1602_DIS_CHAR(u8 x,u8 y,u8 z)

{

  u8 address;

  if(x==1) //If you want to display it in the first line

    address=0x80+y; //The first row address + column address

  else

    address=0xC0+y; //The first address of the second row + the column address

  LCD1602_Write(address,0); //Set display address

  LCD1602_Write(z,1); //Write character data

}

/****************************************************************/

//Combined graphics display function LCD1602_DIS_FACE(), invisible parameters and return values

/****************************************************************/

void LCD1602_DIS_FACE(void)

{

  LCD1602_DIS_CHAR(1,1,'*');

  LCD1602_DIS_CHAR(2,2,'.');

  LCD1602_DIS_CHAR(1,3,'*');

  LCD1602_DIS_CHAR(1,4,'|');

  LCD1602_DIS_CHAR(2,4,'|');

  LCD1602_DIS_CHAR(1,5,'*');

  LCD1602_DIS_CHAR(2,6,'_');

  LCD1602_DIS_CHAR(1,7,'*');

  LCD1602_DIS_CHAR(1,8,'|');

  LCD1602_DIS_CHAR(2,8,'|');

  LCD1602_DIS_CHAR(1,9,'*');

  LCD1602_DIS_CHAR(2,10,'x');

  LCD1602_DIS_CHAR(1,11,'*');

  LCD1602_DIS_CHAR(1,12,'|');

  LCD1602_DIS_CHAR(2,12,'|');

  LCD1602_DIS_CHAR(1,13,'*');

  LCD1602_DIS_CHAR(2,14,'v');

  LCD1602_DIS_CHAR(1,15,'*'); 

}

Keywords:STM8 Reference address:STM8 LCD

Previous article:STM8L152 LCD module principle and driver
Next article:STM8 4-wire driver 1602 garbled code

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号