18: LCD12864 display

Publisher:心有所属Latest update time:2019-08-13 Source: eefocusKeywords:LCD12864 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Write the picture description here

#Instruction System



Write the picture description here

#Code


* 【Course 19】 ****LCD12864 Experiment***********

*

* 【Explanation】 ****There is no ready-made font library in the simulation environment, so you need to make your own Chinese character font library

*

* 【Description】 ****Show "Sourceshare Technology"

*

******************************************************************     


Basic operations:

Read status: RS=0,RW=1,EN=1

Output: D0~D7=status word;

Write instruction: RS=0, RW=0, EN=falling edge pulse

D0~D7=instruction code;

Read data: RS=1, RW=1, EN=1

Output: D0~D7=data;

Write data: RS=1, RW=1, EN=falling edge pulse

D0~D7=data;

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

#include //51 header file,


//---------Two commonly used macro definitions-------------- 

#define uint8 unsigned char

#define uint16  unsigned int

//--------12864 control pin definition-------------

sbit RS = P3^5;

sbit RW = P3^6;

sbit EN = P3^4;


sbit CS2 = P3^0;

sbit CS1 = P3^1;


uint8 code yuan[]=

{

/*------------------------------------------------------------------------------

; Source file/text: source


; Width × height (pixels): 16×16

------------------------------------------------------------------------------*/

 0x10,0x21,0x06,0xE0,0x00,0xFE,0x02,0xF2,

 0x5A,0x56,0x52,0x52,0x52,0xF2,0x02,0x00,

 0x04,0xFC,0x03,0x40,0x30,0x0F,0x20,0x11,

 0x4D,0x81,0x7F,0x01,0x05,0x09,0x30,0x00

};


uint8 code xiang[]=

{


 0x00,0x04,0x04,0x74,0x54,0x54,0x55,0x56,

 0x54,0x54,0x54,0x74,0x04,0x04,0x00,0x00,

 0x08,0x08,0x09,0x09,0x09,0x29,0x49,0x89,

 0x7D,0x0B,0x0B,0x09,0x08,0x08,0x08,0x00

};

uint8 code k[]=

{

/*-- Character: Family --*/

/*-- Songti 12; The corresponding dot matrix under this font is: width x height = 16x16 --*/

 0x10,0x12,0x92,0x72,0xFE,0x51,0x91,0x00,

 0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00,

 0x04,0x02,0x01,0x00,0xFF,0x00,0x04,0x04,

 0x04,0x02,0x02,0x02,0xFF,0x01,0x01,0x00

};

uint8 code ji[]=

{

/*-- Character: Technique --*/

/*-- Songti 12; The corresponding dot matrix under this font is: width x height = 16x16 --*/

 0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xC8,

 0x48,0x48,0x7F,0x48,0xC8,0x48,0x08,0x00,

 0x01,0x41,0x80,0x7F,0x00,0x40,0x40,0x20,

 0x13,0x0C,0x0C,0x12,0x21,0x60,0x20,0x00

};

//-----------Function declaration------------------

void DelayMS(uint16 dly);



//----------Declaration of LCD module---------------

bit BUSY(void); //测忙

void Write_cmd(uint8 cmd); //write command

void Write_dat(uint8 dat); //write data

//void LCD_Init(void);


void Set_page(uint8 page); //Set page

void Set_Line(uint8 line); //Set the starting line

void Set_Col(uint8 col); //Set column

void Set_ONOFF(uint8 switch); //1 on, 0 off

void Clear(void); //清屏

void LCD_Init(void); //LCD screen initialization

void Display(uint8 screen,uint8 page,uint8 col,uint8 *p); //Display Chinese characters

void Select_Screen(uint8 swich); //Select LCD screen (left or right)


//---------Main Task---------------------

void main(void)

{

LCD_Init();

Display(1,0,0,yuan); //source

Display(1,2,0,xiang); //enjoy

Display(1,4,0,ke); //科

Display(1,6,0,ji); //技


Display(2,0,0,yuan);

Display(2,2,0,xiang);

Display(2,4,0,ke);

Display(2,6,0,ji);

while(1)

{

}

}


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

** Name: void DelayMS(uint16 dly)

** Function: millisecond delay (12M crystal oscillator)

** Input parameter: dly

User delay parameters   

** Export parameters: None   

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

void DelayMS(uint16 dly)

{

uint16 x,y;

for(x=dly;x>0;x--)

for(y=124;y>0;y--);

}


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

** Name: bit BUSY(void)

** Function: Check whether LCD1602 is in busy state;

** Input parameters: None   

** Export parameter: bit Bit

Returns 1, then BUSY

Return 0, then OK   

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

bit BUSY(void)

