RT12864M液晶模塊單片機(jī)驅(qū)動(dòng)程序
/*------外部晶振為 12MHz-------*/
/*--------最后修改2011.02.26-------*/
#include "STC12C5620AD.h"
#include "RT12864M.h"
#include "delay.h"
/**********************自定義字符編碼*************************/
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, //天線圖形
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}; //攝氏圖形
/**********************LCD檢測(cè)是否忙*************************/
bit LCD_Test_Busy(void)
{
bit Temp;
LCD_DATAPORT=0xff; //數(shù)據(jù)口先全部置位
LCD_RS=0;
LCD_RW=1;
LCD_E=1;
Temp=(bit)(LCD_DATAPORT & 0x80); //取最高位,1為忙
LCD_E=0;
return Temp;
}
/*************************LCD寫命令**************************/
void LCD_Write_CMD(uchar cmd)
{
while(LCD_Test_Busy()); //先檢測(cè)LCD是否忙
LCD_RS=0;
LCD_RW=0;
LCD_E=1;
LCD_DATAPORT=cmd; //寫入命令
LCD_E=0;
}
/*************************LCD寫數(shù)據(jù)**************************/
void LCD_Write_DATA(uchar Inputdata)
{
while(LCD_Test_Busy()); //先檢測(cè)LCD是否忙
LCD_RS=1;
LCD_RW=0;
LCD_E=1;
LCD_DATAPORT=Inputdata; //寫入數(shù)據(jù)
LCD_E=0;
}
/************ 寫入自定義字符或圖形到 CGRAM *****************/
void LCD_Write_CGRAM(uchar *Char_Code)
{
uchar i;
LCD_Write_CMD(0x34); //打開擴(kuò)充指令
LCD_Write_CMD(0x02); //SR=0,允許輸入CGRAM地址
LCD_Write_CMD(0x30); //恢復(fù)基本指令
LCD_Write_CMD(0x40); //CGRAM地址
for(i=0;i<32;i++)
{
LCD_Write_DATA(Char_Code[i*2]);
LCD_Write_DATA(Char_Code[i*2+1]);
}
}
/**********************設(shè)置操作地址**************************/
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);
}
/*************************顯示一個(gè)CGRAM**************************/
/**************參數(shù):行號(hào),列號(hào),要顯示的CGRAM*****************/
void LCD_Display_CGRAM(uchar x,uchar y,uchar add1,uchar add2)
{
LCD_Set_XY(x,y); //先確定顯示行和列
LCD_Write_DATA(add1);
LCD_Write_DATA(add2);
}
/**************在X(行)Y(列)顯示字符串********************/
void LCD_Display_String( uchar x,uchar y,uchar *str )
{
LCD_Set_XY(x,y); //先確定起始行和列
while (*str!=