128*64 LCD screen (ST7920) C51 driver

Publisher:RainbowPromiseLatest update time:2016-11-18 Source: eefocusKeywords:128*64 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/**************************
 Resources used by the file
1. Port: P0.0, P0.1
2. Call delay_ms function
******************************/
#define TIME 1
#define display_TIME 1000

sbit CS=P1^0; //Chip select
sbit SCLK=P0^0; //Clock
sbit STD=P0^1; //Data
//sbit LCD_ON=P0^2; //Backlight switch

uchar code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //The first line of Chinese characters
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //The second line of Chinese characters
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //The third line of Chinese characters
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //The fourth line of Chinese characters
};
/******************************
 Serial transmission of one byte of data
******************************/
void SendByte(uchar dat)
{
 uchar i;
   for(i=0;i<8;i++)
   {
     SCLK=0; //SCLK=0;
     if(dat&0x80)
  STD=1; //STD=1;
     else STD=0; //STD=0;   
     SCLK=1; //SCLK=1;
     dat=dat<<1;     
   }
}
/***************************
  Write control command
***************************/
void SendCMD(uchar dat)

   CS=1; //CS=1;
   SendByte(0xF8); //11111,00,0 RW=0,RS=0 synchronization flag, send instruction from CPU to LCD 
   SendByte(dat&0xF0); //high four bits
   SendByte((dat&0x0F)<<4);//low four bits
   CS=0; //CS=0;
}
/***************************
 Write display data or single-byte character
***************************/
void SendDat(uchar dat)
{
   CS=1; //CS=1; 
   SendByte(0xFA); //11111,01,0 RW=0,RS=1
   SendByte(dat&0xF0); //High four bits
   SendByte((dat&0x0F)<<4);//Low four bits     
   CS=0; //CS=0;
}
/***************************
 Clear the Chinese characters displayed on the screen
***************************/
void clear_LCD(void)
{
   SendCMD(0x01); //0000,0001 Clear DDRAM
   delay_ms(TIME); 

   SendCMD(0x34); //Extended instruction, allow graphic displaySendCMD
   (0x30); //Basic instruction set bit2, bit1, bit0 in bit2 control
}
/***************************
 Initialize LCM
*******************************/
void init_lcm(void)
{
   CS=0; //CS=0;
   delay_ms(TIME); 
   SendCMD(0x30); //Basic instruction set//bit2, bit1, bit0 in bit2 controlSendCMD
   (0x0C); //0000,1100 Overall display, cursor off, cursor position off
   SendCMD(0x01); //0000,0001 Clear DDRAM
   delay_ms(TIME); 
}
/****************************
   Display picture 128*64
****************************/
void display_picture(uchar *biao)
{
 uchar x,y,i,j,k;
 x=0x80;
 SendCMD(0x34); //Turn off the image display
  for(k=0;k<2;k++)
 { 
  y=0x80;
     for(j=0;j<32;j++)
  {
   SendCMD(y);
           SendCMD(x);
           for(i=0;i<16;i++)
   {
     SendDat(*biao++);   
   }
   y++;
  }
  x=0x88;
 }
  SendCMD(0x36); //Turn on the image display
}
/****************************
   Display the string on the entire screen
****************************/
void display(uchar *str)
{  
 uchar i,k=0;
    while(*str!='\0')
    { 
    if(k==0)SendCMD(0x80);
    else if(k==16)SendCMD(0x90);
    else if(k==32)SendCMD(0x88); 
    else if(k==48)SendCMD(0x98);
    k++;
  if(k==65)
  { 
   k=0;
   for (i=0;i<49;i++)
     {
      str--;
     }
   delay_ms(display_TIME); 
   clear_LCD();
    }
      SendDat(*str++); 
    }

/****************************
   Display the string at the specified position
****************************/
void display_char(uchar row,uchar col,uchar *puts)
{
 bit flag=0;
 SendCMD(0x30); //8BitMCU, basic instruction setwhile
    (*puts != '\0') //Judge whether the string is displayed
    {
     if(col==8) //Judge line break
        { //If not judged, automatically from the first row to the third rowcol
         =0;
            row++;
        }
        if(row==4)
        { 
         row=0; //One screen is displayed and returns to the upper left corner of the screen
        }             
        if(!flag)SendCMD(AC_TABLE[8*row+col]); //Send position commandSendDat
        (*puts++); //A Chinese character needs to be written twiceif
        (flag)col++;
  flag=~flag;
  }
}


Keywords:128*64 Reference address:128*64 LCD screen (ST7920) C51 driver

Previous article:DS18B20 multi-point temperature detection C51 program
Next article:PS/2 Keyboard Interface C51 Driver

Recommended ReadingLatest update time:2024-11-16 13:03

Based on 51 single chip microcomputer + DS1302 clock module + LCD1602 display
DS1302 clock module introduction basic introduction Overview The DS1302 slow-chargeable real-time clock chip contains a real-time clock/calendar and 31 bytes of nonvolatile static RAM. The real-time clock/calendar can count seconds, minutes, hours, days, weeks, months, and years. 31-day month, the date at the end of t
[Microcontroller]
Based on 51 single chip microcomputer + DS1302 clock module + LCD1602 display
MCU + LCD12864 digital oscilloscope program + Proteus simulation
Digital oscilloscope based on 51 single-chip microcomputer and Proteus simulation   #include AT89X52.h #include intrins.h //12864 control pin definition sbit DI = P2 ^ 2; //Data instruction selection pin sbit RW = P2 ^ 1; //Read and write selection pin sbit E= P2 ^ 0; //Read and write enable pin sbit CS1 = P2 ^ 4;
[Microcontroller]
MCU + LCD12864 digital oscilloscope program + Proteus simulation
How to Update LCD Data Using PIC Microcontroller
To update the LCD, the contents of the LCDDATA register can be modified to light or unlight each pixel on the LCD display. The application firmware typically creates modifications to buffer variables that correspond to elements on the display (e.g., character positions, bar graphs, battery displays, etc.).   When th
[Microcontroller]
How to Update LCD Data Using PIC Microcontroller
MSP430 MCU drives LCD1602 C language program
/*******************************************************************************/                         1.msp430 single chip C language /************************************************************************/ #include"msp430f6638.h" /*********************************************** P5.3----E P57 P56 P55 P54 P
[Microcontroller]
128*64 LCD simple microcontroller code
The control chip is the commonly used HD61202 column driver and HD61203 row driver.      A Chinese character is composed of 16*16 pixels.   The scanning order is up and down, then to the second column and up and down again, and so on. Show results:  References: Teach you how to learn single-chip C pr
[Microcontroller]
128*64 LCD simple microcontroller code
Design of ultra-low power LCD display circuit module
   LCD display module: LCD liquid crystal display is an extremely low power display device with small operating current, light weight, low power consumption, long life, clear and beautiful writing. It is widely used in portable instruments and higher-end instruments for low-power applications. Pin 1: VSS is the ground
[Power Management]
Design of ultra-low power LCD display circuit module
LCD1602, LCD1640 LCD 4-bit bus mode programming successful
//Since the IO of 2051 is not enough, we must save the IO port. As a last resort, we modified the program based on a lot of information // and got the following program that can run successfully. This program can be written normally through the test of data image CM1640 LCD module //yusung W-1602A LCD module and Guan
[Microcontroller]
Design and implementation of LCD driver program under embedded Linux
With the rapid development of embedded Linux, it is an excellent operating system platform for developing embedded products because it has no expensive copyright fees, is completely open source, and is customizable and portable. Device drivers are an important part of the Linux kernel, running at the bottom of the Linu
[Microcontroller]
Design and implementation of LCD driver program under embedded Linux
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号