{

bit Bit;

P0 = 0x00;

RS = 0;

RW = 1;

EN = 1;

DelayMS(1);

Bit = (bit)(P0 & 0x80); //The highest bit is the busy signal bit

EN = 0;

return Bit;

}


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

** Name: void Write_cmd(uint8 cmd)

** Function: Write command

** Entry parameter: cmd

control commands   

** Export parameters: None   

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

void Write_cmd(uint8 cmd)

{

while(BUSY()); //测忙

RS = 0;

RW = 0;

EN = 0;

P0 = cmd;

EN = 1;

DelayMS(1);

EN = 0;

}


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

** Required: void Write_dat(uint8 dat)

** Function: write data

** Input parameter: dat

Data to display  

** Export parameters: None   

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

void Write_dat(uint8 dat)

{

while(BUSY()); //测忙

RS = 1;

RW = 0;

EN = 0;

P0 = that;

EN = 1;

DelayMS(1);

EN = 0;

}


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

** Name: void LCD_Init(void)

** Function: LCD initialization

** Input parameters: None 

** Export parameters: None   

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

/*void LCD_Init(void)

{


Write_cmd(0x34); //Extended instruction operation

    DelayMS(5);

    Write_cmd(0x30); //Basic instruction operation

    DelayMS(5);

    Write_cmd(0x0C); //Display on and off cursor

    DelayMS(5);

    Write_cmd(0x01); //Clear the LCD display content

    DelayMS(5);

}*/


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

** Name: void Set_page(uint8 page)

** Function: Settings page

** Input parameter: uint8 

Page 0~7 Total 8 pages 

** Export parameters: None   

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

void Set_page(uint8 page)

{

page = 0xb8|page; //The first address of the page is 0XB8

Write_cmd(page);

}


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

** Name: void Set_Line(uint8 line)

** Function: Set the starting line

** Input parameter: uint8 

line

** Export parameters: None   

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

void Set_Line(uint8 line)

{

line = 0xc0|line;

Write_cmd(line);

}


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

** Name: void Set_Col(uint8 col)

** Function: Set the starting position of the column

** Input parameter: uint8 

col

** Export parameters: None   

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

void Set_Col(uint8 col)

{

col = col&0x3f;

col = 0x40|col;

Write_cmd(col);

}


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

** Name: void Select_Screen(uint8 switch)

** Function: Select screen --- left and right screen

** Input parameter: uint8 

switch

** Export parameters: None   

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

void Select_Screen(uint8 swich)

{

switch(swich)

{

case 0: CS1 = CS2 =0; //full screen

break;

case 1: CS1 = 0; CS2 = 1; //left screen

break;

case 2: CS1 =1; CS2 = 0; //右屏

break;

default:

break;

}

}


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

** Name: void Set_ONOFF(uint8 switch) //0 or 1

** Function: Set the display switch

** Input parameter: uint8 

swich 0---off

1---Open

** Export parameters: None   

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

void Set_ONOFF(uint8 switch) //0 or 1

{

swich = 0x3e|swich;

Write_cmd(swich);

}


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

** 名称 :void Clear(void)

** Function: Clear screen

** Input parameters: None

** Export parameters: None   

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

void Clear(void)

{

uint8 i,j;


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

{

Set_page(i);

Set_Col(0);

for(j=0;j<64;j++)

{

Write_dat(0x00);

}

}

}


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

** Name: void LCD_Init(void)

** Function: Initialization

** Input parameters: None

** Export parameters: None   

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

void LCD_Init(void)

{

while(BUSY()); //测忙

Set_ONOFF(1);

Clear();

Set_Line(0);

}


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

** 名称 :void Display(uint8 screen,uint8 page,uint8 col,uint8 *p)

** Function: Display of Chinese characters

** Input parameter: uint8 

screen

page

col column

*p Displayed Chinese character pointer

** Export parameters: None   

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

void Display(uint8 screen,uint8 page,uint8 col,uint8 *p)

{

uint8 i;

Select_Screen(screen);

Set_page(page);

Set_Col(col);

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

{

Write_dat(p[i]);

}

Set_page(page+1);

Set_Col(col);

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

{

Write_dat(p[i+16]);

}

}


Keywords:LCD12864 Reference address:18: LCD12864 display

Previous article:107: Operation of DS1302
Next article:199: Temperature reading of DS18B20

Recommended ReadingLatest update time:2024-11-16 12:55

51 MCU serial communication Bad Apple video playback source program (LCD12864 display)
The program originated from a competition project of my team. The project file is a large project with a lot of content written by other team members. It is not easy for me to post it directly, so I had to capture a small module I wrote and put it up for everyone to share. This program can mainly realize the two func
[Microcontroller]
51 MCU serial communication Bad Apple video playback source program (LCD12864 display)
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号