?? lcd_st7565.c
字號:
//包含所需頭文件
#include "config.h"
#include "LCD_Font.h"
void LCD_WriteData(uint8 Data)
{
LCD_CS_OUT(0);
LCD_A0_OUT(1);
spi_write(Data);
LCD_CS_OUT(1);
}
void LCD_WriteCMD(uint8 CMD)
{
LCD_CS_OUT(0);
LCD_A0_OUT(0);
spi_write(CMD);
LCD_CS_OUT(1);
}
void LCD_DisplayOnOff(uint8 On)
{
On &= 0x01;
LCD_WriteCMD(0xAE | On);
}
void LCD_PowerControl(uint8 Power)
{
Power &= 0x07;
LCD_WriteCMD(0x28 | Power);
}
void LCD_SetStartLine(uint8 LineStart)
{
LineStart &= 0x3F;
LCD_WriteCMD(0x40 | LineStart);
}
void LCD_SetPageAddress(uint8 Page)
{
Page &= 0x0F;
LCD_WriteCMD(0xB0 | Page);
}
void LCD_SetColumnAddress(uint8 Column)
{
LCD_WriteCMD(0x10 | (Column>>4));
LCD_WriteCMD(Column & 0x0F);
}
void LCD_SetV0_Voltage_Regulator(uint8 Ratio)
{
Ratio &= 0x07;
LCD_WriteCMD(0x20 | Ratio);
}
// Electronic Volume Setting
void LCD_SetElectronicVolume(uint8 Volume)
{
Volume &= 0x3F;
LCD_WriteCMD(0x81);
LCD_WriteCMD(Volume);
}
void LCD_Init(void)
{
DDRB |= BIT(LCD_CS) | BIT(LCD_A0) | BIT(LCD_RST);
LCD_RST_OUT(0);
_delay_us(50);
LCD_RST_OUT(1);
_delay_us(1000);
LCD_BackLightOn();
// LCD Bias Setting
LCD_WriteCMD(0xA2); // LCD Bias Set: 1/9 bias
//LCD_WriteCMD(0xA3); // LCD Bias Set: 1/7 bias
_delay_us(50);
// LCD ADC Setting
//LCD_WriteCMD(0xA0); // Set ADC 0: Noraml
LCD_WriteCMD(0xA1); // Set ADC 0: Reverse
_delay_us(50);
// Common Output Setting
LCD_WriteCMD(0xC0); // Normal : COM0~COM63
//LCD_WriteCMD(0xC8); // Reverse : COM63~COM0
_delay_us(50);
// V5 Output Voltage
LCD_SetV0_Voltage_Regulator(0x04);
_delay_us(50);
// Electronic volume control
LCD_SetElectronicVolume(0x20);
_delay_us(100);
LCD_WriteCMD(0xA4); // Display Normal
//LCD_WriteCMD(0xA5); // All point On
_delay_us(50);
//LCD_WriteCMD(0xA6); // Display Normal
LCD_WriteCMD(0xA7); // Display Reverse
_delay_us(50);
LCD_WriteCMD(0xAC);
LCD_WriteCMD(0x00);
_delay_us(50);
LCD_PowerControl(0x07);
LCD_DisplayOnOff(1);
LCD_SetStartLine(0x00);
}
//-----------------------------------------------------------------------------
// LCD:Clear picture.
//-----------------------------------------------------------------------------
void LCD_CLR(uint8 Data)
{
uint8 adrPage, adrLaw;
for(adrPage = 0; adrPage < MAX_PAGE; adrPage++)
{
LCD_SetPageAddress(adrPage);
LCD_SetColumnAddress(0);
for(adrLaw = 0; adrLaw < MAX_COLUMN; adrLaw++)
{
LCD_WriteData(Data);
}
}
}
//-----------------------------------------------------------------------------
// LCD : Display Chinese.
// Size: 16x16
//-----------------------------------------------------------------------------
uint8 LCD_DisplayHZ(char* XH_HZ, uint8 adrPage, uint8 adrColumn)
{
uint8 *dptr; // dptr_adderss for HZ code.
uint8 i, j;
char charH, charL;
charH = *XH_HZ++;
charL = *XH_HZ;
for(j=0; j<sizeof(HZ_Table)/sizeof(HZ_t); j++)
{
dptr = &HZ_Table[j].Hz_Data[0];
if(charH == pgm_read_byte(dptr) && charL == pgm_read_byte(dptr+1))
break;
}
if(j<sizeof(HZ_Table)/sizeof(HZ_t))
dptr = HZ_Table[j].Table;
else
return FALSE;
LCD_SetPageAddress(adrPage);
LCD_SetColumnAddress(adrColumn);
for(i=0; i< 16; i++)
{
LCD_WriteData(pgm_read_byte(dptr));
dptr ++;
}
LCD_SetPageAddress(adrPage+1);
LCD_SetColumnAddress(adrColumn);
for(i=0; i< 16; i++)
{
LCD_WriteData(pgm_read_byte(dptr));
dptr ++;
}
return TRUE;
}
//-----------------------------------------------------------------------------
// LCD : lcd Display ASCII.
// Size : 8X16
//-----------------------------------------------------------------------------
void LCD_DisplayASCII(uint8 XH_Dig, uint8 adrPage, uint8 adrColumn)
{
uint8 *dptr; // dptr_adderss for Dig code.
uint8 i;
if(XH_Dig < 0x20) XH_Dig = 0x20;
dptr = &ASCII[(XH_Dig-0x20)*16];
LCD_SetPageAddress(adrPage);
LCD_SetColumnAddress(adrColumn);
for(i=0; i< 8; i++)
{
LCD_WriteData(pgm_read_byte(dptr));
dptr = dptr + 1;
}
LCD_SetPageAddress(adrPage+1);
LCD_SetColumnAddress(adrColumn);
for(i=0; i< 8; i++)
{
LCD_WriteData(pgm_read_byte(dptr));
dptr = dptr + 1;
}
}
//-----------------------------------------------------------------------------
// LCD : lcd Display String.
// ASCII(8*16) 及漢字(16*16) 顯示函數
//-----------------------------------------------------------------------------
uint8 LCD_DisplayString(char *String, uint8 adrPage, uint8 adrColumn)
{
char cData[2];
uint8 uLen,uPage,uCol;
uLen = strlen(String);
uPage = adrPage;
uCol = adrColumn;
while(uLen)
{
cData[0] = *String++;
if(cData[0] <= 0x80)
{
LCD_DisplayASCII(cData[0], uPage, uCol);
uCol += 8;
uLen --;
}
else
{
cData[1] = *String++;
LCD_DisplayHZ(cData, uPage, uCol);
uCol += 16;
uLen -= 2;
}
if(uCol >= MAX_COLUMN)
{
uCol = 0;
uPage += 2;
if(uPage >= MAX_PAGE)
uPage = 0;
}
}
return uLen;
}
//-----------------------------------------------------------------------
// LCD_DisplayPicture
// Picture Size: Hight*Weight
//-----------------------------------------------------------------------
uint8 LCD_DisplayPicture(char *Picture, uint8 adrPage, uint8 adrColumn,
uint8 Weight, uint8 Hight)
{
uint8 *dptr; // dptr_adderss for Dig code.
uint8 i, j;
if((adrPage+Hight)>MAX_PAGE) return FALSE;
if((adrColumn+Weight)>MAX_COLUMN) return FALSE;
dptr = (uint8 *)Picture;
for(i=0; i<Hight; i++)
{
LCD_SetPageAddress(adrPage+i);
LCD_SetColumnAddress(adrColumn);
for(j=0; j<Weight; j++)
{
LCD_WriteData(pgm_read_byte(dptr));
}
}
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -