求大神指导,究竟要怎么写才对啊!!弄了好几天也弄不出来:'(ps:12864为串行,sclk为clk,std为sid)
#define comm 0 //指令0
#define datt 1 //数据1
void delay(unsigned int t);
void lcd_wcmd(uchar dat_comm,uint content);
void lcd_init_();
void lcd_pos(uchar X,uchar Y);
void clrram ();
void wr_byte0();
void wr_byte1();
//void chn_dat(int f);
void chn_disp (uchar *chn) ;
uchar tab1[]={"当前纸浆浓度为:"};
uchar tab2[]={"比例系数为: "};
uchar tab3[]={"K=10 "};
void delay(unsigned int t)
{
while(t>0) t--;
}
/*----------------LCD写位操作0 -----------------*/
void wr_byte0()
{
sclk=0;
std=0;
delay(1);
sclk=1;
std=0;
delay(2);
sclk=0;
std=0;
delay(1);
}
/*----------------LCD写位操作1 -----------------*/
void wr_byte1()
{ sclk=0;
std=0;
delay(1);
std=1;
sclk=1;
delay(2);
sclk=0;
std=0;
delay(1);
}
void lcd_wcmd(uchar dat_comm, uint content)
{
uint i,j;
sclk=0;
std=0;
delay(1);
for(i=0;i<5;i++)
wr_byte1();
wr_byte0();
if(dat_comm)
wr_byte1(); //data
else
wr_byte0(); //comman
wr_byte0();
for(j=0;j<2;j++)
{
for(i=0;i<4;i++)
{
if(content&0x80)
wr_byte1();
else
wr_byte0();
content=content<<1;
}
for(i=0;i<4;i++)
wr_byte0();
}
delay(3);
}
/******************************************************************/
/* 液晶初始化-字库 */
/******************************************************************/
void lcd_init_() //LCD字库初始化程序
{
CSOUT;
SIDOUT;
CLKOUT;
RSTOUT;
RST0;
delay(100);
RST1;
lcd_wcmd (comm,0x30);//30---基本指令动作
lcd_wcmd (comm,0x01); // 清屏,地址指针指向00H
lcd_wcmd (comm,0x06); //光标的移动方向
lcd_wcmd (comm,0x0a); //开显示,关游标
}
void lcd_pos(uchar X,uchar Y)
{
uchar pos;
if(X==0)
{X=0x80;}
else if(X==1)
{X=0x90;}
else if(X==2)
{X=0x88;}
else if(X==3)
{X=0x98;}
pos=X+Y;
lcd_wcmd(comm,pos);
}
void clrram ()
{
lcd_wcmd(comm,0x34);
delay(5);
lcd_wcmd (comm,0x30);
delay(5);
lcd_wcmd (comm,0x01);
delay(5);
}
void chn_disp (uchar *chn)
{
uchar i,j;
lcd_wcmd (comm,0x30);
lcd_wcmd (comm,0x80);
for (j=0;j<4;j++)
{
for (i=0;i<16;i++)
lcd_wcmd (datt,chn[j*16+i]);
}
}
// void chn_dat(int f)
// {
// int K;
// volatile int c;
// K=10;
// c=K/f;
// printf("c=%d/n,c");
// }
/******************************************************************/
/* 主程序 */
/******************************************************************/
void main(void)
{ InitSysCtrl();
InitPieCtrl();
InitPieVectTable();
InitGpio();
delay(1000);
clrram();
delay(0xffff);
lcd_init_();
while(1)
{
lcd_pos(0,0);
//for (i=0;i<16;i++)
{
chn_disp(tab2);
delay(1000);
}
lcd_pos(1,0);
{
//for (i=0;i<16;i++)
chn_disp(tab1);
delay(1000);
}
/*lcd_pos(3,0);
{
chn_dat(5);
delay(1000);
}*/
/* lcd_pos(3,0);
{
chn_disp(tab3);
delay(0xffff);
}*/
for(i=0;i<50;i++)
{
delay(0xffff);
}
clrram();
}
}
目的就是想让他分行显示,控制每一行怎么显示,可是老是显示乱码,不知道问题出在哪里,还望大神赐教!! |