⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.txt

📁 8线lcd1602的程序
💻 TXT
字号:
#include " reg51.h "
#include " intrins.h "
#define uchar unsigned char
#define uint unsigned int
/********************************************************************/
uchar code ASCII[]={"0123456789ABCDEFnnnnnnnnnnnn"};//=temp|0x30
//lcd1602
#define  LCDIO     P0
sbit LCD1602_RS=P1^0;
sbit LCD1602_RW=P1^1;
sbit LCD1602_EN=P1^2;

//*****************************************
void Delay(unsigned char i)
{
 while(i--);
}

/******************** LCD 显示部分开始 *************************************/
//****************************************************************************

/********************************************************************/
void LCD_en_command(unsigned char command)
{
 LCDIO=command;
 LCD1602_RS=0;
 LCD1602_RW=0;
 LCD1602_EN=0;
 Delay(5);
 LCD1602_EN=1;
}
/********************************************************************/
void LCD_en_dat(unsigned char dat)
{
 LCDIO=dat;
 LCD1602_RS=1;
 LCD1602_RW=0;
 LCD1602_EN=0;
 Delay(5);
 LCD1602_EN=1;
}
/********************************************************************/
void LCD_set_xy( uchar x, unsigned char y )
{
 unsigned char address;
 if (y == 0)
  address = 0x80 + x;
 else
     address = 0xC0 + 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)
{
 LCD_en_command(0x01);//clear screen
 LCD_en_command(0x38);//set 8 bit data transmission mode
 LCD_en_command(0x0c);//open display (enable lcd display)
 LCD_en_command(0x80);//set lcd first display address
 LCD_en_command(0x01);//clear screen
}
/********************lcd显示结束************************************************/

/******************* OTHER PART ***********************************/
void delay_nms(unsigned int n)
{
    unsigned int i=0,j=0;
    for (i=n;i>0;i--)
     for (j=0;j<1140;j++)
      ;
}


void main()
{
 unsigned char temp;
  LCD_init();
 while(1)
 {

  LCD_write_string(0x00,0,"AT24C02 TEST");
     LCD_write_char(0x0e,0,ASCII[2]);
     LCD_write_char(0x0f,0,(temp%10)|0x30);
     LCD_write_string(0x00,1,"TIMER0 JISHU");
     LCD_write_char(0x0e,1,(200/10)|0x30);
     LCD_write_char(0x0f,1,(300%10)|0x30);

 }
}
/***********************************************************************/



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -