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

📄 lcd.c

📁 LCD program for NXP89Cx61
💻 C
字号:
/*****************************************************
*						LCD Library	                       *
*			Supported hardware	:	2x16 LCD		    	  *
*			Author					:	Vijay Manohar .D    *
*			Date						:	13 July 2007	     *
******************************************************/

#include "lcd.h"

void LCD_Init (void) { 	
	Wrt_Cmd (DISPLAY_MODE);
	Wrt_Cmd (DISP_ON_CUR_OFF);
	Wrt_Cmd (LCD_CLEAR);
	Wrt_Cmd (INC_CURSOR);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Cheacking the Busy Flag of LCD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void Busy() {
	Flag = 1;
	RS = 0;
	RW = 1;
	while (Flag) {	//Polling whether for the Busy Flag (or Flag != 0) 
		En = 0;	
		Delay ();
		En = 1;
		/*Low to High pulse must be applied during reading from LCD */
	}
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Writing command to LCD 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void Wrt_Cmd (bit_8 val) {
	Busy ();
	LCD_PORT = val;
	RS = 0;
	RW = 0;
	En = 1;
	Delay ();
	En = 0;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Writing String to LCD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void Wrt_String (bit_8 *String) {
	Busy ();
	while (*String) Wrt_Data (*String++);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Writing data to LCD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void Wrt_Data (bit_8 Ch) {
	Busy ();
	LCD_PORT = Ch;
	RS = 1;
	RW = 0;
	En = 1;
	Delay ();
	En = 0;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Writing 8-bit Value to LCD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void Wrt_Value (bit_8 X) {
	bit_8 temp;
	temp = X / 0x10;
	if (temp > 9) return;
	else 	Wrt_Data (temp + 0x30);
	temp = X % 0x10;
	if (temp > 9) return;
	else  Wrt_Data (temp + 0x30);
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Bringing Cursor to (X,Y) location of LCD
		X -> 1,2
		Y -> 1,16
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void GotoXY (bit_8 X, bit_8 Y) {
	if ((X < 1 || X > 2) && (Y <1 || Y > 16)) {
		X = 1;
		Y = 1;
	}
	if (X == 1) Wrt_Cmd (0x7F + Y);
	else Wrt_Cmd (0xBF + Y);
}
/************************
	Milli Second Delay
************************/
void Delay () {
	unsigned int i;
	for (i = 0; i < 255; i++);		
 }

 

⌨️ 快捷键说明

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