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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 液晶顯示屏模塊1602驅(qū)動程序源代碼

          液晶顯示屏模塊1602驅(qū)動程序源代碼

          作者: 時間:2011-11-17 來源:網(wǎng)絡(luò) 收藏

          模塊源代碼

          //lcd1602 drive program for 51 mcu
          //designed by Wangchao
          //2006-6-14

          #i nclude "reg52.h"
          /********************************************************************/
          //lcd part
          #define LINE10
          #define LINE21
          #define LINE1_HEAD0x80
          #define LINE2_HEAD0xC0
          #define LCD_DELAY_TIME40
          #define DATA_MODE0x38
          #define OPEN_SCREEN0x0C
          #define DISPLAY_ADDRESS0x80
          #define CLEARSCREENLCD_en_command(0x01)
          //common part
          #define HIGH1
          #define LOW 0
          #define TRUE 1
          #define ZERO 0

          /*******************************************************************/
          //change this part at different board
          #define LCDIOP2
          sbit LCD1602_RS=P0^7;//data command select1 data0 commandpin 4
          sbit LCD1602_RW=P0^6;//read write select1 read 0 write pin 5
          sbit LCD1602_EN=P0^5;//LCD enable signal pin 6

          /********************************************************************/
          void LCD_delay(void);//lcd delay
          void LCD_en_command(unsigned char command);//write command
          void LCD_en_dat(unsigned char temp);//write data
          void LCD_set_xy( unsigned char x, unsigned char y );//set display address
          void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);//write lcd a character
          void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);//write lcd string
          void LCD_init(void);//lcd initize

          /********************************************************************/
          void delay_nms(unsigned int n);//delay

          /********************************************************************/
          void main(void)
          {
          LCD_init();
          while(TRUE )
          {
          CLEARSCREEN;

          delay_nms(2);
          LCD_write_string(0,LINE1,"Wellcome to DLUT");
          LCD_write_string(0,LINE2,"www.dlut.edu.cn!");

          delay_nms(500);

          CLEARSCREEN;

          delay_nms(2);
          LCD_write_string(0,LINE1," lcd test ");
          LCD_write_string(0,LINE2," successful! ");

          delay_nms(500);

          CLEARSCREEN;

          delay_nms(2);
          LCD_write_string(0,LINE1," I'm WangChao. ");
          LCD_write_string(0,LINE2," Thank You! ");

          delay_nms(500);
          }
          }
          /********************************************************************/
          /******************** LCD PART *************************************/
          void LCD_delay(void)
          {
          unsigned char i;
          for(i=LCD_DELAY_TIME;i>ZERO;i--) //be sure lcd reset
          ;
          }
          /********************************************************************/
          void LCD_en_command(unsigned char command)
          {
          LCDIO=command;
          LCD1602_RS=LOW;
          LCD1602_RW=LOW;
          LCD1602_EN=LOW;
          LCD_delay();
          LCD1602_EN=HIGH;
          }
          /********************************************************************/
          void LCD_en_dat(unsigned char dat)
          {
          LCDIO=dat;
          LCD1602_RS=HIGH;
          LCD1602_RW=LOW;
          LCD1602_EN=LOW;
          LCD_delay();
          LCD1602_EN=HIGH;
          }
          /********************************************************************/
          void LCD_set_xy( unsigned char x, unsigned char y )
          {
          unsigned char address;
          if (y == LINE1)
          address = LINE1_HEAD + x;
          else
          address = LINE2_HEAD + x;
          LCD_en_command(address);
          }
          /********************************************************************/
          void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
          {
          LCD_set_xy( x, y );
          LCD_en_dat(dat);
          }
          /********************************************************************/
          void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
          {
          LCD_set_xy( X, Y ); //set address
          while (*s) // write character
          {
          LCDIO=*s;
          LCD_en_dat(*s);
          s ++;
          }
          }
          /********************************************************************/
          void LCD_init(void)
          {
          CLEARSCREEN;//clear screen
          LCD_en_command(DATA_MODE);//set 8 bit data transmission mode
          LCD_en_command(OPEN_SCREEN);//open display (enable lcd display)
          LCD_en_command(DISPLAY_ADDRESS);//set lcd first display address
          CLEARSCREEN;//clear screen
          }
          /********************************************************************/
          /*********************** OTHER PART *********************************/
          void delay_nms(unsigned int n)
          {
          unsigned int i=0,j=0;
          for (i=n;i>0;i--)
          for (j=0;j1140;j++);
          }
          /********************************************************************/

          led顯示器相關(guān)文章:led顯示器原理




          評論


          相關(guān)推薦

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