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

📄 lcd+test.c.bak

📁 基于51最小系统的LCD显示程序,包括电路图,源程序
💻 BAK
字号:
/*************************************************************
	LCD1602 Drive Program
	For 51 MCU
				by Donald
				2006-7-19
**************************************************************/
#include "reg52.h"

#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 	CLR						0x01
#define		BUSY 					0x80 		//LCD Busy Tag

#define 	LCDIO					P2
sbit 		LCD1602_RS=P0^7;	//Data Command Pin		1 data		0 command	pin 4 
sbit 		LCD1602_RW=P0^6;	//Read Write Pin		1 read 		0 write   	pin 5
sbit 		LCD1602_EN=P0^5;	//LCD Enable Signal		pin 6

/****************************************************************/
void delay_5ms(void);											//LCD Delay Function 
void LCD_command(unsigned char command,unsigned char BusyC);	//write command function
void LCD_data(unsigned char temp,unsigned char BusyC);			//write data function
void LCD_set_xy( unsigned char x, unsigned char y );			//set display address function
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);//write lcd a character function
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);//write lcd string function
void LCD_init(void);											//lcd initize function
unsigned char ReadStatus(void);

void delay_400ms(void);											//delay function

/********************************************************************/
void main(void)
{
	LCD_init(); 
	while(1)				
	{
		LCD_command(CLR,0);
		LCD_write_string(0,LINE1,"Wellcome to DUT");
	    LCD_write_string(0,LINE2,"www.dlut.edu.cn");
	       
	    delay_400ms();delay_400ms();
	    LCD_command(CLR,0);
	       
	    LCD_write_string(0,LINE1,"   LCD Test     ");
	    LCD_write_string(0,LINE2,"   Successful!  ");
	        
	    delay_400ms();delay_400ms();

		LCD_command(CLR,0);

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

	    delay_400ms(); delay_400ms();    	       
	}
}
//
//
//
void delay_5ms(void)   
{
	unsigned int i=5552;
	while(i--);
}
//
//
//
void LCD_command(unsigned char command,unsigned char BusyC)
{
	if (BusyC) ReadStatus(); //Test it busy or not
	LCDIO=command;
	LCD1602_RS=0;   
	LCD1602_RW=0;
	LCD1602_EN=0;
	LCD1602_EN=0;
	LCD1602_EN=1;
}
//
//
//
void LCD_data(unsigned char dat,unsigned char BusyC)
{
	if (BusyC) ReadStatus(); //Test it busy or not
	LCDIO=dat;
	LCD1602_RS=1;
	LCD1602_RW=0;
	LCD1602_EN=0;
	LCD1602_EN=0;
	LCD1602_EN=1;
}
//
//
//
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_command(address,1); 
}
//
//
//
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{
	LCD_set_xy( x, y ); 
	LCD_data(dat,1);
}
//
//
//
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_data(*s);   
	s ++;
    }
}
//
//
//
void LCD_init(void)
{
	delay_400ms();	
	LCD_command(CLR,0);//clear screen 
	LCD_command(DATA_MODE,1);//set 8 bit data transmission mode 
	LCD_command(OPEN_SCREEN,1);//open display (enable lcd display)
	LCD_command(DISPLAY_ADDRESS,1);//set lcd first display address 
	LCD_command(CLR,1);//clear screen
}
//
//LCD Delay Function
//
void delay_400ms(void)      
{
	unsigned char i = 5;
	unsigned int j;
	while(i--){
		j=7269;
		while(j--);
	}; 	
}

//
//Read the LCD State
//
unsigned char ReadStatus(void)
{
	LCDIO = 0xFF; 
	LCD1602_RS = 0;
	LCD1602_RW = 1;
	LCD1602_EN = 0;
	LCD1602_EN = 0;
	LCD1602_EN = 1;
	while (LCDIO & BUSY); //Test Busy State
	return(LCDIO);
}

⌨️ 快捷键说明

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