📄 lcddrive.c
字号:
#include "lcddrive.h"
#include <string.h>
#define databus P2
sbit CS=P1^1;
sbit CD=P3^5;
sbit WRB=P3^6;
//sbit TCK = P1^4; //底板时钟线接口,待连接外部中断0 P3.2
sbit TDA = P1^3; //底板数据线接口
void LCD_WriteCommand(char com)
{
CS=0;
CD=0; //write command
WRB=0;
databus=com;
WRB=1;
CD=1;
CS=1;
}
void LCD_WriteData(char dat)
{
CS=0;
CD=1; //write display datas
WRB=0;
databus=dat;
WRB=1;
CD=0;
CS=1;
}
void CopyRAMToLCD(int x1, int y1, int x2, int y2)
{
unsigned char row,row1,bytenum,j;
int validbytecnt;
unsigned char temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8;
unsigned char h11,h12,h13,h14,h15,h16,h17,h18,d1,d2,d3,d4;
unsigned char *pdatabuf_1=0;
//unsigned char *pdatabuf_2=0;
validbytecnt=0;
// GUI_FillSCR(0xaa);
// if((x1 > GUI_LCM_XMAX)||(y1 > GUI_LCM_YMAX)) return;
//截取有效图形-有效行数
// if( (y2-y1) < GUI_LCM_YMAX) validcolnum=y2-y1+1;
// else validcolnum=GUI_LCM_YMAX-y1+1;
//截取有效图形-有效列数
// if((x2-x1) < GUI_LCM_XMAX) validrownum=x2-x1+1;
// else validrownum=GUI_LCM_XMAX-x1+1;
// pdatabuf=&DispBuff[0][0];//(INT8U*)malloc(sizeof(INT8U)*validcolnum*((pPicture->width/8)*4+1));//动态申请内存,行字节数扩展至4倍加1
// memcpy(pdatabuf, 0xFF, 20);
// *pdatabuf=0xff;
for (row=y1,row1=0; row<=y2; row++,row1++) //行
{
// pdata_1=DispRAM+row*((GUI_LCM_XMAX/8)*4+1); //扩展后图:pdata_1指向第col行首地址
pdatabuf_1=DispBuff_uc1698; //扩展后图:pdata_1指向第col行首地址
//pdatabuf_2=&DispBuff[0][0];
//pdatabuf_2 += row*(GUI_LCM_XMAX/8); //原图:pdata_2指向第col行首地址
// DispBuff[1][2]=0x36;
for (bytenum=0; bytenum<(GUI_LCM_XMAX/8);bytenum++) //列
{
// temp=*(pdatabuf_2+bytenum); //change 1byte B/W data to 4k-color data
// DispBuff[row][bytenum]=0x25;
temp=DispBuff[row1][bytenum]; //change 1byte B/W data to 4k-color data
temp1=temp&0x80;
temp2=(temp&0x40)>>3;
temp3=(temp&0x20)<<2;
temp4=(temp&0x10)>>1;
temp5=(temp&0x08)<<4;
temp6=(temp&0x04)<<1;
temp7=(temp&0x02)<<6;
temp8=(temp&0x01)<<3;
h11=temp1|temp1>>1|temp1>>2|temp1>>3;
h12=temp2|temp2>>1|temp2>>2|temp2>>3;
h13=temp3|temp3>>1|temp3>>2|temp3>>3;
h14=temp4|temp4>>1|temp4>>2|temp4>>3;
h15=temp5|temp5>>1|temp5>>2|temp5>>3;
h16=temp6|temp6>>1|temp6>>2|temp6>>3;
h17=temp7|temp7>>1|temp7>>2|temp7>>3;
h18=temp8|temp8>>1|temp8>>2|temp8>>3;
d1=h11|h12;
d2=h13|h14;
d3=h15|h16;
d4=h17|h18;
//扩展后的数据保存扩展内存中
*(pdatabuf_1++)=d1;
// validbytecnt++;
// row+=2;
// if(row>=validrownum) break;
*(pdatabuf_1++)=d2;
// validbytecnt++;
// row+=2;
// if(row>=validrownum) break;
*(pdatabuf_1++)=d3;
// validbytecnt++;
// row+=2;
// if(row>=validrownum) break;
*(pdatabuf_1++)=d4;
// validbytecnt++;
// row+=2;
// if(row>=validrownum) break;
}
LCD_WriteCommand(0x70|(row>>4)); //set row MSB address
LCD_WriteCommand(0x60|(row&0x0F)); //set row LSB address
LCD_WriteCommand(0x12); //set column MSB address // 12
LCD_WriteCommand(0x05); //set column LSB address //37 05
for(j=x1;j<(x2+3)/2;j++) //保证每行写满81个字节
{
//DispBuff_uc1698[j]=0xf0;
LCD_WriteData(DispBuff_uc1698[j]);
}
}
}
void delay(uint t)
{
uint i;
while(--t)
for(i=0;i<100;i++);
}
void init_uc1698(void)
{
LCD_WriteCommand(0xe2); //system reset
delay(100);
LCD_WriteCommand(0x31);
LCD_WriteCommand(0x08);
LCD_WriteCommand(0x2b); // internal power control
//wr_command(0x25); //set TC=-0.05%
LCD_WriteCommand(0xA0); //set line rate
LCD_WriteCommand(0xeb); //0XEA//set bias
LCD_WriteCommand(0xf1); //set com end
LCD_WriteCommand(0x9f); //set duty :1/160
LCD_WriteCommand(0x81); //set VLCD value
LCD_WriteCommand(0x80); //VLCD=(CV0+Cpm*pm)*(1+(T-25)*CT%)
LCD_WriteCommand(0xc4); //0XC4 //set LCD mapping control //scan dirction com0~127
LCD_WriteCommand(0x89); //set RAM address control
LCD_WriteCommand(0xd1); // R_G_B
LCD_WriteCommand(0xd5); //4k color
LCD_WriteCommand(0xc8);
LCD_WriteCommand(0x18);
//wr_command(0xde);
//wr_command(0xad); //0xad//display on
LCD_WriteCommand(0xad); //0xad//display on
}
void RAM_ADDRESS(void)
{
LCD_WriteCommand(0xf4); //set oolumn start address
LCD_WriteCommand(0x25); // start address
LCD_WriteCommand(0xf6); // set column end address
LCD_WriteCommand(0x5a); //(0x4f+1)*3=240 5a //90
LCD_WriteCommand(0xf5); //set row start address
LCD_WriteCommand(0x00); //start address=0x00
LCD_WriteCommand(0xf7); //set row end address
LCD_WriteCommand(0x9f); //row end address=9f
LCD_WriteCommand(0x70); //set row MSB address
LCD_WriteCommand(0x60); //set row LSB address
LCD_WriteCommand(0x12); //set column MSB address // 12
LCD_WriteCommand(0x05); //set column LSB address //37 05
LCD_WriteCommand(0xf8); //inside mode
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -