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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)LCD實(shí)驗(yàn)1

          單片機(jī)LCD實(shí)驗(yàn)1

          作者: 時(shí)間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
          代碼如下:
          //filename:global.h
          #include
          //#include
          //#include
          #define uchar unsigned char
          #define uint unsigned int
          //filename:T6963C.H
          #define DATA_PORT P0
          //-------------------------------------------
          // 管腳定義
          //------------------------------------------
          sbit CD=P2^0; //數(shù)據(jù)(L)/命令(H)選擇
          sbit WRIT=P2^1; //寫,低電平有效
          sbit CE=P2^2; //使能,低電平有效
          //===========================================
          // 函數(shù)聲明
          //-------------------------------------------
          void delay_lcd(char);
          void write_data(char);
          void write_text(char);
          void write_com(char);
          void clr_lcd(char,char,int);
          void lcd_init_graph();
          void lcd_init_text();
          void text_out(char a);
          int asc2lcd(int asc);
          //--------------------------------------------
          // 寫數(shù)據(jù)函數(shù)
          //--------------------------------------------
          void write_data(char dat){
          CD=0; //數(shù)據(jù)
          CE=0; //LCD使能
          WRIT=0; //寫
          DATA_PORT=dat; //把數(shù)據(jù)送到P口
          delay_lcd(1); //當(dāng)晶振較高時(shí)加延時(shí)
          WRIT=1; //關(guān)寫
          CE=1; //關(guān)使能
          }
          //--------------------------------------------
          // 寫數(shù)據(jù)函數(shù)
          //--------------------------------------------
          void write_text(char text){
          CD=0; //數(shù)據(jù)
          CE=0; //LCD使能
          WRIT=0; //寫
          DATA_PORT=text; //把數(shù)據(jù)送到P口
          delay_lcd(1); //當(dāng)晶振較高時(shí)加延時(shí)
          WRIT=1; //關(guān)寫
          CE=1; //關(guān)使能
          }
          //--------------------------------------------
          // 寫命令函數(shù)
          //--------------------------------------------
          void write_com(char com){
          CD=1; //命令
          CE=0;
          WRIT=0;
          DATA_PORT=com;
          delay_lcd(1); //當(dāng)晶振較高時(shí)加延時(shí)
          WRIT=1;
          CE=1;
          }
          void clr_lcd(char x,char y,int length){
          int i,place;
          place=x*30+y;
          write_data(place&0xff);
          write_data(place/256);
          write_com(0x24); //設(shè)置
          for(i=0;i
          write_data(0xff); //寫入空格,清屏
          write_com(0xb2); //關(guān)閉自動(dòng)寫
          }
          //--------------------------------------------
          // LM4229初始化函數(shù)
          //--------------------------------------------
          void lcd_init_graph(){
          write_data(0); //圖形首地址
          write_data(0);
          write_com(0x42); //圖形首地址設(shè)置
          write_data(30);
          write_data(0);
          write_com(0x43); //圖形區(qū)域設(shè)置
          write_com(0x80); //設(shè)置為OR模式
          write_com(0x98); //關(guān)閉文本顯示,開圖形顯示
          }
          //--------------------------------------------
          // LM4229初始化函數(shù)
          //--------------------------------------------
          void lcd_init_text(){
          write_data(0);
          write_data(0);
          write_com(0x40); //set text home address
          write_data(30);
          write_data(0);
          write_com(0x41); //set text area;
          write_com(0x84); //text attribute mode
          write_com(0x94); //text on graphic off
          }
          void cursor_on(){
          write_com(0xA0);
          write_com(0x93);
          write_com(0x94); //text on graphic off
          }
          void print_text(char x,char y,char a){
          int place;
          place=x*30+y;
          write_data(place&0xff); //寫地址低8位
          write_data(place/256); //寫地址高8位
          write_com(0x24); //設(shè)置地址
          write_com(0xb0); //設(shè)置數(shù)據(jù)自動(dòng)寫
          write_text(a);
          write_com(0xb2); //自動(dòng)復(fù)位
          }
          void text_out(char a){
          write_com(0xb0); //設(shè)置數(shù)據(jù)自動(dòng)寫
          write_text(a);
          write_com(0xb2); //自動(dòng)復(fù)位
          }
          void text_location(int place){
          write_data(place&0xff); //寫地址低8位
          write_data(place/256); //寫地址高8位
          write_com(0x24); //設(shè)置地址
          }
          void print_string(char* str){
          int i;
          int ch;
          for(i=0;str[i]!=0;i++)
          {
          ch=asc2lcd(str[i]);
          text_out(ch);
          }
          }
          //--------------------------------------------
          // 延時(shí)函數(shù)
          //--------------------------------------------
          void delay_lcd(uchar t){
          for(;t!=0; t--);
          }
          //===================================================
          int asc2lcd(int asc){
          uint r;
          r=asc-32;
          return r;
          }
          //latest revise:2010-2-11
          //by:alex shoal
          //email:alex.shoal@gmail.com
          main(){
          int place=5;
          char ch=0x00;
          lcd_init_text();
          text_location(place);
          print_string("Hello,china! ");
          while(1);
          }



          關(guān)鍵詞: 單片機(jī)LCD實(shí)

          評論


          技術(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); })();