for(j=0;j<120;j++);
}
三、诺基亚5110液晶显示时间路程源程序
/*
Nokia5110LCDtest
芯片型号:
AT89S52
by:
ysit1990@
data:
2012.06.20
描述:
基于网上参考例子修改测试于杭州电子科技大学集训期间
*/
/***********************************************************************
pindescriptioni/o
;VCC(3.3V)+3.3v供电电源
;CLK:
LCD_CLKP2.0时钟
;DA:
SDINP2.1数据输入
;D/C:
LCD_DCP2.21写数据0写命令
;SCE:
LCD_SCEP2.3片选信号
;RSET:
LCD_RESTP2.4复位信号
;GND--接地
;LED+5v背光
***********************************************************************/
#include
#include//包含_nop_();一机器周期延时空指令
#defineucharunsignedchar
#defineuintunsignedint
sbitLCD_CLK=P1^5;//时钟
sbitSDIN=P1^4;//数据
sbitLCD_DC=P1^3;//1写数据,0写指令
sbitLCD_SCE=P1^2;//片选
sbitLCD_REST=P1^1;//复位,0复位
/*function
************************/
///////////SPI写操作
voidLCD_write_byte(unsignedchardat,unsignedcharcommand);
///////////5110初始化
voidLCD_init(void);
///////////清屏
voidLCD_clear(void);
//////////显示一个字符
voidLCD_write_char(unsignedcharc);
//////////显示字符串
voidLCD_write_String(unsignedcharX,unsignedcharY,unsignedchar*s);
//////////显示一个汉字
voidLCD_WRITE_ZH(unsignedcharX,unsignedcharY,unsignedcharZH[][32],unsignedcharindex);
///////////显示汉字串
voidLCD_WRITE_ZH_STRING(ucharX,ucharY,//起始坐标
ucharZHS[][32],//汉字字符串
ucharwidth,//每个字符边长
ucharindex,//起始索引号
ucharnum,//显示个数
ucharspace);//间距
/////////////////////////画图
voidLCD_draw_bmp_pixel(ucharX,ucharY,uchar*map,ucharwidth,ucharheight);
//ASCII码的字库
ucharcodeASCII_6_8[][6]=
{
{0x00,0x3e,0x51,0x49,0x45,0x3e}//0
{0x00,0x00,0x42,0x7f,0x40,0x00}//1
{0x00,0x42,0x61,0x51,0x49,0x46}//2
{0x00,0x21,0x41,0x45,0x4b,0x31}//3
{0x00,0x18,0x14,0x12,0x7f,0x10}//4
{0x00,0x27,0x45,0x45,0x45,0x39}//5
{0x00,0x3c,0x4a,0x49,0x49,0x30}//6
{0x00,0x01,0x71,0x09,0x05,0x03}//7
{0x00,0x36,0x49,0x49,0x49,0x36}//8
{0x00,0x06,0x49,0x49,0x29,0x1e}//9
{0x00,0x00,0x36,0x36,0x00,0x00}//:
{0x00,0x38,0x44,0x44,0x44,0x20}//c
{0x00,0x7c,0x04,0x18,0x04,0x78}//m
{0x00,0x48,0x54,0x54,0x54,0x20}//s
};
/*///////////////////////////////////////////////////////////汉字字模参考*/
staticconstcharHanzi[][24]={
/*--文字:
支--*/
/*--宋体12;此字体下对应的点阵为:
宽x高=16x16*/
{0xFE,0x22,0x22,0xFE,0x00,0x08,0x48,0x88,0x08,0xFF,0x08,0x00,
0x07,0x02,0x02,0x07,0x00,0x00,0x00,0x09,0x08,0x0F,0x00,0x00},//时0
{0x00,0xF9,0x02,0xF8,0x49,0x49,0x49,0x49,0xF9,0x01,0xFF,0x00,
0x00,0x0F,0x00,0x03,0x02,0x02,0x02,0x02,0x0B,0x08,0x0F,0x00},//间1
{0x9E,0x12,0xF2,0x9E,0x48,0xC4,0xAB,0x92,0xAA,0xC6,0x40,0x00,
0x0F,0x08,0x07,0x04,0x00,0x0F,0x04,0x04,0x04,0x0F,0x00,0x00},//路0
{0x12,0xD2,0xFE,0x51,0x80,0x2F,0x29,0xE9,0x29,0x2F,0x00,0x00,
0x01,0x00,0x0F,0x00,0x08,0x09,0x09,0x0F,0x09,0x09,0x08,0x00},//程1
};
/*--文字:
持--*/
/*--宋体12;此字体下对应的点阵为:
宽x高=16x16--
/***********************************************************
函数名称:
LCD_write_byte
函数功能:
模拟SPI接口时序写数据/命令LCD
入口参数:
data:
写入的数据;
command:
写数据/命令选择;
出口参数:
无
备注:
***********************************************************/
voidLCD_write_byte(unsignedchardat,unsignedcharcommand)
{
unsignedchari;
LCD_SCE=0;//5110片选有效,允许输入数据
if(command==0)//写命令
LCD_DC=0;
elseLCD_DC=1;//写数据
for(i=0;i<8;i++)//传送8bit数据
{
if(dat&0x80)
SDIN=1;
else
SDIN=0;
dat=dat<<1;
LCD_CLK=0;
LCD_CLK=1;//时钟上升沿写
}
LCD_SCE=1;//禁止5110
}
/***********************************************************
函数名称:
LCD_init
函数功能:
5110初始化
入口参数:
无
出口参数:
无
备注:
***********************************************************/
voidLCD_init(void)
{
LCD_SCE=0;//片选LCD
LCD_REST=0;//产生一个让LCD复位的低电平脉冲
_nop_();
LCD_REST=1;
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);//使用基本命令,V=0,水平寻址
LCD_clear();//清屏
LCD_write_byte(0x0c,0);//设定显示模式,正常显示
LCD_SCE=1;//禁止LCD
}
/***********************************************************
函数名称:
LCD_set_XY
函数功能:
设置LCD坐标函数
入口参数:
X:
0-83横坐标
Y:
0-5纵坐标
出口参数:
无
备注:
***********************************************************/
voidLCD_set_XY(unsignedcharX,unsignedcharY)
{
LCD_write_byte(0x80|X,0);//X行(横坐标)
LCD_write_byte(0x40|Y,0);//column列(纵坐标)
}
/*------------------------------------------
LCD_clear:
LCD清屏函数
--------------------------------------------*/
voidLCD_clear(void)
{
unsignedchart;
unsignedchark;
LCD_set_XY(0,0);
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0x00,1);
}
}
}
/***********************************************************
函数名称:
LCD_write_char
函数功能:
显示英文字符
入口参数:
c:
显示的字符
出口参数:
无
备注:
***********************************************************/
voidLCD_write_char(unsignedcharc)
{
unsignedchari;
c-=0x20;//ASCII码减去0x20
for(i=0;i<6;i++)
LCD_write_byte(ASCII_6_8[c][i],1);
}
/*-------------------------------------------
;名称:
英文字符串显示函数
;参数:
*s:
英文字符串指针
---------------------------------------------*/
voidLCD_write_String(unsignedcharX,unsignedcharY,unsignedchar*s)
{
LCD_set_XY(X,Y);
while(*s)//等效*s!
='\0'
{
LCD_write_char(*s);
s++;
}
}
/*-------------------------------------------------