25. 自己定義資料型別關鍵字
25
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
typedef signed long int32;
typedef unsigned long uint32;
typedef unsigned char bool;
73. LCM共有11種指令
73
指令
動作
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
執行
時間
功能設定 0 0 0 0 1 DL(1) N(2) F(3) X X 40 us
清除顯示器 0 0 0 0 0 0 0 0 0 1 1.64ms
游標回左上角 0 0 0 0 0 0 0 0 1 X 40 us
設定輸入模式 0 0 0 0 0 0 0 1 I/D(4) S(4) 40 us
螢幕開或關 0 0 0 0 0 0 1 D C B 40 us
游標/顯示移位 0 0 0 0 0 1 S/C(5) R/L(5) X X 40 us
設定CGRAM地址 0 0 0 1 A A A A A A 40 us
設定DDRAM地址 0 0 1 A A A A A A A 40 us
讀取BF與地址 0 1 BF(6) A A A A A A A 40 us
寫資料至RAM 1 0 D D D D D D D D 40 us
從RAM讀資料 1 1 D D D D D D D D 40 us
74. 日立HD44780相容LCD之常用指令表
74
No. Instruction Hex Decimal
1 Function Set: 8-bit, 1 Line, 5x7 Dots 0x30 48
2 Function Set: 8-bit, 2 Line, 5x7 Dots 0x38 56
3 Function Set: 4-bit, 1 Line, 5x7 Dots 0x20 32
4 Function Set: 4-bit, 2 Line, 5x7 Dots 0x28 40
5 Entry Mode 0x06 6
6
Display off Cursor off
(clearing display without clearing DDRAM content)
0x08 8
7 Display on Cursor on 0x0E 14
8 Display on Cursor off 0x0C 12
9 Display on Cursor blinking 0x0F 15
10 Shift entire display left 0x18 24
12 Shift entire display right 0x1C 30
13 Move cursor left by one character 0x10 16
14 Move cursor right by one character 0x14 20
15 Clear Display (also clear DDRAM content) 0x01 1
16 Set DDRAM address or cursor position on display 0x80+add 128+add
17 Set CGRAM address or set pointer to CGRAM location 0x40+add 64+add
81. 81
/*******************************************************************************************
* @fn LCD_ClrLine
* @brief Clear a certain line
* @param uint8 line: 1 is the first line, and 2 is the second line
* @return None
******************************************************************************************/
void LCD_ClrLine(uint8 line)
{
uint8 i;
if(line < LCD_MaxRows)
{
LCD_CursorSet(line, 0);
for(i=0;i<LCD_MaxCols;i++){
LCD_DataWr(' ');
}
LCD_CursorSet(line, 0);
}
}
/************************************
* @fn LCD_ClrScr
* @brief Clear whole screen
* @param None
* @return None
***********************************/
void LCD_ClrScr(void)
{
LCD_CmdWr(LCD_CMD_CLS);
}
/***********************************************
* @fn LCD_DataWr
* @brief Write a data to the LCD
* @param uint8 data: the data
* @return None
**********************************************/
void LCD_DataWr(uint8 data)
{
delayms(1);
LCD_RS = LCD_SEL_DATA;
LCD_RW = LCD_IO_WRITE;
LCD_DATA_PORT = data;
delayms(1);
LCD_EN = 1;
delayms(1);
LCD_EN = 0;
}
82. 82
/***********************************************************************************
* @fn LCD_CursorSet
* @brief Set the position of the cursor
* @param (uint8 row, uint8 col) sets the position
* @return None
**********************************************************************************/
static void LCD_CursorSet(uint8 row, uint8 col)
{
switch(row){
case 0:
if(LCD_MaxRows==1){
if (col < (LCD_MaxCols >> 1)) // If used only one line LCD
LCD_CmdWr(0x80 + col); // First half of line starts at 0x80
else // Second half of line starts at 0xC0
LCD_CmdWr(0xC0 + col - (LCD_MaxCols >> 1));
}else{
LCD_CmdWr(0x80 + col); // select line 1
}
break;
case 1:
LCD_CmdWr(0xC0 + col); // select line 2
break;
case 2:
LCD_CmdWr(0x80 + LCD_MaxCols + col); // select line 3
break;
case 3:
LCD_CmdWr(0xC0 + LCD_MaxCols + col); // select line 4
break;
}
}
83. 83
/*************************************************************************************
* @fn LCD_DispChar
* @brief Show a character at specific postion
* @param (uint8 row, uint8 col) is the postion, and char c: the character to show
* @return None
************************************************************************************/
void LCD_DispChar(uint8 row, uint8 col, char c)
{
if(row < LCD_MaxRows && col < LCD_MaxCols)
{
LCD_CursorSet(row, col);
LCD_DataWr(c);
}
}
/***********************************************************************************
* @fn LCD_DispStr
* @brief Display a string from a specific position
* @param (uint8 row, uint8 col) sets the position and char *s is the string
* @return None
*********************************************************************************/
void LCD_DispStr(uint8 row, uint8 col, char *s)
{
uint8 i;
if(row < LCD_MaxRows && col < LCD_MaxCols){
LCD_CursorSet(row, col);
i = col;
while( i < LCD_MaxCols && *s){
LCD_DataWr(*s++);
i++;
}
}
}
84. /***************************************************************************************************
* @fn LCD_DispHorBar
* @brief Display the horizon bar
* @param (uint8 row, uint8 col) sets the position, uint8 val sets the value of full (100%)
* @return None
***************************************************************************************************/
void LCD_DispHorBar(uint8 row, uint8 col, uint8 val)
{
uint8 i, full, frac;
full = val/5; // how many full blocks to turn on
frac = val%5; // portion of block
if(row < LCD_MaxRows && (col + full -1) < LCD_MaxCols){
i = 0;
LCD_CursorSet(row, col);
while(full > 0)
{
LCD_DataWr(5); // Send Custom character #5, which is full block
i++;
full--;
}
if(frac>0){
LCD_DataWr(frac); // custom char #frac
}
}
}
/**************************************
* @fn LCD_DispHorBarInit
* @brief HorizonBar Initilize
* @param None
* @return None
*************************************/
void LCD_DispHorBarInit(void)
{
LCD_DefChar(1, &LCD_DispBar1[0]);
LCD_DefChar(2, &LCD_DispBar2[0]);
LCD_DefChar(3, &LCD_DispBar3[0]);
LCD_DefChar(4, &LCD_DispBar4[0]);
LCD_DefChar(5, &LCD_DispBar5[0]);
}
84
85. 85
/**********************************************************
* @fn LCD_DefChar
* @brief This function help you define your own pattern
* @param uint8 id: offset of the CGRAM, uint8 *pat points
* to the pattern table (array).
* @return None
***********************************************************/
void LCD_DefChar(uint8 id, uint8 *pat)
{
uint8 i;
LCD_CmdWr(0x40 + ( id<<3 )); // Set address of CGRAM
for(i=0;i<8;i++){
LCD_DataWr(*pat++);
}
}
/********************************************************
* @fn delayms
* @brief delay with ms
* @param time = 0 ~ 255, the maximum delay is 255 ms
* @return None
********************************************************/
void delayms(uint8 time)
{
uint8 n;
while(time>0)
{
n = 162;
while(n>0) n--;
time --;
}
}