📄 display.c
字号:
#include "m8c.h"
#include "PSoCAPI.h"
#include "utils.h"
#include "globdefs.h"
#include "spim.h"
#include "display.h"
void LcdSendData ( char data );
void LcdSendCommand ( char command );
void LcdInit ( void )
{
int i;
SPIM_Start(SPIM_SPIM_MODE_0 | SPIM_SPIM_MSB_FIRST);
CLEARBIT(LCD_PORT, LCD_RST_BIT);
delayi(0xFF);
SETBIT(LCD_PORT, LCD_RST_BIT);
// Enable SPI port: No interrupt, MSBit first, Master mode
LcdSendCommand(0x21);
LcdSendCommand(0xBF);
LcdSendCommand(0x13);
LcdSendCommand(0x20);
LcdSendCommand(0x0C); // LCD in normal mode.
//clear display
LcdSendCommand(0x40);
LcdSendCommand(0x80);
for(i=0; i<504; i++) LcdSendData(0x00);
}
//--------------------------------------------------------------------------------------------------
// Name : LcdContrast
// Description : Set display contrast.
// Argument(s) : contrast -> Contrast value from 0x00 to 0x7F.
// Return value : None.
// Notes : No change visible at ambient temperature.
//--------------------------------------------------------------------------------------------------
void LcdContrast ( char contrast )
{
// LCD Extended Commands.
LcdSendCommand(0x21);
// Set LCD Vop (Contrast).
LcdSendCommand(0x80);
// LCD Standard Commands, horizontal addressing mode.
LcdSendCommand(0x20);
}
//--------------------------------------------------------------------------------------------------
// Name : LcdClear
// Description : Clears the display.
// Argument(s) : None.
// Return value : None.
//--------------------------------------------------------------------------------------------------
void LcdClear ( void )
{
int i;
for(i=0; i<504; i++) LcdSendData(0x00);
LcdSendCommand(0x40);
LcdSendCommand(0x80);
}
//--------------------------------------------------------------------------------------------------
// Name : LcdGotoXY
// Description : Sets cursor location to xy location corresponding to basic font size.
// Argument(s) : x, y -> Coordinate for new cursor position. x range 0..83, y - 0..5
// Return value : None.
//--------------------------------------------------------------------------------------------------
void LcdGoto ( char x, char y )
{
LcdSendCommand(0x40 | y);
LcdSendCommand(0x80 | x);
}
//--------------------------------------------------------------------------------------------------
// Name : LcdChr
// Description : Displays a character at current cursor location and increment cursor location.
// Argument(s) : ch -> Character to write.
// dt (available only with DRAW_OVER_BACKGROUND directive) -> drawing type
// Return value : None.
//--------------------------------------------------------------------------------------------------
void LcdChr ( char ch )
{
int i;
for(i=0; i<5; i++) LcdSendData(FontLookup[ch-32][i]);
// empty space after character
LcdSendData(0x00);
}
void LcdStr ( char *dataPtr )
{
int i;
while ( *dataPtr )
{
char ch = *dataPtr++;
for(i=0; i<5; i++) LcdSendData(FontLookup[ch-32][i]);
// empty space after character
LcdSendData(0x00);
}
}
void LcdCStr ( const char *dataPtr )
{
int i;
while ( *dataPtr )
{
char ch = *dataPtr++;
for(i=0; i<5; i++) LcdSendData(FontLookup[ch-32][i]);
// empty space after character
LcdSendData(0x00);
}
}
void LcdVBargraph (char x, char ystart, char yend, char yposition)
{
char i,j,ch;
LcdSendCommand(0x40 | yend);
LcdSendCommand(0x80 | x);
LcdSendData(0xFF);
for (i=0; i<6 ; i++)
{ switch (yposition)
{
case 0 : ch=0x80; break;
case 1 : ch=0x80; break;
case 2 : ch=0xC0; break;
case 3 : ch=0xE0; break;
case 4 : ch=0xF0; break;
case 5 : ch=0xF8; break;
case 6 : ch=0xFC; break;
case 7 : ch=0xFE; break;
default: ch=0xFF; break;
};
LcdSendData(ch);
}
LcdSendData(0xFF);
for (j=yend-1; j>ystart; j--)
{
if (yposition > 8) yposition -=8; else yposition=0;
LcdSendCommand(0x40 | j);
LcdSendCommand(0x80 | x);
LcdSendData(0xFF);
for (i=0; i<6 ; i++)
{ switch (yposition)
{
case 0 : ch=0x00; break;
case 1 : ch=0x80; break;
case 2 : ch=0xC0; break;
case 3 : ch=0xE0; break;
case 4 : ch=0xF0; break;
case 5 : ch=0xF8; break;
case 6 : ch=0xFC; break;
case 7 : ch=0xFE; break;
default: ch=0xFF; break;
};
LcdSendData(ch);
};
LcdSendData(0xFF);
};
if (yposition > 8) yposition -=8; else yposition=0;
LcdSendCommand(0x40 | ystart);
LcdSendCommand(0x80 | x);
LcdSendData(0xFF);
for (i=0; i<6 ; i++)
{ switch (yposition)
{
case 0 : ch=0x01; break;
case 1 : ch=0x81; break;
case 2 : ch=0xC1; break;
case 3 : ch=0xE1; break;
case 4 : ch=0xF1; break;
case 5 : ch=0xF9; break;
case 6 : ch=0xFD; break;
case 7 : ch=0xFF; break;
default: ch=0xFF; break;
};
LcdSendData(ch);
}
LcdSendData(0xFF);
}
void LcdHBargraph (char y, char xstart, char xend, char xposition)
{
int i;
LcdSendCommand(0x40 | y);
LcdSendCommand(0x80 | xstart);
LcdSendData(0x7E);
for (i=1; i<=xposition; i++) LcdSendData(0x7E);
for (i=xposition+1; i<xend-xstart; i++) LcdSendData(0x42);
LcdSendData(0x7E);
}
void LcdSendData ( char data )
{
SETBIT(LCD_PORT, LCD_DC_BIT);
// Send data to display controller.
SPIM_SendTxData(data);
// Wait until SPI cycle complete.
while ( ! (bSPIM_ReadStatus() & SPIM_SPIM_SPI_COMPLETE) );
}
void LcdSendCommand ( char command )
{
CLEARBIT(LCD_PORT, LCD_DC_BIT);
// Send command to display controller.
SPIM_SendTxData(command);
// Wait until SPI cycle complete.
while ( ! (bSPIM_ReadStatus() & SPIM_SPIM_SPI_COMPLETE) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -