|
#include "LCM.h"
#include "C8051F020.H"
void Delay_us(unsigned char Times)
{
unsigned char i;
for (i=0; i<Times; i++)
{
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();
}
}
void Delay_ms(unsigned char Times)
{
unsigned char i;
for (i=0; i<Times; i++)
{
Delay_us(250);
Delay_us(250);
Delay_us(250);
Delay_us(250);
}
}
void Delay_s(unsigned char Times)
{
unsigned char i;
for (i=0; i<Times; i++)
{ Delay_ms(250);
Delay_ms(250);
Delay_ms(250);
Delay_ms(250);
}
}
void LCD_WriteReg(unsigned char index,unsigned int val)
{
LCD_CS_L();
LCD_RS_L();
// DATA_OUTPUT();
DATA_LO_PORT = (unsigned char)index;
DATA_HI_PORT = 0;
//DATA_HI_PORT = (unsigned char)(index>>8);
LCD_WR_L();
NOP();
NOP();
LCD_WR_H();
LCD_RS_H();
DATA_LO_PORT = (unsigned char)val;
DATA_HI_PORT = (unsigned char)(val>>8);
LCD_WR_L();
NOP();
NOP();
LCD_WR_H();
LCD_CS_H();
}
unsigned int LCD_ReadReg(unsigned char index)
{
unsigned int ret;
LCD_CS_L();
LCD_RS_L();
// DATA_OUTPUT();
DATA_LO_PORT = (unsigned char)index;
DATA_HI_PORT = 0;
//DATA_HI_PORT = (unsigned char)(index>>8);
LCD_WR_L();
NOP();
NOP();
LCD_WR_H();
LCD_RS_H();
// DATA_INPUT();
ret = DATA_HI_PIN;
ret <<= 8;
ret += DATA_LO_PIN;
LCD_RD_L();
NOP();
NOP();
LCD_RD_H();
LCD_CS_H();
return ret;
}
void LCD_WriteStart()
{
LCD_CS_L();
LCD_RS_L();
// DATA_OUTPUT();
DATA_LO_PORT = 0x22;
DATA_HI_PORT = 0x00;
LCD_WR_L();
NOP();
NOP();
LCD_WR_H();
LCD_RS_H();
}
void LCD_WriteData(unsigned int val)
{
DATA_LO_PORT = (unsigned char)val;
DATA_HI_PORT = (unsigned char)(val>>8);
LCD_WR_L();
NOP();
NOP();
LCD_WR_H();
}
void LCD_WriteEnd()
{
LCD_CS_H();
}
void LCD_ReadStart()
{
LCD_CS_L();
LCD_RS_L();
// DATA_OUTPUT();
DATA_LO_PORT = 0x22;
DATA_HI_PORT = 0x00;
LCD_WR_L();
NOP();
NOP();
LCD_WR_H();
LCD_RS_H();
// DATA_INPUT();
LCD_RD_L();//dummy read
NOP();
LCD_RD_H();
NOP();
NOP();
}
unsigned int LCD_ReadData()
{
unsigned int ret;
LCD_RD_L();
NOP();
ret = DATA_HI_PIN;
ret <<= 8;
ret += DATA_LO_PIN;
LCD_RD_H();
NOP();
NOP();
return ret;
}
void LCD_ReadEnd()
{
LCD_CS_H();
}
void delay_Nms(unsigned int n)
{
while(n--)
Delay_ms(1);
}
#define Display_ON() LCD_WriteReg(0x07,0x0173)
#define Display_OFF() LCD_WriteReg(0x07,0x0000)
void LCD_Init()
{
// PORT_INI();
LCD_RST_L();
delay_Nms(10);
LCD_RST_H();
//delay 10ms
delay_Nms(10);
//initializing funciton 1
LCD_WriteReg(0xe5,0x8000);
LCD_WriteReg(0x00,0x0001);
LCD_WriteReg(0x2b,0x0010);
LCD_WriteReg(0x01,0x0100);
LCD_WriteReg(0x02,0x0700);
LCD_WriteReg(0x03,0x1230);
LCD_WriteReg(0x04,0x0000);
LCD_WriteReg(0x08,0x0202);
LCD_WriteReg(0x09,0x0000);
LCD_WriteReg(0x0a,0x0000);
LCD_WriteReg(0x0c,0x0000);
LCD_WriteReg(0x0d,0x0000);
LCD_WriteReg(0x0f,0x0000);
LCD_WriteReg(0x50,0x0000);
LCD_WriteReg(0x51,0x00ef);
LCD_WriteReg(0x52,0x0000);
LCD_WriteReg(0x53,0x013f);
LCD_WriteReg(0x60,0x2700);
LCD_WriteReg(0x61,0x0001);
LCD_WriteReg(0x6a,0x0000);
LCD_WriteReg(0x80,0x0000);
LCD_WriteReg(0x81,0x0000);
LCD_WriteReg(0x82,0x0000);
LCD_WriteReg(0x83,0x0000);
LCD_WriteReg(0x84,0x0000);
LCD_WriteReg(0x85,0x0000);
LCD_WriteReg(0x90,0x0010);
LCD_WriteReg(0x92,0x0000);
LCD_WriteReg(0x93,0x0003);
LCD_WriteReg(0x95,0x0110);
LCD_WriteReg(0x97,0x0000);
LCD_WriteReg(0x98,0x0000);
//power setting function
LCD_WriteReg(0x10,0x0000);
LCD_WriteReg(0x11,0x0000);
LCD_WriteReg(0x12,0x0000);
LCD_WriteReg(0x13,0x0000);
delay_Nms(200);
LCD_WriteReg(0x10,0x17b0);
LCD_WriteReg(0x11,0x0004);
delay_Nms(50);
LCD_WriteReg(0x12,0x013e);
delay_Nms(50);
LCD_WriteReg(0x13,0x1f00);
LCD_WriteReg(0x29,0x000f);
delay_Nms(50);
LCD_WriteReg(0x20,0x0000);
LCD_WriteReg(0x21,0x0000);
//initializing function 2
LCD_WriteReg(0x30,0x0204);
LCD_WriteReg(0x31,0x0001);
LCD_WriteReg(0x32,0x0000);
LCD_WriteReg(0x35,0x0206);
LCD_WriteReg(0x36,0x0600);
LCD_WriteReg(0x37,0x0500);
LCD_WriteReg(0x38,0x0505);
LCD_WriteReg(0x39,0x0407);
LCD_WriteReg(0x3c,0x0500);
LCD_WriteReg(0x3d,0x0503);
//display on
LCD_WriteReg(0x07,0x0173);
//Display_ON();
}
void LCD_SetXY(unsigned int x, unsigned int y)
{
LCD_WriteReg(0x20,x);
LCD_WriteReg(0x21,y);
}
void LCD_SetWindow(unsigned int startX,unsigned int startY,unsigned int endX,unsigned int endY)
{
LCD_SetXY(startX,startY);
LCD_WriteReg(0x50,startX);
LCD_WriteReg(0x52,startY);
LCD_WriteReg(0x51,endX);
LCD_WriteReg(0x53,endY);
}
void LCD_SetWindowToFullScreen()
{
LCD_SetXY(0,0);
LCD_WriteReg(0x50,0x0000);
LCD_WriteReg(0x52,0x0000);
LCD_WriteReg(0x51,0x00ef);
LCD_WriteReg(0x53,0x013f);
}
void LCD_test()
{
unsigned int i,j;
LCD_WriteStart();
for(i=0;i<320;i++)
for(j=0;j<240;j++)
{
if(i>279)LCD_WriteData(0x0000);
else if(i>239)LCD_WriteData(0x001f);
else if(i>199)LCD_WriteData(0x07e0);
else if(i>159)LCD_WriteData(0x07ff);
else if(i>119)LCD_WriteData(0xf800);
else if(i>79)LCD_WriteData(0xf81f);
else if(i>39)LCD_WriteData(0xffe0);
else LCD_WriteData(0xffff);
}
LCD_WriteEnd();
}
void LCD_ClearScreen(unsigned int color)
{
unsigned long n = 240L*320L;
LCD_SetWindowToFullScreen();
LCD_WriteStart();
while(n--)LCD_WriteData(color);
LCD_WriteEnd();
}
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_SetWindow(startX,startY,endX,endY);
LCD_WriteStart();
while(totalPixels--)
LCD_WriteData(/*pgm_read_word*/(pic++));
LCD_WriteEnd();
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_SetXY(startX,startY);
LCD_WriteStart();
for(i = 0; i<sizeX; i++)
{
LCD_WriteData(/*pgm_read_word*/(pic++));
}
startY++;//换行
}
LCD_WriteEnd();
return 0;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|