RT12864M LCD module MCU driver

Publisher:beta13Latest update time:2015-07-01 Source: 51heiKeywords:RT12864M Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
 /*-----------RT12864M module-----------*/

/*------External crystal oscillator is 12MHz-------*/           
 /*--------Last modified 2011.02.26-------*/

#include "STC12C5620AD.h"
#include "RT12864M.h"
#include "delay.h"
/**************************Custom character encoding****************************/
unsigned char code CGROM_Code[]={0x00,0x00,0x00,0x00,0x7F,0xFE,0x60,0x06,0x33,0xCC,0x19,0x98,0x0C,0x30,0x06,0x60, 0x03,0xC0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80
           , //Antenna graphics
          0x00,0x00,0xE0,0x00,0xA0,0x00,0xEE,0x00,0x1B,0x00,0x31,0x00,0x30,0x00,0x30,0x00,
         0x30,0x00,0x30,0x00,0x31,0x00,0x1B,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //Celsius graphics 
/**********************LCD test is busy****************************/
bit LCD_Test_Busy(void)        
  {
   bit Temp;
   LCD_DATAPORT=0xff; //Data port all set first
   LCD_RS=0;
   LCD_RW=1;
   LCD_E=1;
   Temp=(bit)(LCD_DATAPORT & 0x80); //Take the highest bit, 1 is busy
   LCD_E=0;
   return Temp;
  }
/*************************LCD write command******************************/
void LCD_Write_CMD(uchar cmd)
  {
 while(LCD_Test_Busy()); //First check if LCD is busy
 LCD_RS=0;
 LCD_RW=0;
 LCD_E=1;
    LCD_DATAPORT=cmd; //Write command
 LCD_E=0;
  }
/*************************LCD write data**************************/
void LCD_Write_DATA(uchar Inputdata)
  {
 while(LCD_Test_Busy()); //First check if LCD is busy
 LCD_RS=1;
 LCD_RW=0;
 LCD_E=1;
    LCD_DATAPORT=Inputdata; //Write data
 LCD_E=0;
  }
/************ Write custom characters or graphics to CGRAM *****************/
void LCD_Write_CGRAM(uchar *Char_Code)
{
 uchar i;
 LCD_Write_CMD(0x34); //Open extended instructions                  
 LCD_Write_CMD(0x02); //SR=0, allow input of CGRAM address
 LCD_Write_CMD(0x30); //Restore basic instructions
 LCD_Write_CMD(0x40); //CGRAM address
 for(i=0;i<32;i++)
  {
   LCD_Write_DATA(Char_Code[i*2]);
   LCD_Write_DATA(Char_Code[i*2+1]);
  }
}
/**********************Set operation address**************************/
void LCD_Set_XY(uchar x,uchar y)
{
 uchar Address;
 switch(x)
 {
 case 0: 
     Address = 0x80 + y;
     break; 
    case 1: 
     Address = 0x90 + y;
  break;         
 case 2: 
  Address = 0x88 + y;
  break; 
    case 3: 
  Address = 0x98 + y;
  break; 
 default:
  Address = 0x80 + y;
  }
    LCD_Write_CMD(Address); 
}
/*************************Display a CGRAM******************************/
/**************Parameters: row number, column number, CGRAM to be displayed********************/
void LCD_Display_CGRAM(uchar x,uchar y,uchar add1,uchar add2)

    LCD_Set_XY(x,y); //First determine the display row and column       
 LCD_Write_DATA(add1);
 LCD_Write_DATA(add2);
}
/**************Display a string at X (row) Y (column)********************/
void LCD_Display_String( uchar x,uchar y,uchar *str )
  {
    LCD_Set_XY(x,y); //First determine the starting row and columnwhile
 (*str!='') 
      {
        LCD_Write_DATA(*str);
     str++;
   }
  }

/**************Display value at X (row) Y (column)************************/
void LCD_Display_Value( uchar x,uchar y,uchar val )
{
 LCD_Set_XY(x,y); //Determine the starting row and column first
 LCD_Write_DATA(val);
}
/**************Display array at X (row) Y (column)************************/
void LCD_Display_Array( uchar x,uchar y,uchar *Array,uchar Lenth )
{
 LCD_Set_XY(x,y); //Determine the starting row and column firstwhile
 (Lenth--)
  {
   LCD_Write_DATA(*Array);
   Array++;
  }
}
/*****************************LCD initialization**************************/
void LCD_Init(void)
{
 LCD_RST=0;
 Delay_us(10);
 LCD_RST=1; //LCD reset
    LCD_Write_CMD(0x30); //Function setting (parallel, basic instructions)   
    LCD_Write_CMD(0x0c); //Overall display, cursor
    LCD_Write_CMD(0x01); //Clear screen
 LCD_Write_CMD(0x06); //Move cursor right, not overall
 LCD_Write_CGRAM(CGROM_Code); //Write custom characters
}

This is a subroutine header file and schematic diagram extracted from a complete project. Please go to http://www.51hei.com/bbs/dpj-19294-1.html  to download it.

Keywords:RT12864M Reference address:RT12864M LCD module MCU driver

Previous article:Electronic tag identification system using ZigBee and RFID technology
Next article:State machine mode key scanning microcontroller program

Latest Microcontroller Articles
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号