📄 register_lcd_driver.c
字号:
/*********************************************************************
Author : ADI - Apps www.analog.com/MicroConverter
Date : August 2006
File : Register_LCD_Driver.c
Hardware : Applicable to ADuC702x rev H or I silicon
Description : This file provides the routines necessary to interface
to a Register based LCD display module.
*********************************************************************/
#include <ADuC7020.h> // Include ADuC7020 Header File
#include <Register_LCD_Driver.h>
unsigned long ulValue = 0;
volatile unsigned char RdStatus = 0;
unsigned char Init_MC08_LCD()
{
GP0DAT = 0xA0000000; // P0.5 = RS, E = P0.7
GP1DAT = 0xFF000000; // P1.[7..0] = DB[0..7]
GP2DAT = 0x01000000; // P2.0 = R/W
return 0x1;
}
unsigned char Select_Function_Set(unsigned char ucFunctionSet)
{
unsigned long ulFunction = 0;
delay (10000);
RdStatus = ReadStatus();
ulFunction = ucFunctionSet;
ulFunction = (ulFunction << 16);
ulFunction |= 0xFF000000;
GP0DAT = 0xA0000000; // Clear RS pin(P0.5), clear E pin (P0.7) -> R/W)
GP2DAT = 0x01000000; // Clear R/W pin (P2.0 -> R/W)
delay (5);
GP0SET = 0x800000; // Set E high
delay (5); // allow min 800ns Setup time
GP1DAT = ulFunction; // Write to register
delay (5); // allow Hold time of 500nS min
GP0CLR = 0x800000; // Set E low
delay (5);
return 0x1;
}
unsigned char Set_DDRAM_ADDR_LCD(unsigned char addr)
{
unsigned long ulAddr = 0;
delay (10000);
addr |= 0x80; // Set MSB of register
ulAddr = addr;
ulAddr = (ulAddr << 16);
ulAddr |= 0xFF000000;
GP1DAT |= ulAddr; // Write to register
//Set RS pin of LCD low for Register access
GP2DAT = 0x01000000; // Set RS pin of LCD low for Register access (P2.0 -> RS)
GP0DAT = 0x40000000; // Clear R/W pin. (P0.6 -> R/W)
GP0DAT = 0xC0800000; // Set E pin. (P0.7 -> E)
delay(500);
GP0DAT = 0xC0000000; // Clear E pin. (P0.7 -> E)
GP1DAT = 0x00300000; // Configure data bus as Input
return 0x1;
}
unsigned char Display_On_LCD(void)
{
GP1DAT = 0xFF0F0000; // Write 0x0F - Turn on Display, cursor on and blinking
//Set RS pin of LCD low for Register access
GP2DAT = 0x01000000; // Set RS pin of LCD low for Register access (P2.0 -> RS)
GP0DAT = 0x40000000; // Clear R/W pin. (P0.6 -> R/W)
GP0DAT = 0xC0800000; // Set E pin. (P0.7 -> E)
delay(500);
GP0DAT = 0xC0000000; // CLear E pin. (P0.7 -> E)
GP1DAT = 0x00300000; // Configure data bus as Input
return 0x1;
}
unsigned char Display_Off_LCD(unsigned char ucFunctionSet)
{
GP1DAT = 0xFF0B0000; // Write 0x0B - Turn off Display
//Set RS pin of LCD low for Register access
GP2DAT = 0x01000000; // Set RS pin of LCD low for Register access (P2.0 -> RS)
GP0DAT = 0x40000000; // Clear R/W pin. (P0.6 -> R/W)
GP0DAT = 0xC0800000; // Set E pin. (P0.7 -> E)
delay(500);
GP0DAT = 0xC0000000; // Clear E pin. (P0.7 -> E)
GP1DAT = 0x00300000; // Configure data bus as Input
return 0x1;
}
unsigned char Clear_Display_LCD(unsigned char ucFunctionSet)
{
unsigned long ulFunction = 0;
delay (10000);
RdStatus = ReadStatus();
ulFunction = ucFunctionSet;
ulFunction = (ulFunction << 16);
ulFunction |= 0xFF000000;
GP0DAT = 0xA0000000; // Clear RS pin(P0.5), clear E pin (P0.7) -> R/W)
GP2DAT = 0x01000000; // Clear R/W pin (P2.0 -> R/W)
delay (5);
GP0SET = 0x800000; // Set E high
delay (5); // Allow min 800ns Setup time
GP1DAT = ulFunction; // Write to register
delay (5); // Allow Hold time of 500nS min
GP0CLR = 0x800000; // Set E low
delay (2000); // Minimum clear time of 1.58mS
return 0x1;
}
unsigned char Set_Entry_Mode(unsigned char ucFunctionSet)
{
unsigned long ulFunction = 0;
delay (10000);
RdStatus = ReadStatus();
ulFunction = ucFunctionSet;
ulFunction = (ulFunction << 16);
ulFunction |= 0xFF000000;
GP0DAT = 0xA0000000; // Clear RS pin(P0.5), clear E pin (P0.7) -> R/W)
GP2DAT = 0x01000000; // Clear R/W pin (P2.0 -> R/W)
delay (5);
GP0SET = 0x800000; // Set E high
delay (5); // allow min 800ns Setup time
GP1DAT = ulFunction; // Write to register
delay (5); // allow Hold time of 500nS min
GP0CLR = 0x800000; // Set E low
delay (5);
return 0x1;
}
unsigned char Wr_Data_LCD(unsigned char ucFunctionSet)
{
unsigned long ulFunction = 0;
delay (10000);
RdStatus = ReadStatus();
ulFunction = ucFunctionSet;
ulFunction = (ulFunction << 16);
ulFunction |= 0xFF000000;
GP0DAT = 0xA0200000; // Set RS pin(P0.5), clear E pin (P0.7) -> R/W)
GP2DAT = 0x01000000; // Clear R/W pin (P2.0 -> R/W)
delay (5);
GP0SET = 0x800000; // Set E high
delay (5); // allow min 800ns Setup time
GP1DAT = ulFunction; // Write to register
delay (5); // allow Hold time of 500nS min
GP0CLR = 0x800000; // Set E low
delay (5);
GP0CLR = 0x200000; // Set RS low
return 0x1;
}
unsigned char ReadStatus(void)
{
unsigned long ulFunction = 0;
unsigned char Status = 0;
delay (10000);
GP1DAT = 0x00000000; // Set Port 1 to input mode
GP0DAT = 0xA0000000; // Clear RS pin(P0.5), clear E pin (P0.7) -> R/W)
GP2DAT = 0x01010000; // Clear R/W pin (P2.0 -> R/W)
delay (5);
GP0SET = 0x800000; // Set E high
delay (5); // allow min 800ns Setup time
Status = (unsigned char)GP1DAT; // Write to register
delay (5); // allow Hold time of 500nS min
GP0CLR = 0x800000; // Set E low
delay (5);
GP2CLR = 0x10000; // Clear R/W
return Status;
}
void delay (int length)
{
while (length >0)
length--;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -