最近使用1621驱动LCD,参考的是此网站09年大风一个帖子中的程序,有两个问题没搞明白,请各位大侠指点一下啊
#define Lcd_Delay _nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
void Lcd_Data(uchar Start,uchar cData)//将数据当中的字节与LCD上的进行同步
// Start --要开始同页面地址,每个页面为4个有效位,总其为32X4字节
// Length --要同步的页面数量
{
uchar i;
LCD_CS=0;
Lcd_Delay;
Lcd_Delay;
Lcd_Delay;
//Send ID 101B
LCD_CLK=0;
Lcd_Delay;
LCD_IO=1;
Lcd_Delay;
LCD_CLK=1;
Lcd_Delay;
LCD_CLK=0;
Lcd_Delay;
LCD_IO=0;
Lcd_Delay;
LCD_CLK=1;
Lcd_Delay;
LCD_CLK=0;
Lcd_Delay;
LCD_IO=1;
Lcd_Delay;
LCD_CLK=1;
Lcd_Delay;
//Send Address 6bit
Start=Start*2;
for(i=0;i<6;i++) 此处地址为什么要乘以2呢?????
{
if(Start&0x20) LCD_IO=1;
else LCD_IO=0;
Lcd_Delay;
LCD_CLK=0;
Lcd_Delay;
Start=Start<<1;
LCD_CLK=1;
Lcd_Delay;
}
//Send data 8bit
for(i=0;i<8;i++) 每次发送数据不是发送4位吗 这里怎么每次发8位?
{
if(cData&0x01) LCD_IO=1;
else LCD_IO=0;
Lcd_Delay;
LCD_CLK=0;
Lcd_Delay;
cData=cData>>1;
LCD_CLK=1;
Lcd_Delay;
}
LCD_CS=1;
Lcd_Delay;
}
//=============================================================================
void Lcd_Command(uchar Command) //向指定的LCD当中写入一个命令
//每个命令应以100三个位为起始,命令长度为9位,实际有效位为8位,因此在最后补一个0
// LcdSelect--LCD的片选确定,取值为0,1,2
// Command----要写入的8位命令
{
uchar i;
LCD_CS=0;
Lcd_Delay;
Lcd_Delay;
Lcd_Delay;
//Send ID 100B
LCD_CLK=0;
Lcd_Delay;
LCD_IO=1;
Lcd_Delay;
LCD_CLK=1;
Lcd_Delay;
LCD_CLK=0;
Lcd_Delay;
LCD_IO=0;
Lcd_Delay;
LCD_CLK=1;
Lcd_Delay;
LCD_CLK=0;
Lcd_Delay;
LCD_IO=0;
Lcd_Delay;
LCD_CLK=1;
Lcd_Delay;
for(i=0;i<8;i++)
{
LCD_CLK=0;
Lcd_Delay;
if(Command&0x80) LCD_IO=1;
else LCD_IO=0;
Command=Command<<1;
Lcd_Delay;
LCD_CLK=1;
Lcd_Delay;
}
///最后补一个0
LCD_CLK=0;
Lcd_Delay;
LCD_IO=0;
Lcd_Delay;
LCD_CLK=1;
Lcd_Delay;
LCD_CS=1;
Lcd_Delay;
}
//=============================================================================
void Lcd_Refresh(void) //重新对LCD进行刷屏
{
uchar i;
for(i=0;i<LCD_BUFF_MAX;i++)
Lcd_Data(i,lcd.buff);
}
//=============================================================================
void Lcd_Cls(void) //清空LCD显示区
{
//功能: 清空LCD显示区
//返值: 无
//入口: cSelectIc LCD的片选,取值为0,1,2
uchar i;
for(i=0;i<LCD_BUFF_MAX;i++)
lcd.buff=0;
Lcd_Refresh();
}
//=============================================================================
void Lcd_Init(void)//初始化LCD,二个屏都进行处理,同时进行清屏
{
LCD_CLK=1;
Lcd_Delay;
LCD_IO=1;
Lcd_Delay;
Lcd_Command(0x00); //控制器掉电(控制字)
Lcd_Command(0x02); //控制器液晶关闭(控制字)
Lcd_Command(0x18); //初始化LCD控制器
Lcd_Command(0x01); //控制器上电(控制字)
Lcd_Command(0x03); //控制器液晶显示(控制字)
Lcd_Command(0x29); //控制器液晶模式1/3BAIS 1/4DUTY(控制字)
Lcd_Cls();
} |