12864显示Word文件下载.docx
《12864显示Word文件下载.docx》由会员分享,可在线阅读,更多相关《12864显示Word文件下载.docx(18页珍藏版)》请在冰豆网上搜索。
io_LCD12864_DATAPORT=byCmd;
_nop_();
SET_EN
voidv_Lcd12864SendData_f(unsignedcharbyData)//发送数据
SET_DATA
io_LCD12864_DATAPORT=byData;
voidv_DelayMs_f(unsignedintnDelay)//延时
unsignedinti;
for(;
nDelay>
0;
nDelay--)
{
for(i=125;
i>
i--);
}
voidv_Lcd12864Init_f(void)//初始化
v_Lcd12864SendCmd_f(0x30);
//基本指令集
v_DelayMs_f(50);
v_Lcd12864SendCmd_f(0x01);
//清屏
v_Lcd12864SendCmd_f(0x06);
//光标右移
v_Lcd12864SendCmd_f(0x0c);
//开显示
voidv_Lcd12864SetAddress_f(unsignedcharx,y)//地址转换
unsignedcharbyAddress;
switch(y)
case0:
byAddress=0x80+x;
break;
case1:
byAddress=0x90+x;
break;
case2:
byAddress=0x88+x;
case3:
byAddress=0x98+x;
default:
v_Lcd12864SendCmd_f(byAddress);
voidv_Lcd12864PutString_f(unsignedcharx,unsignedchary,unsignedchar*pData)
v_Lcd12864SetAddress_f(x,y);
while(*pData!
='
\0'
)
v_Lcd12864SendData_f(*pData++);
}
voidv_Lcd12864DrawPicture_f(unsignedcharcode*pPicture)
unsignedchari,j,k;
v_Lcd12864SendCmd_f(0x34);
v_Lcd12864SendCmd_f(0x36);
for(i=0;
i<
2;
i++)
for(j=0;
j<
32;
j++)
v_Lcd12864SendCmd_f(0x80+j);
if(i==0)
v_Lcd12864SendCmd_f(0x80);
else
v_Lcd12864SendCmd_f(0x88);
for(k=0;
k<
16;
k++)
v_Lcd12864SendData_f(*pPicture++);
unsignedcharu8_Lcd12864ReadByte_f(void)
unsignedcharbyReturnValue;
io_LCD12864_DATAPORT=0xff;
byReturnValue=io_LCD12864_DATAPORT;
returnbyReturnValue;
voidv_Lcd12864ClearRam_f(void)
v_Lcd12864SendData_f(0x00);
voidv_Lcd12864DrawPoint_f(unsignedcharX,unsignedcharY,unsignedcharColor)
unsignedcharRow,Tier,Tier_bit;
unsignedcharReadOldH,ReadOldL;
Tier=X>
>
4;
Tier_bit=X&
0x0f;
if(Y<
32)
Row=Y;
Row=Y-32;
Tier+=8;
v_Lcd12864SendCmd_f(Row+0x80);
v_Lcd12864SendCmd_f(Tier+0x80);
u8_Lcd12864ReadByte_f();
ReadOldH=u8_Lcd12864ReadByte_f();
ReadOldL=u8_Lcd12864ReadByte_f();
if(Tier_bit<
8)
switch(Color)
ReadOldH&
=(~(0x01<
<
(7-Tier_bit)));
ReadOldH|=(0x01<
(7-Tier_bit));
ReadOldH^=(0x01<
v_Lcd12864SendData_f(ReadOldH);
v_Lcd12864SendData_f(ReadOldL);
switch(Color)
ReadOldL&
=(~(0x01<
(15-Tier_bit)));
ReadOldL|=(0x01<
(15-Tier_bit));
ReadOldL^=(0x01<
voidv_Lcd12864DrawLineX_f(unsignedcharX0,unsignedcharX1,unsignedcharY,unsignedcharColor)
{unsignedcharTemp;
if(X0>
X1)
Temp=X1;
X1=X0;
X0=Temp;
X0<
=X1;
X0++)
v_Lcd12864DrawPoint_f(X0,Y,Color);
voidv_Lcd12864DrawLineY_f(unsignedcharX,unsignedcharY0,unsignedcharY1,unsignedcharColor)
unsignedcharTemp;
if(Y0>
Y1)
Temp=Y1;
Y1=Y0;
Y0=Temp;
for(;
Y0<
=Y1;
Y0++)
v_Lcd12864DrawPoint_f(X,Y0,Color);
voidv_Lcd12864DrawLine_f(unsignedcharStartX,unsignedcharStartY,unsignedcharEndX,unsignedcharEndY,unsignedcharColor)
intt,distance;
/*根据屏幕大小改变变量类型(如改为int型)*/
intx=0,y=0,delta_x,delta_y;
charincx,incy;
delta_x=EndX-StartX;
delta_y=EndY-StartY;
if(delta_x>
0)
incx=1;
elseif(delta_x==0)
v_Lcd12864DrawLineY_f(StartX,StartY,EndY,Color);
return;
incx=-1;
if(delta_y>
incy=1;
elseif(delta_y==0)
v_Lcd12864DrawLineX_f(StartX,EndX,StartY,Color);
incy=-1;
delta_x=ABS(delta_x);
delta_y=ABS(delta_y);
delta_y)
distance=delta_x;
distance=delta_y;
v_Lcd12864DrawPoint_f(StartX,StartY,Color);
/*DrawLine*/
for(t=0;
t<
=distance+1;
t++)
x+=delta_x;
y+=delta_y;
if(x>
distance)
x-=distance;
StartX+=incx;
if(y>
y-=distance;
StartY+=incy;
/************************************************************/
//绘制电子钟圆形面板//
voidClock_plate()
floatsta,x,y;
//绘制外围圆圈,如绘制连续的线条侧可以减少步长,将0.1改为0.02即可
for(sta=0;
sta<
=2*PI;
sta+=2*PI/60)//把圆均分成60等份
{
x=sin(sta);
y=cos(sta);
v_Lcd12864DrawPoint_f(62+31*x,32+31*y,1);
/////////////////////////////////////////////////////////////////
//运用ds1302时钟芯片用K1K2调整年月日时分
#include<
reg51.h>
#defineucharunsignedchar
#defineuintunsignedint
ucharcodeline1[]="
现在是北京时间:
"
;
ucharcodeline0[]="
年月日"
ucharcodeline2[]="
星期"
ucharcodeasc[]="
0123456789"
ucharcodeweek[]="
一二三四五六日"
ucharcodes0[]="
smhdynw"
/*d1302的接口*/
//使用P1口向LCD传送数据
sbitrst=P3^2;
//时钟5
sbitio=P3^3;
//数据6
sbitsclk=P3^4;
//复位7
sbitk1=P2^1;
//选项控制按钮
sbitk2=P2^2;
//+1
sbitk3=P2^3;
//-1
/*12864的接口*/
sbitrs=P3^5;
//1数据0指令
sbitrw=P3^6;
//0写1读
sbite=P3^7;
//LCD的使能
ucharc1;
//记录k1所按的次数
structtime
//定义一个结构体
uchars;
//秒
ucharm;
//分
ucharh;
//时
uchard;
//日
uchary;
//月
ucharw;
//星期
ucharn;
//年
}time1;
ucharread_1302(uchard)//读ds1302的内容
uchara,i;
sclk=0;
rst=1;
for(i=0;
i<
8;
i++)//发命令字低位先行
sclk=0;
if(d&
0x01)//发1
io=1;
else
io=0;
sclk=1;
//产生时钟上升沿
d>
=1;
i++)//收1302发八位数据
a>
//产生下降沿
if(io==1)//收1
{a|=0x80;
rst=0;
returna;
voidwrite_1302(uchara,ucharb)//写数据到1302
uchari;
i++)//发命令字(地址)
if(a&
for(i=0;
i++)//发数据
if(b&
b>
voiddelay(ucharx)//延时
uchary;
for(;
x>
0;
x--);
for(y=100;
y>
y--);
voidget_time()//获取1302的当前时间
{time1.s=read_1302(0x81);
//读秒钟
time1.m=read_1302(0x83);
//读分钟
time1.h=read_1302(0x85);
//读小时
time1.d=read_1302(0x87);
time1.y=read_1302(0x89);
time1.w=read_1302(0x8b);
time1.n=read_1302(0x8d);
voidLCDcon(bitx,uchard)//LCD液晶的控制函数
e=0;
rw=0;
//写
rs=x;
delay
(1);
e=1;
P1=d;
delay
(2);
voidLCD_init()//LCD初始化
LCDcon(0,0x0c);
//开液晶光标
LCDcon(0,0x01);
delay(200);
LCDcon(0,0x80);
//显示的首地址
line1[i]!
='
i++)
LCDcon(1,line1[i]);
voiddisplayinit()//显示固定不变的部分
LCDcon(0,0x90);
//显示首地址
LCDcon(1,'
2'
);
0'
LCDcon(0,0x92);
LCDcon(1,line0[0]);
LCDcon(1,line0[1]);
LCDcon(0,0x94);
LCDcon(1,line0[2]);
LCDcon(1,line0[3]);
LCDcon(0,0x96);
LCDcon(1,line0[4]);
LCDcon(1,line0[5]);
LCDcon(0,0x8a);
:
'
//小时与分钟的分界
LCDcon(0,0x8c);
//秒钟与分钟的分界
LCDcon(0,0x9a);
LCDcon(1,line2[0]);
//星
LCDcon(1,line2[1]);
LCDcon(0,0x9b);
LCDcon(1,line2[2]);
//期
LCDcon(1,line2[3]);
voidsub_display()//显示调整的项目
LCDcon(0,0x98);
if(c1==0)//k11次都没按显示左三角形
LCDcon(1,0x10);
else
LCDcon(1,s0[c1-1]);
voiddisplay()//显示时间
uchart;
get_time();
LCDcon(0,0x91);
//显示年
LCDcon(1,asc[time1.n>
4]);
LCDcon(1,asc[time1.n&
0x0f]);
LCDcon(0,0x93);
//显示月
LCDcon(1,asc[(time1.y>
4)&
0x01]);
LCDcon(1,asc[time1.y&
LCDcon(0,0x95);
//显示日
LCDcon(1,asc[(time1.d>
0x03]);
LCDcon(1,asc[time1.d&
LCDcon(0,0x89);
//显示小时
LCDcon(1,a