LCD5110STM32程序 #ifndef __LCD5110_H__ #define __LCD5110_H__ #include "GPIO.h" #define sclk PDout(0)//时钟 #define sdin PDout(1) //数据 #define dc PDout(2)//1写数据,0写指令 #define sce PDout(3)//片选 #define res PDout(4)//复位,0复位 #define test PDout(5)//复位,0复位 #define uchar unsigned char #define uint unsigned int unsigned char hanzi[]={ 0 }; uchar china_char[][24]= { //杨(0) {0x88,0x68,0xFF,0x48,0x88,0x22,0xF2,0x2A,0xE6,0x22,0xE0,0x00,0x00,0x00,0x0F,0x00,0x02,0x09,0x04,0x03,0x08,0x08,0x07,0x00},/*"杨",0*/ // 蓬(1) {0x26,0xEA,0x42,0x57,0xDA,0xAE,0xEA,0xAF,0xDA,0x42,0x42,0x00,0x08,0x07,0x08,0x0A,0x0A,0x0A,0x0F,0x0A,0x0A,0x0A,0x08,0x00},/*"蓬",1*/ //勃(2) {0x18,0x2A,0x2A,0xAF,0x6A,0x2A,0x18,0x10,0xFF,0x10,0xF0,0x00,0x02,0x02,0x0A,0x0F,0x01,0x09,0x04,0x03,0x08,0x08,0x07,0x00},/*"勃",2*/ 0 } ; //6x8.h文件: /*----------------------------------------------- 6 x 8 font 1 pixel space at left and bottom index = ASCII - 32 -----------------------------------------------*/ uchar font6x8[][6] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },// sp { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 },// ! { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 },// " { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 },// # { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 },// $ { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 },// % { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 },// & { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 },// ' { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 },// ( { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 },// ) { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 },// * { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 },// + { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 },// , { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 },// - { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 },// . { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 },// / { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E },// 0 { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 },// 1 { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 },// 2 { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 },// 3 { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 },// 4 { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 },// 5 { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 },// 6 { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 },// 7 { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 },// 8 { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E },// 9 { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 },// : { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 },// ; { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 },// < { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 },// = { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 },// > { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 },// ? { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E },// @ { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C },// A { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 },// B { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 },// C { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C },// D { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 },// E { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 },// F { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A },// G { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F },// H { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 },// I { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 },// J { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 },// K { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 },// L { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F },// M { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F },// N { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E },// O { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 },// P { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E },// Q { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 },// R { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 },// S { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 },// T { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F },// U { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F },// V { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F },// W { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 },// X { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 },// Y { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 },// Z { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 },// [ { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 },// 55 { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 },// ] { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 },// ^ { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 },// _ { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 },// ' { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 },// a { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 },// b { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 },// c { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F },// d { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 },// e { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 },// f { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C },// g { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 },// h { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 },// i { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 },// j { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 },// k { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 },// l { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 },// m { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 },// n { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 },// o { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 },// p { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC },// q { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 },// r { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 },// s { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 },// t { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C },// u { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C },// v { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C },// w { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 },// x { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C },// y { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 },// z { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 }// horiz lines }; void delay(unsigned int ms)//1ms延时函数 { unsigned int i,x; for(x=0;x<ms;x++) { for(i=0;i<100;i++); } } void LCD_DC(unsigned char dt, unsigned char command)//写指令0写数据1 dt:写的内容; { unsigned char i; sce=0; //5110使能 dc=command; //通过command(=dc)来控制是写指令(0)还是写数据(1) if (command == 0) //写命令 sdin = 0; //串口关使能 else sdin = 1; //写数据,串口使能 for(i=0;i<8;i++)//8位数据 { if(dt&0x80) //写入的东西从高位开始读 sdin=1; //串口使能 else sdin=0; //其他关串口使能 sclk=0; //CP0 dt=dt<<1; //让指令依次左移使之读出 sclk=1; //CP1 } dc=1; //写数据 sce=1; //关使能 sdin=1; //串口开 } void LCDchushi(void)//初始化 { res=0; //0 使复位 delay(10); res=1; //关复位 sce=0; delay(10); sce=1; delay(10); LCD_DC(0x21,0);//初始化Lcd,功能设定使用扩充指令 0写指令 LCD_DC(0xC6,0);//设定液晶偏置电压 0写指令 LCD_DC(0x06,0);//温度校正 0写指令 LCD_DC(0x13,0);;//1:48 0写指令 LCD_DC(0x20,0);//使用基本指令 0写指令 LCD_DC(0x0C,0);//设定显示模式,正常显示 0写指令 } void LCD_set_XY(unsigned char X, unsigned char Y) { LCD_DC(0x40|Y, 0);// column 0100 0000 0写指令 0x40|Y?可能是指令集中设置行的指令 LCD_DC(0x80|X, 0);// row 1000 0000 0写指令 0x80|X?可能是指令集中设置列的指令 } void LCD_clear(void) //清屏函数 { unsigned char t; unsigned char k; LCD_set_XY(0,0);//光标初始为左上角 for(t=0;t<6;t++)//行 { for(k=0;k<84;k++)//列 { LCD_DC(0x00,1); //写数据 0x00 清空 } } } /*--------------------------------------------- LCD_write_char: 显示英文字符 输入参数:c:显示的字符; 编写日期:2004-8-10 最后修改日期:2004-8-10 -----------------------------------------------*/ void LCD_write_char(uchar c) { uchar line; c-= 32; for (line=0; line<6; line++) LCD_DC(font6x8[c][line], 1); } /*--------------------------------------------- LCD_write_char: 英文字符串显示函数 输入参数:*s:英文字符串指针; X、Y: 显示字符串的位置 ----------------------------------------------*/ void LCD_write_String(uchar X,uchar Y,char *s) { LCD_set_XY(X,Y); while (*s) { LCD_write_char(*s); s++; } } /*-------------------------------------------- LCD_draw_map: 位图绘制函数 输入参数:X、Y:位图绘制的起始X、Y坐标; *map:位图点阵数据; Pix_x:位图像素(长) Pix_y:位图像素(宽) 编写日期:2004-8-13 最后修改日期:2004-8-13 ---------------------------------------------*/ void LCD_draw_map(uchar X,uchar Y,uchar *map, uchar Pix_x,uchar Pix_y) { uint i,n; uchar row; if (Pix_y%8==0) row=Pix_y/8;//计算位图所占行数 else row=Pix_y/8+1; for (n=0;n<row;n++) { LCD_set_XY(X,Y); for(i=0; i<Pix_x; i++) LCD_DC(map[i+n*Pix_x], 1); Y++;//换行 } } /*-------------------------------------------- LCD_write_chi: 在LCD上显示汉字 输入参数:row、page:显示汉字的起始列、页; dd要显示的汉字数组,*chi为汉字数组指针 12*12汉字点阵的宽度 ----------------------------------------------*/ //显示12(宽)*12(高)点阵列汉字 void LCD_write_chi(uchar row, uchar page,uchar dd,uchar (*chi)[24]) //row:列 page:页 dd:字符 { uchar row_i,xx,num=0; row*=12; for(xx=0;xx<2;xx++) { LCD_set_XY(row, page);// 列,页 for(row_i=num; row_i<num+12;row_i++) LCD_DC(chi[dd][row_i],1); num=num+12; page++; } } void LCD5110_My(void) { sce=0; res=0; delay(1); res=1; LCDchushi(); LCD_clear(); LCD_write_chi(0,0,0,china_char);//列,行 LCD_write_chi(1,0,1,china_char); LCD_write_chi(2,0,2,china_char); LCD_write_String(0,2,"Ph:13119136957");//列,行 LCD_write_String(0,3,"QQ:1192473824");//列,行 } #endif
- 粉丝: 9
- 资源: 7
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助