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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 自制51單片機(jī)常用頭文件(st7920并行方式)

          自制51單片機(jī)常用頭文件(st7920并行方式)

          作者: 時(shí)間:2016-11-10 來(lái)源:網(wǎng)絡(luò) 收藏
          /*--------------------------------------------------------------------------

          ST7920.H

          本文引用地址:http://www.ex-cimer.com/article/201611/317350.htm

          The user function is C51.
          Copyright (c) 1988-2004 Keil Elektronik GmbH sum zhaojun
          All rights reserved.
          --------------------------------------------------------------------------*/
          // 并行方式
          #ifndef __ST7920_H__
          #define __ST7920_H__

          #define uchar unsigned char
          #define uint unsigned int

          sbit LCD_RS = P3^2; // 指令/數(shù)據(jù)選擇
          sbit LCD_RW = P3^3; // 并行讀寫(xiě)選擇信號(hào)
          sbit LCD_EN = P3^4; // 并行使能信號(hào)
          sbit LCD_PSB = P3^5; // 并/串選擇端口:H - 并行;L - 串行
          sbit LCD_RES = P3^6;// LCD復(fù)位,LCD模塊自帶復(fù)位電路。可不接

          #define LCD_DATA P1 // MCU P1<------>LCM
          /*****************************************************
          函 數(shù) 名:void Delay_LCD(void)
          功 能:5ms延時(shí)
          入口參數(shù):無(wú)
          返 回 值:無(wú)
          ****************************************************/
          void Delay_LCD(uint t)
          {
          uint i,j;

          for (i=0; i{
          for (j=0; j<10; j++)
          {
          ;
          }
          }
          }
          /*****************************************************
          函 數(shù) 名:void WriteCommandLCM()
          功 能:向LCM中寫(xiě)入指令
          入口參數(shù):WCLCM
          返 回 值:無(wú)
          ****************************************************/
          void WriteCommandLCM(uchar WCLCM)
          {
          LCD_RS = 0; // 選擇寫(xiě)入指令
          LCD_RW = 0; // 寫(xiě)入
          LCD_EN = 1; // 使能

          LCD_DATA = WCLCM; // 寫(xiě)入指令
          LCD_EN = 0;
          Delay_LCD(5);
          }
          /*****************************************************
          函 數(shù) 名:void WriteDataLCM()
          功 能:向LCM1602中寫(xiě)入數(shù)據(jù)
          說(shuō) 明:將形參WDLCM中的數(shù)據(jù)寫(xiě)入LCM中
          入口參數(shù):WDLCM
          返 回 值:無(wú)
          *****************************************************/
          void WriteDataLCM(uchar WDLCM)
          {
          LCD_RS = 1; // 選擇寫(xiě)入數(shù)據(jù)
          LCD_RW = 0; // 寫(xiě)入
          LCD_EN = 1; //

          LCD_DATA = WDLCM; // 寫(xiě)入數(shù)據(jù)
          LCD_EN = 0;
          Delay_LCD(5);
          }
          /*****************************************************
          函 數(shù) 名:void LCMInit()
          功 能:初始化LCM
          說(shuō) 明:LCM在工作前先要對(duì)顯示屏初始化,否則模塊無(wú)法正常工作
          入口參數(shù):無(wú)
          返 回 值:無(wú)
          *****************************************************/
          void LCMInit(void)
          {
          Delay_LCD(20);
          LCD_PSB = 1; // 選擇并行傳輸方式
          Delay_LCD(20);

          LCD_RES = 0; // 復(fù)位,可不要
          Delay_LCD(1);
          LCD_RES = 1;

          WriteCommandLCM(0x30); // 選擇基本指令集
          Delay_LCD(10);
          WriteCommandLCM(0x0c); // 開(kāi)顯示(無(wú)游標(biāo)、反白)
          Delay_LCD(10);
          WriteCommandLCM(0x01); // 清顯示并設(shè)地址指針為00H
          Delay_LCD(50);
          }
          /*****************************************************
          函 數(shù) 名:void DisplayListChar()
          功 能:向指點(diǎn)的地址寫(xiě)入字符串
          入口參數(shù):x-橫坐標(biāo),y-縱坐標(biāo),s-字符串
          返 回 值:無(wú)
          *****************************************************/
          void DisplayListChar(uchar x, uchar y, uchar code *s)
          {
          uchar add; // 顯示地址

          switch (y) // 顯示地址計(jì)數(shù)
          {
          case 0: add = x + 0x80; break; // 第一行的地址
          case 1: add = x + 0x90; break; // 第二行的地址
          case 2: add = x + 0x88; break; // 第三行的地址
          case 3: add = x + 0x98; break; // 第四行的地址
          default: break;
          }

          WriteCommandLCM(0x30); // 基本指令
          WriteCommandLCM(add); // 寫(xiě)入地址

          while (*s > 0) // 寫(xiě)入字符串
          {
          WriteDataLCM(*s);
          s++;
          Delay_LCD(50);
          }
          }

          /*****************************************************
          函 數(shù) 名:void DisplayPicture()
          功 能:寫(xiě)入一幅128x64的圖片
          入口參數(shù):img - 圖片數(shù)組名
          返 回 值:無(wú)
          *****************************************************/
          //顯示圖片(圖片為公司名稱(chēng))
          void DisplayPicture(uchar code *img)
          {
          uint j = 0;
          uchar x,y;
          // -------------- 上半屏 ----------------
          for (y=0; y<32; y++) // 垂直坐標(biāo)32位
          {
          for (x=0; x<8; x++) // 水平坐標(biāo)16字節(jié)
          {
          WriteCommandLCM(0x36); // 擴(kuò)展指令
          WriteCommandLCM(y+0x80); // 先寫(xiě)入垂直坐標(biāo)
          WriteCommandLCM(x+0x80); // 再寫(xiě)入水平坐標(biāo)

          WriteCommandLCM(0x30); // 基本指令
          WriteDataLCM(img[j++]); // 連續(xù)寫(xiě)入16位數(shù)據(jù)
          WriteDataLCM(img[j++]);
          }
          }
          // --------------- 下半屏 ---------------
          j = 512; // 下半屏起始數(shù)據(jù)

          for (y=0; y<32; y++) // 垂直坐標(biāo)32位
          {
          for (x=0; x<8; x++) // 水平坐標(biāo)16字節(jié)
          {
          WriteCommandLCM(0x36); // 擴(kuò)展指令
          WriteCommandLCM(y+0x80); // 先寫(xiě)入垂直坐標(biāo)
          WriteCommandLCM(x+0x88); // 再寫(xiě)入水平坐標(biāo)

          WriteCommandLCM(0x30); // 基本指令
          WriteDataLCM(img[j++]); // 連續(xù)寫(xiě)入16位數(shù)據(jù)
          WriteDataLCM(img[j++]);
          }
          }
          }

          #endif



          評(píng)論


          技術(shù)專(zhuān)區(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); })();