原创 转载:诺基亚 3310 液晶屏 LCD 驱动

2010-12-28 15:40 1885 10 10 分类: 消费电子

#include "global.h"

#include "nokia3310.h"

#include "font.h"

#include "bmp.h"



void LCDClear(void)//LCD清屏

{

unsigned int i;

LCD_write_byte(0x0C,0);

LCD_write_byte(0x80,0);

for(i=0;i<504;i++)

{

LCD_write_byte(0,1);

}

}



void LCD_set_XY(uchar X,uchar Y)//设置LCD坐标函数

{

LCD_write_byte(0x40|Y,0);//列

LCD_write_byte(0x80|X,0);//行

}



void LCDInit(void)//LCD初始化

{

P0&=~LCD_RST;//产生一个让LCD复位的低电平脉冲

nop();

P0|=LCD_RST;

P0&=~LCD_CE;//关闭LCD

nop();

P0|= LCD_CE;//使能LCD

nop();

LCD_write_byte(0x21,0);//使用扩展命令设置LCD模式

LCD_write_byte(0xc8,0);//设置偏置电压

LCD_write_byte(0x06,0);//温度校正

LCD_write_byte(0x13,0);//1:48

LCD_write_byte(0x20,0);//使用基本命令

LCDClear();// 清屏

LCD_write_byte(0x0c,0);//设定显示模式,正常显示

P0&=~LCD_CE;//关闭LCD

}





void DisplayBmp(void)

{

uchar X,Y;

for(X=0;X<84;X++)

{

for(Y=0;Y<6;Y++)

{

LCD_set_XY(X,Y);

LCD_write_byte(Bmp[BmpPointer][X*6+Y],1);

}

}

DisCount++;

if(DisCount>20)

{

DisCount=0;

BmpPointer++;

if(BmpPointer>1)

{

BmpPointer=0;

}

}

}

/*-----------------------------------------------------------------------

LCD_write_chinese_string: 在LCD上显示汉字



输入参数:X、Y :显示汉字的起始X、Y坐标;

ch_with :汉字点阵的宽度

num :显示汉字的个数;

line :汉字点阵数组中的起始行数

row :汉字显示的行间距

编写日期 :2008-6-11

最后修改日期 :2008-6-12

-----------------------------------------------------------------------*/



void Nokia3310(void)

{

uchar X;

uchar Num;

uint FontAddr;

if(GetPowerFlag==0)

{

DisplayBmp();

return;

}

for(Num=0;Num<4;Num++)

{

for(X=0;X
{

FontAddr=(X*2)+(Num*BIGX*2);

LCD_set_XY(X+Num*BIGX,0);

LCD_write_byte(Font_CN_BIG[FontAddr],1);

LCD_set_XY(X+Num*BIGX,1);

LCD_write_byte(Font_CN_BIG[FontAddr+1],1);

}

}

LCD_set_XY(80,0);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);

LCD_set_XY(80,1);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);

LCD_set_XY(80,2);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);

LCD_write_byte(0x00,1);



for(Num=0;Num<4;Num++)

{

for(X=0;X<16;X++)

{

FontAddr=(X*2)+(Num*16*2);

LCD_set_XY(X+20+Num*16,2);

LCD_write_byte(Font_CN[FontAddr],1);

LCD_set_XY(X+20+Num*16,3);

LCD_write_byte(Font_CN[FontAddr+1],1);

}

}

for(Num=0;Num<6;Num++)

{

for(X=0;X<14;X++)

{

FontAddr=(X*2)+(Num*14*2);

LCD_set_XY(X+Num*14,4);

if((WorkMode==ShaoShuiM)&&((Num==0)||(Num==1)))

{

LCD_write_byte(~Font_CN_MENU[FontAddr],1);

}

else if((WorkMode==PaoChaM)&&((Num==2)||(Num==3)))

{

LCD_write_byte(~Font_CN_MENU[FontAddr],1);

}

else if((WorkMode==HuoGuoM)&&((Num==4)||(Num==5)))

{

LCD_write_byte(~Font_CN_MENU[FontAddr],1);

}

else

{

LCD_write_byte(Font_CN_MENU[FontAddr],1);

}

LCD_set_XY(X+Num*14,5);

if((WorkMode==ShaoShuiM)&&((Num==0)||(Num==1)))

{

LCD_write_byte(~Font_CN_MENU[FontAddr+1],1);

}

else if((WorkMode==PaoChaM)&&((Num==2)||(Num==3)))

{

LCD_write_byte(~Font_CN_MENU[FontAddr+1],1);

}

else if((WorkMode==HuoGuoM)&&((Num==4)||(Num==5)))

{

LCD_write_byte(~Font_CN_MENU[FontAddr+1],1);

}

else

{

LCD_write_byte(Font_CN_MENU[FontAddr+1],1);

}

}

}

}



void LCD_write_byte(uchar Byte,uchar Cmd)//Cmd=0传送命令否则传送数据

{

unsigned char i;

P0&=~LCD_CE;//使能LCD

if(Cmd==0)

P0&=~LCD_DC;//传送命令

else P0|=LCD_DC;//传送数据

for(i=0;i<8;i++)

{

P0&=~SPI_CLK;

if((Byte&0x80)==0)P0&=~SPI_MOSI;

else P0|=SPI_MOSI;

P0|=SPI_CLK;

Byte<<=1;

}

P0|=LCD_CE;//关闭LCD

}

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
10
关闭 站长推荐上一条 /1 下一条