1602 of 51 programs

Publisher:美梦小狮子Latest update time:2016-10-30 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include

#include
#include
#define lcd_bus P0 // data bus
sbit rs =P2^4; // data & instruction selection, H: write data, L: write instruction
sbit rw =P2^3; // read & write selection, H:read, L:write
sbit e =P2^2; // read and write enable
sbit bf =P0^7; // busy and idle status flag, H: internal execution, L: idle
void chk_busy(void); // detect LCD busy and idle
void init_lcd(void); // LCD initialization
void wr_comm(unsigned char comm); // write instruction
void wr_comm_no(unsigned char comm); // write instruction, do not detect busy and idle
void wr_da ta(unsigned char dat); // write data
void wr_str(unsigned char *p); // Display string
unsigned char rd_lcd(void); // Read LCD data
void delayus(unsigned char us); // Delay subroutine us
void delayms(unsigned int ms); // Delay subroutine ms

void main()
{
  delayms(200);
  init_lcd(); // LCD initialization
  wr_comm(0x80); // The first character address of the first line
  wr_str("lcd1602");
  wr_comm(0xc0); // The first character address of the second line
  wr_str("Tai shan Dizn Zi");
  while(1);
}
/*------------------LCD initialization-----------------*/
void init_lcd(void)
{
  wr_comm_no(0x38); // Do not detect busy or idle
  delayms(5);
  wr_comm_no(0x38);
  delayms(5);
  wr_comm_no(0x38);
  delayms(5);
  wr_comm_no(0x38);
  delayms(5);
  wr_comm(0x38); // Set LCD to 16*2 display, 5*7 dot matrix, 8-bit data interface, detect busy signal
  delayus(3); // Delay 11us
  wr_comm(0x08); // Turn off the display, detect the busy signal
  delayus(3);
  wr_comm(0x01); // Clear the screen, detect the busy signal
  delayus(3);
  wr_comm(0x06); // Display cursor automatically moves right, the whole screen does not move, detect the busy signal
  delayus(3);
  wr_comm(0x0c); // Turn on the display, do not display the cursor, detect the busy signal
  delayus(3);
}
/*--------------Detect LCD busy---------------*/
void chk_busy(void)
{
  lcd_bus=0xff;
  rs=0;
  rw=1;
  ;
  e=1;
  while(bf==1);
  e=0;
}
/*------------Write command to LCD--------------*/
void wr_comm(unsigned char comm)
{
  chk_busy();
  rs=0; // H: write data, L: write instruction
  rw=0;
  e=0;
  ;
  lcd_bus=comm; // content
  delayus(3);
  e=1;
  ;
  e=0;
}
/*------------write command to LCD without detecting busy/idle--------------*/
void wr_comm_no(unsigned char comm)
{
  rs=0; // H: write data, L: write instruction
  rw=0;
  e=0;
  ;
  lcd_bus=comm; // content
  delayus(3);
  e=1;
  ;
  e=0;
}
/*------------write data to LCD--------------*/
void wr_dat (unsigned char dat)
{
  chk_busy();
  rs=1; // H: write data, L: write instruction
  rw=0;
  e=0;
  ;
  lcd_bus=dat; // content
  delayus(3);
  e=1;
  ;
  e=0;
}
/*--------------read LCD data---------------*/
unsigned char rd_lcd(void)
{
  unsigned char rd_da ta;
  chk_busy(); // Detect busy
  rs=1;
  rw=1;
  e=1;
  ;
  rd_da ta=lcd_bus;
  e=0;
  return rd_da ta;
}
/*-------------write string----------------*/
void wr_str(unsigned char *s)
{
   while(*s>0) // the string ends with 0
   {
      wr_data (*s);
      s++;
   }
}
/*---------------delay subroutine us----------------*/
void delayus(unsigned char us)
{
  while(--us); // a cycle of 2us
}
/*---------------ms delay subroutine----------------*/
void delayms(unsigned int ms) //delay n ms
{
  while(ms)
  {
  int i;
  i=110;
  while(i--);
  ms=ms-1;
  }
}

Reference address:1602 of 51 programs

Previous article:12864 (with font library) Display graphics and Chinese characters-51 program
Next article:ATMEGA16 serial port sending and interrupt receiving CVAVR program

Recommended ReadingLatest update time:2024-11-16 12:49

1602 LCD simple display program
The 1602 LCD manual provides an initialization process. Since the "busy" bit is not detected, the program is relatively complicated. We have summarized a simpler and more convenient process for everyone. The one described in the manual is just for your understanding. Below I will write out the program for everyone to
[Microcontroller]
LCD1602 scrolling display program
******************************************LCD1602 header file************************************/ #ifndef _LCD1602_H_ #define _LCD1602_H_ //Input mode settings #define LCD_AC_AUTO_INCREMENT 0x06 //After data read and write operations, AC automatically increases by one #define LCD_AC_AUTO_DECREASE 0x04 //After data
[Microcontroller]
LCD1602 (taking 51 single chip microcomputer as an example)
introduce Meaning of the name The 16 in the name of LCD1602 stands for a maximum of 16 characters in one line, and the 2 stands for two lines. Pin Description Take my LCD1602 as an example. VSS: S=series means common connection, usually refers to the voltage of the common ground terminal of the circuit. VDD: D=de
[Microcontroller]
LCD1602 (taking 51 single chip microcomputer as an example)
MCU high efficiency code reading 18B20 displayed on LCD1602
#include STC89C5xRC.H #include intrins.h sbit DATA_IO = P3^2; /* 软件延时函数,延时时间(t*10)us */ void DelayX10us(unsigned char t) {     do {         _nop_();         _nop_();         _nop_();         _nop_();         _nop_();         _nop_();         _nop_();         _nop_();     } while (--t); } bit GetACK() {         bit a
[Microcontroller]
MCU high efficiency code reading 18B20 displayed on LCD1602
PIC microcontroller DS18B20 sampling LCD1602 display
#include "18b20.h"  #include "main.h"  //--------------Generate reset pulse--------------------//  void tx_reset()  {      ADCON1=0X06;      TR ISA 5=0;     DQ=1;      delay_us2(10,5); //65us      while(!DQ); //Judge whether the bus is busy      DQ=0;      delay_us2(10,23); //730us  }  //----------------Waiting for t
[Microcontroller]
ATMEGA16 driver 1602 LCD program
The following table shows   the hardware connection between 16*2 LCD and  MCU : 1 VSS Grounding 2 V CC Connect to power supply , +5V 3 VO Adjust the visibility, ground it 4 RS Register selection, 1-data, 0-instruction 5 R/W Read/write selection, 1-read, 0-write. If the LCD function does not use
[Microcontroller]
Design of LCD1602 electronic clock based on single chip microcomputer
Learning tasks: (1) Basic understanding of LCD1602 (2) Using LCD1602 to realize minute and second timing based on 51 single chip microcomputer; (3) Using buttons to control the adjustment of minutes and seconds (two buttons control the increase of minutes and seconds respectively); (4) Able to realize the function of
[Microcontroller]
Proteus MCU simulation LCD1602 small example
Original address: Proteus MCU simulation LCD1602 small example Author: Lele #include reg52.h #define uchar unsigned char #define uint unsigned int uchar code table ="CHINA !";//The first line displays the string uchar code table1 ="SHANGHAI yaohua";//The second line displays the string sbit lcden=P3^4;
[Microcontroller]
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号