12864是属于LCD 液晶显示的,LCD是 Liquid Crystal Display 的简称,LCD 的构造是在两片平行的玻璃当中放置液态的晶体,两片玻璃中间有许多垂直和水平的细小电线,透过通电与否来控制杆状水晶分子改变方向,将光线折射出来产生画面。
12864就是利用这样的原理实现字符与图片的显示的。但是单纯的液晶屏仅仅指那两片玻璃屏,不容易 *** 作,所以一般都会加上驱动IC。
下面我以图片详细像你说明:
这个就是那两片玻璃,中间夹有液体。 *** 作它很麻烦,要用到很多的连接线:
那上下两侧的就是用来控制屏幕的,这些接口和玻璃瓶是通过两个小东西连接的:
连接之后就是这个样子了:
当然只是这样还是不行的,还要加上背光,不然显示出来的字符或图片看不到,背光是用很多串联的LED实现的:
大体就是这样了。
1602是指的16字符2行的那种吧。如果是,其点阵是这样的结构。其IC带有字库。想显示字符,只需要输入对应字的地址。
而12864的点阵是连续的。一般不带有字库。想写一个圆点,都要自己想好要写那些位置。屏上每个点都对应字IC内部RAM中一个BIT. 黑白的程序已经很久没有用了。不知道240*320彩屏的对LZ有帮助没有。区别是彩屏一个像素点需要16BIT数据(或者18,或者24).
//---------------------------------------------------------------------------
#include "reg51.h"
typedef bit uint1
typedef unsigned char uint8, uchar, UCHAR
typedef unsigned int uint16, uint, UINT
typedef unsigned long uint32, ulong, ULONG
//---------------------------------------------------------------------------
sbit A0=P3^2
sbit _RES=P3^0
sbit _WR=P3^1
sbit _LE=P3^6
sbit _CS=P3^3
//---------------------------------------------------------------------------
void Delay10ms(UINT t)
void W_COM(UCHAR dat)
void W_DATA1(UCHAR dat)
void W_DATA2(UCHAR dat1, UCHAR dat2)
void Init(void)
void ILI9320_HSD24_Initial(void)
void LCD_CtrlWrite_ILI9320(UINT com, UINT dat)
void Edge(void)
void Test(void)
void Clear(void)
void Full(void)
void Red(void)
void Green(void)
void Blue(void)
void RGBMix(void)
void Bar(void)
void Show(UINT sx, UINT ex, UINT sy, UINT ey, UINT dat)
void SetShowArea(UINT sx, UINT ex, UINT sy, UINT ey)
//void ShowPic(UCHAR* ppic, UCHAR size, UCHAR ystart, UCHAR xstart)
//---------------------------------------------------------------------------
void main(void)
{
_LE = 0
_CS = 0
ILI9320_HSD24_Initial()
while(1)
{
Full()
Delay10ms(400)
Clear()
Delay10ms(400)
Red()
Delay10ms(400)
Green()
Delay10ms(400)
Blue()
Delay10ms(400)
/*RGBMix()
Delay10ms(400)
Bar()
Delay10ms(400)*/
}
}
//---------------------------------------------------------------------------
void Delay10ms(UINT t)
{
UCHAR i
while( t > 0 )
{
t--
for ( i = 0 i < 255 i++ )
}
}
//---------------------------------------------------------------------------
void W_COM(UCHAR dat)
{
A0 = 0
_LE = 1
P1 = 0x00
_LE = 0
P1 = dat
_WR = 0
_WR = 1
}
//---------------------------------------------------------------------------
void W_DATA1(UCHAR dat)
{
A0 = 1
P1 = dat
_WR = 0
_WR = 1
}
//---------------------------------------------------------------------------
void W_DATA2(UCHAR dat1, UCHAR dat2)
{
A0 = 1
_LE = 1
P1 = dat1
_LE = 0
P1 = dat2
_WR = 0
_WR = 1
}
//---------------------------------------------------------------------------
void Init(void)
{
_RES = 1
Delay10ms(100)
_RES = 0
Delay10ms(100)
_RES = 1
/*W_COM(0xE5)
W_DATA2(0x80, 0x00)*/
W_COM(0x00)
W_DATA2(0x00, 0x01)
Delay10ms(10)
W_COM(0x01)
W_DATA2(0x01, 0x00)
W_COM(0x02)
W_DATA2(0x07, 0x00)
W_COM(0x03)
W_DATA2(0x10, 0x30)
//W_DATA2(0x0030)
W_COM(0x04)
W_DATA2(0x00, 0x00)
W_COM(0x08)
W_DATA2(0x02, 0x02)
W_COM(0x09)
W_DATA2(0x00, 0x00)
W_COM(0x0A)
W_DATA2(0x00, 0x00)
W_COM(0x0C)
W_DATA2(0x00, 0x00)
W_COM(0x0D)
W_DATA2(0x00, 0x00)
W_COM(0x0F)
W_DATA2(0x00, 0x00)
W_COM(0x10)
W_DATA2(0x00, 0x00)
W_COM(0x11)
W_DATA2(0x00, 0x07)
W_COM(0x12)
W_DATA2(0x00, 0x00)
W_COM(0x13)
W_DATA2(0x00, 0x00)
Delay10ms(100)
W_COM(0x10)
W_DATA2(0x17, 0xB0)
W_COM(0x11)
W_DATA2(0x00, 0x37)
Delay10ms(100)
W_COM(0x12)
W_DATA2(0x01, 0x3A)
Delay10ms(100)
W_COM(0x13)
W_DATA2(0x16, 0x00)
W_COM(0x29)
W_DATA2(0x00, 0x0C)
Delay10ms(100)
W_COM(0x20)
W_DATA2(0x00, 0x00)
W_COM(0x21)
W_DATA2(0x00, 0x00)
W_COM(0x30)
W_DATA2(0x05, 0x04)
W_COM(0x31)
W_DATA2(0x07, 0x03)
W_COM(0x32)
W_DATA2(0x07, 0x02)
W_COM(0x35)
W_DATA2(0x01, 0x01)
W_COM(0x36)
W_DATA2(0x0A, 0x1F)
W_COM(0x37)
W_DATA2(0x05, 0x04)
W_COM(0x38)
W_DATA2(0x00, 0x03)
W_COM(0x39)
W_DATA2(0x07, 0x06)
W_COM(0x3C)
W_DATA2(0x07, 0x07)
W_COM(0x3D)
W_DATA2(0x09, 0x1F)
W_COM(0x50)
W_DATA2(0x00, 0x00)
W_COM(0x51)
W_DATA2(0x00, 0xEF)
W_COM(0x52)
W_DATA2(0x00, 0x00)
W_COM(0x53)
W_DATA2(0x01, 0x3F)
W_COM(0x60)
W_DATA2(0x27, 0x00)
W_COM(0x61)
W_DATA2(0x00, 0x01)
W_COM(0x6A)
W_DATA2(0x00, 0x00)
W_COM(0x80)
W_DATA2(0x00, 0x00)
W_COM(0x81)
W_DATA2(0x00, 0x00)
W_COM(0x82)
W_DATA2(0x00, 0x00)
W_COM(0x83)
W_DATA2(0x00, 0x00)
W_COM(0x84)
W_DATA2(0x00, 0x00)
W_COM(0x85)
W_DATA2(0x00, 0x00)
W_COM(0x90)
W_DATA2(0x00, 0x10)
W_COM(0x92)
W_DATA2(0x00, 0x00)
W_COM(0x93)
W_DATA2(0x00, 0x03)
W_COM(0x95)
W_DATA2(0x01, 0x10)
W_COM(0x97)
W_DATA2(0x00, 0x00)
W_COM(0x98)
W_DATA2(0x00, 0x00)
W_COM(0x07)
W_DATA2(0x01, 0x73)
}
//---------------------------------------------------------------------------
void SetShowArea(UINT sx, UINT ex, UINT sy, UINT ey)
{
W_COM(0x50)
W_DATA2(0, sx)
W_COM(0x51)
W_DATA2(0, ex)
W_COM(0x52)
W_DATA2(sy/256, sy%256)
W_COM(0x53)
W_DATA2(ey/256, ey%256)
}
//---------------------------------------------------------------------------
void Clear(void)
{
Show(0x0000, 0x00EF, 0x0000, 0x013F, 0x0000)
}
//---------------------------------------------------------------------------
void Full(void)
{
Show(0x0000, 0x00EF, 0x0000, 0x013F, 0xFFFF)
}
//---------------------------------------------------------------------------
void Red(void)
{
Show(0x0000, 0x00EF, 0x0000, 0x013F, 0xF800)
}
//---------------------------------------------------------------------------
void Green(void)
{
Show(0x0000, 0x00EF, 0x0000, 0x013F, 0x07E0)
}
//---------------------------------------------------------------------------
void Blue(void)
{
Show(0x0000, 0x00EF, 0x0000, 0x013F, 0x001F)
}
//---------------------------------------------------------------------------
void RGBMix(void)
{
Show(0x0000, 0x00EF, 0x0000, 0x013F, 0xFFE0)
Delay10ms(400)
Show(0x0000, 0x00EF, 0x0000, 0x013F, 0x07FF)
Delay10ms(400)
Show(0x0000, 0x00EF, 0x0000, 0x013F, 0xF81F)
Delay10ms(400)
Clear()
/*
Show(0x00, 0x3F, 0x00, 0x34, 0xFF, 0xE0)
Show(0x00, 0x3F, 0x35, 0x6A, 0x07, 0xFF)
Show(0x00, 0x3F, 0x6B, 0x9F, 0xF8, 0x1F)
Show(0x40, 0x7F, 0x00, 0x34, 0xF8, 0x00)
Show(0x40, 0x7F, 0x35, 0x6A, 0x07, 0xE0)
Show(0x40, 0x7F, 0x6B, 0x9F, 0x00, 0x1F)*/
}
//---------------------------------------------------------------------------
void Bar(void)
{
Clear()
/*
Show(0x1F, 0x5F, 0x1A, 0x35, 0xF8, 0x00)
Show(0x1F, 0x5F, 0x50, 0x6B, 0x07, 0xE0)
Show(0x1F, 0x5F, 0x86, 0x9F, 0x00, 0x1F) */
}
//---------------------------------------------------------------------------
void Show(UINT sx, UINT ex, UINT sy, UINT ey, UINT dat)
{
UINT x, y, i, j
SetShowArea(sx, ex, sy, ey)
x = ex - sx
y = ey - sy
W_COM(0x22)
for ( i = 0 i <= y i++ )
for ( j = 0 j <= x j++ )
W_DATA2(dat/256, dat%256)
}
//---------------------------------------------------------------------------
void ILI9320_HSD24_Initial(void)
{
// VCI=2.8V
//************* Reset LCD Driver ****************//
_RES = 1
Delay10ms(1) // Delay 1ms
_RES = 0
Delay10ms(10) // Delay 10ms // This delay time is necessary
_RES = 1
Delay10ms(50) // Delay 50 ms
//************* Start Initial Sequence **********//
LCD_CtrlWrite_ILI9320(0x00E5, 0x8000) // Set the internal vcore voltage
LCD_CtrlWrite_ILI9320(0x0000, 0x0001) // Start internal OSC.
LCD_CtrlWrite_ILI9320(0x0001, 0x0100) // set SS and SM bit
LCD_CtrlWrite_ILI9320(0x0002, 0x0700) // set 1 line inversion
LCD_CtrlWrite_ILI9320(0x0003, 0x1030) // set GRAM write direction and BGR=1.
LCD_CtrlWrite_ILI9320(0x0004, 0x0000) // Resize register
LCD_CtrlWrite_ILI9320(0x0008, 0x0202) // set the back porch and front porch
LCD_CtrlWrite_ILI9320(0x0009, 0x0000) // set non-display area refresh cycle ISC[3:0]
LCD_CtrlWrite_ILI9320(0x000A, 0x0000) // FMARK function
LCD_CtrlWrite_ILI9320(0x000C, 0x0000) // RGB interface setting
LCD_CtrlWrite_ILI9320(0x000D, 0x0000) // Frame marker Position
LCD_CtrlWrite_ILI9320(0x000F, 0x0000) // RGB interface polarity
//*************Power On sequence ****************//
LCD_CtrlWrite_ILI9320(0x0010, 0x0000) // SAP, BT[3:0], AP, DSTB, SLP, STB
LCD_CtrlWrite_ILI9320(0x0011, 0x0000) // DC1[2:0], DC0[2:0], VC[2:0]
LCD_CtrlWrite_ILI9320(0x0012, 0x0000) // VREG1OUT voltage
LCD_CtrlWrite_ILI9320(0x0013, 0x0000) // VDV[4:0] for VCOM amplitude
Delay10ms(200) // Dis-charge capacitor power voltage
LCD_CtrlWrite_ILI9320(0x0010, 0x17B0) // SAP, BT[3:0], AP, DSTB, SLP, STB
LCD_CtrlWrite_ILI9320(0x0011, 0x0037) // DC1[2:0], DC0[2:0], VC[2:0]
Delay10ms(50) // Delay 50ms
LCD_CtrlWrite_ILI9320(0x0012, 0x013A) // VREG1OUT voltage
Delay10ms(50) // Delay 50ms
LCD_CtrlWrite_ILI9320(0x0013, 0x1C00) // VDV[4:0] for VCOM amplitude
LCD_CtrlWrite_ILI9320(0x0029, 0x000A) // VCM[4:0] for VCOMH
Delay10ms(50)
LCD_CtrlWrite_ILI9320(0x0020, 0x0000) // GRAM horizontal Address
LCD_CtrlWrite_ILI9320(0x0021, 0x0000) // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
LCD_CtrlWrite_ILI9320(0x0030, 0x0007)
LCD_CtrlWrite_ILI9320(0x0031, 0x0203)
LCD_CtrlWrite_ILI9320(0x0032, 0x0001)
LCD_CtrlWrite_ILI9320(0x0035, 0x0007)
LCD_CtrlWrite_ILI9320(0x0036, 0x0407)
LCD_CtrlWrite_ILI9320(0x0037, 0x0607)
LCD_CtrlWrite_ILI9320(0x0038, 0x0106)
LCD_CtrlWrite_ILI9320(0x0039, 0x0007)
LCD_CtrlWrite_ILI9320(0x003C, 0x0007)
LCD_CtrlWrite_ILI9320(0x003D, 0x001E)
//------------------ Set GRAM area ---------------//
LCD_CtrlWrite_ILI9320(0x0050, 0x0000) // Horizontal GRAM Start Address
LCD_CtrlWrite_ILI9320(0x0051, 0x00EF) // Horizontal GRAM End Address
LCD_CtrlWrite_ILI9320(0x0052, 0x0000) // Vertical GRAM Start Address
LCD_CtrlWrite_ILI9320(0x0053, 0x013F) // Vertical GRAM Start Address
LCD_CtrlWrite_ILI9320(0x0060, 0x2700) // Gate Scan Line
LCD_CtrlWrite_ILI9320(0x0061, 0x0001) // NDL,VLE, REV
LCD_CtrlWrite_ILI9320(0x006A, 0x0000) // set scrolling line
//-------------- Partial Display Control ---------//
LCD_CtrlWrite_ILI9320(0x0080, 0x0000)
LCD_CtrlWrite_ILI9320(0x0081, 0x0000)
LCD_CtrlWrite_ILI9320(0x0082, 0x0000)
LCD_CtrlWrite_ILI9320(0x0083, 0x0000)
LCD_CtrlWrite_ILI9320(0x0084, 0x0000)
LCD_CtrlWrite_ILI9320(0x0085, 0x0000)
//-------------- Panel Control -------------------//
LCD_CtrlWrite_ILI9320(0x0090, 0x0010)
LCD_CtrlWrite_ILI9320(0x0092, 0x0000)
LCD_CtrlWrite_ILI9320(0x0093, 0x0003)
LCD_CtrlWrite_ILI9320(0x0095, 0x0110)
LCD_CtrlWrite_ILI9320(0x0097, 0x0000)
LCD_CtrlWrite_ILI9320(0x0098, 0x0000)
LCD_CtrlWrite_ILI9320(0x0007, 0x0173) // 262K color and display ON
}
//---------------------------------------------------------------------------
void LCD_CtrlWrite_ILI9320(UINT com, UINT dat)
{
W_COM( com&0xFF )
W_DATA2( dat>>8, dat&0xFF )
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)