12864實(shí)際應(yīng)用的驅(qū)動程序
這是一個(gè)12864結(jié)合ST168進(jìn)行方位顯示的程序:
本文引用地址:http://www.ex-cimer.com/article/201611/321640.htm使用技巧:只需從中復(fù)制有關(guān)12864的驅(qū)動程序,修改相關(guān)參數(shù)即可
#include
#define uint unsigned int //宏定義
sbit SID = P2^1; //串行數(shù)據(jù)RW端口
sbit SCLK = P2^2; //串行同步時(shí)鐘 E
sbit cs=P2^0; //為寫rs端口
sbit psb=P2^3;
uchar code display1[]={"123"},
//定義一個(gè)要顯示的數(shù)據(jù)串,只當(dāng)是12864中的字庫,必須要雙引號,特定意義
display8[]={"456"},
display2[]={"789"},
display9[]={"458"},
display3[]={"654"},
display7[]={"785!"},
display4[]={"4254"},
display10[]={"4587"},
display5[]={"1010"},
display6[]={"15420"},
display12[]={"1201245"},
displayrt[]={"前42452??!"},
display13[]={"4524返回"};
char dir=0,dil=0,zongjil[]={"5204 次"},
zongjir[]={"右4520"};
void delayms(uint t) //約延時(shí)n(ms)
{ for(i=0;i<125;i++); }
}
{
uchar i; for(i=0;i<8;i++)
{ SCLK = 0;
Dbyte=Dbyte<<1;
SID = CY; //移出的位給SID,CY為Dbyte的最好位,下降沿將數(shù)據(jù)傳入
SCLK = 1;
SCLK = 0; }
uchar ReceiveByte(void) //檢查忙碌的時(shí)候調(diào)用
{ uchar i,temp1,temp2;
temp1 = 0;
temp2 = 0;
for(i=0;i<8;i++)
{ temp1=temp1<<1;//傳出來的是從高位到低位,從SID中傳出來
SCLK = 1;
SCLK = 0;//下降沿傳出數(shù)據(jù)
temp1++;
}
for(i=0;i<8;i++)
{
temp2=temp2<<1;
SCLK = 0;
SCLK = 1;
SCLK = 0;
}
void CheckBusy( void )
{
do SendByte(0xfc); //11111,RW(1),RS(0),0
//BF(.7)=1 Busy
}
void Lcd_WriteCmd(uchar Cbyte )
{ CheckBusy();
SendByte(0xf8); //11111,RW(0)A(低表示從單片機(jī)到LCD,RS(0)B(低表示指令),0C固定我0;
SendByte(0xf0&Cbyte); //高四位
SendByte(0xf0&(Cbyte<<4));
}
{ CheckBusy();
SendByte(0xfa);
//高四位
SendByte(0xf0&Dbyte<<4);//低四位(先執(zhí)行<<)
{ delayms(50);
Lcd_WriteCmd(0x30);
//選擇基本指令集
delayms(1);
Lcd_WriteCmd(0x0c);
//開顯示(無游標(biāo)、不反白)
delayms(1);
delayms(20); }
void LCD12864_Write_Str(unsigned char x,unsigned char y,char *buff)//尋找地址
{ unsigned char addr,i=0;
if(x==1)addr=0x80;
if(x==2)addr=0x90;
if(x==3)addr=0x88;
addr=addr+y;
write_com(0x30);//發(fā)出尋地址指令 //
delay_ms(10);
//基本指令功能.
write_com(addr);//尋找地址
while(buff[i]!=)
{ Lcd_WriteData(buff[i]);
//write_data(buff[i]); i++; } }
{ uchar shuju,num[]={"0123456789"},a=1,b=1;
psb=0;
Lcd_Init(); // LCD初始化 ,讓LCD處于白屏狀態(tài).
{ Lcd_Init();
//shuju&=0xf8;
dil++;
if((shuju==0xfd|shuju==0xfb)&&b==1)
zongjil[8]=num[dil/10];
zongjil[9]=num[dil];
zongjir[9]=num[dir];
switch(shuju) { case 0xf7: { LCD12864_Write_Str(2,0,display8);//左
case 0xef: { LCD12864_Write_Str(2,0,display9);//左
break;
case 0xfe:
{ LCD12864_Write_Str(2,0,display7); LCD12864_Write_Str(1,0,display3); break; } //(行,列,字符)
case 0xfd: { LCD12864_Write_Str(2,0,display10);//右
LCD12864_Write_Str(3,0,zongjir);
a=0;
break;
}
{ LCD12864_Write_Str(2,0,display11);//右
b++; a=0;
case 0xe0: { LCD12864_Write_Str(2,0,display13);
default: LCD12864_Write_Str(2,0,display12);
LCD12864_Write_Str(1,0,display6); break; }
delayms(500); } }
評論