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

📄 lcd_funct.c

📁 DS8007 双智能卡读卡DEMO源代码。
💻 C
字号:
/*---------------------------------------------------------------------------
 *  Copyright (C) 2004 Dallas Semiconductor Corporation, All Rights Reserved.
 * 
 *  Permission is hereby granted, free of charge, to any person obtaining a
 *  copy of this software and associated documentation files (the "Software"),
 *  to deal in the Software without restriction, including without limitation
 *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
 *  and/or sell copies of the Software, and to permit persons to whom the
 *  Software is furnished to do so, subject to the following conditions:
 * 
 *  The above copyright notice and this permission notice shall be included
 *  in all copies or substantial portions of the Software.
 * 
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *  IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
 *  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *  OTHER DEALINGS IN THE SOFTWARE.
 * 
 *  Except as contained in this notice, the name of Dallas Semiconductor
 *  shall not be used except as stated in the Dallas Semiconductor
 *  Branding Policy.
 * ---------------------------------------------------------------------------
 */

#include "DS8007.h"
#include "LCD_Funct.h"

void LCD_Init()
{
	LCD_Delay();			// Delay to ensure LCD power-up complete
	
	LCD_WRCmd(FnctSet);		// Write FnctSet instruction
	LCD_WRCmd(DispCnt);    	// Write Display Control instruction
	LCD_WRCmd(DispClear);	// Write Display Clear instruction
	LCD_WRCmd(EntryMode);	// Write Entry Mode instruction
}

// Write a string to the 2x20 LCD module
void LCD_WRStr(uint8_t LCD_Str[])
{
	int     i = 0;

	while ((LCD_Str[i] != '\0')	&& (i < 20))
	{
		LCD_WRChr(LCD_Str[i]) ;					// Write first 20 characters
		i++;
	}
	
	if  (LCD_Str[i] != '\0')
	    LCD_WRCmd(Line2Ad);						// Set CGRAM address to first char 2nd line

	while ((LCD_Str[i] != '\0')	&& (i < 40))
	{
		LCD_WRChr(LCD_Str[i]) ;
		i++;
	}
}

// Write a single character to the 2x20 LCD module
void LCD_WRChr(char LCD_Chr)
{
	LCD_Busy();				// Wait for not busy
	LCD_RS = 1;	 			// Set RS high for character write
	LCD_Dat = LCD_Chr;		// Output character
	LCD_EN = 1;				// Set enable high
	LCD_EN = 0;				// Clear enable
	LCD_RS = 0;
	LCD_Dat = 0xFF;			// Re-establish Port Pins as inputs
}

// Write a command to the 2x20 LCD module
void LCD_WRCmd(uint8_t LCD_Cmd)
{
	LCD_EN = 0;				// Make sure the LCD enable is low 
	LCD_RS = 0;				// Set LCD register select and R/W lines
	LCD_RW = 0;
  	LCD_Busy();				// Make sure display not busy

	LCD_Dat = LCD_Cmd;		// Output instruction
	LCD_EN = 1;				// Set enable high
	LCD_EN = 0;				// Clear enable
	LCD_Dat = 0xFF;			// Re-establish Port Pins as inputs
}

// Set the cursor position to a specific location
int LCD_Curpos(uint8_t VPos, uint8_t HPos)
{
	int rtn;
	uint8_t Addr, Cmd;

	// Check input range 1..2 line, 1..20 characters per line
	if (((VPos == 0) || (VPos > 2)) || ((HPos == 0) || (HPos > 20)))
		rtn = -1;
	else
	{
		if(VPos == 2) Addr = (0x40 + (HPos - 1));
		else Addr = HPos - 1;
		rtn = 0;
		Cmd = Addr | 0x80;
		LCD_WRCmd(Cmd);
	}
	return(rtn);    
}

// Test the LCD Module to see if it is Busy (loop until
// not busy) 
void LCD_Busy()
{
	uint8_t LCD_Stat = LCD_Dat;			// Get byte containing status

	while (LCD_Stat & 0x80){			// Wait for busy flag to clear
		LCD_RW = 1;						// LCD RW needs to be high
		LCD_EN = 1;						// Strobe enable signal
		LCD_Stat = LCD_Dat;				// Read staus
		LCD_EN = 0;
		LCD_RW = 0;
	}
}

// Time delay for 2x20 LCD module (approximately 50 ms)
void LCD_Delay()
{
	uint8_t	i, j ;

	for (i=0;i!=100;i++)
	{
		for (j=0;j!=153;j++);
	}
}

⌨️ 快捷键说明

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