📄 lcd.c
字号:
/***********************************************************************************
/----------------------Copyright (c) 2005 ~ 2008 Miartech. All Rights Reserved.-----------------------/
/***********************************************************************************
**-----------------------------------------File Info--------------------------------------------
** Last modified Date: 2008-06-24
** Descriptions: HMC16223(16*2 Words LCD)'s Primary Functions
**--------------------------------------------------------------------------------------------
** Created By: Kelven
** Created Date: 2006-11-23
**--------------------------------------------------------------------------------------------
** Modified by: Kelven
** Modified date: 2007-09-04
** Version: V4.0.0
** Descriptions:
**--------------------------------------------------------------------------------------------
** Modified by: Kelven
** Modified date: 2008-06-24
** Version: V4.0.1
** Descriptions: Updating Key Configrating Function, Added PLC Chip Register Value Setting Module
***********************************************************************************/
#include "..\inc\LCD.h"
/*--------------------------------------------------------------------------------------------
** --Note: Only When LCD_E Have a High-to-Low Pulse,The HMC16223 Can Send or Receive Data Correct --**
**------------------------------------------------------------------------------------------*/
/***********************************************************************************
** Function Name: LCD_Wait
** Input Parameters:None
** Output Parameters:None
** Implement:Check Bit7 of LCD_DATA to Determine Whether the LCD is Busy or Ready
***********************************************************************************/
void LCD_Wait(void)
{
bit bLCD_Busy_Flag;
do
{
LCD_RS = 0;
LCD_RW = 1;
LCD_E = 1;
bLCD_Busy_Flag = LCD_DATA7;//Read BUSY FLAG (BF). BF=1: Internal Operation;BF=0:Can Accept Instruction.
LCD_E = 0;
}
while(bLCD_Busy_Flag==1);
}
/***********************************************************************************
** Function Name: Init_LCD
** Input Parameters:None
** Output Parameters:None
** Implement:Initialization Of LCD & Wirte Intial Value Of LCD's Registers
***********************************************************************************/
void Init_LCD(void)
{
BYTE cForCnt;
LCD_DATA5 = 1;
LCD_DATA4 = 1;
for(cForCnt = 0;cForCnt < 3;cForCnt ++)
{
LCD_E = 1;
LCD_E = 0;
TOOL_Delay_MS(20);
}
LCD_DATA5 = 1;
LCD_DATA4 = 0;
LCD_E = 1;
LCD_E = 0;
LCD_Wait();
/*******************************************************************************
//Set Interface Data Length(DL), Number of Display Lines(L) and Character Font(F).0 0 0 0 1 DL N F X X
//DL=1: 8Bits;DL=0: 4Bits. N=1: 2Lines; N=0: 1Lines. F=1:5X11 Dots; F=0: 5X7 Dots.
*******************************************************************************/
DSP_Write_Cmd(0x28); //4Bits Data Length;2Lines Display;5X7Dots. Function Set = 00101000;
/*******************************************************************************
//Set Display (D),Cursor(C) and Blinking of Cursor(B) ON/OFF.D=1:Display ON; D=0:Display OFF.
//C=1:Cursor ON; C=0:Cursor OFF. B=1:Blink ON;B=0,Blink OFF. 0 0 0 0 0 0 1 D C B
*******************************************************************************/
//DSP_Write_Cmd(0x08); //Display OFF;Cursor OFF;Blink OFF. Display ON/OFF control = 00001000;
/*******************************************************************************
//Set Cursor Moving Direction and Enable the Shift of the Display. 0 0 0 0 0 0 0 1 I/D S
//I/D=1: Increment; 1/D=0: Decrement;S=1: Whole Display Shift When Data is Written.
*******************************************************************************/
DSP_Write_Cmd(0x06); //Moving Direction = Increment;Disable Whole Shift. Entry Mode Set = 00000110;
/*******************************************************************************
//Move the Cursor and Shift the Display Without Changing DDRAM Contents. 0 0 0 0 0 1 S/C R/L X X
//S/C=1: Display Shift;S/C=0:Cursor move. R/L=1:Shift to Right;R/L=0:Shift to Left.
*******************************************************************************/
//DSP_WriteCom(0x10); //Cursor move;Shift to Right. Cursor or Display shift Set = 00010000;
DSP_Write_Cmd(0x0c); //Display ON;Cursor OFF;Blink OFF. Display ON/OFF control = 00001100;
}
/***********************************************************************************
** Function Name: Write_To_LCD
** Input Parameters:cData_Byte:The Data Write to LCD
** Output Parameters:None
** Implement:Wirte Data/Command to LCD
***********************************************************************************/
void Write_To_LCD(BYTE cData_Byte)
{
BYTE cSend_Data;
LCD_RW = 0;
cSend_Data = 0;
cSend_Data = (P2 & 0x0f);
cSend_Data |= (cData_Byte & 0xf0);
P2 = cSend_Data;
cData_Byte = cData_Byte<<4;
LCD_E = 1;
LCD_E = 0;
cSend_Data = (P2 & 0x0f);
cSend_Data |= (cData_Byte & 0xf0);
P2 = cSend_Data;
LCD_E = 1;
LCD_E = 0;
}
/***********************************************************************************
** Function Name: DSP_Write_Data
** Input Parameters:cDSP_Data_Byte:The Data Write to LCD
** Output Parameters:None
** Implement:Wirte Display Data to LCD
***********************************************************************************/
void DSP_Write_Data(BYTE cDSP_Data_Byte)
{
LCD_RS = 1;
Write_To_LCD(cDSP_Data_Byte);
LCD_Wait();
}
/***********************************************************************************
** Function Name: DSP_Write_Cmd
** Input Parameters:cLCD_Cmd_Byte:The Command Write to LCD
** Output Parameters:None
** Implement:Wirte Command to LCD
***********************************************************************************/
void DSP_Write_Cmd(BYTE cLCD_Cmd_Byte)
{
LCD_RS = 0;
Write_To_LCD(cLCD_Cmd_Byte);
LCD_Wait();
}
/***********************************************************************************
** Function Name: DSP_Show
** Input Parameters:cDSP_Addr:The Address of DSP;ptrDSP_Str:The Pointer to DSPString Address
** Output Parameters:None
** Implement:Wirte Dispaly Address of LCD & The Character String That Want to Display
***********************************************************************************/
void DSP_Show(BYTE cDSP_Addr, BYTE code *ptrDSP_Str)
{
BYTE cString_Length = 0;
DSP_Write_Cmd(cDSP_Addr);
while(ptrDSP_Str[cString_Length] != 0x00)
{
DSP_Write_Data(ptrDSP_Str[cString_Length]);
cString_Length ++;
}
}
/***********************************************************************************
** Function Name: DSP_One_Char
** Input Parameters:cXRow:Horizontal Position;cYRow:Vertical Position;cData:Display Data
** Output Parameters:None
** Implement: Display the Data on the Appointed Position
***********************************************************************************/
/*void DSP_One_Char(BYTE cXRow, BYTE cYRow, BYTE cData)
{
cYRow &= 0x01;
cXRow &= 0x0F; //restrict X<=15;Y<=1
if (cYRow == 0x01)
{
cXRow |= 0x40; //When cYRow == 0x01:cXRow Must Add a offset:0x40;
}
cXRow |= 0x80; //cXRow Add the Address offset:0x80;
DSP_Write_Cmd(cXRow);
//DSP_Write_Data(cData);
DSP_Write_Data((cData>>4) + 0x30);
DSP_Write_Data((cData & 0x0f) + 0x30);
}
/***********************************************************************************
** Function Name: DSP_Data_Format
** Input Parameters:Data:The Display Data Need to Change Format to ASCII
** Output Parameters:None
** Implement: Change Int Format Data to ASCII Format
***********************************************************************************/
void DSP_Data_Format(WORD wDSP_Data)
{
DSP_Write_Data((wDSP_Data/1000 + 0x30));
DSP_Write_Data(((wDSP_Data%1000)/100 + 0x30));
DSP_Write_Data(((wDSP_Data%100)/10 + 0x30));
DSP_Write_Data(((wDSP_Data%10) + 0x30));
}
/***********************************************************************************
** Function Name: DSP_Data_Format
** Input Parameters:cDSP_Data:The Display Char Data Need to Change Format to ASCII
** Output Parameters:None
** Implement: Change Char Format Data to ASCII Format
***********************************************************************************/
void DSP_Char_Format(BYTE cDSP_Data)
{
DSP_Write_Data((cDSP_Data/100 + 0x30));
DSP_Write_Data(((cDSP_Data%100)/10 + 0x30));
DSP_Write_Data(((cDSP_Data%10) + 0x30));
}
/***********************************************************************************
** Function Name: DSP_HEX_Format
** Input Parameters:cDSP_Data:The Display HEX Data Need to Change Format to ASCII
** Output Parameters:None
** Implement: Change HEX Format Data to ASCII Format
***********************************************************************************/
void DSP_HEX_Format(BYTE hDSP_Data)
{
BYTE htemp=0;
htemp = hDSP_Data/0x10;
if((htemp >= 0) && (htemp <= 9))
DSP_Write_Data(htemp + 0x30);
else
DSP_Write_Data(htemp + 0x37);
htemp = hDSP_Data%0x10;
if((htemp >= 0) && (htemp <= 9))
DSP_Write_Data(htemp + 0x30);
else
DSP_Write_Data(htemp + 0x37);
}
/***********************************************************************************
** Function Name: Clear_DSP
** Input Parameters:None
** Output Parameters:None
** Implement:Clean All Character Strings Displayed On LCD
***********************************************************************************/
void Clear_DSP(void)
{
DSP_Write_Cmd(0x01);
TOOL_Delay_MS(2);
}
/***********************************************************************************
** End Of File **
***********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -