LCD:1602 display program

Publisher:书香门第Latest update time:2016-10-14 Source: eefocusKeywords:LCD Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include

#include

sbit RS=P3^7;
sbit RW=P3^6;
sbit E=P3^5;
sbit BF=P2^7;


void delay(unsigned char n) //about n(ms) delay
{
  unsigned char i,j,k;
  for(k=0;k     {
   for(j=0;j<10;j++) //about 1ms delay
     {
    for(i=0;i<32;i++) //about 0.1ms delay
     {;}
        }
    }
}

unsigned char test(void) //Busy check, test=1, busy. test=0, data and command operations are possible
{
  bit busy;
  RS=0;
  RW=1;
  E=1;
  _nop_();  
  _nop_()  
  ; _nop_();  
  _nop_();
  busy=BF;
  E=0;
  return busy;  
}

void WriteInstruction(unsigned char dictate)  //写指令、地址
{
  while(test()==1);
  RS=0;
  RW=0;
  E=0;
  _nop_();  
  _nop_();  
  _nop_();
  P2=dictate;
  _nop_();  
  _nop_();  
  _nop_();  
  _nop_();
  E=1;
  _nop_();  
  _nop_();  
  _nop_();  
  _nop_();
  E=0;
}

void wData(unsigned char dat) //写数据
{
  while(test()==1);
  RS=1;
  RW=0;
  E=0;
  _nop_();  
  _nop_();  
  _nop_(); _nop_();
  P2=dat;
  _nop_();   _nop_(
  );  
  _nop_();  
  _nop_();
  E=1;
  _nop_();  
  _nop_();  
  _nop_();  
  _nop_();
  E=0;
}

void WriteAddress(unsigned char x) //write address
{
  unsigned char x1;
  x1=x+0x80;
  WriteInstruction(x1);
// WriteInstruction(x|0x80); // another way to calculate address
}
  
void LcdInitiate(void) //LCD initialization
{
  delay(15);
  WriteInstruction(0x38);
  delay(5);
  WriteInstruction(0x38); 
  delay(5);
  WriteInstruction(0x38); 
  delay(5);

  WriteInstruction(0x0f); //Display setting
  delay(5);
  WriteInstruction(0x06); //Input mode
  delay(5);

  WriteInstruction(0x01);  //清屏
  delay(5);
  
}

main()
{
   unsigned char string[]={"my Computer"};
 unsigned char i=0;
  
  while(1)
   {
    LcdInitiate(); //Initialize  
    WriteAddress(0x02); //Write address, character display position
 i=0;
 while(string[i]!='\0') //Write string from write address
  {
    wData(string[i]); //Write a character
    i++;
    delay(200);
  }
    WriteAddress(0x42); //Write address
 delay(15);
 i=0;
 while(string[i]!='\0') //Write string from write address
  {
    wData(string[i]);
    i++;
    delay(200);
  }


 for(i=0;i<10;i++)
   {
     delay(200);
   } 
  }

}

Keywords:LCD Reference address:LCD:1602 display program

Previous article:C51 Timer/Counter
Next article:c51: Function

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号