📄 ssd1815.c
字号:
// Functions for SSD1815
#include "delay.h"
// Function for sending a byte to LCD
void SendByte(bit DatCmd, uint8 dByte)
{
#ifdef MCU_6800
LCD_DataPort = 0x00; // Set the port as Output
LCD_A0 = DatCmd;
LCD_RW = 0;
LCD_E = 1;
LCD_CS = 0;
LCD_DataPort = dByte;
//DelayUs(4);
LCD_E = 0;
//LCD_RW = 1;
LCD_CS = 1;
LCD_DataPort = 0xFF;
#elif defined(MCU_8080)
LCD_DataPort = 0x00; // Set the port as Output
LCD_A0 = DatCmd;
LCD_CS = 0;
LCD_RD = 1;
LCD_WR = 0;
LCD_DataPort = dByte;
//DelayUs(4);
LCD_WR = 1;
LCD_CS = 1;
LCD_DataPort = 0xFF;
#elif defined(LCD_4SPI)
uint8 i;
LCD_A0 = DatCmd;
LCD_CS = 0;
for (i = 0; i < 8; i++)
{
LCD_SCK = 0;
LCD_SID = (dByte<<i) & 0x80;
//DelayUs(4);
LCD_SCK = 1;
}
LCD_CS = 1;
#endif
}
// Function for setting Column Address
void SetCA(uint8 CAddr)
{
// CAddr < LCD_CMAX
//CAddr += 36;
SendByte(iCmd, CAddr & 0x0F);
SendByte(iCmd, (CAddr >> 4) | 0x10);
}
// Function for setting Page Address
void SetPA(uint8 PAddr)
{
//PAddr's range is from 0 to LCD_PMAX
SendByte(iCmd, LCD_P0 + PAddr);
}
// Goto specific position
void Gotoxy(uint8 page, uint8 col)
{
SetPA(page);
SetCA(col);
}
// Function for setting Contrast
void SetContrast(uint8 CValue)
{
// CValue < 64
SendByte(iCmd, 0x81);
SendByte(iCmd, CValue);
}
#ifdef LCD_8BIT
// Read a data from LCD DDRAM
uint8 ReadData(uint8 PAddr, uint8 CAddr)
{
uint8 dByte;
Gotoxy(PAddr, CAddr);
LCD_DataPort = 0xFF; // Set the port as input
LCD_CS = 0;
LCD_A0 = iDat;
#ifdef MCU_6800
LCD_RW = 1;
LCD_E = 1;
//DelayUs(4); // A dummy read
LCD_E = 0;
//DelayUs(4);
LCD_E = 1;
//DelayUs(4);
dByte = LCD_DataPort; // Actual read
LCD_E = 0;
#else
LCD_WR = 1;
LCD_RD = 0;
//DelayUs(4); // A dummy read
LCD_RD = 1;
//DelayUs(4);
LCD_RD = 0;
//DelayUs(4);
dByte = LCD_DataPort; // Actual read
LCD_RD = 1;
#endif
LCD_CS = 1;
return dByte;
}
// Reverse display of Page PAddr
void ReversePage(uint8 PAddr)
{
uint8 col, Original;
for (col = 0; col < LCD_CMAX; col++)
{
Original = ReadData(PAddr, col);
SetCA(col);
SendByte(iDat, ~Original);
}
}
#endif
#ifdef LCD_ICOMAX
// Set LCD specific Icon ON/OFF
void SetIcon(uint8 State, uint8 index)
{
SetPA(8); // Goto Icon Page
SetCA(ICONS[index]);
//SetCA(131 - ICONS[index]); // For Reversed Segments
SendByte(iDat, State);
}
// Turn On/Off all icons
void Allicons(bit State)
{
uint8 i;
for (i = 0; i < LCD_ICOMAX; i++)
{
if (State)
SetIcon(0xFF, i);
else
SetIcon(0x00, i);
}
}
// Display each Icon and then hide them one by one
void ICON_Test(void)
{
uint8 i;
//Allicons(1);
//delay1s();
//Allicons(0);
//delay1s();
for (i = 0; i < 2*LCD_ICOMAX; i++)
{
if (i < LCD_ICOMAX)
{
SetIcon(0xFF, i);
}
else
{
SetIcon(0x00, i - LCD_ICOMAX);
}
delay100ms();
}
delay500ms();
}
#endif
void Tile(uint8 fst, uint8 snd)
{
uint8 i,j;
//SendByte(iCmd, LCD_OFF);
for (i = 0; i < LCD_PMAX; i++)
{
Gotoxy(i, 0);
for (j = 0; j < LCD_CMAX/2; j++)
{
SendByte(iDat, fst);
SendByte(iDat, snd);
}
}
//SendByte(iCmd, LCD_ON);
}
// Clear LCD screen
void Clear(void)
{
Tile(0x00,0x00);
DelayUs(4);
}
// Clear page X
void ClearPage(uint8 PAddr)
{
uint8 Col = LCD_CMAX;
Gotoxy(PAddr, 0);
while(Col-- != 0)
{
SendByte(iDat, 0x00);
//delay100ms();
}
SetCA(0);
}
// Wait some time and clear the screen
void wait_and_clear(void)
{
DelayMs(1200);
Clear();
}
// Function for initializing LCD
void LCD_Initial(void)
{
LCD_RST = 0;
DelayUs(8);
LCD_RST = 1;
SendByte(iCmd, LCD_BIAS); // Set LCD power supply Bias Ratio
SendByte(iCmd, LCD_ADC); // Set ADC
SendByte(iCmd, LCD_SHL); // Set SHL
SendByte(iCmd, 0x2F); // Set Power Control Register
//DelayMs(10);
SendByte(iCmd, 0x24); // Set Internal Register Ratio
SetContrast(0x13);
SendByte(iCmd, LCD_DATN);
//SendByte(iCmd, LCD_DATR);
SendByte(iCmd, LCD_ON);
Clear();
}
// Display LCD Test Graphics
void LCD_Test(void)
{
uint8 i;
uint8 code TestData[][2] =
{
{0xFF,0xFF}, // 1. All
{0x00,0x00}, // 2. None
{0xFF,0x00}, // 3. Virtical 1
{0x00,0xFF}, // 4. Virtical 2
{0xAA,0x55}, // 7. Stars 2
{0x55,0xAA}, // 8. Stars 2
{0xAA,0xAA}, // 5. Horizontal 1
{0x55,0x55}, // 6. Horizontal 2
};
for (i = 0; i < 8; i++)
{
Tile(TestData[i][0], TestData[i][1]);
wait_and_clear();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -