LCD display module 1602 driver source code

Publisher:rho27Latest update time:2011-11-17 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

LCD display module 1602 driver source code

//lcd1602 drive program for 51 mcu
//designed by Wangchao
//2006-6-14

#i nclude "reg52.h"
/********************************************************************/
//lcd part
#define  LINE1     0
#define  LINE2     1
#define  LINE1_HEAD    0x80
#define  LINE2_HEAD    0xC0
#define  LCD_DELAY_TIME   40
#define  DATA_MODE    0x38
#define  OPEN_SCREEN    0x0C
#define  DISPLAY_ADDRESS   0x80
#define  CLEARSCREEN    LCD_en_command(0x01)
//common part
#define  HIGH   1
#define  LOW    0
#define  TRUE    1
#define  ZERO    0

/*******************************************************************/
//change this part at different board
#define  LCDIO     P2
sbit LCD1602_RS=P0^7;   //data command select  1 data  0 command  pin 4
sbit LCD1602_RW=P0^6;   //read write select   1 read   0 write     pin 5
sbit LCD1602_EN=P0^5;   //LCD enable signal             pin 6

/********************************************************************/
void LCD_delay(void);//lcd delay
void LCD_en_command(unsigned char command);//write command
void LCD_en_dat(unsigned char temp);//write data
void LCD_set_xy( unsigned char x, unsigned char y );//set display address
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);//write lcd a character
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);//write lcd string
void LCD_init(void);//lcd initize

/********************************************************************/
void delay_nms(unsigned int n);//delay

/********************************************************************/
void main(void)
{
LCD_init();
while(TRUE )
{
CLEARSCREEN;

delay_nms(2);
LCD_write_string(0,LINE1,"Wellcome to DLUT");
LCD_write_string(0,LINE2,"www.dlut.edu.cn!");

delay_nms(500);

CLEARSCREEN;

delay_nms(2);
LCD_write_string(0,LINE1,"   lcd test     ");
LCD_write_string(0,LINE2,"   successful!  ");

delay_nms(500);

CLEARSCREEN;

delay_nms(2);
LCD_write_string(0,LINE1," I'm WangChao.  ");
LCD_write_string(0,LINE2,"   Thank You!  ");

delay_nms(500);
}
}
/********************************************************************/
/******************** LCD PART *************************************/
void LCD_delay(void)
{
unsigned char i;
for(i=LCD_DELAY_TIME;i>ZERO;i--)  //be sure lcd reset
;
}
/********************************************************************/
void LCD_en_command(unsigned char command)
{
LCDIO=command;
LCD1602_RS=LOW;
LCD1602_RW=LOW;
LCD1602_EN=LOW;
LCD_delay();
LCD1602_EN=HIGH;
}
/********************************************************************/
void LCD_en_dat(unsigned char dat)
{
LCDIO=dat;
LCD1602_RS=HIGH;
LCD1602_RW=LOW;
LCD1602_EN=LOW;
LCD_delay();
LCD1602_EN=HIGH;
}
/********************************************************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y == LINE1)
address = LINE1_HEAD + x;
else
address = LINE2_HEAD + 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)
{
CLEARSCREEN;//clear screen
LCD_en_command(DATA_MODE);//set 8 bit data transmission mode
LCD_en_command(OPEN_SCREEN);//open display (enable lcd display)
LCD_en_command(DISPLAY_ADDRESS);//set lcd first display address
CLEARSCREEN;//clear screen
}
/********************************************************************/
/*********************** 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++);
}
/********************************************************************/

Reference address:LCD display module 1602 driver source code

Previous article:Operational amplifier design principle and circuit description
Next article:Optimize algorithm design using customizable microcontrollers

Recommended ReadingLatest update time:2024-11-16 17:29

51 MCU drives 1602 LCD assembly language program
LCMRS EQU P2.4 LCMRW EQU P2.5 LCMEN EQU P2.6 LCMDATA EQU P0 ORG 0000H LJMP MAIN ORG 0030H MAIN: MOV SP,#60H LCALL LCMSET LCALL LCMCLR MOV A,#80H LCALL LCMWR0 MOV DPTR,#TAB0 LCALL LCMWR2 MOV A,#0C0H LCALL LCMWR0 MOV DPTR,#TAB1 LCALL LCMWR2 SJMP$ TAB0: DB "I AM YUAN MING",00H TAB1: DB "NICE TO MEET YOU",00H LCMLAY:
[Microcontroller]
PIC microcontroller drives LCD1602 to display two lines of strings in a loop
#include pic.h __CONFIG(0x1832); //Chip configuration word, watchdog off, power-on delay on, power-off detection off, low voltage programming off, encryption, 4M crystal HS oscillation //LCD control line macro definition #define rs RA0   #define rw RA1 #define e RA2 char web = {"www.51hei.com"}; char tel = {"QQ
[Microcontroller]
AVR MCU ATMEGA16 1602 LCD driver and experience
I developed my own AVR microcontroller chip development board, and the 1602 LCD screen experiment was successful! I was very pleased. I wrote the program for a whole day, and repeated the experiment, and finally succeeded at 0:00 am.      During this process, the biggest problem was the so-called matching 1602 LCD scr
[Microcontroller]
1602 LCD screen driver source program 1
rs bit p2.6 r_w bit p2.5 enable bit p2.7 db0_db7 data p1 org 0000h ajmp main org 0050h main:mov sp,#60h lcall initial lcall cls main1: ll2:lcall key cjne a,#00h,l1 ajmp lp l1:cjne a,#01h,l2a ajmp lp l2a:cjne a,#02h,l2 ajmp lp l2:cjne a,#03h,l3 ajmp lp l3:cjne a,#04h,l4 ajmp l
[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号