//以下4个底层函数在CMLCD_DriverIO.c中定义
void LCD_Reset(void);
void LCD_COM_W(unsigned char com_d);
void LCD_Data_W(unsigned char dd);
unsigned char LCD_Data_R(void);
unsigned char LCD_show_buf[32]; //用于LCD的显示缓存的空间
unsigned char LCD_show_Addr=0x00; //实际上是对于LCD当前操作的图层的参数
//===================================================//
//程序:void LCD_Initial(void)
//描述:CM320X240LCD初始化函数
//参数:null
//返回:
//Note: Edit by Mz xinqiang zhang
//Date: 2006 07 29 beijing
//===================================================//
void LCD_Initial(void)
{
LCD_Reset(); //复位LCD,如果用户将LCD的复位用端口控制的话
LCD_COM_W(0x40); //设置LCD系统参数,后面跟着P1~P8的参数
LCD_Data_W(0x30);
LCD_Data_W(0x87);
LCD_Data_W(0x07);
LCD_Data_W(0x27); //每一行的有效显示字节数0x27+1=40,即320个点
LCD_Data_W(0x32);//0x42); 每一行所占用的存储器数量,下一行起始的计算就利用它
LCD_Data_W(0xF0);
LCD_Data_W(0x32);
LCD_Data_W(0x00);
LCD_COM_W(0x44); //设置LCD的SCROLL参数,后面跟着P1~P10的参数
LCD_Data_W(0x00); //设置第一图层的起始地址,低
LCD_Data_W(0x00); //设置第一图层的起始地址,高
LCD_Data_W(0xF0); //设置第一图层的SL1(即Y轴点数)
LCD_Data_W(0x00); //设置第二图层的起始地址,低
LCD_Data_W(0x40); //设置第二图层的起始地址,高
LCD_Data_W(0xF0); //设置第二图层的SL2
LCD_Data_W(0x00); //设置第三图层起始地址
LCD_Data_W(0x80);
LCD_Data_W(0x00); //设置第四图层的起始地址
LCD_Data_W(0x00);
LCD_COM_W(0x5A); //设置Scroll的点数
LCD_Data_W(0x00); //1个点 (垂直方向的)
LCD_COM_W(0x5B); //设置图层关系
LCD_Data_W(0x0d); //两个图层、异或的关系、graphic模式
// LCD_COM_W(0x53); //设置光标模式
// LCD_Data_W(0x0F);
// LCD_Data_W(0x0F);
LCD_COM_W(0x59); //Display ON
LCD_Data_W(0x14); //1、2区开显示
LCD_COM_W(0x4c);
}
//===================================================//
//程序:void LCD_Setlayer(unsigned char layer)
//描述:CM320X240LCD活动图层选择
//参数:layer=选择图层(1~4)
//返回:
//Note: Edit by Mz xinqiang zhang
//Date: 2006 08 01 beijing
//===================================================//
void LCD_Setlayer(unsigned char layer)
{
switch(layer)
{
case 1: LCD_show_Addr = 0x00;break;
case 2: LCD_show_Addr = 0x40;break;
default: LCD_show_Addr = 0x00;break;
}
}
//===================================================//
//程序:void LCD_Clear(bit is_Clear,unsigned char layer)
//描述:CM320X240LCD显示清屏函数
//参数:is_Clear=选择填充的色(0/1) layer=选择图层(1~4)
//返回:
//Note: Edit by Mz xinqiang zhang
//Date: 2006 07 29 beijing
//===================================================//
void LCD_Clear(bit is_Clear)
{
unsigned char show_Data,i,j,Addr_H=0;
if(is_Clear)
show_Data = 0xFF;
else
show_Data = 0x00;
Addr_H = Addr_H+LCD_show_Addr;
LCD_COM_W(0x46); //设置当前地址
LCD_Data_W(0x00);
LCD_Data_W(Addr_H);
LCD_COM_W(0x42);
for(i=0;i<240;i++)
{
for(j=0;j<0x32;j++)
{
LCD_Data_W(show_Data);
}
}
}
//===================================================//
//程序:void LCD_ONOFF(bit is_ON,unsigned char layer)
//描述:CM320X240LCD显示清屏函数
//参数:is_ON=选择关闭/打开(0/1) layer=选择图层数(1~3)
//返回:
//注意:只有在打开LCD的命令当中layer参数才有效
//Note: Edit by Mz xinqiang zhang
//Date: 2006 07 29 beijing
//===================================================//
void LCD_ONOFF(bit is_ON,unsigned char layer)
{
switch(layer)
{
case 1:layer = 0x04;
case 2:layer = 0x14;
default: break;
}
if(is_ON)
{
LCD_COM_W(0x59);
}
else
{
LCD_COM_W(0x58);
}
LCD_Data_W(layer);
}
//===================================================//
//程序:void LCD_PutPixel(unsigned int Index_x,unsigned char Index_y)
//描述:CM320X240LCD画点子程序
//参数:Index_x X轴坐标(0~319) Index_y y轴坐标(0~239)
//返回:
//Note: Edit by Mz xinqiang zhang
//Date: 2006 07 29 beijing
//===================================================//
void LCD_Back_dot(unsigned int Addr,unsigned char b,bit mode);
void LCD_PutPixel(unsigned int Index_x,unsigned char Index_y,bit mode)
{
unsigned int Addr_Byte;
Addr_Byte = (unsigned int)Index_y*0x32;
Addr_Byte = Addr_Byte+(Index_x>>3)+(unsigned int)(LCD_show_Addr<<8);
Index_x = Index_x&0x07;
switch(Index_x)
{
case 0:Index_y = 0x80;break;
case 1:Index_y = 0x40;break;
case 2:Index_y = 0x20;break;
case 3:Index_y = 0x10;break;
case 4:Index_y = 0x08;break;
case 5:Index_y = 0x04;break;
case 6:Index_y = 0x02;break;
case 7:Index_y = 0x01;break;
}
LCD_Back_dot(Addr_Byte,Index_y,mode);
}
//***************************************************************************//
//程序:void LCD501_Line(unsigned int x,unsigned int y,unsigned int e_x,
// unsigned int e_y)
//描述:画直线程序
//参数:x 要画线的x起点坐标 y 要画的线的y起点坐标
// e_x 要画线的x 终点坐标 e_y 要画的线的y起点坐标
//返回:无
//声明:小丑 200505121 sunnorth Mz Design
//注意:
//***************************************************************************//
void LCD_Line(unsigned int x,unsigned int y,unsigned int e_x,unsigned int e_y,bit mode)
{
int Offset_x,Offset_y,Offset_k = 0;
int Err_d = 1;
if(y>e_y)
{
Offset_x = x;
x = e_x;
e_x = Offset_x;
Offset_x = y;
y = e_y;
e_y = Offset_x;
}
Offset_x = e_x-x;
Offset_y = e_y-y;
LCD_PutPixel(x,y,mode);
if(Offset_x<=0)
{
Offset_x = x-e_x;
Err_d = -1;
}
if(Offset_x>Offset_y)
{
while(x!=e_x)
{
if(Offset_k>0)
{
y+=1;
Offset_k += (Offset_y-Offset_x);
}
else Offset_k += Offset_y;
x+=Err_d;
LCD_PutPixel(x,y,mode);
}
}
else
{
while(y!=e_y)
{
if(Offset_k>0)
{
x+=Err_d;
Offset_k += (Offset_x-Offset_y);
}
else Offset_k += Offset_x;
y+=1;
LCD_PutPixel(x,y,mode);
}
}
}
//***************************************************************************//
//程序:void LCD501_Rectangle(unsigned left, unsigned top,
// unsigned right, unsigned bottom, unsigned Mode)
//描述:画矩形程序
//参数:left - 矩形的左上角横坐标,范围0到118
// top - 矩形的左上角纵坐标,范围0到50
// right - 矩形的右下角横坐标,范围1到119
// bottom - 矩形的右下角纵坐标,范围1到51
// Mode - 绘制模式,可以是下列数值之一:
// PAINT_HOLLOW: 矩形框(空心矩形)
// PAINT_SOLID: 矩形面(实心矩形)
//声明:xinqiang 20050521 sunnorth Mz Design
//注意:无
//***************************************************************************//
void LCD_Rectangle(unsigned left, unsigned top, unsigned right, unsigned bottom, unsigned Mode)
{
unsigned uiTemp;
/* if(left>right)
{
uiTemp = left;
left = right;
right = left;
}
if(top>bottom)
{
uiTemp = top;
top = bottom;
bottom = uiTemp;
} */
/* if(Mode==0)
{
LCD_Line(left,top,left,bottom);
LCD_Line(left,top,right,top);
LCD_Line(right,bottom,left+1,bottom);
LCD_Line(right,bottom,right,top+1);
}
else
{ */
for(uiTemp=top;uiTemp<=bottom;uiTemp++)
{
LCD_Line(left,uiTemp,right,uiTemp,Mode);
}
// }
}
void LCD_Back