/*------外部晶振为 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!='