LCD12864 LCD display modular program

Publisher:心灵清澈Latest update time:2014-12-11 Source: LCD12864 液晶显示器 模块化程序Keywords:LCD12864 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/**********************
lcd12864.h header file
**********************/
#ifndef _LCD12864_H_
#define _LCD12864_H_
extern void lcd12864_busy(); //Busy flag functionextern
void led12864_clear(); //Clear screenextern
void lcd12864_init(); //Initialization functionextern
void lcd12864_pxy(unsigned char p,unsigned char x,unsigned char y); //Data display position, p=0 left half screen, p=1 right half screen, p=2 both half screens selected, xy are the displayed coordinates, the fourth quadrant, represented by positive values.
extern void lcd12864_zifu(unsigned char p,unsigned char x,unsigned char,unsigned char m); //The display position of the mth character, the same as the definition of Chinese characters, except that the value of the xy coordinates should be less than or equal to 7.
extern void lcd12864_hanzi(unsigned char p,unsigned char x,unsigned char y,unsigned char m); //The display position of the mth Chinese character, p=0 left half screen, p=1 right half screen, p=2 both half screens are selected, xy is the display coordinates, the fourth quadrant, expressed as positive values, the value of x or y should be less than or equal to 3. m is the mth Chinese character displayed.
#endif

 

 

/**********************
 lcd12864.c file
**********************/

#include
#define uint unsigned int
#define uchar unsigned char
sbit cs2=P2^0;
sbit cs1=P2^1;
sbit e=P2^2;
sbit rw=P2^3;
sbit rs=P2^4;
uchar code zifu[]=
{
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//,0
 0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  

 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//。1
 0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!2
 0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
};
uchar code ziku[]=
{
  //0x80,0x40,0xF0,0x2C,0x43,0x20,0x98,0x0F,0x0A,0xE8,0x08,0x88,0x28,0x1C,0x08,0x00,//"你",
 //0x00,0x00,0x7F,0x00,0x10,0x0C,0x03,0x21,0x40,0x3F,0x00,0x00,0x03,0x1C,0x08,0x00,

 0x80,0x84,0x44,0x44,0x24,0x14,0x04,0xFF,0x04,0x14,0x24,0x24,0x46,0xC4,0x40,0x00,//"李",0 The numbers after the Chinese characters represent the codes of the Chinese characters for easy use
    0x00,0x08,0x08,0x08,0x09,0x49,0x89,0x7D,0x0D,0x0B,0x09,0x08,0x0C,0x08,0x00,0x00,

 0x10,0x10,0x10,0xFF,0x90,0x50,0xFE,0x92,0x92,0x92,0x92,0x92,0x9A,0xD3,0x82,0x00,//"振",1 
    0x02,0x42,0x81,0x7F,0x40,0x30,0x0F,0x00,0xFF,0x40,0x07,0x18,0x28,0x64,0x22,0x00,

  0x80,0x40,0x20,0xF8,0x07,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x68,0x4C,0x08,0x00,//"伟",2
    0x00,0x00,0x00,0xFF,0x02,0x02,0x02,0x02,0x02,0xFF,0x02,0x12,0x22,0x1F,0x02,0x00,

 0x00,0x00,0x00,0xC0,0x70,0x20,0x00,0xFF,0x00,0x10,0x20,0xC0,0x80,0x00,0x00,0x00,//小3
 0x04,0x02,0x01,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x07,0x02,0x00,

 0x00,0x04,0x84,0x44,0x3C,0x44,0x85,0x06,0x04,0xC4,0x3C,0x44,0x84,0x04,0x00,0x00,//卒4
 0x04,0x05,0x04,0x04,0x04,0x04,0x05,0xFE,0x05,0x04,0x04,0x04,0x05,0x04,0x04,0x00,

 0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00,//Set 5
 0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00,

 0x20,0x21,0x2E,0xE4,0x00,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x00,//Count 6
 0x00,0x00,0x00,0x7F,0x20,0x10,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,

 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//,7
 0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  

 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//。8
 0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!9
 0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
 
};

