我司专业设计生产单色液晶模块、TFT液晶模块、OLED显示模块,下面是其中一款RA8835主控芯片的参考例程,
如需要其他控制器的参考例程可与我联系哦!
********************************
* Author Date : 2008/07/21* Company : TSINGTEK* Case : 320 x 240* Device : AT89S52 at 12.0MHZ* Compiled Using Keil C v7.50***********************************/#include <reg52.h>#include <intrins.h>#define uchar unsigned char#define uint unsigned int
#define LCD_BUS P1 sbit _RD=P3^0;sbit _CS=P3^1; sbit _RES=P3^4; sbit A0=P3^2; sbit _WR=P3^5;
uchar code systom[]={0x32,0x87,0x07,0x27,0x42,0xf0,0x28,0x00,};uchar code scroll[]={0x00,0x00,0xf0,0x00,0x28,0xf0,0x50,0x00,0x00,0x00,};uchar code tab[]={"*HANGZHOU TSINGTEK TECHNOLOGY CO...,LTD*"};uchar code tab1[]={"*** HG320240 ***** HG320240 *******"};uchar code tab2[]={"$$$$$ WEB: $$$$$"};uchar code tab3[]={" EDITOR: MR QIN QQ:381198464"};uchar code CGTAB[][32]={ /* 点阵:16x16 提取点阵方向:横向(先上->下, 再左->右) 字节掉转:否 字节方式:C语言 */0x00,0x40,0x37,0x10,0x83,0x60,0x2F,0x08, // 清0x13,0x22,0xE3,0x22,0x23,0x22,0x22,0x22,0x40,0x48,0xFC,0x40,0xF8,0x40,0xFE,0x08,0xFC,0x08,0xF8,0x08,0xF8,0x08,0x28,0x10,
0x00,0x40,0x20,0x20,0x00,0x0F,0xE0,0x21, // 达0x21,0x22,0x22,0x24,0x28,0x50,0x8F,0x00,0x80,0x80,0x80,0x80,0x88,0xFC,0x80,0x00,0x40,0x20,0x10,0x18,0x08,0x06,0xFC,0x00,
0x01,0x21,0x11,0x09,0x09,0x01,0xFF,0x04, // 光0x04,0x04,0x04,0x08,0x08,0x10,0x20,0x40,0x00,0x08,0x0C,0x10,0x20,0x04,0xFE,0x40,0x40,0x40,0x40,0x40,0x42,0x42,0x3E,0x00,
0x02,0x02,0x02,0x7F,0x42,0x42,0x7F,0x42, // 电0x42,0x7F,0x42,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x10,0xF8,0x10,0x10,0xF0,0x10,0x10,0xF0,0x10,0x00,0x04,0x04,0xFC,0x00,
0x00,0x7F,0x44,0x47,0x4C,0x52,0x41,0x42, // 图0x46,0x49,0x70,0x46,0x41,0x40,0x7F,0x40,0x04,0xFE,0x04,0xE4,0x44,0x84,0x04,0x84,0x44,0x3C,0x94,0x04,0x04,0x84,0xFC,0x04,
0x00,0x7F,0x11,0x11,0x11,0x11,0x11,0xFF, // 形0x11,0x11,0x11,0x11,0x21,0x21,0x41,0x01,0x80,0xC4,0x0C,0x10,0x20,0x44,0x0C,0xD0,0x20,0x42,0x06,0x08,0x10,0x20,0x40,0x80,
0x00,0x1F,0x10,0x10,0x1F,0x10,0x10,0x1F, // 显0x14,0x44,0x34,0x14,0x04,0x04,0xFF,0x00,0x10,0xF8,0x10,0x10,0xF0,0x10,0x10,0xF0,0x50,0x44,0x4C,0x50,0x40,0x44,0xFE,0x00,
0x00,0x3F,0x00,0x00,0x00,0x00,0xFF,0x01, // 示0x01,0x09,0x19,0x21,0x41,0x01,0x05,0x02,0x10,0xF8,0x00,0x00,0x00,0x04,0xFE,0x00,0x00,0x20,0x18,0x0C,0x04,0x00,0x00,0x00,
0x11,0x11,0x1F,0x11,0xFD,0x13,0x32,0x3B, // 模0x56,0x53,0x90,0x1F,0x10,0x10,0x11,0x16,0x10,0x14,0xFE,0x10,0x18,0xFC,0x08,0xF8,0x08,0xF8,0x40,0xFE,0x40,0xB0,0x0E,0x04,
0x10,0x10,0x10,0x10,0x13,0xFC,0x10,0x10, // 块0x10,0x17,0x1C,0xF1,0x41,0x02,0x04,0x08,0x80,0x80,0x80,0x88,0xFC,0x88,0x88,0x88,0x88,0xFE,0x80,0x40,0x20,0x10,0x0E,0x04,
}; /**延迟子程序***/ void delayus(uint us){while(us--);}
void Delay(uint t){uint i,j;for(i=0;i<t;i++)for(j=0;j<10;j++);}/*读数据代码*/uchar Cmdread(){uchar cmdcode;
LCD_BUS=0xff; _CS=0; A0=0; _RD=0; cmdcode=LCD_BUS; _RD=1; _WR=1; _CS=1; return cmdcode;}/***忙标志***/void lcd_busy(void){ uchar busy;
do { busy =(Cmdread() & 0x40);
}while(busy);
}/*****读数据或参数*****/uchar ReadData(void){ char address_data; lcd_busy(); LCD_BUS=0xff; A0 = 1; _CS = 0; _RD = 0; address_data = LCD_BUS; _RD = 1; _CS = 1; A0 = 1; return address_data;}/*******写指令代码******/void CmdWrite(uchar cmdcode){_CS=0;A0=1;LCD_BUS=cmdcode; //写入指令代码_RD=1;_WR=0;_WR=1;_CS=1;}/******写数据或参数*****/void DataWrite(uchar wrdata){lcd_busy();_CS=0;A0=0;LCD_BUS=wrdata; //写入数据或参数_RD=1;_WR=0;_WR=1;_CS=1;}
/********整屏幕写入 ******/void FullScreenFill(uchar low,uchar high,uchar fill_data){uchar i,j;CmdWrite(0x46); //光标显示位置设置DataWrite(low);DataWrite(high);CmdWrite(0x42);for(i=0;i<240;i++)for(j=0;j<40;j++)DataWrite(fill_data);}/****模块初始化***/void LCD_Initial(){unsigned int i;CmdWrite(0x40); //系统设置for(i=0;i<8;i++) {DataWrite(systom[i]);};
CmdWrite(0x44); //显示区域设置for(i=0;i<10;i++) {DataWrite(scroll[i]);};
CmdWrite(0x58); //显示状态设置,显示总开关关闭DataWrite(0x54); //打开各区显示和关光标
CmdWrite(0x5b); //合成方式设置DataWrite(0x00);
CmdWrite(0x5d); //光标形状设置DataWrite(0x07);DataWrite(0x87);
CmdWrite(0x5c); //CGRAM 的起始地址为7800HDataWrite(0x00);DataWrite(0x78);
CmdWrite(0x5a); //点设定DataWrite(0x00);
FullScreenFill(0x00,0x00,0x00); //清显示1区FullScreenFill(0x00,0x28,0x00); //清显示二区FullScreenFill(0x00,0x50,0x00); //清显示三区CmdWrite(0x59); //打开显示总开关}/**********写入字符串*********/void PrintStr(uint x,uint y,uchar code *pstr){unsigned int j; j=40*y+x; CmdWrite(0x4c); CmdWrite(0x46); DataWrite(j%256); DataWrite(j/256); CmdWrite(0x42);while(*pstr!=0){ DataWrite(*pstr); pstr++;}}/**写入自定义字符**/void cgramwrite(){uint i,j;CmdWrite(0x5c);DataWrite(0x00);DataWrite(0x10);CmdWrite(0x46);DataWrite(0x00);DataWrite(0x14);//csr=0x1400;字摸地址80HCmdWrite(0x4c);CmdWrite(0x42);;for(i=0;i<10;i++)for(j=0;j<32;j++){DataWrite(CGTAB[i][j]);}}/**********文本方式下写入汉字************/void textwrite(uint x,uint y,uchar coder){uint i,j;cgramwrite(); i=40; j=i*y+x; CmdWrite(0x4f); CmdWrite(0x46); DataWrite(j%256); DataWrite(j/256); CmdWrite(0x42); DataWrite(coder); DataWrite(coder+1); j++; CmdWrite(0x46); DataWrite(j%256); DataWrite(j/256); CmdWrite(0x42); DataWrite(coder+2); DataWrite(coder+3);}/**********图形方式下写入汉字************/void mapwrite(uchar x,uchar y,uchar coder){ uint i,j,k;CmdWrite(0x4c);for(i=0;i<16;i++){ j=40*(y+i)+x+0x2800; CmdWrite(0x46); DataWrite(j%256); DataWrite(j/256); CmdWrite(0x42); DataWrite(CGTAB[coder][i]); k=40*(y+i)+x+1+0x2800; CmdWrite(0x46); DataWrite(k%256); DataWrite(k/256); CmdWrite(0x42); DataWrite(CGTAB[coder][i+16]);}}/****图形方式下写入一串汉字***/void writemaphz(uchar x,uchar y){ uint i; for(i=0;i<10;i++) {mapwrite(x,y,i);x=x+3;}}/**主程序**/void main(){Delay(30);LCD_Initial();
textwrite(7,12,0x80);textwrite(10,12,0x84);textwrite(13,12,0x88);textwrite(16,12,0x8c);textwrite(19,12,0x90);textwrite(22,12,0x94);textwrite(25,12,0x98);textwrite(28,12,0x9c);textwrite(31,12,0xe0);textwrite(34,12,0xe4);
PrintStr(0,1,tab);PrintStr(3,3,tab1);PrintStr(2,5,tab2);PrintStr(0,28,tab3);writemaphz(4,200);while(1);}
http://qdgdlcd.b2b168.com