工业控制液晶显示器

来源:互联网 发布:单片机和嵌入式关键词 编辑:程序博客网 时间:2024/04/29 08:18

玩了一段时间,算是比较熟悉了,在这共享一下代码啦~

 

//写一个数据子程序:
Write_Byte(uchar dc_data)
{
    uchar xdata DC;   //定义一个外部RAM变量
    //uchar i;
    CS0 = 0;
 DC = dc_data;   //数据dc_data写到外部RAM(即LCD控制板)。
 CS0 = 1;
    //加入适当的空操作延时
 //当采用更高速的单片机时应加入更多的空操作延时
 //这里加上8个空操作延时,在AT89C51,22MHz下是完全没问题的。
    //for(i=0;i<1;i++){} 
}
//读一个字节数据子程序:
uchar Read_Byte(void)
{
    uchar xdata DC;
    CS0 = 0;
 return DC;
}
//////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////
/*
//测试从显示终端机读取时间。
test_timer()
{
  uchar  i;

  Read_date();
  while(Date[0] == 0){}   //等待显示终端机送年月日数据到单片机
  for(i=0;i<3;i++)
  {
     DIS_Value((6*16)+(i*24),32,Date[i+1],2);
  }
  Read_time();
  while(Date[4] == 0){}   //等待显示终端机送时分秒数据到单片机
  for(i=0;i<3;i++)
  {
     DIS_Value((6*16)+(i*24),48,Date[i+5],2);
  }
}
*/
//指令头,每一条指令都规定为"0x81, command1,command2,Fcolor,Bcolor"
command_head(unsigned char command1,unsigned char command2)
{
   Write_Byte(0x81);
   Write_Byte(command1);
   Write_Byte(command2);
   Write_Byte(Fcolor);
   Write_Byte(Bcolor);
}

//清屏子程序
Lcd_Clr()
{
   command_head(0x43,0x4c);
   Write_Byte(0x84);
}
//保存原桌面内容
void COPY_DC()
{
   command_head(0x43,0x44);
   Write_Byte(0x84);
}
//恢复原来桌面
void EXIT_DC()
{
   command_head(0x45,0x44);
   Write_Byte(0x84);
}
Bell()  //打开蜂鸣器。
{
   Write_Byte(0x81);
   Write_Byte(0x42);
   Write_Byte(0x42);
   Write_Byte(0x01);   //设置蜂鸣器的时间
   Write_Byte(0x84);
}
// 清矩形
void Clr_squ(unsigned short x0,unsigned short y0,unsigned short width,unsigned short heith)
{
   command_head(0x43,0x58);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);

   Write_Byte(width/100);
   Write_Byte(width%100);
   Write_Byte(heith/100);
   Write_Byte(heith%100);

   Write_Byte(0x84);
}

// 反色矩形
void inv_squ(unsigned short x0,unsigned short y0,unsigned short width,unsigned short heith)
{
   command_head(0x43,0x4e);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);

   Write_Byte(width/100);
   Write_Byte(width%100);
   Write_Byte(heith/100);
   Write_Byte(heith%100);

   Write_Byte(0x84);
}
/*
//读取年月日
Read_date()
{
     Date[0] = 0;
     command_head(0x52,0x44);
     Write_Byte(0x84);
}
//读取时分秒
Read_time()
{
     Date[4] = 0;
     command_head(0x52,0x54);
     Write_Byte(0x84);
}
*/
//画圆子程序。
DIS_Ellipse(unsigned short x0,unsigned short y0,unsigned short xr,unsigned short yr)
{
   command_head(0x44,0x45);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);
   Write_Byte(xr/100);
   Write_Byte(xr%100);
   Write_Byte(yr/100);
   Write_Byte(yr%100);
   Write_Byte(x0/100);
   Write_Byte(0x84);
}

/*
//画直线子程序。
DIS_Line(unsigned short x0,unsigned short y0,unsigned short x1,unsigned short y1,unsigned short with)
{

   command_head(0x44,0x4c);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);
   Write_Byte(x1/100);
   Write_Byte(x1%100);
   Write_Byte(y1/100);
   Write_Byte(y1%100);
   Write_Byte(with/100);
   Write_Byte(with%100);
   Write_Byte(0x84);
}
*/
//在指定的开始位置(x0,y0)显示字符串子程序。
//当x0大于800且已打开光标功能时在以光标为开始位置显示字符串子程序。
/*DIS_String(unsigned short x0,unsigned short y0,char *fmt)
{

   command_head(0x44,0x57);

   //Write_Byte(0xE0);//字体以红色显示
   //Write_Byte(0x1C);//背景为透明

   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);

   while(*fmt)
   {
     Write_Byte(*fmt);
  fmt++;
   }
   Write_Byte(0x84);
}
*/

//在指定的开始位置(x0,y0)显示字符串子程序。
//当x0大于800且已打开光标功能时在以光标为开始位置显示字符串子程序。
DIS_StringN(unsigned short x0,unsigned short y0,char *fmtn,uchar n)
{
   uchar  i;
   command_head(0x44,0x57);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);

   for(i=0;i   {
      Write_Byte(*fmtn);
    fmtn++;
    }
   Write_Byte(0x84);
}


//在指定的开始位置(x0,y0)显示字符串子程序。
//当x0大于800且已打开光标功能时在以光标为开始位置显示字符串子程序。
DIS_String64(unsigned short x0,unsigned short y0,char *fmt)
{

   command_head(0x54,0x04);

   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);

   while(*fmt)
   {
     Write_Byte(*fmt);
  fmt++;
   }
   Write_Byte(0x84);
}

/*
//显示时间子程序
void Dis_time(unsigned short x0,unsigned short y0,unsigned char i)
{
   command_head(0x44,0x54);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);
   Write_Byte(i);
   Write_Byte(0x84);
}
*/
/*
//设置时间子程序;
//年,月,日,时 ,分,秒,星期。
void Set_time(uchar year,uchar month,uchar day,uchar hour,uchar minute,uchar second,uchar date)
{
   command_head(0x53,0x54);
   Write_Byte(year);
   Write_Byte(month);
   Write_Byte(day);
   Write_Byte(hour);
   Write_Byte(minute);
   Write_Byte(second);
   Write_Byte(date);
   Write_Byte(0x84);
}
*/
/*
//显示变量子程序
DIS_Value(unsigned short x0,unsigned short y0,unsigned short Va,unsigned char i)
{
   command_head(0x44,0x56);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);

   Write_Byte(Va/100);
   Write_Byte(Va%100);
   Write_Byte(i);
   Write_Byte(0x84);
}
*/
//显示位图子程序
DIS_BMP(unsigned short x0,unsigned short y0,uchar N1)
{
   command_head(0x44,0x53);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);
   Write_Byte(N1);
   Write_Byte(0x84);
}
/*
//自动显示位图子程序
AUTO_BMP(unsigned short x0,unsigned short y0,uchar N1,uchar N2,uchar T)
{
   command_head(0x5a,0x44);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);
   Write_Byte(N1);
   Write_Byte(N2);
   Write_Byte(T);
   Write_Byte(0x84);
}
*/
////////////////////////////////////////////////////////////////////////
//显示一个字符
DIS_Byte(unsigned short x0,unsigned short y0,char fmt)
{
   command_head(0x44,0x57);
   Write_Byte(x0/100);
   Write_Byte(x0%100);
   Write_Byte(y0/100);
   Write_Byte(y0%100);
   Write_Byte(fmt);
   Write_Byte(0x84);

原创粉丝点击