/*void delay(uchar i) //1ms delay function 
{
    uchar a,b;
    for(b=i;b>0;b--)
        for(a=110;a>0;a--);
}*/
void lcd12864_busy() //Busy flag function
{
 uchar i;
 rw=1;
 rs=0;
 while(1)
 {
  P0=0xff;
  e=1;
  //i=P0;
  e=0;
  i=P0;
  i=i&0x80;
  if(i!=0x80)
  break;
 }
}
lcd12864_writedat(uchar dat) //Write data function
{
 //lcd12864_busy();
 rw=0;
 rs=1;
 e=1;
 P0=dat;
 e=0;
}
lcd12864_writecom(uchar com) //Write command function
{
 //lcd12864_busy();
 rw=0;
 rs=0;
 e=1;
 P0=com;
 e=0;
}
void lcd12864_init() //initialization function
{
  lcd12864_writecom(0x3f); //turn on display, turn off display to 0x3e
  lcd12864_writecom(0xb8); //set page address to 0. The first page.
  lcd12864_writecom(0xc0); //set the display start row address, the first row is displayed on the LCD screen
  lcd12864_writecom(0x40); //set the column address
}
lcd12864_pxy(uchar p,uchar x,uchar y) //data position, p=0 left half screen, p=1 right half screen, p=2 both half screens are selected, xy is the display coordinates, the fourth quadrant, represented by positive values.
{
  switch(p)
 {
  case 0:cs1=0;cs2=1;break;
  case 1:cs1=1;cs2=0;break;
  case 2:cs1=0;cs2=0;break;
 }
  lcd12864_writecom(0xb8+y);
  lcd12864_writecom(0x40+x);
}
lcd12864_zifu(uchar p,uchar x,uchar y,uchar m) //The display position of the mth character is the same as the definition of the test character, except that the value of the xy coordinate should be less than or equal to 7.
{
 uchar i;
 lcd12864_pxy(p,x*8,y);
 for(i=0;i<8;i++)
 {
  lcd12864_writedat(zifu[i+m*8]);
 }
}
lcd12864_hanzi(uchar p,uchar x,uchar y,uchar m) //The display position of the mth Chinese character, p=0 left half screen, p=1 right half screen, p=2 both half screens are selected, xy is the display coordinates, the fourth quadrant, expressed as positive values, the value of x or y should be less than or equal to 3. m is the mth Chinese character displayed.
{
 uchar i;
 lcd12864_pxy(p,x*16,2*y);
 for(i=0;i<16;i++)
 lcd12864_writedat(ziku[i+m*32]);
 lcd12864_pxy(p,x*16,2*y+1);
 for(i=0;i<16;i++)
 lcd12864_writedat(ziku[i+m*32+16]);
}
void lcd12864_clear() //screen clearing function
{            
 uint i;
 lcd12864_pxy(2,0,0); //clear the first, second, third and fourth pages of the left and right screens
 for(i=0;i<256;i++)
 {
  lcd12864_writedat(0x00);
 }          
 lcd12864_pxy(2,0,4); // Clear the fifth, sixth, seventh and eighth pages of the left and right screens
 for(i=0;i<256;i++)
 {
  lcd12864_writedat(0x00);
 }
}

 

 

/******************************************
 main.c main file
******************************************/

#include
#include"lcd12864.h"
void main()
{
 lcd12864_init();
 lcd12864_clear();
 lcd12864_hanzi(0,0,0,0);//Li
 lcd12864_hanzi(0,1,0,1 );//Zhen
 lcd12864_hanzi(0,2,0,2);//Wei
 lcd12864_hanzi(0,3,0,8);// .
 lcd12864_hanzi(0,0,2,3);//small
 lcd12864_hanzi(0,1,2,4);//pawn
 lcd12864_hanzi(0,2,2,5);//set
 lcd12864_hanzi(0,3,2, 6);// count
 lcd12864_hanzi(1,0,2,9);//!
 lcd12864_zifu(1,6,6,8); //! The upper left part is separated and displayed in the form of characters
 lcd12864_zifu(1,7,6 ,9); //! The upper right part
 lcd12864_zifu(1,6,7,10); //! The lower left part
 lcd12864_zifu(1,7,7,11); //! The lower right part
 while(1);
}

Keywords:LCD12864 Reference address:LCD12864 LCD display modular program

Previous article:DS18B20 temperature test program (51 single chip digital tube display) + circuit diagram
Next article:STC12C5A60S2 (ADC query method 10-bit mode) + 1602 display

Recommended ReadingLatest update time:2024-11-16 14:30

[C51 code] LCD12864 header file [upper and lower screen]
Model: LCD12864a3 Driver: ST7920A Chinese character display coordinate diagram: Graphical display coordinate graph: /*==================== lcd12864.h =====================*/ #ifndef _LCD12864_h_ #define _LCD12864_h_ #include Atmel/AT89X51.h #include "delay.h" #include "link.h" /*==================
[Microcontroller]
[C51 code] LCD12864 header file [upper and lower screen]
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号