原创 诺基亚3310液晶屏驱动程序

2008-11-21 14:42 3773 17 19 分类: MCU/ 嵌入式
#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<BIGX;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
}

文章评论2条评论)

登录后参与讨论

飞言走笔 2011-1-11 13:02

这30个我检索过得一半……

用户944075 2010-3-23 22:45

好东西 分享了

xucun915_925777961 2008-11-27 13:50

好东西 顶
相关推荐阅读
12864_944456583 2010-04-28 09:10
关于VMware虚拟机下串口配置使用技巧
 USB转串口使用设置:   在Windows下可以使用超级终端来连接交换机和路由器等工业设备,而且在Windows下使用usb转串口的线也有相应的驱动,但是如何在Linux下使用呢?   首先要有一...
12864_944456583 2008-11-21 14:51
用单片机实现的感应触摸电路的原理图
家电中最常用的感应触摸电路,通过单片机检测电压的变化来识别是否有手指按下 ...
12864_944456583 2008-11-21 14:48
AVR单片机捕获中断实现红外线解码
1 红外线编码红外线编码是数据传输和家用电器遥控常用的一种通讯方法,其实质是一种脉宽调制的串行通讯。家电遥控中常用的红外线编码电路有μPD6121G型HT622型和7461型等。本文就以这些电路的编码...
12864_944456583 2008-11-21 14:45
用三极管实现RS232的转换电路图
用三极管实现RS232的转换电路图: ...
12864_944456583 2008-11-21 14:41
最详细电磁炉原理讲解
                                       最详细电磁炉原理讲解           日期: 2008-03-22             发表人: 稻田守望者   ...
我要评论
2
17
关闭 站长推荐上一条 /2 下一条