这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 12864液晶屏驱动源码线路见sbit

共2条 1/1 1 跳转至

12864液晶屏驱动源码线路见sbit

助工
2012-05-28 13:13:47     打赏

sbit CS=P1^0;    //RS
sbit SID=P1^1;  //RW
sbit SCLK=P1^2;   //E
sbit CH = P1^3;      //PSB
sbit RST=P1^4; 
void delay(unsigned int t);
void sendbyte(unsigned char zdata);
void write_com(unsigned char cmdcode);
void write_data(unsigned char Dispdata);
void lcdinit();
void lcd_char(unsigned char code *s);
unsigned int lcd_data(int g);
void Test();
void delay(unsigned int t)
{
 unsigned int i,j;
 for(i=0; i<t;  i++)
    for(j=0; j<10; j++);
}

void sendbyte(unsigned char zdata)
{
 unsigned int i;
 for(i=0; i<8; i++)
 {
  if((zdata << i) & 0x80)
  {
   SID = 1;
  }
  else
  {
   SID = 0;
  }
  SCLK = 0;
  SCLK = 1;
 }
}

void write_com(unsigned char cmdcode)
{
 CS = 1;
 sendbyte(0xf8);
 sendbyte(cmdcode & 0xf0);
 sendbyte((cmdcode << 4) & 0xf0);
 delay(2);
}

void write_data(unsigned char Dispdata)
{
 CS = 1;
 sendbyte(0xfa);
 sendbyte(Dispdata & 0xf0);
 sendbyte((Dispdata << 4) & 0xf0);
 delay(2);
}

void lcdinit()

 RST = 0;
 delay(100);
 RST = 1;
 delay(20000);
 write_com(0x30);
 delay(50);
 write_com(0x0c);
 delay(50);
}

void lcd_char(unsigned char code *s)

 while(*s > 0)
    {
  write_data(*s);
  s++;
  delay(50);
    }
}

unsigned int lcd_data(int g)
{
unsigned int thousand,handred,ten,ge,databit;
databit=0;
thousand=(int)(g/1000);handred=((int)(g/100))%10;ten=((int)(g/10))%10;ge=((int)(g))%10;
if(g<0)write_data(0x2d);databit++;
    if(thousand)write_data(thousand+0x30);databit++;
  if(handred)write_data(handred+0x30);databit++;
  if(ten)write_data(ten+0x30);databit++;
  write_data(ge+0x30);databit++;
  if(databit%2)return databit/2;
  else return (int)(databit/2)+1;
}

void Test()
{  unsigned int temp;
 write_com(0x03);
 delay(50); 
   
 write_com(0x80);
 lcd_char("电子产品世界");
 write_com(0x90);
 lcd_char("发帖换工具书");
 write_com(0x88);
 lcd_char("ulan");
 }




关键词: 12864     液晶屏     驱动     源码     路见     delay         

高工
2012-05-28 15:36:53     打赏
2楼
什么情况?

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]