#include "lcd12864.h"
#include "ziku.h"
#include <string.h>
static void delay(uint j)//延时
{
uchar i
for(j!=0j--)
for(i=0i<100i++)
}
void busy(void)
{
uchar i
for(i=0i<50i++)
_nop_()
}
void wdata(uchar wdata)
{
busy() //忙提示
LCD_RW=0
LCD_DI=1
P0=wdata
LCD_EN=0
LCD_EN=1
LCD_EN=0
}
void wcode(uchar wcode)
{
busy()
LCD_RW=0
LCD_DI=0
P0=wcode
LCD_EN=0
LCD_EN=1
LCD_EN=0
}
void subinit()
{
delay(10)
wcode(0xc0)//设置显示初始行
}
//设置显示位置
void setxy(uchar x,uchar y)
{
if ((y>=0)&(y<=63))
{
LCD_CSA=0
LCD_CSB=1
}
else //if (y<=127)
{
LCD_CSA=1
LCD_CSB=0
}
wcode(0x40|(y%64))
wcode(0xb8|x)
P0=0xff
}
void wdram(uchar x,uchar y,uchar dd)
{
setxy(x,y)
wdata(dd)
P0=0xff
LCD_CSA=1
LCD_CSB=1
}
//复位.
void Lcd_RST(void)
{
//rst=0
LCD_REST=0
delay(50)
LCD_REST=1
Lcd_Clear(0,7,0,128)
wcode(0x3f)//开显示
}
//LCD初始化
void Lcd_Init(void)
{
LCD_POR=0
Lcd_RST()
LCD_CSA=0
LCD_CSB=1
wcode(0x3e)subinit()
LCD_CSA=1
LCD_CSB=0
wcode(0x3e)subinit()
Lcd_Clear(0,7,0,128)
LCD_CSA=0
LCD_CSB=1
wcode(0x3f)//开显示
LCD_CSA=1
LCD_CSB=0
wcode(0x3f)//开显示
}
void Lcd_On(void)
{
LCD_CSA=0
LCD_CSB=1
wcode(0x3f)//开显示
LCD_CSA=1
LCD_CSB=0
wcode(0x3f)//开显示
}
//LCD 清显示屏
void Lcd_Clear(uchar StartLine,uchar StopLine,uchar StartRow,uchar StopRow)
{
uchar x,y
for(x=StartLinex<StopLine+1x++)
{
for(y=StartRowy<StopRowy++)
{
wdram(x,y,0)
}
}
}
//显示一个汉字
void Lcd_DispOneChar(uchar x,uchar y,uchar * hz,uchar disp_mode,uchar Width)
{
uchar i
for(i=0i<Widthi++)
{
if(disp_mode==WHITE)
{
wdram(x,y+i,*(hz+i))
wdram(x+1,y+i,*(hz+Width+i))
}
else
{
wdram(x,y+i,0xff-*(hz+i))
wdram(x+1,y+i,0xff-*(hz+Width+i))
}
}
if(Width==12)
{
for(i=12i<14i++)
{
if(disp_mode==WHITE)
{
wdram(x,y+i,0)
wdram(x+1,y+i,0)
}
else
{
wdram(x,y+i,0xff)
wdram(x+1,y+i,0xff)
}
}
for(i=1i<4i++)
{
if(disp_mode==WHITE)
{
wdram(x,y-i,0)
wdram(x+1,y-i,0)
}
else
{
wdram(x,y-i,0xff)
wdram(x+1,y-i,0xff)
}
}
}
}
void Lcd_Disp_String(uchar x,uchar y,char *pString,uchar disp_mode)
{
uchar i,j
uchar LineDispCode[16]
//strlen(),为字符串长度测量。
memset(LineDispCode,0,16) //清零数组
strcpy(LineDispCode,pString) //字符串之间的相互复制。
for(i=0i<strlen(pString)i++)
{
LineDispCode[i]=*(pString+i)
}
i=0
while(LineDispCode[i]!=0)
{
if(LineDispCode[i]>=0xA0)
{
//显示的是汉字
for(j=0j<ZIMO_NUMj++)
{
if(GB_12[j].Index[0]==LineDispCode[i] &&
GB_12[j].Index[1]==LineDispCode[i+1])
{
//显示的是汉字
Lcd_DispOneChar(x,y,GB_12[j].Msk,disp_mode,12)
y+=16
break
}
}
i+=2
}
else
{
//显示的是ASCII编码
for(j=0j<ASC_NUMj++)
{
if(ASC_12[j].Index==LineDispCode[i])
{
//显示的是汉字
Lcd_DispOneChar(x,y,ASC_12[j].Msk,disp_mode,8)
y+=8
break
}
}
i++
}
if(i>=16)
{
break
}
}
}
//显示数字.
void Lcd_Disp_OneNum(uchar x,uchar y,uchar num,uchar disp_mode)
{
switch(num)
{
case 0:{Lcd_Disp_String(x,y,"0",disp_mode)}break
case 1:{Lcd_Disp_String(x,y,"1",disp_mode)}break
case 2:{Lcd_Disp_String(x,y,"2",disp_mode)}break
case 3:{Lcd_Disp_String(x,y,"3",disp_mode)}break
case 4:{Lcd_Disp_String(x,y,"4",disp_mode)}break
case 5:{Lcd_Disp_String(x,y,"5",disp_mode)}break
case 6:{Lcd_Disp_String(x,y,"6",disp_mode)}break
case 7:{Lcd_Disp_String(x,y,"7",disp_mode)}break
case 8:{Lcd_Disp_String(x,y,"8",disp_mode)}break
case 9:{Lcd_Disp_String(x,y,"9",disp_mode)}break
default: break
}
}
//显示二位数。
void Disp_2num(uchar x,uchar y,uchar num,uchar disp_mode)
{
uchar ch[2]
ch[0]=num%10
ch[1]=num/10
Lcd_Disp_OneNum(x,y,ch[1],disp_mode)
Lcd_Disp_OneNum(x,y+8,ch[0],disp_mode)
}
//*****************************************************
//显示三位数。
void Disp_3num(uchar x,uchar y,uint num,uchar disp_mode)
{
uchar ch[2]
ch[0]=num/100
ch[1]=num%100
if(ch[0])
Lcd_Disp_OneNum(x,y, ch[0],disp_mode)
else
Lcd_Disp_String(x,y," ",disp_mode)
Disp_2num(x,y+8, ch[1],disp_mode)
}
//*****************************************************
//显示四位数。
void Disp_4num(uchar x,uchar y,uint num,uchar disp_mode)
{
uchar ch[4],tmp
tmp=num/100
ch[0]=tmp/10
ch[1]=tmp%10
tmp=num%100
ch[2]=tmp/10
ch[3]=tmp%10
Lcd_Disp_OneNum(x,y,ch[0],disp_mode)
Lcd_Disp_OneNum(x,y+8,ch[1],disp_mode)
Lcd_Disp_OneNum(x,y+16,ch[2],disp_mode)
Lcd_Disp_OneNum(x,y+24,ch[3],disp_mode)
}
void Lcd_DispIco2(uchar x,uchar y,uchar *pIco)//显示老肯图标
{
uchar i,j
for(i=0i<4i++)
{
for(j=0j<32j++)
{
wdram(x+i,y+j,*pIco)
pIco++
}
}
}
//*****************************************************
//显示多位数。 disp_mode&0x10==1时,进行即每位都显示,否则大于0的位置不显示。
void Disp_NumGB16(uchar x,uchar y,ulong Data,uchar num,uchar disp_mode)
{
uchar idata ch=0,i,tmp
for(i=0i<numi++)
{
tmp=Data%10
Data/=10
if((disp_mode&0x10)||tmp>0||Data>0||num<=2)
Lcd_Disp_OneNum(x,y+(num-i-1)*8,tmp,disp_mode%10)
else
Lcd_Disp_String(x,y+(num-i-1)*8," ",disp_mode%10)
}
}
源码很多给你找了一个给你参考参考把:
http://wenku.baidu.com/link?url=yi6M9n7jl61QAsB9J0oW8pOabWJ5bN6OwKPXGOEvjQHOwT75AX-KnB3UYQvXm2maFqqO_a1sKJC03HcQfvC1mtOk3j3UqSwixaUUSz0-5l3
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)