?? lcd_a.c
字號:
#include "Main.h"
#include "Port.h"
#include "LCD_A.h"
#include "Delay_T0.h"
extern char LCD_data_G[LCD_LINES][LCD_CHARACTERS+1] ;
static void LCD_Send_Byte(const tByte, const bit) ;
static void LCD_SetDDRAM(tByte);
static void LCD_Delay(void);
extern char str0[];
#define LCD_DISPLAY_OFF_CURSOR_OFF_BLINKING_OFF 0x08
#define LCD_DISPLAY_ON_CURSOR_OFF_BLINKING_OFF 0x0C
#define LCD_INC_ADDR_NO_SCROLL 0x06
#define LCD_CURSOR_OFF 0x08
#define LCD_DISPLAY_ON 0x04
#define LCD_CLEAR_DISPLAY 0x01
#define LCD_4BIT_2LINE_5x8FONT 0x28
void LCD_Init(const bit TURN_DISPLAY_ON)
{
tByte loop;
tByte l,c;
Hardware_Delay_T0(10);
// Set up the LCD port
LCD_D4 = 1;
LCD_D5 = 1;
LCD_D6 = 1;
LCD_D7 = 1;
LCD_RS = 1;
LCD_EN = 1;
Hardware_Delay_T0(10);
LCD_RS = 0;
LCD_EN = 0;
// Now wait for the display to initialise
// - data sheet says at least 40 ms
Hardware_Delay_T0(100);
// Data sheet says send this instruction 3 times...
for (loop = 0; loop < 3; loop++)
{
// Using a 4-bit bus, 2 display lines and a 5x7 dot font
LCD_Send_Byte(LCD_4BIT_2LINE_5x8FONT,0);
Hardware_Delay_T0(1);
}
// Turn the display off and the cursor off and blinking off
LCD_Send_Byte(LCD_DISPLAY_OFF_CURSOR_OFF_BLINKING_OFF,0);
Hardware_Delay_T0(1);
// Clear the display
LCD_Send_Byte(LCD_CLEAR_DISPLAY,0);
Hardware_Delay_T0(1);
// Invisible cursor (dummy function call to avoid library error)
LCD_Control_Cursor(0,0,0);
Hardware_Delay_T0(1);
// Clear the display
LCD_Send_Byte(LCD_CLEAR_DISPLAY,0);
Hardware_Delay_T0(1);
if (TURN_DISPLAY_ON)
{
// Increment display address for each character but do not scroll
LCD_Send_Byte(LCD_INC_ADDR_NO_SCROLL,0);
Hardware_Delay_T0(1);
// Update all characters in the display
for (l = 0; l < LCD_LINES; l++)
{
for (c = 0; c < LCD_CHARACTERS; c++)
{
LCD_data_G[l][c] = '*';
LCD_Update();
Hardware_Delay_T0(1);
}
}
// LCD_Send_Byte(LCD_DISPLAY_ON_CURSOR_OFF_BLINKING_OFF,0);
// Hardware_Delay_T0(1);
}
}
void LCD_Update(void)
{
tByte Character,Line;
tByte Data;
for(Line=0;Line<2;Line++)
for(Character=0;Character<16;Character++)
{
if (Line == 0)
{
LCD_SetDDRAM(0x00 + Character); // First line
}
else
{
LCD_SetDDRAM(0x40 + Character); // Second line
}
Data = LCD_data_G[Line][Character];
LCD_Send_Byte(Data,1);
}
}
//不太優化,但是很靈活.DATA_FLAG=0為寫入命令,DATA_FLAG=1為寫入數據
void LCD_Send_Byte(const tByte DATA, const bit DATA_FLAG)
{
LCD_D4 = 0;
LCD_D5 = 0;
LCD_D6 = 0;
LCD_D7 = 0;
LCD_RS = DATA_FLAG; // Data register
LCD_EN = 0;
LCD_Delay();
// Write the data (high nybble)
LCD_D4 = ((DATA & 0x10) == 0x10);
LCD_D5 = ((DATA & 0x20) == 0x20);
LCD_D6 = ((DATA & 0x40) == 0x40);
LCD_D7 = ((DATA & 0x80) == 0x80);
LCD_Delay();
LCD_EN = 1;
LCD_Delay();
LCD_EN = 0;
LCD_Delay();
LCD_D4 = 0;
LCD_D5 = 0;
LCD_D6 = 0;
LCD_D7 = 0;
LCD_RS = DATA_FLAG;
LCD_EN = 0;
LCD_Delay();
LCD_D4 = ((DATA & 0x01) == 0x01);
LCD_D5 = ((DATA & 0x02) == 0x02);
LCD_D6 = ((DATA & 0x04) == 0x04);
LCD_D7 = ((DATA & 0x08) == 0x08);
LCD_Delay();
LCD_EN = 1;
LCD_Delay();
LCD_EN = 0;
LCD_Delay();
}
void LCD_Control_Cursor(const bit VISIBLE, const bit BLINKING,
const tByte ADDRESS)
{
// Cursor / blinking appears at current DDRAM address
// - use SetDDRAM() to alter the cursor position
tByte Command = 0x0C;
if (VISIBLE)
{
Command |= 0x02;
}
if (BLINKING)
{
Command |= 0x01;
}
LCD_Send_Byte(Command,0);
LCD_SetDDRAM(ADDRESS);
}
/*------------------------------------------------------------------*-
LCD_SetDDRAM()
Set the DDRAM to a particular address.
Used to determine where we write to in the LCD RAM and - thus -
whether the text appears on Line 0, Line 1, etc.
See text for details.
Params: The DDRAM address we wish to write to.
-*------------------------------------------------------------------*/
void LCD_SetDDRAM(tByte ADDRESS)
{
ADDRESS &= 0x7f;
ADDRESS |= 0x80;
LCD_Send_Byte(ADDRESS,0);
}
void LCD_Delay(void)
{
int x;
x++;
x++;
x++;
}
void Displayonechar( char x, char y, char DData)
{
/*
x&=1;
y&=15;
if(x)
y|=0x40;
y|=0x80;
*/
// LCD_Send_Byte(y,0);
// LCD_Send_Byte(DData,1);
// LCD_Update();
// LCD_Send_Byte(Data,1);
/*
//memcpy(LCD_data_G[x][y],DData,1);
//LCD_Update();
*/
LCD_data_G[x][y]=DData;
LCD_Update();
}
void Displaylistchar( char x, char y, char DData[])
{
int l=0;
int j;
// DData="asd";
j=strlen(DData);
//x&=0x1;
//y&=0xf;
while(y<=15)
{
Displayonechar(x,y,DData[l]);
l++;
y++;
}
//memcpy(LCD_data_G[x][y],Info,length);
//LCD_Update();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -