#include "reg51.h"
#include "intrins.h"
#include "absacc.h"
#include ".\inc\ASCII816.h"//标准ASCII码库
#include ".\inc\HZTable.h"//自制的汉字库
#include ".\inc\menu.h"
//自制的菜单库
sbit LCD12232_A0=P3^3;
sbit LCD12232_RW=P3^1; //读写
sbit LCD12232_E1=P3^5; //片选1(Master)
sbit LCD12232_E2=P3^4; //片选2(slave)
#define LCD12232_DATA P1 //数据口
void ClearScreen(void);
/*----------------------------------------------------------------------------
调用方式:void OutMI(unsigned char i)
函数说明:发指令i到主窗口。(内函数,私有,用户不直接调用)
------------------------------------------------------------------------------*/
void OutMI(unsigned char i)
{
LCD12232_E2=0; //确认
LCD12232_A0=0;
LCD12232_RW=1;
LCD12232_E1=1; _nop_();
LCD12232_DATA = i;
while( LCD12232_DATA & 0x80 ); //busy?
LCD12232_E1=0; _nop_();
LCD12232_RW=0;
LCD12232_E1=1; _nop_();
LCD12232_DATA=i;_nop_();
LCD12232_E1=0; _nop_();
}
/*------------------------------------------------------------------------------
调用方式:void OutMD(unsigned char i)
函数说明:发数据i到主窗口。(内函数,私有,用户不直接调用)
-------------------------------------------------------------------------------*/
void OutMD(unsigned char i)
{
LCD12232_E2=0; //确
LCD12232_A0=0;
LCD12232_RW=1;
LCD12232_E1=1; _nop_();
LCD12232_DATA = i;
while( LCD12232_DATA & 0x80 );
LCD12232_E1=0; _nop_();LCD12232_A0=1;
LCD12232_RW=0;
LCD12232_E1=1; _nop_();
LCD12232_DATA=i; _nop_();
LCD12232_E1=0; _nop_();
}
*------------------------------------------------------------------------------
调用方式:void OutSI(unsigned char i)
函数说明:发指令i到从窗口。(内函数,私有,用户不直接调用)
-------------------------------------------------------------------------------*/
void OutSI(unsigned char i)
{
LCD12232_E1=0; //确认
LCD12232_A0=0;
LCD12232_RW=1;
LCD12232_E2=1; _nop_();
LCD12232_DATA = i;
while( LCD12232_DATA & 0x80 );
LCD12232_E2=0; _nop_();
LCD12232_RW=0;
LCD12232_E2=1; _nop_();
LCD12232_DATA=i; _nop_();
LCD12232_E2=0; _nop_();
}
/*------------------------------------------------------------------------------
调用方式:void OutSD(unsigned char i)
函数说明:发数据i到从窗口。(内函数,私有,用户不直接调用)
-------------------------------------------------------------------------------*/
void OutSD(unsigned char i)
{
LCD12232_E1=0; //确认
LCD12232_A0=0;
LCD12232_RW=1;
LCD12232_E2=1; _nop_();
LCD12232_DATA =i;
while( LCD12232_DATA & 0x80 );
LCD12232_E2=0; _nop_();
LCD12232_A0=1;
LCD12232_RW=0;
LCD12232_E2=1; _nop_();
LCD12232_DATA=i; _nop_();
LCD12232_E2=0; _nop_();
}
/*--------------------------------------------------------------------------------------------------*/
//显示8*8点阵
//字模被竖着切分
//lin:行(0-3), column: 列(0-14)
//address : 字模区首地址
void Show88(unsigned char lin,unsigned char column,unsigned int address)
{
unsigned char i,j;
if( column > 14) return;
if( column < 7 ) //8*8点阵都在左屏(Master)
{ OutMI( 0xB8 | lin); //设置显示行
OutMI( column*8 ); //设置显示列
for(i=0; i<8 ; i++ ) { OutMD( CBYTE[address+i] ); }
}
if( column == 7) //8*8点阵,前6个在左屏(Master),后两个在右屏(Slave)
{ OutMI( 0xB8 | lin); //设置显示行
OutMI( column*8 ); //左屏
for(i=0; i<6 ; i++ )
{ OutMD( CBYTE[address+i] ); }
OutSI( 0xB8 | lin); //设置显示行
OutSI( 0 ); //右屏
for(i=0; i<3 ; i++ ) { OutSD( CBYTE[address+i+5] ); }
}
if( column > 7) //8*8点阵都在右屏(Slave)
{ OutSI( 0xB8 | lin); //设置显示行
OutSI( column*8-61 );
for(i=0; i<8 ; i++ ) { OutSD( CBYTE[address+i] ); }
}
}
/*------------------------------------------------------------------------------------------------*/
//显示8*16字符
//旋转90度:字模被竖着切分
//lin:行(0-3), column: 列(0-15)
//character:字符代码(标准ASCII码)
void ShowChar(unsigned char lin,unsigned char column,unsigned char character)
{ lin=lin<<1;
Show88(lin ,column,ASCII816[character-0x20] );
Show88(lin+1,column,ASCII816[character-0x20]+8 );
}
/*----------------------------------------------------------------------------------------------*/
//显示一个汉字
//旋转90度:字模被竖着切分
//lin:行(0-3), column: 列(0-7)
//hzcode: 汉字代码(自定义的)
//uchar code HZtable
void ShowHZ(unsigned char lin,unsigned char column,unsigned int hzcode)
{
lin=lin<<1; //lin*2
Show88(lin,column,HZTable[hzcode]);
Show88(lin,column+1,HZTable[hzcode]+8);
Show88(lin+1,column,HZTable[hzcode]+16);
Show88(lin+1,column+1,HZTable[hzcode]+24);
}
////////////////////////////////////////////////////////////////////////
/*------------------------------------------------------------------------------
调用方式:void LcdIni(void)
函数说明:12232点阵液晶初始化,开机后仅调用一次。
------------------------------------------------------------------------------*/
void InitLCD(void)
{
OutMI(0XE2);OutSI(0XE2);//复位
OutMI(0XAE);OutSI(0XAE);//POWER SAVE
OutMI(0XA4);OutSI(0XA4);//动态驱动
OutMI(0XA9);OutSI(0XA9);//1/32占空比
OutMI(0XA0);OutSI(0XA0);//时钟线输出
OutMI(0XEE);OutSI(0XEE);//写模式
OutMI(0XC0);OutMI(0X00);//显示起始行为0,列地址为0
OutSI(0XC0);OutSI(0X00);//显示起始行为0,列地址为0
OutMI(0XAF);OutSI(0XAF); //开显示
ClearScreen();
}
/*------------------------------------------------------------------------------
调用方式:void clrscr(void)
函数说明:清屏
------------------------------------------------------------------------------*/
void clrscr(void)
{
unsigned char i;
unsigned char page;
for( page=0;page<2; page ++)
{
for(i=0;i<5;i++) ShowChar( page,i,' ');
}
}///////////////////////////////////////////////////////////////////////
/*------------------------------------------------------------------------------
调用方式:void SetPage(unsigned char page0,unsigned char page1)
函数说明:同时设置主从显示页为0-3页。(内函数,私有,用户不直接调用)
------------------------------------------------------------------------------*/
void SetPage(unsigned char page0,unsigned char page1)
{
OutMI(0xB8|page1);
OutSI(0xB8|page0);
}
/*------------------------------------------------------------------------------
调用方式:void SetAddress(unsigned char address0,unsigned char address1)
函数说明:同时设置主从列地址为0-121。(内函数,私有,用户不直接调用)
-------------------------------------------------------------------------------*/
void SetAddress(unsigned char address0,unsigned char address1)
{
OutMI(address1&0x7F);
OutSI(address0&0x7F);
}
/*------------------------------------------------------------------------------
调用方式:void PutChar0(unsigned char ch)
函数说明:在左页当前地址画一个字节8个点。(内函数,私有,用户不直接调用)
-------------------------------------------------------------------------------*/
void PutChar0(unsigned char ch)
{
OutSD(ch);
}
/*------------------------------------------------------------------------------
调用方式:void PutChar1(unsigned char ch)
函数说明:在右页当前地址画一个字节8个点。(内函数,私有,用户不直接调用)
-------------------------------------------------------------------------------*/
void PutChar1(unsigned char ch)
{
OutMD(ch);
}
/*------------------------------------------------------------------------------
调用方式:void DrawBmp(unsigned char x,bit layer,unsigned char width,unsigned char *bmp)
函数说明:画一个图,横坐标是x,layer表示上下层,width是图形的宽,高都是16,bmp是
图形指针
使用zimo21软件,采用纵向取模得到bmp数据。
------------------------------------------------------------------------------*/
void DrawBmp(unsigned char x0,bit layer,unsigned char width,unsigned char *bmp)
{
unsigned char x,address,i=0; //address表示显存的物理地址
unsigned char page=0;
bit window=0; //page表示上下两页,window表示左右两页
if (layer) page=2;
for (x=x0;x<x0+width;x++)
{
if (x>62) {window=1;address=x%62;}
else address=x;
SetPage(page,page);
SetAddress(address,address);
if (window)
{
PutChar0(bmp[i]);
}
else
{
PutChar1(bmp[i]);// Master ,画上层
}
SetPage(page+1,page+1);
SetAddress(address,address);
if (window)
{
PutChar0(bmp[i+width]);
}
else
{
PutChar1(bmp[i+width]);//画下层
}
i++;
}
}
void ClearScreen(void)
{
unsigned char i;
unsigned char page;
for (page=0;page<4;page++)
{
SetPage(page,page);
SetAddress(0,0);
for (i=0;i<62;i++)
{
PutChar1(0x0);
PutChar0(0x0);
}
}
}
//显示一行字符串(汉字,字母混排,一行16字节)
//lin:行
//lineheadaddr: 此行汉字代码区首地址
void ShowLine(unsigned char lin,unsigned char linehead[])
{ unsigned char i;
unsigned char byte;
unsigned int hzcode;
for( i=0; i<16; )
{ byte=linehead[i];
if(byte < 0x80) //字母
{
if(i>15) return; //!!编译器有问题,须强制退出
ShowChar(lin, i , byte);
i=i+1;
}
else // byte >= 0x80(汉字)
{
if(i>15) return; //!!编译器有问题,须强制退出
byte=byte & 0x7f; //最高位置0,即:减去0x8000
hzcode=(unsigned int)byte<<8; //?? //高8位
hzcode=hzcode+linehead[i+1]; //加低8位,组合成整型数地址
ShowHZ( lin,i,hzcode);
i=i+2;
}
}
}
//显示一屏汉字
//pageheadaddr:此屏汉字代码地址区首地址
void ShowPage(unsigned char pagehead[][16])
{ unsigned char i;
for(i=0;i<2;i++) ShowLine(i,pagehead[i]); //1行8个汉字,16字节
}unsigned char ReadByte_1()
{
unsigned char dat;
LCD12232_E2=0; //确
LCD12232_A0=1;
LCD12232_RW=1;
LCD12232_E1=1; _nop_(); _nop_();
LCD12232_DATA=0xff;
dat=LCD12232_DATA; _nop_(); _nop_();
LCD12232_E1=0; _nop_(); _nop_();
return dat;
}unsigned char ReadByte_2()
{
unsigned char dat;
LCD12232_E1=0; //确
LCD12232_A0=1;
LCD12232_RW=1;
LCD12232_E2=1; _nop_(); _nop_();
LCD12232_DATA=0xff;
dat=LCD12232_DATA; _nop_(); _nop_();
LCD12232_E2=0; _nop_(); _nop_();
return dat;
}
//反显一个8*8字块
//lin:行(0-3), column: 列(0-7)
void ReverseShow88(unsigned char lin,unsigned char column)
{
unsigned char i,j,dat[8];
if( column > 14) return;
if( column < 7 ) //8*8点阵都在左屏(Master)
{ OutMI( 0xB8 | lin); //设置显示行
OutMI( column*8 ); //设置显示列
dat[i]=~ReadByte_1();
for(i=0;i<8;i++)
{
dat[i]=~ReadByte_1();
}
OutMI( 0xB8 | lin); //设置显示行
OutMI( column*8 ); //设置显示列
for(i=0; i<8 ; i++ ) { OutMD(dat[i]); }
}
if( column == 7) //8*8点阵,前6个在左屏(Master),后两个在右屏(Slave)
{ OutMI( 0xB8 | lin); //设置显示行
OutMI( column*8 ); //左屏
dat[i]=~ReadByte_1();
for(i=0;i<6;i++)
{
dat[i]=~ReadByte_1();
}
OutMI( 0xB8 | lin); //设置显示行
OutMI( column*8 ); //左屏
for(i=0; i<6 ; i++ )
{ OutMD(dat[i]); }
OutSI( 0xB8 | lin); //设置显示行
OutSI( 0 ); //右屏
dat[i]=~ReadByte_2();
for(i=0;i<2;i++)
{
dat[i]=~ReadByte_2();
}
OutSI( 0xB8 | lin); //设置显示行
OutSI( 0 ); //右屏
for(i=0; i<2 ; i++ ) { OutSD(dat[i]); }
}
if( column > 7) //8*8点阵都在右屏(Slave)
{ OutSI( 0xB8 | lin); //设置显示行
OutSI( column*8-62 );
dat[i]=~ReadByte_2();
for(i=0;i<8;i++)
{
dat[i]=~ReadByte_2();
}
OutSI( 0xB8 | lin); //设置显示行
OutSI( column*8-62 );
for(i=0; i<8 ; i++ ) { OutSD(dat[i]); }
}
}
//反显一行
ReverseShow(unsigned char lin)
{
unsigned char i;
lin=lin*2;
for(i=0;i<15;i++)
{
ReverseShow88(lin,i);
ReverseShow88(lin+1,i);
}
}
//反显一个汉字
ReverseShowHZ(unsigned char lin,unsigned char col)
{
lin=lin*2;
ReverseShow88(lin,col);
ReverseShow88(lin+1,col);
ReverseShow88(lin,col+1);
ReverseShow88(lin+1,col+1);
}
//反显一个字符
ReverseShowChar(unsigned char lin,unsigned char col)
{
lin=lin*2;
ReverseShow88(lin,col);
ReverseShow88(lin+1,col);
}
void Reset() //液晶复位
{
_nop_(); _nop_();}