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

📄 1602.txt

📁 51单片机实现1602的驱动,可以显示数字,程序很简单不过很通用
💻 TXT
字号:
#include "at89x52.h"
#include "intrins.h"
#define  uchar unsigned char
#define data P0
/********************************************************/
sbit RS = P2^7;  
sbit RW = P2^6;
sbit E =  P2^5;

/********************************************************/

void init_lcd(void);           //lcd init function
void display(uchar position,char *c3);    // the function to display the strings
void write_calculate(char *c1);//the function to calculate the format
         //of the strings
void write_lcd(char c2);      //the function to process the strings
void delay(unsigned int time);        //the delay to avoid the busy time
void command(uchar function);   //to enable special function
void print_me(uchar position,char *string);   //the interface of the lcd driver

void main(void)               //the main function
{
   char work[]="Hello world";
   char work2[]="JudeKimi";
   init_lcd();
   while(1)
   {
    print_me(0x03,work);
  
delay(3);
print_me(0x43,work2);
   }
}

////////////////////////////////////////////////////////////
void delay (unsigned int time)  
{
      while(time!=0) time--;  //10us per
}

///////////////////////////////////////////////////////////

void print_me(uchar position,char * string)
{
  delay(1000);     //after a time the lcd will initialize             
  
  display(position,string);
}

//////////////////////////////////////////////////////////

void init_lcd()  //the initilalization of the lcd function
{
command(0x01);     //to clear the lcd it is needed by most 1602
      //it often cost 1.64ms 
delay(300);
command(0x38);     //set lcd 2 line display 5*10 dot cost 40us

delay(10);

command(0x0c);     //set lcd on cursor off cost 40us
delay(10);
command(0x06);     //regist ac auto ++ , never goes the picture
}
/////////////////////////////////////////////////////////////////
void command(uchar function)
{
  data=function;    //put the command to P0
  RS=0;       //when the RS RW is low it switch to
  RW=0;      // write command mode
  E=1;
  delay(3);     //when E jump from high to low command excuted
  E=0;
}
/////////////////////////////////////////////////////////////////
void display(uchar position,char *c3)    // the function to display the strings
{
command((0x80+position));    // set the position of screen 
//...........screen....................//
//00h 01h 02h 03h 04h 05h 06h . . . . 27h
//40h 41h . . . . . . . . . . . . .. .67h
write_calculate(c3);

}
/////////////////////////////////////////////////////////////////
void write_calculate(char *c1)
{
  while(*c1!=0)
{
write_lcd(*c1);
c1++;
  }
}
/////////////////////////////////////////////////////////////////
void write_lcd(char c2)
{
  P0=c2;
  RS=1;RW=0;E=1;
  delay(2);
  E=0;
  //delay(100);    //to avoid a serial of writing!
}

⌨️ 快捷键说明

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