<form id="lpvjh"><nobr id="lpvjh"><th id="lpvjh"></th></nobr></form>

<form id="lpvjh"></form>
<form id="lpvjh"><th id="lpvjh"></th></form>

<form id="lpvjh"></form>

<address id="lpvjh"></address>

    <span id="lpvjh"><th id="lpvjh"></th></span>

      文章詳情

      KS0108控制器12864液晶應用程序

      日期:2021-11-26 12:52
      瀏覽次數:1449
      摘要:

      /*清達光電KS0108控制器12864液晶應用程序*/
      #include <reg52.h>
      #include <stdio.h>
      #include <intrins.h>
      #define uchar unsigned char
      #define uint unsigned int
      #define buslcd P1

      sbit A0=P3^0;      ///////RS
      sbit RW=P3^1;
      sbit E=P3^2;
      sbit CS1=P3^4;
      sbit CS2=P3^5;
      sbit RST=P3^6;

      uchar code tab1[][8]={
       0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00,    /*"H"=28h*/
       0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00,    /*"G"=27h*/
       0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,    /*"1"=11h*/
       0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00,    /*"2"=12h*/
       0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,    /*"8"=18h*/
       0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00,    /*"6"=16h*/
       0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,    /*"4"=14h*/
       0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00,    /*"2"=12h*/
       0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00,    /*"E"=25h*/
       0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00,    /*"D"=24h*/
       0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00,    /*"I"=29h*/
       0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00,    /*"T"=34h*/
       0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00,    /*"O"=2Fh*/
       0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00,    /*"R"=32h*/
       0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,    /*":"=1Ah*/
       0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00,    /*"M"=2Dh*/
       0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00,    /*"R"=32h*/
       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    /*" "=32h*/
       0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00,    /*"L"=2Ch*/
       0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00,    /*"I"=29h*/
       0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00,    /*"U"=35h*/
       0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00,    /*"Q"=31h*/
       0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00,    /*"Q"=31h*/
       0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,    /*":"=1Ah*/
       0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,    /*"4"=14h*/
       0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00,    /*"5"=15h*/
       0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00,    /*"3"=13h*/
       0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,    /*"1"=11h*/
       0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,    /*"8"=18h*/
       0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00,    /*"9"=19h*/
       0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00,    /*"7"=17h*/
       0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00,    /*"3"=13h*/
       0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,    /*"1"=11h*/
      };
      uchar code tab2[][32]={
      /* 點陣:16x16
         提取點陣方向:縱向
         字節掉轉:是
         字節方式:C語言 */
      0x10,0x10,0xD0,0xFF,0x90,0x10,0x08,0xC8,    // 杭
      0x49,0x4E,0x48,0xE8,0x4C,0x08,0x00,0x00,
      0x04,0x03,0x00,0xFF,0x80,0x41,0x20,0x1F,
      0x00,0x00,0x00,0x3F,0x40,0x40,0x70,0x00,

      0x80,0x70,0x00,0xFF,0x00,0x10,0x60,0x00,    // 州
      0xFE,0x00,0x10,0x60,0x00,0xFF,0x00,0x00,
      0x00,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,
      0x3F,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,

      0x10,0x22,0x64,0x0C,0xC0,0x44,0x54,0x54,    // 清
      0x54,0x7F,0x54,0x54,0xD6,0x44,0x40,0x00,
      0x04,0x04,0xFE,0x01,0x00,0x00,0xFF,0x15,
      0x15,0x15,0x55,0x95,0x7F,0x01,0x00,0x00,

      0x40,0x42,0xCC,0x00,0x20,0x20,0x20,0xA0,    // 達
      0x7F,0x20,0x20,0x20,0x30,0x20,0x00,0x00,
      0x40,0x20,0x1F,0x20,0x50,0x48,0x46,0x41,
      0x40,0x41,0x42,0x4C,0x58,0x60,0x20,0x00,

      0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F,    // 光
      0x40,0xC0,0x50,0x48,0x46,0x64,0x40,0x00,
      0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,
      0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,

      0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,    // 電
      0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00,
      0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,
      0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00,

      0x10,0x22,0x64,0x0C,0x80,0x04,0xC4,0x34,    // 液
      0x05,0xC6,0xBC,0x24,0x24,0xE6,0x04,0x00,
      0x04,0x04,0xFE,0x01,0x02,0x01,0xFF,0x42,
      0x21,0x16,0x08,0x15,0x23,0x60,0x20,0x00,

      0x00,0x00,0x00,0x00,0xFF,0x49,0x49,0x49,    // 晶
      0x49,0x49,0xFF,0x00,0x00,0x80,0x00,0x00,
      0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,
      0xFF,0x49,0x49,0x49,0x49,0xFF,0x01,0x00,

      0x00,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,    // 顯
      0x92,0x92,0x92,0xFF,0x02,0x00,0x00,0x00,
      0x40,0x42,0x44,0x4D,0x40,0x7F,0x40,0x40,
      0x40,0x7F,0x40,0x49,0x44,0x66,0x40,0x00,

      0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xC2,    // 示
      0x42,0x42,0x42,0x43,0x42,0x60,0x40,0x00,
      0x00,0x10,0x08,0x04,0x06,0x40,0x80,0x7F,
      0x00,0x00,0x02,0x04,0x0C,0x18,0x00,0x00,

      0x10,0x10,0xD0,0xFF,0x94,0x14,0xE4,0xBF,    // 模
      0xA4,0xA4,0xA4,0xBF,0xF4,0x26,0x04,0x00,
      0x04,0x03,0x00,0xFF,0x08,0x89,0x8B,0x4A,
      0x2A,0x1E,0x2A,0x2A,0x4B,0xC8,0x48,0x00,

      0x20,0x20,0x20,0xFF,0x20,0x20,0x10,0x10,    // 塊
      0xFF,0x10,0x10,0x10,0xF8,0x10,0x00,0x00,
      0x08,0x18,0x08,0x0F,0x84,0x46,0x22,0x1A,
      0x07,0x0A,0x12,0x22,0x43,0xC2,0x42,0x00,
      };

      /************
        延時子程序
      *****************/
      void Delay(uint t)
      {uint i,j;
      for(i=0;i<t;i++)
      for(j=0;j<305;j++)
      _nop_();_nop_();_nop_();_nop_();
      }
      /***********
       忙判斷子程序
      ************/
      void Busy()
      {
       A0=0;
       RW=1;
      buslcd=0xff;
       E=1;
      _nop_();
      while(buslcd&0x80);
      E=0;
      _nop_();
      }
      /*********************
       寫入左半屏指令 子程序
      **********************/
      void Writecom1(uchar wcom)
      {
      CS1=1;CS2=0;
       Busy();
       buslcd=wcom;
       A0=0;
       RW=0;
       E=1;
      _nop_();
        E=0;
      _nop_();}
      /*********************
       寫入左半屏數據 子程序
      **********************/
      void Writedata1(uchar wdata)
      {
      CS1=1;CS2=0;
       Busy();
       buslcd=wdata;
       A0=1;
       RW=0;
       E=1;
      _nop_();
       E=0;
      _nop_();}
      /*********************
       寫入右半屏指令 子程序
      ***********************/
      void Writecom2(uchar wcom)
      {
      CS1=0;CS2=1;
       Busy();
       buslcd=wcom;
       A0=0;
       RW=0;
       E=1;
      _nop_();
        E=0;
      _nop_();}
      /************************
       寫入右半屏數據 子程序
      *************************/
      void Writedata2(uchar wdata)
      {
      CS1=0;CS2=1;
       Busy();
       buslcd=wdata;
       A0=1;
       RW=0;
       E=1;
      _nop_();
       E=0;
      _nop_();}

      /*********************
      讀出左半屏數據 子程序
      **********************/
      uchar Readdata1()
      {
      uchar rdata;
      CS1=1;CS2=0;
       Busy();
       A0=1;
       RW=1;
       E=1;
       rdata=buslcd;
      _nop_();_nop_();_nop_();
       E=0;
      _nop_();
      return rdata;
      }
      /**********************
      讀出右半屏數據 子程序
      ****************************/
      uchar Readdata2()
      {
      uchar rdata;
      CS1=0;CS2=1;
       Busy();
       A0=1;
       RW=1;
       E=1;
       rdata=buslcd;
      _nop_();_nop_();_nop_();
       E=0;
      _nop_();
      return rdata;
      }
      /*********************
          清屏子程序
      ****************************/
      void Clear(void)
      {uchar i,j;
      for(i=0;i<8;i++)
      {Writecom1(0xb8+i);Writecom1(0x40);
      Writecom2(0xb8+i);;Writecom2(0x40);
      for(j=0;j<64;j++)
      {Writedata1(0);Writedata2(0);}}
      }
      /**********************
          液晶初始化子程序
      ***********************/
      void INT()
      {
      Delay(3);
      Writecom1(0x3f);
      Writecom2(0x3f);
      Writecom1(0xc0);
      Writecom2(0xc0);
      Writecom1(0xb8);
      Writecom2(0xb8);
      Writecom1(0x40);
      Writecom2(0x40);
      Clear();
      }
      /*******************************************************
           8*8字體 x,y 為液晶對應地址 coder為字母的字摸
      *******************************************************/
      void display8(uchar x,uchar y,uchar coder)
      {
         uchar i;
         for(i=0;i<8;i++)
         {
         if(x<64)
         {
         Writecom1(0xb8+y);
         Writecom1(0x40+x);
         Writedata1(tab1[coder][i]);
          }
          else
          {
         Writecom2(0xb8+y);
         Writecom2(x);
         Writedata2(tab1[coder][i]);
          }
          x++;
         }
      }

      /*********************************
                8*88寫入 一串
      **************************************************/
      void hz88(uchar x,uchar y,uchar m,uchar mend)
      {
       uchar i;
       for(i=m;i<mend;i++)
       {
       display8(x,y,i); 
       x=x+8;}
      }
      /*****************************************************
          漢字寫入  x,y 為液晶對應地址 coder為漢字的字摸
      *****************************************************/
      void hz11(uchar x,uchar y,uchar coder)
      {
        uchar i,n,m;
        uchar j=1;
        n=x;m=y;
        for(i=0;i<16;i++)
        {
        if(x<64)
         {
         Writecom1(0xb8+y);
         Writecom1(0x40+x);
         Writedata1(tab2[coder][i]);
        }
        else
        {
        Writecom2(0xb8+y);
        Writecom2(x);
        Writedata2(tab2[coder][i]);
        } x++;}
       
        x=n;y=m+1;
        for(i=0;i<16;i++)
        {
        if(x<64)
         {
         Writecom1(0xb8+y);
         Writecom1(0x40+x);
         Writedata1(tab2[coder][i+(j<<4)]);
        }
        else
        {
        Writecom2(0xb8+y);
        Writecom2(x);
        Writedata2(tab2[coder][i+(j<<4)]);
        }x++;}
      }
      /*******************************
      16*16漢字寫入 一串
      ***************************************/
      void hz1616(uchar x,uchar y,uchar m,uchar mend)
      {
       uchar i;
       for(i=m;i<mend;i++)
       {
        hz11(x,y,i);
        x=x+16;}
      }
      /*************
       主程序
      **************/
      void main()
      {
      uchar i;
      RST=0;
      Delay(1);
      RST=1;
      _nop_(); _nop_();
      INT();
       hz1616(16,0,0,6);
       hz1616(16,2,6,12);
       hz88(32,5,0,8);
       hz88(0,6,8,21);
       hz88(0,7,21,33);
      while(1);
      }
       

      新博体育