?? st7920_graphics.c
字號:
// Wait and Clear
void WAC(void)
{
DelayMs(1000);
gTile(0x00, 0x00);
}
// Read data from GDRAM
uint16 ReadData(uint8 xUnit, yBit)
{
uint16 dByte;
Locate(xUnit, yBit);
LCD_DataPort = 0xFF;
LCD_RS = iDat;
LCD_RW = 1;
// A Dummy Read
LCD_E = 1;
LCD_E = 0;
// Read Higher Byte
LCD_E = 1;
DelayUs(80);
dByte = LCD_DataPort;
dByte <<= 8;
LCD_E = 0;
// Read Lower Byte
LCD_E = 1;
DelayUs(80);
dByte |= LCD_DataPort;
LCD_E = 0;
LCD_DataPort = 0xFF;
return dByte;
}
// Locate a position in Gaphic Mode
void Locate(uint8 xUnit, yBit)
{
// 1xUnit = 16 dots, 1yBit = 1 dot
SetMode(LCD_GMODE);
SendByte(iCmd, 0x80 + yBit);
SendByte(iCmd, 0x80 + xUnit);
}
// Tile LCD screen with two datas in Gaphic Mode
void gTile(uint8 fst, snd)
{
uint8 i, k;
for (i = 0; i < LCD_YMAX; i++)
{
Locate(0, i);
for (k = 0; k < LCD_XMAX; k++)
{
SendByte(iDat, fst);
SendByte(iDat, snd);
}
}
}
// Draw a Horizontal Line with special style
void LineHs(uint8 X0, Y0, xUnits, Style)
{
uint8 i;
Locate(X0, Y0);
for (i = 0; i < xUnits; i++)
{
SendByte(iDat, Style);
SendByte(iDat, Style);
}
}
// Draw a Horizontal Line
void LineH(uint8 X0, Y0, xDots)
{
uint8 i;
uint8 xUnit;
uint16 OldData;
uint16 NewData;
for (i = 0; i < xDots; i++)
{
xUnit = (i + X0)/16;
OldData = ReadData(xUnit, Y0);
NewData = OldData|(0x0001 << (15 - i%16));
Locate(xUnit, Y0);
SendByte(iDat, NewData >> 8);
SendByte(iDat, NewData & 0x00FF);
}
}
// Draw a Vertical Line
void LineV(uint8 X0, Y0, yBits)
{
uint8 i;
uint8 xUnit = X0/16;
uint16 OldData;
uint16 NewData;
for (i = 0; i < yBits; i++)
{
OldData = ReadData(xUnit, Y0 + i);
NewData = OldData|(0x0001 << (15 - X0%16));
Locate(xUnit, Y0 + i);
SendByte(iDat, NewData >> 8);
SendByte(iDat, NewData & 0x00FF);
}
}
// Display Standard Testing Graphics
void GraphicTest(void)
{
uint8 i, k;
uint8 code TestData[][2] =
{
{0xFF,0xFF},// All
{0x00,0x00},// None
{0xAA,0xAA},// Virtical 1
{0x55,0x55},// Virtical 2
{0xFF,0x00},// Horizontal 1
{0x00,0xFF},// Horizontal 2
{0xAA,0x55},// Stars 1
{0x55,0xAA} // Stars 2
};
for (i = 0; i < 4; i++)
{
gTile(TestData[i][0], TestData[i][1]);
WAC();
}
for (k = 4; k < 8; k++)
{
for (i = 0; i < 32; i += 2)
{
LineHs(0, i, LCD_XMAX, TestData[k][0]);
LineHs(0, i + 1, LCD_XMAX, TestData[k][1]);
}
WAC();
}
// Fullscreen Rectangle
LineH(0, 0, LCD_CMAX);
LineH(0, LCD_YMAX - 1, LCD_CMAX);
LineV(0, 0, LCD_YMAX);
LineV(LCD_CMAX - 1, 0, LCD_YMAX);
WAC();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -