📄 lcd.c
字号:
#include "..\inc\uTypes.h"
#include "..\inc\44b0x.h"
#include "..\inc\console.h"
#include "..\inc\sysUtils.h"
#include "lcd.h"
#define LCM_DELAY 1000
#define NOP __asm { nop }
void lcmInit (void)
{
int i;
//先初始化端口
//PORT C GROUP
//BUSWIDTH=16
//Configure PORTA0.0 AS output
rPCONA = 0x3fE;
// PORT B GROUP
/* BIT 10 9 8 7 6 5 4 3 2 1 0 */
/* /CS5 /CS4 /CS3 /CS2 /CS1 nWBE3 nWBE2 /SRAS /SCAS SCLK SCKE */
/* EXT NIC 8019 IDE D12 NC NC Sdram Sdram Sdram Sdram */
/* 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 */
rPDATB = 0x7ff;
rPCONB = 0x7ff;
/* PC15 14 13 12 11 10 9 8 */
/* o o RXD1 TXD1 o o o o */
/* NC NC Uart1 Uart1 NC NC NC NC */
/* 01 01 11 11 01 01 01 01 */
/* PC7 6 5 4 3 2 1 0 */
/* o o o o o o o o */
/* NC NC NC NC LED LED LED LED */
/* 01 01 01 01 01 01 01 01 */
rPDATC = 0x0000; //All IO is low
rPCONC = 0x5f555555;
rPUPC = 0x3000; //PULL UP RESISTOR should be enabled to I/O
//PORT D GROUP
/* PORT D GROUP(I/O OR LCD) */
/* BIT7 6 5 4 3 2 1 0 */
/* VF VM VLINE VCLK VD3 VD2 VD1 VD0 */
/* 01 01 01 01 01 01 01 01 */
//rPDATD= 0x00;
//rPCOND= 0x5555;
//rPUPD = 0x00;
//delayMs (100);
printf("====main panel init====\n");
//************* Start Initial Sequence **********//
printf("init ili9320.\n");
rPDATC=(rPDATC&0xfffe);
delayMs(200);
rPDATC=(rPDATC|0x1); //rst
//************* Start Initial Sequence ********//
SendCmd(0x0000, 0x0001); // Start internal OSC.
delayMs(50);
SendCmd(0x0001, 0x0100); // set SS and SM bit
SendCmd(0x0002, 0x0700); // set 1 line inversion
SendCmd(0x0003, 0x1088); // set GRAM write direction and BGR=1.
SendCmd(0x0004, 0x0000); // Resize register
SendCmd(0x0007, 0x0000); //chg // Resize register
SendCmd(0x0008, 0x0202); // set the back porch and front porch
SendCmd(0x0009, 0x0100); //chg // set non-display area refresh cycle ISC[3:0]
SendCmd(0x000A, 0x0008); //chg // FMARK function
SendCmd(0x000C, 0x0000); // RGB interface setting
SendCmd(0x000D, 0x0000); //chg // Frame marker Position
SendCmd(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ***************//
SendCmd(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
SendCmd(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
SendCmd(0x0012, 0x0000); // VREG1OUT voltage
SendCmd(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
delayMs(200); // Dis-charge capacitor power voltage
SendCmd(0x0010, 0x1090); //17b0 // SAP, BT[3:0], AP, DSTB, SLP, STB
SendCmd(0x0011, 0x0010); // DC1[2:0], DC0[2:0], VC[2:0]
delayMs(50); // delayMs 50ms
SendCmd(0x0012, 0x0111); //13a // VREG1OUT voltage
delayMs(50); // delayMs 50ms
SendCmd(0x0013, 0x1800); //1a00 // VDV[4:0] for VCOM amplitude
SendCmd(0x0029, 0x000C); // VCM[4:0] for VCOMH
delayMs(50);
SendCmd(0x0020, 0x0000); // GRAM horizontal Address
SendCmd(0x0021, 0x0000); // GRAM Vertical Address
// ---- Adjust the Gamma Curve ------- //
SendCmd(0x0030, 0x0000);
SendCmd(0x0031, 0x0505);
SendCmd(0x0032, 0x0004);
SendCmd(0x0035, 0x0006);
SendCmd(0x0036, 0x0707);
SendCmd(0x0037, 0x0105);
SendCmd(0x0038, 0x0002);
SendCmd(0x0039, 0x0707);
SendCmd(0x003C, 0x0704);
SendCmd(0x003D, 0x0807);
//------------------ Set GRAM area -------------//
SendCmd(0x0050, 0x0000); // Horizontal GRAM Start Address
SendCmd(0x0051, 0x00EF); // Horizontal GRAM End Address
SendCmd(0x0052, 0x0000); // Vertical GRAM Start Address
SendCmd(0x0053, 0x013F); // Vertical GRAM Start Address
SendCmd(0x0060, 0x2700); // Gate Scan Line
SendCmd(0x0061, 0x0001); // NDL,VLE, REV
SendCmd(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control -------//
SendCmd(0x0080, 0x0000);
SendCmd(0x0081, 0x0000);
SendCmd(0x0082, 0x0000);
SendCmd(0x0083, 0x0000);
SendCmd(0x0084, 0x0000);
SendCmd(0x0085, 0x0000);
//-------------- Panel Control -----------------//
SendCmd(0x0090, 0x0010);
SendCmd(0x0092, 0x0000);
SendCmd(0x0093, 0x0003);
SendCmd(0x0095, 0x0110);
SendCmd(0x0097, 0x0000);
SendCmd(0x0098, 0x0000);
SendCmd(0x0007, 0x0173); // 65K color and display ON
}
/*CMD=RS low;Data=RS high*/
void SendCmd(U16 cmd,U16 par)
{
lcmWriteCmd((0x0000|cmd));
lcmWriteData((0x0000|par));
}
void lcmWriteCmd (U16 byCmd)
{
rPDATA=rPDATA|0x0001;
rPDATA=rPDATC&(~0x0001);
#ifdef MRTOS
(*(volatile unsigned short*)(0x04000000+0))=byCmd;
rPDATA=rPDATA|0x0001;
#else
(*(volatile unsigned short*)(0x0a000000+0))=byCmd;
#endif
}
void lcmWriteData (U16 byData)
{
rPDATA=rPDATC&(~0x0001);
rPDATA=rPDATA|0x0001;
#ifdef MRTOS
(*(volatile unsigned short*)(0x04000000+0))=byData;
rPDATA=rPDATC&(~0x0001);
#else
(*(volatile unsigned short*)(0x0a000000+2))=byData;
#endif
}
void delayMs (int nDelay)
{
int i;
for (i = 0; i < nDelay; ++ i);
}
void LCD_Set_XY(unsigned int x, unsigned int y)
{
SendCmd(0x0020,(x&0x00ff));
SendCmd(0x0021,(y&0x01ff));
}
void LCD_Set_Window(unsigned int startX,unsigned int startY,unsigned int endX,unsigned int endY)
{
LCD_Set_XY(startX,startY);
SendCmd(0x0050,(startX&0x00ff));
SendCmd(0x0052,(startY&0x00ff));
SendCmd(0x0051,(endX&0x01ff));
SendCmd(0x0053,(endY&0x01ff));
}
void LCD_test(void)
{
unsigned int i,j;
(*(volatile unsigned short *)(0x04000000+0))=0x0022; //start write
for(i=0;i<320;i++)
for(j=0;j<240;j++)
{
if(i>279)lcmWriteData(0x0000);
else if(i>239)lcmWriteData(0x001f);
else if(i>199)lcmWriteData(0x07e0);
else if(i>159)lcmWriteData(0x07ff);
else if(i>119)lcmWriteData(0xf800);
else if(i>79)lcmWriteData(0xf81f);
else if(i>39)lcmWriteData(0xffe0);
else lcmWriteData(0xffff);
}
//LCD_Write_End();
}
unsigned char LCD_DrawPicture(unsigned char startX, unsigned char startY, unsigned int *pic, unsigned char sizeX, unsigned char sizeY)
{
unsigned int endX,endY;
unsigned long totalPixels = (unsigned long)sizeX * (unsigned long)sizeY;
endX = startX+sizeX-1;
endY = startY+sizeY-1;
if(endX>239 || endY>319)return 1;
LCD_Set_Window(startX,startY,endX,endY);
#ifdef MRTOS
(*(volatile unsigned short*)(0x04000000+0))=0x0022; //start write
rPDATA=rPDATA|0x0001;
#else
(*(volatile unsigned short*)(0x0a000000+2))=0x0022; //start write
#endif
while(totalPixels--)lcmWriteData(*(pic+=2));
//LCD_Write_End();
return 0;
}
unsigned char LCD_DrawPicture2(unsigned char startX, unsigned char startY, unsigned int *pic, unsigned char sizeX, unsigned char sizeY)
{
unsigned int i,j;
if((startX+sizeX)>240 || (startY+sizeY)>320)return 1;
for (j = 0; j<sizeY; j++)
{
LCD_Set_XY(startX,startY);
#ifdef MRTOS
(*(volatile unsigned short*)(0x04000000+0))=0x0022; //start write
rPDATA=rPDATA|0x0001;
#else
(*(volatile unsigned short*)(0x0a000000+2))=0x0022; //start write
#endif
for(i = 0; i<sizeX; i++)
{
lcmWriteData(*(pic+=2));
}
startY++;//换行
}
//LCD_Write_End();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -