一下程序在运用时,紧紧结合每句后边的注释进行修正,比方端口的联接问题
这是一个12864结合ST168进行方位显现的程序:
运用技巧:只需从中仿制有关12864的驱动程序,修正相关参数即可
#include
#define uint unsigned int //宏界说
sbit SID = P2^1; //串行数据RW端口
sbit SCLK = P2^2; //串行同步时钟 E
sbit cs=P2^0; //为写rs端口
sbit psb=P2^3;
uchar code display1[]={“123”},
//界说一个要显现的数据串,只当是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) //约延时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的最好位,下降沿将数据传入
SCLK = 1;
SCLK = 0; }
uchar ReceiveByte(void) //查看繁忙的时分调用
{ uchar i,temp1,temp2;
temp1 = 0;
temp2 = 0;
for(i=0;i<8;i++)
{ temp1=temp1<<1;//传出来的是从高位到低位,从SID中传出来
SCLK = 1;
SCLK = 0;//下降沿传出数据
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(低表明从单片机到LCD,RS(0)B(低表明指令),0C固定我0;
SendByte(0xf0&Cbyte); //高四位
SendByte(0xf0&(Cbyte<<4));
}
{ CheckBusy();
SendByte(0xfa);
//高四位
SendByte(0xf0&Dbyte<<4);//低四位(先履行<<)
{ delayms(50);
Lcd_WriteCmd(0x30);
//挑选根本指令集
delayms(1);
Lcd_WriteCmd(0x0c);
//开显现(无游标、不反白)
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);//宣布寻地址指令 //
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处于白屏状况.
{ 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); } }