Our Latest News

lcd1602 only bright not display_lcd1602 simple display program

lcd1602 only bright not display

LCD1602 LCD is a widely used character LCD module, usually used with a microcontroller, the microcontroller to control the content of the display, so when encountered lcd1602 only light does not show how to do? The following teaches you a few check methods.

  1, check whether the hardware short / short circuit, with a digital multimeter red and black meter pen point to the LCD1602 power and ground pins respectively, that is, as shown in the figure VCC and GND pins.

2, power on the measurement of power supply voltage is normal, power on the digital multimeter red and black pens are point to the LCD1602 VCC and GND two pins, observe the digital multimeter reading is 5V (commonly used 5V voltage supply) measurement as shown in the figure two points position.

  3, check whether the minimum system of the microcontroller is working properly, using an oscilloscope to measure whether the crystal circuit of the microcontroller is oscillating, the microcontroller, crystal and other components are well welded.

  4, check the LCD1602 connected to the line whether there is a disconnected line or poor contact interface, may also be the cause of damage to the line, using a digital multimeter conductivity measurement gear to measure the line and wiring is normal conductivity.

  5, the above hardware are checked normal no problem to check the driver, check whether the driver is correct, as shown in the figure.

lcd1602 simple display program

The lcd1602 LCD manual provides an initialization process, because it does not detect the “busy” bit, so the procedure is more complicated, and we summarize a more simple and convenient process to provide you with that described in the manual, you can simply as an understanding, the following I write out the procedure for everyone to see, our initialization only used 4 statements, not as tedious as the manual introduced.

#include 《reg52.h》

  #define LCD1602_DB P0

  sbit LCD1602_RS = P1^0;

  sbit LCD1602_RW = P1^1;

  sbit LCD1602_E = P1^5;

  void InitLcd1602();

  void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str);

  void main(){

  unsigned char str[] = “Kingst Studio”;

  InitLcd1602();

  LcdShowStr(2, 0, str);

  LcdShowStr(0, 1, “Welcome to KST51”);

  while (1);

  }

/* Waiting for LCD to be ready */

void LcdWaitReady(){

  unsigned char sta;

  LCD1602_DB = 0xFF;

  LCD1602_RS = 0;

  LCD1602_RW = 1;

  do {

  LCD1602_E = 1;

sta = LCD1602_DB; //read status word

 LCD1602_E = 0;

}while (sta & 0x80); //bit7 equals to 1 means the LCD is busy, repeat the detection until it equals to 0

  }

  /* Write one byte command to LCD1602 LCD, cmd-command value to be written */

 void LcdWriteCmd(unsigned char cmd){

  LcdWaitReady();

  LCD1602_RS = 0;

  LCD1602_RW = 0;

  LCD1602_DB = cmd;

  LCD1602_E = 1;

  LCD1602_E = 0;

  }

/* Write one byte of data to LCD1602 LCD, date-the data value to be written */

void LcdWriteDat(unsigned char dat){

  LcdWaitReady();

  LCD1602_RS = 1;

  LCD1602_RW = 0;

  LCD1602_DB = dat;

  LCD1602_E = 1;

  LCD1602_E = 0;

  }

/* Set the display RAM start address, i.e. the cursor position, (x, y) – corresponding to the character coordinates on the screen */

void LcdSetCursor(unsigned char x, unsigned char y){

  unsigned char addr;

if (y == 0){ // Calculate the address of the display RAM from the input screen coordinates

  addr = 0x00 + x; //first line of characters address from 0x00

  }else{

  addr = 0x40 + x; //the second line of characters starts at 0x40

  }

  LcdWriteCmd(addr | 0x80); //set the RAM address

  }

/* Show the string on the LCD, (x, y) – corresponding to the starting coordinates on the screen, str – string pointer */

  void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str) {

  LcdSetCursor(x, y); //Set the starting address

  while (*str ! = ”){ //write string data continuously until the end character is detected

  LcdWriteDat(*str++); //fetch the data pointed to by str first, then str adds 1 to itself

  }

  }

/* Initialize 1602 LCD */

  void InitLcd1602() {

  LcdWriteCmd (0x38); //162 display, 57 dot matrix, 8-bit data interface

  LcdWriteCmd (0x0C); //Display on, cursor off

  LcdWriteCmd (0x06); //text does not move, address automatically +1

  LcdWriteCmd (0x01); //clear screen

  }

LcdWriteDat(*str++) is a line of pointer str, you must understand the operation of str. This is a very common way of abbreviation. There are a few other points about this program that are worth mentioning.

  First, we modularized all the functions of the program using functions, which is very good for the maintenance of the program, no matter what kind of function you want to write, just call the corresponding function, so pay attention to learn this programming method.

  Second, we are used to using liquid crystal, but also the mathematical (x, y) coordinates for screen positioning, but different from the mathematical coordinate system is that the coordinates of the upper left corner of the liquid crystal is x = 0, y = 0, to the right is x + offset, the lower side is y + offset.

  Third, the first contact with multiple parameters passed function, and also with a pointer type of parameters, so pay more attention to familiarize yourself with.

  Fourth, read and write data and instruction procedures, each time must be “busy” judgment.

  Fifth, to appreciate the clever use of pointers in this place, you can try to rewrite the program without pointers to try to feel the advantages of pointers.

    GET A FREE QUOTE

    FPGA IC & FULL BOM LIST

    We'd love to

    hear from you

    Highlight multiple sections with this eye-catching call to action style.

      Contact Us

      Exhibition Bay South Squre, Fuhai Bao’an Shenzhen China

      • Sales@ebics.com
      • +86.755.27389663