|
- #include "LCD.h"
- unchar code tab1[]={
- "成都市飞宇达中文字库液晶模块"
- "支持文字与绘图两种混和显示模式 "
- "支持2 Page 显示模式(And, Or, Nor, Xor) "
- "内建两个显示 RAM,可做成4 灰阶的显示效果"
- "内建中文字库储存7602个标准GB码的简体中文"
- "提供全角(16x16)与半角(8x16) 文字显示模式"
- "内建8x8 键盘扫瞄界面(Key Scan) "
- "光标、反白、闪烁功能,光标高度与宽度可调"
- "支持屏幕水平卷动及垂直卷动功能 "
- "内建512Byte SRAM 可自行造字 "
- "提供中/英文文字对齐功能 "
- "显示字型可放大到32x32、48x48 或64x64 "
- "支持可将字型由ROM 直接读出使用 "
- "内建粗体字形与行距设定 "
- "内建10-Bit ADC 支持触控屏幕应用 "
- };
- unchar d,h,m,s,n;
- unchar xHzTable1[64];
- //定义中文字库
- unchar code HZTable1[32]={
- 0x02,0x00,0x02,0x00,0x02,0x04,0x7F,0xFE,0x04,0x40,0x04,0x40,0x04,0x4C,0x0C,0x70,
- 0x0A,0x40,0x0A,0xA0,0x10,0xA0,0x11,0x10,0x22,0x18,0x24,0x0E,0x48,0x04,0x00,0x00,
- };//灰
- unchar code HZTable2[32]={
- 0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,0x22,0x20,0x2F,0xFC,0x22,0x20,0x23,0xE0,
- 0x20,0x00,0x27,0xF8,0x22,0x10,0x21,0x20,0x20,0xC0,0x41,0x30,0x46,0x0E,0x98,0x04,
- };//度
- unchar code HZTable3[32]={
- 0x00,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x04,0x40,0x04,0x40,
- 0x44,0x48,0x24,0x48,0x14,0x50,0x14,0x60,0x04,0x40,0xFF,0xFE,0x00,0x00,0x00,0x00,
- };//显
- unchar code HZTable4[32]={
- 0x00,0x00,0x1F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x01,0x00,0x01,0x00,
- 0x11,0x20,0x11,0x10,0x21,0x08,0x41,0x0C,0x81,0x04,0x01,0x00,0x05,0x00,0x02,0x00,
- }; //示
- //$$$$$$$$$$$$
- unchar LCD_CmdRead(unchar Addr)
- {
- unchar Data;
- cs1=0;
- rs=1;
- rd=1;
- BUS=Addr;
- wr=0;
- wr=1;
- BUS=0XFF;
- rs=0;
- wr=1;
- rd=1;
- rd=0;
- Data=BUS;
- return Data;
- }
- //$$$$$$$$$$$$
- void LCD_CmdWrite(unchar cmdaddr)//8080
- { cs1=0;
- rd=1;
- rs=1;
- BUS=cmdaddr;
- wr=0;
- wr=1;
- cs1=1;
- }
- //$$$$$$$$$$$$
- void LCD_DataWrite(unchar wrdata)
- {
- while(busy==0);
- cs1=0;
- rd=1;
- rs=0;
- BUS=wrdata;
- wr=0;
- wr=1;
- cs1=1;
- }
- ///////////////////////////////////////////
- void No_Snow_Mode(void)
- {
- unchar temp;
- temp=LCD_CmdRead(MISC);
- temp&=0x7f;
- LCD_CmdWrite(MISC);
- LCD_DataWrite(temp);
- }
- ///////////////////////////////////////////
- void Snow_Mode(void)
- {
- unchar temp;
- temp=LCD_CmdRead(MISC);
- temp|=0x80;
- LCD_CmdWrite(MISC);
- LCD_DataWrite(temp);
- }
- //******************X,Y坐标定位******************
- void LCD_GotoXY(unchar xx,unchar yy)
- { LCD_CmdWrite(CURX);
- LCD_DataWrite(xx);
- LCD_CmdWrite(CURY);
- LCD_DataWrite(yy);
- }
- //***********存取DDRAM2*******************************
- void Access_Page2(void)
- {
- unchar temp;
- temp=LCD_CmdRead(MAMR);
- temp &=0xfe;
- temp |=0x02;
- LCD_CmdWrite(MAMR);
- LCD_DataWrite(temp);
- }
- //$$$$$$$$$$$$
- void displays(unchar *m)
- {
- unint iiii=0,pppp=0,c=0,eeee=0;
- Snow_Mode();
- LCD_CmdWrite(WLCR);
- LCD_DataWrite(0x04);
- LCD_CmdWrite(CURX);
- LCD_DataWrite(0x00);
- LCD_CmdWrite(CURY);
- LCD_DataWrite(0x00);
- LCD_CmdWrite(MWCR);
- for(eeee=0;eeee<3;eeee++)
- {
- c=0;
- for(iiii=0;iiii<80;iiii++)
- {
- for(pppp=0;pppp<40;pppp++)
- {
- LCD_DataWrite(m[c++]);
- }
- }
- }
- }
- //$$$$$$$$$$$$
- void lcd_grayscale_mode()
- {
- unchar temp;
- temp=LCD_CmdRead(MAMR);
- temp&=0x8f;
- temp|=0x03;
- LCD_CmdWrite(MAMR);
- LCD_DataWrite(temp);
- }
- //$$$$$$$$$$$$
- void display_gray(unchar x,unsigned char y,unchar *m)
- {
- unchar temp_x,temp_y;
- unint iiii=0,jjjj=0,c=0;
- temp_x=x;temp_y=y;
- Snow_Mode();
- LCD_CmdWrite(WLCR);
- LCD_DataWrite(0x04);
- lcd_grayscale_mode();
- for(iiii=0;iiii<128;iiii++)
- {
- LCD_GotoXY(temp_x,temp_y+iiii);
- LCD_CmdWrite(0xb0);
- for(jjjj=0;jjjj<40;jjjj++)
- {
- LCD_DataWrite(m[c++]);
- }
- }
- }
- ///////////////////////////////////////////
- void HzConvert(unchar *Hztable0,unchar *Hztable,unint number)
- //Hztable0为待转换的数据地址,Hztable为转换过后的数据地址,number为转换数据字节数
- {
- unchar i=0,j=0,tem;
- unint temp=0x0;
- for(j=0;j<number;j++)
- {
- tem=0x80;
- temp=0;
- for(i=8;i>0;i--)
- {
- if(Hztable0[j]&tem)
- {
- temp|=0x03<<(i*2-2);
- }
- tem=tem>>1;
- }
- Hztable[j*2]=(temp>>8)&0xff;
- Hztable[j*2+1]=temp&0xff;
- }
- }
- //$$$$$$$$$$$$灰度模式下显示一个汉字
- //x:0~39; y:0~239
- void HzDisplayOne(unchar x,unchar y,unchar *m)
- {
- unchar temp_x,temp_y;
- unint iiii=0,jjjj=0,c=0;
- temp_x=x;temp_y=y;
- Snow_Mode();
- LCD_CmdWrite(WLCR);
- LCD_DataWrite(0x04);
- lcd_grayscale_mode();
- for(iiii=0;iiii<16;iiii++)
- {
- LCD_GotoXY(temp_x,temp_y+iiii);
- LCD_CmdWrite(0xb0);
- for(jjjj=0;jjjj<4;jjjj++)
- {
- LCD_DataWrite(m[c++]);
- }
- }
- }
- ///////////////////////////////////////////一行显示4个汉字(在灰度模式下)
- //start_x:0~39;start_y:0~239;
- void writelinhz(unchar start_x,unchar start_y)
- {
- HzConvert(HZTable1,xHzTable1,32);
- HzDisplayOne(start_x,start_y,xHzTable1);
- start_x+=2;
- if(start_x>39)
- {
- start_y+=40;
- start_x=0;
- }
- HzConvert(HZTable2,xHzTable1,32);
- HzDisplayOne(start_x,start_y,xHzTable1);
- start_x+=2;
- if(start_x>39)
- {
- start_y+=40;
- start_x=0;
- }
- HzConvert(HZTable3,xHzTable1,32);
- HzDisplayOne(start_x,start_y,xHzTable1);
- start_x+=2;
- if(start_x>39)
- {
- start_y+=40;
- start_x=0;
- }
- HzConvert(HZTable4,xHzTable1,32);
- HzDisplayOne(start_x,start_y,xHzTable1);
- start_x+=2;
- if(start_x>39)
- {
- start_y+=40;
- start_x=0;
- }
- }
-
- ///////////////////////////////////////////
- void lcd_inital()
- {
- LCD_CmdWrite(WLCR); //[00H] , Default --> 0x00
- LCD_DataWrite(0x04); //屏幕显示开启 disp_off输出high
- LCD_CmdWrite(MISC); //[01H] , Default --> 0x00
- LCD_DataWrite(0x08);
- LCD_CmdWrite(ADSR); //[03H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(INTR); //[0FH] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(WCCR); //[10H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(CHWI); //[11H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(MAMR); //[12H] , Default --> 0x11
- LCD_DataWrite(0x11);
- LCD_CmdWrite(AWRR); //[20H] , Default --> 0x27
- LCD_DataWrite(39);
- LCD_CmdWrite(DWWR); //[21H] , Default --> 0x27
- LCD_DataWrite(39);
- LCD_CmdWrite(AWBR); //[30H] , Default --> 0xEF
- LCD_DataWrite(239);
- LCD_CmdWrite(DWHR); //[31H] , Default --> 0xEF
- LCD_DataWrite(239);
- LCD_CmdWrite(AWLR); //[40H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(AWTR); //[50H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(CURX); //[60H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(BGSG); //[61H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(EDSG); //[62H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(CURY); //[70H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(BGCM); //[71H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(EDCM); //[72H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(BTMR); //[80H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(ITCR); //[90H] , Default --> 0x00 需要调整
- LCD_DataWrite(0x80);
- LCD_CmdWrite(PNTR); //[E0H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(FNCR); //[F0H] , Default --> 0x00
- LCD_DataWrite(0x00);
- LCD_CmdWrite(FVHT); //[F1H] , Default --> 0x00
- LCD_DataWrite(0x00);
- }
- /////////////////清屏子程序//////////////////////////
- void clear(void)
- {
- No_Snow_Mode();
- LCD_CmdWrite(WLCR);
- LCD_DataWrite(0x04); //选择绘图模式
- LCD_CmdWrite(PNTR);
- LCD_DataWrite(0x00);
- LCD_CmdWrite(FNCR);
- LCD_DataWrite(0xa8);
- Snow_Mode();
- }
- //////////////全部显示子程序///////////////////////
- void display_all()
- {
- No_Snow_Mode();
- LCD_CmdWrite(WLCR);
- LCD_DataWrite(0x04); //选择绘图模式
- LCD_CmdWrite(PNTR);
- LCD_DataWrite(0xff); //全部填0xff
- LCD_CmdWrite(FNCR);
- LCD_DataWrite(0xa8);
- Snow_Mode();
- }
- //////////////装配测试用///////////////////////////
- void display_snows(unchar dat1,unchar dat2)
- {
- unsigned int iiii=0,pppp=0;
- Snow_Mode();
- LCD_CmdWrite(WLCR);
- LCD_DataWrite(0x04); //选择绘图模式
- LCD_CmdWrite(CURX);
- LCD_DataWrite(0x00); //设定X坐标位置
- LCD_CmdWrite(CURY);
- LCD_DataWrite(0x00); //设定Y坐标位置
- LCD_CmdWrite(MWCR);
- for(iiii=0;iiii<120;iiii++)
- {
- for(pppp=0;pppp<40;pppp++)
- {
- LCD_DataWrite(dat1);
- }
- for(pppp=0;pppp<40;pppp++)
- {
- LCD_DataWrite(dat2);
- }
- }
- }
- /////////////显示一行边框//////////////////////////////////
- void display_kuang(void)
- {
- unsigned int n0,n1;
- Snow_Mode();
- LCD_CmdWrite(WLCR);
- LCD_DataWrite(0x04);
- LCD_CmdWrite(CURX);
- LCD_DataWrite(0x00);
- LCD_CmdWrite(CURY);
- LCD_DataWrite(0x00);
- LCD_CmdWrite(MWCR);
- for(n0=0;n0<40;n0++)
- LCD_DataWrite(0xff);
- for(n0=0;n0<(238);n0++)
- {
- for(n1=0;n1<40;n1++)
- {
- if (n1==0) LCD_DataWrite(0x80);
- else if (n1==39) LCD_DataWrite(0x01);
- else LCD_DataWrite(0x00);
- }
- }
- for(n0=0;n0<40;n0++)
- LCD_DataWrite(0xff);
- }
- /////////////显示中文字库和字符////////////////////
- void display_word(unchar code *cha, unint count )
- {
- unint iiii=0;
- No_Snow_Mode();
- LCD_CmdWrite(WLCR);
- LCD_DataWrite(0x0c);
- LCD_CmdWrite(CURX);
- LCD_DataWrite(0x00);
- LCD_CmdWrite(CURY);
- LCD_DataWrite(0x00);
- LCD_CmdWrite(MWCR);
- for(iiii=0;iiii<count;iiii++)
- {
- LCD_DataWrite(*cha);
- ++cha;
- }
- }
- /////////////在指定的坐标处显示字符串////////////////////
- void LCD_ShowStr(unchar xx,unchar yy,unchar *text)
- {
- No_Snow_Mode();
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
|
评分
-
查看全部评分
|