📄 lcd.c
字号:
/*
*******************************************************************************
* Shanghai Maritime University
* Pudong Avenue 1550#
*
* (c)Copyright 2005,SMSC,Shanghai,China
* All Rights Reserved
*
*
*
* Filename : LCD.c
* Programmer : Chen Jutao(Jason Chen)
* Description: This C file is the dot matrix 2-screen LCD driver function file.
*
********************************************************************************
*/
//#include "Data_types.h"
#include "LCD_CFG.h"
/*
**************************************************************************
* Declaration and macros of Functions in This File
**************************************************************************
*/
#ifndef CHAR
#define CHAR char
#endif
void DispInit(void);
void DispSetFont(INT8U fontIx,Disp_Bitmap_Attrib *font);
void DispSetPic(INT8U picIx,Disp_Bitmap_Attrib *pic);
void DispOnOff(BOOLEAN toggle);
void DispClrScr (void);
void DispSetPageAddr (INT8U pageaddr);
void DispSetYAddr (INT8U Yaddr);
void DispSetStartLine (INT8U startline);
void DispDataWr(BOOLEAN left_right,INT8U data);
#if DISP_NONASCII_CHAR == 1
void DispNAChar(INT8U row,INT8U col,INT8U ix);
#endif
void DispChar (INT8U row,INT8U col,CHAR c);
void DispBitmap(INT8U row, INT8U col,INT8U bitmapTotalPages,INT8U bitmapWidth,INT8U *bitmapData,INT8U dataArrayStartIx);
BOOLEAN DispSetCursor (INT8U row,INT8U col);
void DispStr(INT8U row,INT8U col, CHAR *s);
#if DISP_PICTURE == 1
void DispGraphic(INT8U row,INT8U col);
#endif
#define TRANS(c,i) c*CurBitmap.BitmapArrayLength+i
Disp_Bitmap_Attrib CurBitmap;
/*
**************************************************************************
* Dummy for a Period of Time
*
* Description : This function is used to delay a period and cpu can do nothing.
* Arguments : 'counts' is the dummy counts.
* Returns : None.
**************************************************************************
*/
static void Delay(INT16U counts)
{
int i;
for(i=0;i<counts;i++);
}
/*
**************************************************************************
* Set the Font
*
* Description : This function is used to set the attribute values of the font that is currently used.
* Arguments : 'fontIx' is the index of the font to be set in system font table;
* 'font' is the pointer of font bitmap structure variable.
* Returns : None.
**************************************************************************
*/
void DispSetFont(INT8U fontIx,Disp_Bitmap_Attrib *font)
{
INT_DISABLE()
*font=FontTable[fontIx];
INT_ENABLE()
}
#if DISP_PICTURE == 1
/*
**************************************************************************
* Set the Picture
*
* Description : This function is used to set the picture that is to display.
* Arguments : 'picIx' is the index of the picture to be displayed in system picture table;
* 'pic' is the pointer of picture bitmap structure variable.
* Returns : None.
**************************************************************************
*/
void DispSetPic(INT8U picIx,Disp_Bitmap_Attrib *pic)
{
INT_DISABLE()
*pic=PicTable[picIx];
INT_ENABLE()
}
#endif
/*
**************************************************************************
* Initialize the LCD Screen
*
* Description : This function is used to initialize the LCD screen.System default font will be
* set, and display will be cleared and then turned on.If in multitask mode, the
* binary semaphore of dispaly will also be created.
* Arguments : None
* Returns : None.
**************************************************************************
*/
void DispInit(void)
{
#if MULTITASK == 1
DispSem=xOSSemBCreate(0, 1);
#endif
DispSetFont(FONT0,&CurBitmap);
DispClrScr();
DispOnOff(TRUE);
}
/*
**************************************************************************
* Turn-on or Turn-off the LCD
*
* Description : This function is used to turn-on or off the LCD.
* Arguments : 'toggle' indicates turn-on or turn-off. 'TRUE' means ON;'FALSE' means
* OFF.
* Returns : None.
**************************************************************************
*/
void DispOnOff(BOOLEAN toggle)
{
if(toggle)
Disp_InstrAddr=DISP_CMD_TURNON;
else
Disp_InstrAddr=DISP_CMD_TURNOFF ;
Disp_Aux_InstrAddr=DISP_CMD_AUXILIARY;
return;
}
/*
**************************************************************************
* Clear the LCD Screen
*
* Description : This function is used to clear the LCD screen.
* Arguments : None
* Returns : None.
**************************************************************************
*/
void DispClrScr (void)
{
INT8U i,j;
#if MULTITASK == 1
INT8U err;
xOSSemTake(DispSem, 0, &err);
#endif
DispSetStartLine(0);
DELAY(1);
for(i=0;i<DISP_MAX_PAGES;i++)
{ DispSetPageAddr(i);DispSetYAddr(0);
for(j=0;j<DISP_MAX_COLS/2;j++)
{
Disp_L_DataAddr=0;
Disp_Aux_InstrAddr=DISP_CMD_AUXILIARY;
DELAY(1);
}
DispSetPageAddr(i);DispSetYAddr(0);
for(j=0;j<DISP_MAX_COLS/2;j++)
{
Disp_R_DataAddr=0;
Disp_Aux_InstrAddr=DISP_CMD_AUXILIARY;
DELAY(1);
}
}
#if MULTITASK == 1
xOSSemGive(DispSem);
#endif
}
/*
**************************************************************************
* Set Page Address( X Address )
*
* Description : This function is used to set X address(page address).
* Arguments : 'pageaddr' is the page address to be set.It is from 0 to 7, if other value is
* passed,it will be truncated.
* Returns : None.
**************************************************************************
*/
void DispSetPageAddr (INT8U pageaddr)
{
pageaddr &=0x7;
Disp_InstrAddr=DISP_CMD_SETPAGE+pageaddr;
Disp_Aux_InstrAddr=DISP_CMD_AUXILIARY;
DELAY(1);
return;
}
/*
**************************************************************************
* Set Y Address
*
* Description : This function is used to set Y address(column address).
* Arguments : 'Yaddr' is the Y address to be set.It is from 0 to 63, if other value is
* passed,it will be truncated.
* Returns : None.
**************************************************************************
*/
void DispSetYAddr (INT8U Yaddr)
{
Yaddr &=0x3F;
Disp_InstrAddr=DISP_CMD_SETY+Yaddr;
Disp_Aux_InstrAddr=DISP_CMD_AUXILIARY;
DELAY(1);
return;
}
/*
**************************************************************************
* Set start line
*
* Description : This function is used to set start line.
* Arguments : 'startline' is the start line to be set.It is from 0 to 63, if other value is
* passed,it will be truncated.
* Returns : None.
**************************************************************************
*/
void DispSetStartLine (INT8U startline)
{
startline &=0x3F;
if(startline==0)
Disp_InstrAddr=DISP_CMD_SETSTARTLINE;
else
Disp_InstrAddr=DISP_CMD_SETSTARTLINE+64-startline;
Disp_Aux_InstrAddr=DISP_CMD_AUXILIARY;
DELAY(1);
return;
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -