📄 lcd.c
字号:
#include "ecrsys.h"
#include "lcd.h"
#include <string.h>
#define CMDOFF 0 //Power Off control words
#define CMDON 1 //Power On control words
#define CMDLCDON 3 //ON the LCD display
#define CMDLCDOFF 2 //OFF the LCD display
#define CMDB3C4 0x29 //Control Work Mode.
void LCD_Back(CHR flag)
{
if (flag == ON)
LCD_BL = LCD_BL_ON;
else
LCD_BL = LCD_BL_OFF;
}
#ifdef LCD_DISP
/* 1 2 3 4 5 6 7 8 */
const CHR LCD_CHAR_SEG[] =
{
CHAR_MINUS, CHAR_A, CHAR_b, CHAR_C, CHAR_d, CHAR_E, CHAR_F, CHAR_G,
CHAR_H, CHAR_1, CHAR_J, CHAR_K, CHAR_L, CHAR_M, CHAR_n, CHAR_O,
CHAR_P, CHAR_Q, CHAR_R, CHAR_S, CHAR_t, CHAR_U, CHAR_V, CHAR_W,
CHAR_X, CHAR_y, CHAR_Z
};
const CHR LCD_NUM_SEG[] =
{
CHAR_0, CHAR_1, CHAR_2, CHAR_3, CHAR_4, CHAR_5,
CHAR_6, CHAR_7, CHAR_8, CHAR_9, CHAR_A, CHAR_b,
CHAR_C, CHAR_d, CHAR_E, CHAR_F
};
const CHR LCD_SECT_SEG[]=
{
SECT_NULL,SECT_RA,SECT_PO,SECT_TAIL
};
volatile byte LCD_Buff[MAX_LCD_NUM]; /* The LCD buffer, store the last display data */
/**********************************************************************************************
* Send 1 -bit to LCD, and the data in CY register
**********************************************************************************************/
void LCD_Send_Out_Bit(CHR send_bit)
{
if (send_bit != 0)
LCD_DI = 1;
else
LCD_DI = 0;
LCD_CLK = 1;
LCD_CLK = 0;
LCD_CLK = 1;
}
/******************************************************************************************************
* Procedure: Send_Data_LCD
* : Send the data which stored in the Special_buf[96] to LCD controller.
*
* Input : the Display data ( Segment - Digit data)
* Output : None
*
* Send the Control data to LCD
******************************************************************************************************/
void Wr_Cntrl_LCD(CHR Cmd)
{
CHR tmp;
LCD_EN = 1;
LCD_EN = 0;
LCD_Send_Out_Bit(1);
LCD_Send_Out_Bit(0);
LCD_Send_Out_Bit(0);
for (tmp = 0; tmp < 9; tmp ++ )
{
if ( (Cmd & 0x80 ) != 0 )
LCD_Send_Out_Bit(1);
else
LCD_Send_Out_Bit(0);
Cmd <<= 1;
}
LCD_DI = 1;
LCD_EN = 1;
}
/* Send the data to LCD */
void Wr_Data_LCD(CHR Send_Data, CHR Addr)
{
CHR tmp;
LCD_EN = 1;
LCD_EN = 0;
LCD_Send_Out_Bit(1); //CMD for 101
LCD_Send_Out_Bit(0);
LCD_Send_Out_Bit(1);
//Send the Address first.
for (tmp = 0; tmp < 6; tmp ++ )
{
if ( ( Addr & 0x20 ) != 0 )
LCD_Send_Out_Bit(1);
else
LCD_Send_Out_Bit(0);
Addr <<= 1;
} //Send the Data second.
for (tmp = 0; tmp < 8; tmp ++ )
{
if ( ( Send_Data & 0x01 ) != 0 )
LCD_Send_Out_Bit(1);
else
LCD_Send_Out_Bit(0);
Send_Data >>= 1;
}
LCD_DI = 1;
LCD_EN = 1;
}
/**********************************************************************************************
Reset the LCD controller chip.
03-1-15 11:54 by ZhengXiaoChun
**********************************************************************************************/
void Reset_LCD(void)
{
Wr_Cntrl_LCD(CMDON);
Wr_Cntrl_LCD(CMDLCDON);
Wr_Cntrl_LCD(CMDB3C4);
}
/* Display the data to the LCD, and store the data to the display buffer */
void LCD_Disp(byte data, byte posi)
{
LCD_Buff[posi] = data;
Wr_Data_LCD( data, posi * 2 );
}
void LCD_DispChar(byte posi, byte dsp_char, byte dots)
{
byte tmp;
if(posi >= MAX_LCD_NUM)
return;
posi = MAX_LCD_NUM - posi - 1;
if(dsp_char < 16)//数字
{
tmp = LCD_NUM_SEG[dsp_char]|dots;
}
else if(dsp_char == '-')// '-'
tmp = LCD_CHAR_SEG[0] | dots;
else if(dsp_char == ' ') // ' '
tmp = 0 | dots;
else if(dsp_char == '.')// '.'
tmp = 1;
else if((dsp_char >= '0')&&(dsp_char <= '9'))// '0' ~ '9'
{
dsp_char -= '0';
tmp = LCD_NUM_SEG[dsp_char] | dots;
}
else if((dsp_char >= 'a') && (dsp_char <= 'z'))// 'a' ~ 'z'
{
dsp_char -= 'a';
tmp = LCD_CHAR_SEG[dsp_char] | dots;
}
else if((dsp_char >= 'A') && (dsp_char <= 'Z'))//'A'~ 'Z'
{
dsp_char -= 'A'; //Skip the not used area.
tmp = LCD_CHAR_SEG[dsp_char] | dots;
}
else
tmp = 0 | dots;
LCD_Disp(tmp,posi);
}
/*--------------------------------------------------------------------------------*
* Insert a sect to the LCD display.
*--------------------------------------------------------------------------------*/
void LCD_Insert_Sect(CHR dsp_data,CHR posi, byte dots)
{
byte tmp;
byte i;
if(posi >= MAX_LCD_NUM)
return;
posi = MAX_LCD_NUM - 1 - posi;
for(i=0;LCD_SECT_SEG[i]!=SECT_TAIL;i++)
if(LCD_SECT_SEG[i] == dsp_data)
break;
if(LCD_SECT_SEG[i] == SECT_TAIL)
return;
tmp = LCD_SECT_SEG[i] | dots;
LCD_Disp(tmp,posi);
}
/*----------------------------------------------------------------------------------------
* void LCD_Back(CHAR flag);
* In: On / Off the LCD backlight.
* 03-4-2 11:23 by ZhengXC
*---------------------------------------------------------------------------------------*/
void LCD_Back(CHR flag)
{
if (flag == ON)
LCD_BL = LCD_BL_ON;
else
LCD_BL = LCD_BL_OFF;
}
void LCD_Init(void)
{
byte i;
LCD_EN_DIR = 1;
LCD_CLK_DIR = 1;
LCD_DI_DIR = 1;
LCD_BL_DIR = 1;
LCD_Close_Disp();
}
/* Display the data to the LCD, and store the data to the display buffer */
void LCD_InsPeriod(byte posi)
{
byte tmp;
if(posi >= MAX_LCD_NUM)
return;
posi = MAX_LCD_NUM - posi - 1;
tmp = LCD_Buff[posi]; /* Get the last display data */
tmp |= 0x01; /* 0000 0001B, set the flag */
LCD_Buff[posi] = tmp;
Wr_Data_LCD( tmp , posi * 2 );
}
void LCD_ClrPeriod(byte posi)
{
byte tmp;
if(posi >= MAX_LCD_NUM)
return;
posi = MAX_LCD_NUM - posi - 1;
tmp = LCD_Buff[posi]; /* Get the last display data */
tmp &= 0xfe; /* 1111 1110B, clear the flag */
LCD_Buff[posi] = tmp;
Wr_Data_LCD( tmp , posi * 2 );
}
/*------------------------------------------------------------------------*
Clear the all display information.
注意: 推荐不用这个函数, 因为用这个函数比较危险; 因为无法清除VFD的显示.
*------------------------------------------------------------------------*/
void LCD_Close_Disp(void)
/* Remain, has't used it in the function */
{
byte i;
Reset_LCD();
for( i = 0; i < MAX_LCD_NUM; i ++)
{
LCD_Buff[MAX_LCD_NUM - i - 1] = 0;
Wr_Data_LCD( 0, (MAX_LCD_NUM - i - 1) * 2 );
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -