<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 自制單片機之五(2)……LCD1602的驅(qū)動

          自制單片機之五(2)……LCD1602的驅(qū)動

          作者: 時間:2016-11-13 來源:網(wǎng)絡(luò) 收藏
          具體電路的制作是很簡單的,就接了兩個電阻,一個是10歐姆的背光限流電阻,另一個是2K的LCD極板電壓調(diào)節(jié)電阻。這兩個電阻的阻值怎么定呢?背光比較簡單,它就相當于在后面接了幾個發(fā)光二極管,任何時候你只要在15、16腳串上個100歐的電位器接上電源,調(diào)節(jié)電位器,覺得亮度合適。此時的阻值便可。LCD液晶極板驅(qū)動電壓調(diào)節(jié)電阻的確定就稍微麻煩一點。在各數(shù)據(jù)線,控制線接好關(guān)通上電源的前提下在第3腳(VEE)和地之間接一個10K的電位器。調(diào)節(jié)電位器。當3腳電壓高時為全亮,電壓為0時為全暗(液晶全顯示為黑塊)。你用電位器把屏幕從全暗剛好調(diào)到變亮。這時便可調(diào)試程序。待屏幕能正確顯示后再細調(diào)電位器,使對比度合適。這時的阻值便可確定,然后換成等值的固定電阻焊上便可。

          我們接著上次的系統(tǒng)板制做:

          本文引用地址:http://www.ex-cimer.com/article/201611/316083.htm
          新買的1602LCD,20元,貴不?
          反面:
          組裝后:
          具體電路圖:
          接口說明:
          運行:
          用戶自定義字符的應(yīng)用:
          我們從CGROM表上可以看到,在表的最左邊是一列可以允許用戶自定義的CGRAM,從上往下看著是16個,實際只有8個字節(jié)可用。它的字符碼是00000000-00000111這8個地址,表的下面還有8個字節(jié),但因為這個CGRAM的字符碼規(guī)定0-2位為地址,3位無效,4-7全為零。因此CGRAM的字符碼只有最后三位能用也就是8個字節(jié)了。等效為0000X111,X為無效位,最后三位為000-111共8個。
          如果我們要想顯示這8個用戶自定義的字符,操作方法和顯示CGROM的一樣,先設(shè)置DDRAM位置,再向DDRAM寫入字符碼,例如“A”就是41H。現(xiàn)在我們要顯示CGRAM的第一個自定義字符,就向DDRAM寫入00000000B(00H),如果要顯示第8個就寫入00000111(08H),簡單吧!
          好!現(xiàn)在我們來看怎么向這八個自定義字符寫入字模。有個設(shè)置CGRAM地址的指令大家還記得嗎?趕快再找出來看看。

          從這個指令可以看出指令數(shù)據(jù)的高2位已固定是01,只有后面的6位是地址數(shù)據(jù),而這6位中的高3位就表示這八個自定義字符,最后的3位就是字模數(shù)據(jù)的八個地址了。例如第一個自定義字符的字模地址為01000000-01000111八個地址。我們向這8個字節(jié)寫入字模數(shù)據(jù),讓它能顯示出“℃”
          地址:01000000  數(shù)據(jù):00010000 圖示:○○○■○○○○
             01000001     00000110 ○○○○○■■○
             01000010     00001001 ○○○○■○○■
             01000011     00001000 ○○○○■○○○
             01000100     00001000 ○○○○■○○○
             01000101     00001001 ○○○○■○○■
             01000110     00000110 ○○○○○■■○
             01000111     00000000 ○○○○○○○○
          下面我們寫一段程序讓這8個自定義字符顯示出一個心的圖案:
          # include
          unsigned char table1[]={0x03,0x07,0x0f,0x1f,0x1f,0x1f,0x1f,0x1f,
          0x18,0x1E,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
          0x07,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
          0x10,0x18,0x1c,0x1E,0x1E,0x1E,0x1E,0x1E,
          0x0f,0x07,0x03,0x01,0x00,0x00,0x00,0x00,
          0x1f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x01,
          0x1f,0x1f,0x1f,0x1f,0x1f,0x1c,0x18,0x00,
          0x1c,0x18,0x10,0x00,0x00,0x00,0x00,0x00};//心圖案
          unsigned char table[]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00};//字符℃
          #define CLEARSCREEN LCD_write_command(0x01)
          /**************定義接口************************/
          #define LCDIO P2
          sbit LCD1602_RS=P3^0;
          sbit LCD1602_RW=P3^1;
          sbit LCD1602_EN=P3^2;
          /**************定義函數(shù)************************/
          void LCD_write_command(unsigned char command);//寫入指令函數(shù)
          void LCD_write_dat(unsigned char dat);//寫入數(shù)據(jù)函數(shù)
          void LCD_set_xy( unsigned char x, unsigned char y );//設(shè)置顯示位置函數(shù)
          void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat);//顯示一個字符函數(shù)
          void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s);//顯示字符串函數(shù)
          void LCD_init(void);//初始化函數(shù)
          void delay_nms(unsigned int n);//延時函數(shù)
          /********************************************/
          /************初始化函數(shù)****************/
          void LCD_init(void)
          {
          CLEARSCREEN;//clear screen
          LCD_write_command(0x38);//set 8 bit data transmission mode
          LCD_write_command(0x0c);//open display (enable lcd display)
          LCD_write_command(0x80);//set lcd first display address
          CLEARSCREEN;//clear screen
          }
          /****************************************************/
          /**************寫指令函數(shù)********************************/
          void LCD_write_command(unsigned char command)
          {
          LCDIO=command;
          LCD1602_RS=0;
          LCD1602_RW=0;
          LCD1602_EN=0;
          LCD1602_EN=1;
          delay_nms(10);
          }
          /***************************************************/
          /****************寫數(shù)據(jù)函數(shù)************************/
          void LCD_write_dat(unsigned char dat)
          {
          LCDIO=dat;
          LCD1602_RS=1;
          LCD1602_RW=0;
          LCD1602_EN=0;
          delay_nms(1);
          LCD1602_EN=1;
          }
          /****************************************************/
          /***************設(shè)置顯示位置**************************/
          void LCD_set_xy( unsigned char x, unsigned char y )
          {
          unsigned char address;
          if (y == 1)
          address = 0x80 + x;
          else
          address =0xc0+ x;
          LCD_write_command(address);
          }
          /***************************************************/
          /****************顯示一個字符**********************/
          void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat)
          {
          LCD_set_xy( x, y );
          LCD_write_dat(dat);
          }
          /**********************************************/
          /***************顯示字符串函數(shù)***************/
          void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s)
          {
          LCD_set_xy( X, Y );
          while (*s)
          {
          LCD_write_dat(*s);
          s ++;
          }
          }
          /***********************************************/
          /********** 延時**********************/
          void delay_nms(unsigned int n)
          {
          unsigned int i=0,j=0;
          for (i=n;i>0;i--)
          for (j=0;j<10;j++);
          }
          /**************************************/
          /***********主函數(shù)**************/
          void main(void)
          {
          unsigned char i,j,k,tmp;
          LCD_init();
          delay_nms(100);
          tmp=0x40;//設(shè)置CGRAM地址的格式字
          k=0;
          for(j=0;j<8;j++)
          {
          for(i=0;i<8;i++)
          {
          LCD_write_command(tmp+i); // 設(shè)置自定義字符的 CGRAM 地址
          delay_nms(2);
          LCD_write_dat(table1[k]); // 向CGRAM寫入自定義字符表的數(shù)據(jù)
          k++;
          delay_nms(2);
          }
          tmp=tmp+8;
          }
          LCD_dsp_string(1,1,"LCD TEST ");//在第一行第一列顯示“LCD TEST”
          LCD_dsp_string(1,2,"SUCCESSFUL ");//在第二行第一列顯示“SUCCESSFUL”
          for (i=0;i<4;i++)
          {
          LCD_dsp_char( 12+i,1,i);//在第一行第12列位置顯示心圖案的上半部
          delay_nms(1);
          }
          for (i=4;i<8;i++)
          {
          LCD_dsp_char( 12+i-4,2,i);在第二行第12列位置顯示心圖案的下半部
          delay_nms(1);
          }
          while (1);
          }
          /********************************************************************/
          實際效果如圖:



          關(guān)鍵詞: 單片機LCD1602驅(qū)

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();