HDG12864L-6 STC15W4K32S4仿真显示文字 程序来源于网上
个人学习 领会 理解 程序通过 仿真显示如下
- #include "STC15W4K32S4.h" //单片机定义文件
- #include "intrins.h" //调用_nop_();延时函数用
- #include "pixel.h" //字符和汉字
- #define LCD_Data_Out P0
- sbit RW = P1^0;
- sbit RS = P1^1;
- sbit RST= P1^2;
- sbit CS = P1^3;
- sbit E = P1^4;
- #define X_WIDTH 132
- #define Y_WIDTH 64
- //*****************延时********************
- void delay_ms(uint t)
- {
- int ii,jj;
- if(t<1) t=1;
- for(ii = 0; ii < t; ii++)
- for(jj = 0; jj < 2670; jj++); //busclk:16MHz--1ms
- }
- /***************************LCD12864************************/
- //**************************写命令**************************
- void LCD_WrCmd(byte cmd) //写命令
- {
- RS = 0; CS = 0; RW = 0; E = 1;
- P0 = cmd;
- _nop_();
- E = 0;
- }
- //**************************写数据**************************
- void LCD_WrDat(byte date) //--写数据
- {
- RS = 1; CS = 0; RW = 0; E = 1;
- P0 = date;
- _nop_();
- E = 0;
- }
- //************************清屏*****************************
- void LCD_Fill(byte bmp_data)
- {
- byte y,x;
- for(y = 0; y < 8; y++) //分页,总共8页
- {
- LCD_WrCmd(0xb0+y); //设置页地址
- LCD_WrCmd(0x01); //设置column地址低地址
- LCD_WrCmd(0x10); //设置column地址高地址
- for(x = 0; x < X_WIDTH; x++)
- LCD_WrDat(bmp_data);
- }
- }
- //*************************定指针坐标***********************
- void LCD_Set_Pos(byte x, byte y) //定坐标,指针的位置
- {
- LCD_WrCmd(0xb0+y); //定初始页 ---P39
- LCD_WrCmd(((x&0xf0)>>4)|0x10); //坐标在column的位置MSB ---P40
- LCD_WrCmd((x&0x0f)|0x01); //LSB 0X01 ---P40
- }
- //************************LCD初始化*************************
- void LCD_Init(void)
- {
- RST = 0; //指令表---P37
- delay_ms(10);
- RST = 1;
- delay_ms(0);
- LCD_WrCmd(0xaf); //0xaf LCD On ---P39
- LCD_WrCmd(0x2f); //0x2f 设置上电控制模式 ---P44
- LCD_WrCmd(0x81); //0x81 电量设置模式(显示亮度---P45
- LCD_WrCmd(0x1a); //指令数据0x0000~0x003f
- LCD_WrCmd(0x24); //0x24 V5内部电压调节电阻设置---P45
- LCD_WrCmd(0xa2); //0xa2 5V,0xa1 3V3 LCD偏压设置---P42
- LCD_WrCmd(0xc0); //0xc8 正常,0xc0 倒置 Com 扫描方式设置
- LCD_WrCmd(0xa1); //0xa0 正常,0xa1 反向 Segment方向选择---P42
- LCD_WrCmd(0xa4); //0xa4 全屏点亮/变暗指令 ---P42
- LCD_WrCmd(0xa6); //0xa6 正向反向显示控制指令 ---P42
- LCD_WrCmd(0xac); //0xac 关闭静态指示器---P46
- LCD_WrCmd(0x00); //指令数据
- LCD_WrCmd(0x40+32); //0x40+32 设置显示起始行对应RAM---P39
- LCD_Fill(0x00); //初始清屏
- LCD_Set_Pos(0,0); //指针的位置
- }
- /******************************输出字符****************************/
- void LCD_P6x8Str(byte x,byte y,byte ch[]) //输入字符
- {
- byte c = 0, i = 0, j = 0;
- while(ch[j]!='\0')
- {
- c = ch[j]-48; //F6x8[c][i]从032开始建立ASCLL码数组,要查找,需减32
- if(x>126)
- { x=0;y++; }
- LCD_Set_Pos(x,y);
- for(i=0;i<6;i++)
- LCD_WrDat(F6x8[c][i]);
- x += 6;
- j++;
- }
- }
- void LCD_P8x16Str(byte x,byte y,byte ch[])
- {
-
- }
- /******************************输出汉字字符串***********************/
- void LCD_P14x16Str(byte x,byte y,byte ch[])
- {
- byte wm=0,ii = 0; //字节:0xff
- uint adder = 1; //字:0xffff
- while(ch[ii] != '\0')
- {
- wm = 0;
- adder = 1;
- while(F14x16_Idx[wm] > 127) //why
- {
- if(F14x16_Idx[wm] == ch[ii])
- {
- if(F14x16_Idx[wm + 1] == ch[ii + 1])
- {
- adder = wm * 14;
- break;
- }
- }
- wm += 2;
- }
- if(x>118)
- { x=0; y++; }
- LCD_Set_Pos(x, y);
- if(adder != 1) //显示汉字
- {
- LCD_Set_Pos(x, y);
- for(wm = 0; wm < 14; wm++)
- {
- LCD_WrDat(F14x16[adder]);
- adder += 1;
- }
- LCD_Set_Pos(x,y + 1);
- for(wm = 0; wm < 14; wm++)
- {
- LCD_WrDat(F14x16[adder]);
- adder += 1;
- }
- }
- else //显示空白字符
- {
- ii += 1;
- LCD_Set_Pos(x,y);
- for(wm = 0; wm < 16; wm++)
- {
- LCD_WrDat(0);
- }
- LCD_Set_Pos(x,y + 1);
- for(wm = 0; wm < 16; wm++)
- {
- LCD_WrDat(0);
- }
- }
- x += 14;
- ii += 2;
- }
- }
- //******************输出汉字和字符混合字符串**********************
- void LCD_Print(byte x, byte y, byte ch[])
- {
- byte ch2[3];
- byte ii = 0;
- while(ch[ii] != '\0')
- {
- if(ch[ii] > 127) //汉字的码>127
- {
- ch2[0] = ch[ii];
- ch2[1] = ch[ii + 1];
- ch2[2] = '\0'; //汉字为两个字节
- LCD_P14x16Str(x, y, ch2); //显示汉字
- x += 14; //不太理解
- ii += 2;
- }
- else
- {
- ch2[0] = ch[ii];
- ch2[1] = '\0'; //字母占一个字节
- LCD_P8x16Str(x, y, ch2); //显示字母
- x += 8;
- ii += 1;
- }
- }
- }
- void Draw_BMP(byte x0,byte y0,byte x1,byte y1,byte bmp[])
- {
-
- }
- /**********************主函数*******************************/
- main()
- {
- LCD_Init(); //LCD初始化
- while(1)
- {
- LCD_P6x8Str(0,5,"51");
- LCD_Print(12,4,"黑电子论坛");
- LCD_P6x8Str(12,7,"51");
- LCD_Print(24,14,"黑电子论坛");
- LCD_P6x8Str(24,9,"51");
- LCD_Print(36,0,"黑电子论坛");
- LCD_P6x8Str(33,2,"============");
- LCD_P6x8Str(0,3,"http:www51heicom");
- }
- }
复制代码
请教老师
1.void LCD_P8x16Str(byte x,byte y,byte ch[])
8*16 数字函数 怎么写?
2. 8*16 数字怎么取模?
3.void Draw_BMP(byte x0,byte y0,byte x1,byte y1,byte bmp[])
显示图片函数 怎么写?
|