RT12864M液晶模块单片机驱动程序
/*------外部晶振为 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检测是否忙*************************/
bit LCD_Test_Busy(void)
{
bit Temp;
LCD_DATAPORT=0xff; //数据口先全部置位
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()); //先检测LCD是否忙
LCD_RS=0;
LCD_RW=0;
LCD_E=1;
LCD_DATAPORT=cmd; //写入命令
LCD_E=0;
}
/*************************LCD写数据**************************/
void LCD_Write_DATA(uchar Inputdata)
{
while(LCD_Test_Busy()); //先检测LCD是否忙
LCD_RS=1;
LCD_RW=0;
LCD_E=1;
LCD_DATAPORT=Inputdata; //写入数据
LCD_E=0;
}
/************ 写入自定义字符或图形到 CGRAM *****************/
void LCD_Write_CGRAM(uchar *Char_Code)
{
uchar i;
LCD_Write_CMD(0x34); //打开扩充指令
LCD_Write_CMD(0x02); //SR=0,允许输入CGRAM地址
LCD_Write_CMD(0x30); //恢复基本指令
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]);
}
}
/**********************设置操作地址**************************/
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);
}
/*************************显示一个CGRAM**************************/
/**************参数:行号,列号,要显示的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!=)
{
LCD_Write_DATA(*str);
str++;
}
}
/**************在X(行)Y(列)显示数值********************/
void LCD_Display_Value( uchar x,uchar y,uchar val )
{
LCD_Set_XY(x,y); //先确定起始行和列
LCD_Write_DATA(val);
}
/**************在X(行)Y(列)显示数组********************/
void LCD_Display_Array( uchar x,uchar y,uchar *Array,uchar Lenth )
{
LCD_Set_XY(x,y); //先确定起始行和列
while(Lenth--)
{
LCD_Write_DATA(*Array);
Array++;
}
}
/*************************LCD初始化**************************/
void LCD_Init(void)
{
LCD_RST=0;
Delay_us(10);
LCD_RST=1; //LCD复位
LCD_Write_CMD(0x30); //功能设定(并行、基本指令)
LCD_Write_CMD(0x0c); //整体显示,光标
LCD_Write_CMD(0x01); //清屏
LCD_Write_CMD(0x06); //光标右移,整体不右移
LCD_Write_CGRAM(CGROM_Code); //写入自定义字符
}
这是一个完整项目里面截取出来的子程序 头文件和原理图请到http://www.51hei.com/bbs/dpj-19294-1.html去下载.
RT12864M液晶模块单片机驱 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)