OLED菜单编程实现+普中51单片机
1 实验现象
2 实验原理(略)
3 系统设计(略)
4 硬件设计(略)
5 软件设计
5.1 主函数
#include "OLED.H" #include "bmp.h" void Main_Menu(void); void Main_Show_Menu(void); void Set_Temperature(void); void Set_HighTemperature(void); void Set_LowTemperature(void); void Set_Time(void); u8 MENU=1; u16 temp=125; u16 humidity=564; u8 year=23, month=1, day=28; u8 hour=16, min=24, sec=30, week=5; u16 low_alarmtemp=102, high_alarmtemp=560; int main(void) { u8 t=' '; //空格,space OLED_Init(); //初始化OLED OLED_ColorTurn(0); //0正常显示,1 反色显示 OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示 while(1) { //开机界面,显示一张图片128*64 OLED_DrawBMP(0,0,128,64,BMP12864_BIRD); delay_ms(100); OLED_Clear(); if(MENU==1) //主菜单 { Main_Menu(); delay_ms(100); MENU=11; if(MENU==11) OLED_Clear(); } if(MENU==11) //主菜单的子菜单,刷新温度和湿度数据 { Main_Show_Menu(); delay_ms(100); MENU=2; if(MENU==2) OLED_Clear(); } if(MENU==2) //设置温度 { Set_Temperature(); delay_ms(100); MENU=21; if(MENU==21) OLED_Clear(); } if(MENU==21) //设置高温报警 { Set_HighTemperature(); delay_ms(100); MENU=22; if(MENU==22) OLED_Clear(); } if(MENU==22) //设置低温报警 { Set_LowTemperature(); delay_ms(100); MENU=3; if(MENU==3) OLED_Clear(); } if(MENU==3) //设置时间 { Set_Time(); delay_ms(100); MENU=1; if(MENU==1) OLED_Clear(); } } } void Main_Menu(void) { //0-1页,主菜单,反显方式, Inverse_OLED_ShowChinese(0*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(1*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(2*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(3*16,0, 0,16); //主 Inverse_OLED_ShowChinese(4*16,0, 1,16); //菜 Inverse_OLED_ShowChinese(5*16,0, 2,16); //单 Inverse_OLED_ShowChinese(6*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(7*16,0,18,16); //不显示 //2-3页,当前温度:**.*'C OLED_ShowChinese(0*16,2, 3,16); //当 OLED_ShowChinese(1*16,2, 4,16); //前 OLED_ShowChinese(2*16,2, 5,16); //温 OLED_ShowChinese(3*16,2, 6,16); //度 OLED_ShowChar(4*16+0,2, ':',16); //: OLED_ShowChar(4*16+8,2, '*',16); //* OLED_ShowChar(5*16+0,2, '*',16); //* OLED_ShowChar(5*16+8,2, '.',16); //. OLED_ShowChar(6*16+0,2, '*',16); //* OLED_ShowChar(6*16+8,2, ' ',16); //空格 OLED_ShowChinese(7*16,2, 19,16); //'C //4-5页,当前湿度:**.*% OLED_ShowChinese(0*16,4, 3,16); //当 OLED_ShowChinese(1*16,4, 4,16); //前 OLED_ShowChinese(2*16,4, 7,16); //温 OLED_ShowChinese(3*16,4, 6,16); //度 OLED_ShowChar(4*16+0,4, ':',16); //: OLED_ShowChar(4*16+8,4, '*',16); //* OLED_ShowChar(5*16+0,4, '*',16); //* OLED_ShowChar(5*16+8,4, '.',16); //. OLED_ShowChar(6*16+0,4, '*',16); //* OLED_ShowChar(6*16+8,4, ' ',16); //空格 OLED_ShowChar(7*16+0,4, '%',16); //% OLED_ShowChar(7*16+8,4, ' ',16); //空格 //6-7页,日期:2023-01-27 OLED_ShowChinese(0*16,6, 8,16); //时 OLED_ShowChinese(1*16,6, 9,16); //间 OLED_ShowChar(2*16+0, 6, ':',16); //: OLED_ShowString(2*16+8,6,"2023-01-28",16); //日期 } void Main_Show_Menu(void) { //0-1页,主菜单,反显方式, Inverse_OLED_ShowChinese(0*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(1*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(2*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(3*16,0, 0,16); //主 Inverse_OLED_ShowChinese(4*16,0, 1,16); //菜 Inverse_OLED_ShowChinese(5*16,0, 2,16); //单 Inverse_OLED_ShowChinese(6*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(7*16,0,18,16); //不显示 //2-3页,当前温度:temp=12.5'C OLED_ShowChinese(0*16,2, 3,16); //当 OLED_ShowChinese(1*16,2, 4,16); //前 OLED_ShowChinese(2*16,2, 5,16); //温 OLED_ShowChinese(3*16,2, 6,16); //度 OLED_ShowChar(4*16+0,2, ':',16); //: OLED_ShowChar(4*16+8,2, temp/100+0x30,16); //取temp的百位 OLED_ShowChar(5*16+0,2, temp/10%10+0x30,16); //取temp的十位 OLED_ShowChar(5*16+8,2, '.',16); //. OLED_ShowChar(6*16+0,2, temp%10+0x30,16); //取temp的个位 OLED_ShowChar(6*16+8,2, ' ',16); //空格 OLED_ShowChinese(7*16,2, 19,16); //'C //4-5页,当前湿度:humidity=56.4 % OLED_ShowChinese(0*16,4, 3,16); //当 OLED_ShowChinese(1*16,4, 4,16); //前 OLED_ShowChinese(2*16,4, 7,16); //湿 OLED_ShowChinese(3*16,4, 6,16); //度 OLED_ShowChar(4*16+0,4, ':',16); //: OLED_ShowChar(4*16+8,4, humidity/100+0x30,16); //取humidity的百位 OLED_ShowChar(5*16+0,4, humidity/10%10+0x30,16);//取humidity的十位 OLED_ShowChar(5*16+8,4, '.',16); //. OLED_ShowChar(6*16+0,4, humidity%10+0x30,16); //取humidity的个位 OLED_ShowChar(6*16+8,4, ' ',16); //空格 OLED_ShowChar(7*16+0,4, '%',16); //% OLED_ShowChar(7*16+8,4, ' ',16); //空格 //6-7页,日期:2023-01-27 OLED_ShowChinese(0*16,6, 8,16); //时 OLED_ShowChinese(1*16,6, 9,16); //间 OLED_ShowChar(2*16+0, 6, ':',16); //: OLED_ShowString(2*16+8,6,"2023-01-28",16); //日期 } void Set_Temperature(void) { //0-1页,设置温度,反显方式 Inverse_OLED_ShowChinese(0*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(1*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(2*16,0,10,16); //设 Inverse_OLED_ShowChinese(3*16,0,11,16); //置 Inverse_OLED_ShowChinese(4*16,0, 5,16); //温 Inverse_OLED_ShowChinese(5*16,0, 6,16); //度 Inverse_OLED_ShowChinese(6*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(7*16,0,18,16); //不显示 //2-3页,高温报警:**.*'C OLED_ShowChinese(0*16,2,16,16); //高 OLED_ShowChinese(1*16,2, 5,16); //温 OLED_ShowChinese(2*16,2,12,16); //报 OLED_ShowChinese(3*16,2,13,16); //警 OLED_ShowChar(4*16+0,2, ':',16); //: OLED_ShowChar(4*16+8,2, '*',16); //* OLED_ShowChar(5*16+0,2, '*',16); //* OLED_ShowChar(5*16+8,2, '.',16); //. OLED_ShowChar(6*16+0,2, '*',16); //* OLED_ShowChar(6*16+8,2, ' ',16); //空格 OLED_ShowChinese(7*16,2, 19,16); //'C //4-5页,低温报警:**.*% OLED_ShowChinese(0*16,4,17,16); //低 OLED_ShowChinese(1*16,4, 5,16); //温 OLED_ShowChinese(2*16,4,12,16); //报 OLED_ShowChinese(3*16,4,13,16); //警 OLED_ShowChar(4*16+0,4, ':',16); //: OLED_ShowChar(4*16+8,4, '*',16); //* OLED_ShowChar(5*16+0,4, '*',16); //* OLED_ShowChar(5*16+8,4, '.',16); //. OLED_ShowChar(6*16+0,4, '*',16); //* OLED_ShowChar(6*16+8,4, ' ',16); //空格 OLED_ShowChinese(7*16,4, 19,16); //'C } void Set_HighTemperature(void) { //0-1页,设置温度,正常方式 OLED_ShowChinese(0*16,0,18,16); //不显示 OLED_ShowChinese(1*16,0,18,16); //不显示 OLED_ShowChinese(2*16,0,10,16); //设 OLED_ShowChinese(3*16,0,11,16); //置 OLED_ShowChinese(4*16,0, 5,16); //温 OLED_ShowChinese(5*16,0, 6,16); //度 OLED_ShowChinese(6*16,0,18,16); //不显示 OLED_ShowChinese(7*16,0,18,16); //不显示 //2-3页,高温报警:**.*'C,反显方式 Inverse_OLED_ShowChinese(0*16,2,16,16); //高 Inverse_OLED_ShowChinese(1*16,2, 5,16); //温 Inverse_OLED_ShowChinese(2*16,2,12,16); //报 Inverse_OLED_ShowChinese(3*16,2,13,16); //警 Inverse_OLED_ShowChar(4*16+0,2, ':',16); //: Inverse_OLED_ShowChar(4*16+8,2, high_alarmtemp/100+0x30,16); Inverse_OLED_ShowChar(5*16+0,2, high_alarmtemp/10%10+0x30,16); Inverse_OLED_ShowChar(5*16+8,2, '.',16); //. Inverse_OLED_ShowChar(6*16+0,2, high_alarmtemp%10+0x30,16); Inverse_OLED_ShowChar(6*16+8,2, ' ',16); //空格 Inverse_OLED_ShowChinese(7*16,2, 19,16); //'C //4-5页,低温报警:**.*% OLED_ShowChinese(0*16,4,17,16); //低 OLED_ShowChinese(1*16,4, 5,16); //温 OLED_ShowChinese(2*16,4,12,16); //报 OLED_ShowChinese(3*16,4,13,16); //警 OLED_ShowChar(4*16+0,4, ':',16); //: OLED_ShowChar(4*16+8,4, low_alarmtemp/100+0x30,16); // OLED_ShowChar(5*16+0,4, low_alarmtemp/10%10+0x30,16); // OLED_ShowChar(5*16+8,4, '.',16); //. OLED_ShowChar(6*16+0,4, low_alarmtemp%10+0x30,16); // OLED_ShowChar(6*16+8,4, ' ',16); //空格 OLED_ShowChinese(7*16,4, 19,16); //'C } void Set_LowTemperature(void) { //0-1页,设置温度,正常方式 OLED_ShowChinese(0*16,0,18,16); //不显示 OLED_ShowChinese(1*16,0,18,16); //不显示 OLED_ShowChinese(2*16,0,10,16); //设 OLED_ShowChinese(3*16,0,11,16); //置 OLED_ShowChinese(4*16,0, 5,16); //温 OLED_ShowChinese(5*16,0, 6,16); //度 OLED_ShowChinese(6*16,0,18,16); //不显示 OLED_ShowChinese(7*16,0,18,16); //不显示 //2-3页,高温报警:high_alarmtemp=56.0 OLED_ShowChinese(0*16,2,16,16); //高 OLED_ShowChinese(1*16,2, 5,16); //温 OLED_ShowChinese(2*16,2,12,16); //报 OLED_ShowChinese(3*16,2,13,16); //警 OLED_ShowChar(4*16+0,2, ':',16); //: OLED_ShowChar(4*16+8,2, high_alarmtemp/100+0x30,16); OLED_ShowChar(5*16+0,2, high_alarmtemp/10%10+0x30,16); OLED_ShowChar(5*16+8,2, '.',16); //. OLED_ShowChar(6*16+0,2, high_alarmtemp%10+0x30,16); OLED_ShowChar(6*16+8,2, ' ',16); //空格 OLED_ShowChinese(7*16,2, 19,16); //'C //4-5页,低温报警:low_alarmtemp=10.2 Inverse_OLED_ShowChinese(0*16,4,17,16); //低 Inverse_OLED_ShowChinese(1*16,4, 5,16); //温 Inverse_OLED_ShowChinese(2*16,4,12,16); //报 Inverse_OLED_ShowChinese(3*16,4,13,16); //警 Inverse_OLED_ShowChar(4*16+0,4, ':',16); //: Inverse_OLED_ShowChar(4*16+8,4, low_alarmtemp/100+0x30,16); // Inverse_OLED_ShowChar(5*16+0,4, low_alarmtemp/10%10+0x30,16); // Inverse_OLED_ShowChar(5*16+8,4, '.',16); //. Inverse_OLED_ShowChar(6*16+0,4, low_alarmtemp%10+0x30,16); // Inverse_OLED_ShowChar(6*16+8,4, ' ',16); //空格 Inverse_OLED_ShowChinese(7*16,4, 19,16); //'C } void Set_Time(void) { //0-1页,北京时间,反显方式 Inverse_OLED_ShowChinese(0*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(1*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(2*16,0,14,16); //北 Inverse_OLED_ShowChinese(3*16,0,15,16); //京 Inverse_OLED_ShowChinese(4*16,0, 8,16); //时 Inverse_OLED_ShowChinese(5*16,0, 9,16); //间 Inverse_OLED_ShowChinese(6*16,0,18,16); //不显示 Inverse_OLED_ShowChinese(7*16,0,18,16); //不显示 //2-3页,不显示 //4-5页,2023-01-28(日期显示) OLED_ShowChar(1*16+8,4,'2',16); //2 OLED_ShowChar(2*16+0,4,'0',16); //0 OLED_ShowChar(2*16+8,4,year/10+0x30,16); //十位 OLED_ShowChar(3*16+0,4,year%10+0x30,16); //个位 OLED_ShowChar(3*16+8,4,'-',16); //- OLED_ShowChar(4*16+0,4,month/10+0x30,16); //十位 OLED_ShowChar(4*16+8,4,month%10+0x30,16); //个位 OLED_ShowChar(5*16+0,4,'-',16); //- OLED_ShowChar(5*16+8,4,day/10+0x30,16); //十位 OLED_ShowChar(6*16+0,4,day%10+0x30,16); //个位 //6-7页,16:24:30 week:5(时间显示) OLED_ShowChar(0*16+0,6,hour/10+0x30,16); //十位 OLED_ShowChar(0*16+8,6,hour%10+0x30,16); //个位 OLED_ShowChar(1*16+0,6,':',16); //: OLED_ShowChar(1*16+8,6,min/10+0x30,16); //十位 OLED_ShowChar(2*16+0,6,min%10+0x30,16); //个位 OLED_ShowChar(2*16+8,6,':',16); //: OLED_ShowChar(3*16+0,6,sec/10+0x30,16); //十位 OLED_ShowChar(3*16+8,6,sec%10+0x30,16); //个位 OLED_ShowChar(4*16+0,6,' ',16); //空格 OLED_ShowString(4*16+8,6,"Week:",16); //Week: OLED_ShowChar(7*16+8,6,week+0x30,16); //5 }
5.2 OLED控制函数
#ifndef _OLED_H_ #define _OLED_H_ #include "I2C.H" //OLED控制用函数 void delay_ms(unsigned int ms); void OLED_ColorTurn(u8 i); void OLED_DisplayTurn(u8 i); void OLED_WR_Byte(u8 dat,u8 cmd); void OLED_Set_Pos(u8 x, u8 y); void OLED_Display_On(void); void OLED_Display_Off(void); void OLED_Clear(void); void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 sizey); u32 oled_pow(u8 m,u8 n); void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 sizey); void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 sizey); void OLED_ShowChinese(u8 x,u8 y,u8 no,u8 sizey); void OLED_DrawBMP(u8 x,u8 y,u8 sizex, u8 sizey,u8 BMP[]); void OLED_Init(void); void Inverse_OLED_ShowChar(u8 x,u8 y,u8 chr,u8 sizey); void Inverse_OLED_ShowChinese(u8 x,u8 y,u8 no,u8 sizey); #endif
#include "oled.h" #include "oledfont.h" //存放的字库数据,包含常用的字符和用户自己所取模的中文 #define OLED_CMD 0 //写命令 #define OLED_DATA 1 //写数据 //OLED的显存 //存放格式如下,128*8为一页,共8页. //[0]0 1 2 3 ... 127 //[1]0 1 2 3 ... 127 //[2]0 1 2 3 ... 127 //[3]0 1 2 3 ... 127 //[4]0 1 2 3 ... 127 //[5]0 1 2 3 ... 127 //[6]0 1 2 3 ... 127 //[7]0 1 2 3 ... 127 void delay_ms(unsigned int ms) { unsigned int a; while(ms) { a=1800; while(a--); ms--; } return; } //反显函数 void OLED_ColorTurn(u8 i) { if(i==0) { OLED_WR_Byte(0xA6,OLED_CMD);//正常显示 } if(i==1) { OLED_WR_Byte(0xA7,OLED_CMD);//反色显示 } } //屏幕旋转180度 void OLED_DisplayTurn(u8 i) { if(i==0) { OLED_WR_Byte(0xC8,OLED_CMD);//正常显示 OLED_WR_Byte(0xA1,OLED_CMD); } if(i==1) { OLED_WR_Byte(0xC0,OLED_CMD);//反转显示 OLED_WR_Byte(0xA0,OLED_CMD); } } //发送一个字节 //向SSD1306写入一个字节。 //mode:数据/命令标志 0,表示命令;1,表示数据; void OLED_WR_Byte(u8 dat,u8 mode) { I2C_Start(); Send_Byte(0x78); //从机地址 I2C_WaitAck(); if(mode){Send_Byte(0x40);} else {Send_Byte(0x00);} I2C_WaitAck(); Send_Byte(dat); I2C_WaitAck(); I2C_Stop(); } //坐标设置 void OLED_Set_Pos(u8 x, u8 y) { x+=2; //SH1106的起始地址为0x02列(1.3寸OLED),SSD1306则删除 OLED_WR_Byte(0xb0+y,OLED_CMD); OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD); OLED_WR_Byte((x&0x0f),OLED_CMD); } //开启OLED显示 void OLED_Display_On(void) { OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令 OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON } //关闭OLED显示 void OLED_Display_Off(void) { OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令 OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF } //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!! void OLED_Clear(void) { u8 i,n; for(i=0;i<8;i++) { OLED_WR_Byte (0xb0+i,OLED_CMD); //设置页地址(0~7) // OLED_WR_Byte (0x00,OLED_CMD); //设置显示位置—列低地址,SSD1306,0.96寸OLED OLED_WR_Byte (0x02,OLED_CMD); //设置显示位置—列低地址,SH1106,1.3寸OLED OLED_WR_Byte (0x10,OLED_CMD); //设置显示位置—列高地址 for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA); } //更新显示 } /** * @brief 在指定位置显示一个字符,包括部分字符 * @param x, 显示横坐标,取值范围为0~127 * @param y, 显示纵坐标,取值范围为0~7页 * @param sizey, 字体尺寸(8x16),可调整 * @retval 无 */ void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 sizey) { u8 c=0,sizex=sizey/2; u16 i=0,size1; if(sizey==8)size1=6; else size1=(sizey/8+((sizey%8)?1:0))*(sizey/2); c=chr-' ';//得到偏移后的值 OLED_Set_Pos(x,y); for(i=0;i<size1;i++) { if(i%sizex==0&&sizey!=8) OLED_Set_Pos(x,y++); if(sizey==8) OLED_WR_Byte(asc2_0806[c][i],OLED_DATA);//6X8字号 else if(sizey==16) OLED_WR_Byte(asc2_1608[c][i],OLED_DATA);//8x16字号 // else if(sizey==xx) OLED_WR_Byte(asc2_xxxx[c][i],OLED_DATA);//用户添加字号 else return; } } //反显字符 void Inverse_OLED_ShowChar(u8 x,u8 y,u8 chr,u8 sizey) { u8 c=0,sizex=sizey/2; u16 i=0,size1; if(sizey==8)size1=6; else size1=(sizey/8+((sizey%8)?1:0))*(sizey/2); c=chr-' ';//得到偏移后的值 OLED_Set_Pos(x,y); for(i=0;i<size1;i++) { if(i%sizex==0&&sizey!=8) OLED_Set_Pos(x,y++); if(sizey==8) OLED_WR_Byte(~asc2_0806[c][i],OLED_DATA);//6X8字号 else if(sizey==16) OLED_WR_Byte(~asc2_1608[c][i],OLED_DATA);//8x16字号 // else if(sizey==xx) OLED_WR_Byte(~asc2_xxxx[c][i],OLED_DATA);//用户添加字号 else return; } } //m^n函数 u32 oled_pow(u8 m,u8 n) { u32 result=1; while(n--)result*=m; return result; } /** * @brief 显示数字 * @param x, 显示横坐标,取值范围为0~127 * @param y, 显示纵坐标,取值范围为0~7页 * @param num, 要显示的数字 * @param len, 数字的位数 * @param sizey, 字体尺寸(8x16) * @retval 无 */ void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 sizey) { u8 t,temp,m=0; u8 enshow=0; if(sizey==8)m=2; for(t=0;t<len;t++) { temp=(num/oled_pow(10,len-t-1))%10; if(enshow==0&&t<(len-1)) { if(temp==0) { OLED_ShowChar(x+(sizey/2+m)*t,y,' ',sizey); continue; }else enshow=1; } OLED_ShowChar(x+(sizey/2+m)*t,y,temp+'0',sizey); } } /** * @brief 显示一个字符号串 * @param x, 显示横坐标,取值范围为0~127 * @param y, 显示纵坐标,取值范围为0~7页 * @param *chr, 字符串,指针 * @param sizey, 字符尺寸(8x16),可调整参数 * @retval 无 */ void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 sizey) { u8 j=0; while (chr[j]!='\0') { OLED_ShowChar(x,y,chr[j++],sizey); if(sizey==8)x+=6; else x+=sizey/2; } } /** * @brief 显示汉字,正常显示,可显示取模后的任意点阵 * @param x, 显示横坐标,取值范围为0~127 * @param y, 显示纵坐标,取值范围为0~7页 * @param no, 汉字库中文字的序号 * @param sizey, 汉字尺寸(默认16x16),可调整参数 * @retval 无 */ void OLED_ShowChinese(u8 x,u8 y,u8 no,u8 sizey) { u16 i,size1=(sizey/8+((sizey%8)?1:0))*sizey; for(i=0;i<size1;i++) { if(i%sizey==0) OLED_Set_Pos(x,y++); if(sizey==16) OLED_WR_Byte(Hzk[no][i],OLED_DATA);//16x16字号 // else if(sizey==xx) OLED_WR_Byte(xxx[c][i],OLED_DATA);//用户添加字号 else return; } } //汉字反显 void Inverse_OLED_ShowChinese(u8 x,u8 y,u8 no,u8 sizey) { u16 i,size1=(sizey/8+((sizey%8)?1:0))*sizey; for(i=0;i<size1;i++) { if(i%sizey==0) OLED_Set_Pos(x,y++); if(sizey==16) OLED_WR_Byte(~Hzk[no][i],OLED_DATA); //按位取反 // else if(sizey==xx) OLED_WR_Byte(xxx[c][i],OLED_DATA);//用户添加字号 else return; } } /** * @brief 显示图片 * @param x, 显示横坐标,取值范围为0~127 * @param y, 显示纵坐标,取值范围为0~7页 * @param sizex, 图片水平大小,取值范围为1~128 * @param sizey, 图片数值大小,取值范围为1~64 * @param BMP[], 图片数据矩阵 * @retval 无 */ void OLED_DrawBMP(u8 x,u8 y,u8 sizex, u8 sizey,u8 BMP[]) { u16 j=0; u8 i,m; sizey=sizey/8+((sizey%8)?1:0); for(i=0;i<sizey;i++) { OLED_Set_Pos(x,i+y); for(m=0;m<sizex;m++) { OLED_WR_Byte(BMP[j++],OLED_DATA); } } } //初始化 void OLED_Init(void) { // OLED_RES_Clr(); // delay_ms(200); // OLED_RES_Set(); OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel // OLED_WR_Byte(0x00,OLED_CMD);//---set low column address, SSD1306,0.96寸OLED OLED_WR_Byte(0x02,OLED_CMD);//---set low column address, SH1106,1.3寸OLED OLED_WR_Byte(0x10,OLED_CMD);//---set high column address OLED_WR_Byte(0x40,OLED_CMD);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F) OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常 OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常 OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64) OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F) OLED_WR_Byte(0x00,OLED_CMD);//-not offset OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration OLED_WR_Byte(0x12,OLED_CMD); OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02) OLED_WR_Byte(0x02,OLED_CMD);//选择页寻址模式 OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5) OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7) OLED_Clear(); OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/ }
5.3 I2C驱动函数
#ifndef _I2C_H_ #define _I2C_H_ #include "REG52.h" #define u8 unsigned char //0~255 #define u16 unsigned int //0~65535 #define u32 unsigned long //0~4294967295 sbit OLED_SCL=P1^0;//SCL sbit OLED_SDA=P1^1;//SDA //-----------------OLED端口定义---------------- #define OLED_SCL_Clr() OLED_SCL=0 #define OLED_SCL_Set() OLED_SCL=1 #define OLED_SDA_Clr() OLED_SDA=0 #define OLED_SDA_Set() OLED_SDA=1 #define OLED_RES_Clr() OLED_RES=0 #define OLED_RES_Set() OLED_RES=1 void IIC_delay(void); void I2C_Start(void); void I2C_Stop(void); void I2C_WaitAck(void); void Send_Byte(u8 dat); #endif
#include "I2C.H" //延时 void IIC_delay(void) { u8 t=1; while(t--); } //起始信号 void I2C_Start(void) { OLED_SDA_Set(); OLED_SCL_Set(); IIC_delay(); OLED_SDA_Clr(); IIC_delay(); OLED_SCL_Clr(); } //结束信号 void I2C_Stop(void) { OLED_SDA_Clr(); OLED_SCL_Set(); IIC_delay(); OLED_SDA_Set(); } //等待信号响应 void I2C_WaitAck(void) //测数据信号的电平 { OLED_SDA_Set(); IIC_delay(); OLED_SCL_Set(); IIC_delay(); OLED_SCL_Clr(); IIC_delay(); } //写入一个字节 void Send_Byte(u8 dat) { u8 i; for(i=0;i<8;i++) { OLED_SCL_Clr();//将时钟信号设置为低电平 if(dat&0x80)//将dat的8位从最高位依次写入 { OLED_SDA_Set(); } else { OLED_SDA_Clr(); } IIC_delay(); OLED_SCL_Set(); IIC_delay(); OLED_SCL_Clr(); dat<<=1; } }
5.4 汉字库头文件
#ifndef _OLEDFONT_H_ #define _OLEDFONT_H_ //6*8 ASCII字符集点阵 unsigned char code asc2_0806[][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 }; //16*16 ASCII字符集点阵,实际为8x16 unsigned char code asc2_1608[][16]={ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/ {0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00},/*"!",1*/ {0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/ {0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00},/*"#",3*/ {0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00},/*"$",4*/ {0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00},/*"%",5*/ {0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10},/*"&",6*/ {0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/ {0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00},/*"(",8*/ {0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00},/*")",9*/ {0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00},/*"*",10*/ {0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00},/*"+",11*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00},/*",",12*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01},/*"-",13*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},/*".",14*/ {0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",15*/ {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",16*/ {0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"1",17*/ {0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",18*/ {0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},/*"3",19*/ {0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},/*"4",20*/ {0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},/*"5",21*/ {0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"6",22*/ {0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},/*"7",23*/ {0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",24*/ {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},/*"9",25*/ {0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},/*":",26*/ {0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00},/*";",27*/ {0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00},/*"<",28*/ {0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00},/*"=",29*/ {0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00},/*">",30*/ {0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00},/*"?",31*/ {0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00},/*"@",32*/ {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20},/*"A",33*/ {0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00},/*"B",34*/ {0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00},/*"C",35*/ {0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00},/*"D",36*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00},/*"E",37*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00},/*"F",38*/ {0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00},/*"G",39*/ {0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20},/*"H",40*/ {0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"I",41*/ {0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00},/*"J",42*/ {0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00},/*"K",43*/ {0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00},/*"L",44*/ {0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00},/*"M",45*/ {0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00},/*"N",46*/ {0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00},/*"O",47*/ {0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00},/*"P",48*/ {0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00},/*"Q",49*/ {0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20},/*"R",50*/ {0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00},/*"S",51*/ {0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00},/*"T",52*/ {0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},/*"U",53*/ {0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00},/*"V",54*/ {0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00},/*"W",55*/ {0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20},/*"X",56*/ {0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00},/*"Y",57*/ {0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00},/*"Z",58*/ {0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00},/*"[",59*/ {0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00},/*"\",60*/ {0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00},/*"]",61*/ {0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80},/*"_",63*/ {0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/ {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20},/*"a",65*/ {0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"b",66*/ {0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00},/*"c",67*/ {0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20},/*"d",68*/ {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00},/*"e",69*/ {0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"f",70*/ {0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00},/*"g",71*/ {0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},/*"h",72*/ {0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"i",73*/ {0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00},/*"j",74*/ {0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00},/*"k",75*/ {0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"l",76*/ {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F},/*"m",77*/ {0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},/*"n",78*/ {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},/*"o",79*/ {0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00},/*"p",80*/ {0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80},/*"q",81*/ {0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00},/*"r",82*/ {0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00},/*"s",83*/ {0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00},/*"t",84*/ {0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20},/*"u",85*/ {0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00},/*"v",86*/ {0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00},/*"w",87*/ {0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00},/*"x",88*/ {0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00},/*"y",89*/ {0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00},/*"z",90*/ {0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40},/*"{",91*/ {0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00},/*"|",92*/ {0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00},/*"}",93*/ {0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/ }; unsigned char code Hzk[][32]={ // 16x16, 主(0) 菜(1) 单(2) 当(3) 前(4) 温(5) 度(6) 湿(7) 时(8) 间(9) 设(10) 置(11) 报(12) 警(13) 北(14) 京(15) 高(16) 低(17) {0x00,0x08,0x08,0x08,0x08,0x08,0x09,0xFA,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x40,0x40,0x41,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x41,0x40,0x40,0x00},/*"主",0*/ {0x04,0x04,0x44,0xC4,0x4F,0x44,0x44,0xC4,0x24,0x24,0x2F,0xB4,0x24,0x04,0x04,0x00,0x40,0x44,0x24,0x24,0x15,0x0C,0x04,0xFE,0x04,0x0C,0x15,0x24,0x24,0x44,0x40,0x00},/*"菜",1*/ {0x00,0x00,0xF8,0x49,0x4A,0x4C,0x48,0xF8,0x48,0x4C,0x4A,0x49,0xF8,0x00,0x00,0x00,0x10,0x10,0x13,0x12,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x12,0x13,0x10,0x10,0x00},/*"单",2*/ {0x00,0x40,0x42,0x44,0x58,0x40,0x40,0x7F,0x40,0x40,0x50,0x48,0xC6,0x00,0x00,0x00,0x00,0x40,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00},/*"当",3*/ {0x08,0x08,0xE8,0x29,0x2E,0x28,0xE8,0x08,0x08,0xC8,0x0C,0x0B,0xE8,0x08,0x08,0x00,0x00,0x00,0xFF,0x09,0x49,0x89,0x7F,0x00,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00},/*"前",4*/ {0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00},/*"温",5*/ {0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00},/*"度",6*/ {0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00},/*"湿",7*/ {0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00},/*"时",8*/ {0x00,0xF8,0x01,0x06,0x00,0xF0,0x12,0x12,0x12,0xF2,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x1F,0x11,0x11,0x11,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00},/*"间",9*/ {0x40,0x40,0x42,0xCC,0x00,0x40,0xA0,0x9E,0x82,0x82,0x82,0x9E,0xA0,0x20,0x20,0x00,0x00,0x00,0x00,0x3F,0x90,0x88,0x40,0x43,0x2C,0x10,0x28,0x46,0x41,0x80,0x80,0x00},/*"设",10*/ {0x00,0x17,0x15,0xD5,0x55,0x57,0x55,0x7D,0x55,0x57,0x55,0xD5,0x15,0x17,0x00,0x00,0x40,0x40,0x40,0x7F,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x7F,0x40,0x40,0x40,0x00},/*"置",11*/ {0x10,0x10,0x10,0xFF,0x10,0x90,0x00,0xFE,0x82,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00,0x04,0x44,0x82,0x7F,0x01,0x00,0x00,0xFF,0x80,0x43,0x2C,0x10,0x2C,0x43,0x80,0x00},/*"报",12*/ {0x12,0xEA,0xAF,0xAA,0xEA,0x0F,0xFA,0x02,0x88,0x8C,0x57,0x24,0x54,0x8C,0x84,0x00,0x02,0x02,0xEA,0xAA,0xAA,0xAB,0xAA,0xAB,0xAA,0xAA,0xAA,0xAA,0xEA,0x02,0x02,0x00},/*"警",13*/ {0x00,0x20,0x20,0x20,0x20,0xFF,0x00,0x00,0x00,0xFF,0x40,0x20,0x10,0x08,0x00,0x00,0x20,0x60,0x20,0x10,0x10,0xFF,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00},/*"北",14*/ {0x04,0x04,0x04,0xE4,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00,0x00,0x40,0x20,0x1B,0x02,0x42,0x82,0x7E,0x02,0x02,0x02,0x0B,0x10,0x60,0x00,0x00},/*"京",15*/ {0x04,0x04,0x04,0x04,0xF4,0x94,0x95,0x96,0x94,0x94,0xF4,0x04,0x04,0x04,0x04,0x00,0x00,0xFE,0x02,0x02,0x7A,0x4A,0x4A,0x4A,0x4A,0x4A,0x7A,0x02,0x82,0xFE,0x00,0x00},/*"高",16*/ {0x00,0x80,0x60,0xF8,0x07,0x00,0xFC,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0x00,0x01,0x00,0x00,0xFF,0x00,0x00,0xFF,0x40,0x20,0x00,0x41,0x8E,0x30,0x40,0xF8,0x00},/*"低",17*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*不显示,18*/ {0x00,0x00,0x00,0x38,0x28,0x38,0x00,0x00,0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00},/*摄氏度,19*/ }; #endif
5.5 图片库头文件
#ifndef _BMP_H_ #define _BMP_H_ //图片库,128x64,存放的图片数据 unsigned char code BMP12864_BIRD[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x60, 0xE0,0xE0,0xE0,0xE0,0x60,0x40,0x40,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x80,0xC0,0xE0, 0x60,0x20,0x30,0x30,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x30,0x30,0x30,0x60,0x60, 0xC0,0xC0,0x80,0x00,0x00,0x00,0x38,0x1C,0x0C,0x0C,0x0C,0x18,0xB8,0xF0,0xC0,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0x03,0x03,0x06,0x0C,0x1C,0x38,0xF0,0xF0,0x60,0x30,0x31,0x39,0x1F, 0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x1C,0x1C,0x18,0x00,0x00,0x00, 0x00,0x01,0x01,0x03,0x0F,0x3F,0xF3,0xC2,0x03,0x03,0x03,0x03,0x01,0x01,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0x63,0x77,0x3E,0x38,0x38,0x18,0x18, 0x18,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0xC0,0xE0,0x7F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0xC0,0xF8,0xFC,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFE,0x87,0x03,0x01,0x01, 0x01,0x01,0x01,0x01,0x03,0x03,0x02,0x06,0x0C,0x18,0x38,0x70,0xE0,0xC0,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0x1F,0x7F,0xF8,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0F,0x1E,0x3C,0x70, 0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07, 0x0C,0x38,0x70,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0E,0x1C,0x38,0x70,0x60,0xE0,0xC0,0xC0,0x80, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x01,0x03,0x03,0x06,0x0C,0x18,0x38,0x70,0xE0,0xC0,0x80,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x03,0x07,0x1E,0x38,0xF0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x06,0x06,0x06,0x06,0x06, 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x0E, 0x0E,0x0E,0x0E,0x0C,0x0E,0x0E,0x0C,0x0C,0x04,0x04,0x04,0x04,0x0E,0x0E,0x0F,0x0F, 0x7F,0x3F,0x1F,0x0F,0x0E,0x0E,0x0E,0x0C,0x0C,0x0C,0x8C,0xEC,0xFC,0x3C,0x1C,0x0C, 0x1C,0x7E,0x7E,0x0E,0x1E,0x1E,0x3E,0x7E,0x6C,0x0C,0x0C,0x09,0x0B,0x0F,0x0E,0x0E, 0x0C,0x18,0x18,0x30,0x30,0x30,0x60,0xE0,0xE0,0xE3,0xFF,0xBE,0x8E,0x8C,0x8C,0x8C, 0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x8C,0x84,0x84,0x84,0x84, 0x84,0x86,0x86,0x86,0x84,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06, 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x02, 0x02,0x06,0x06,0x06,0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x03,0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x33,0x3F,0x0F,0x03,0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, 0x0F,0x1F,0x39,0x21,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x03,0x07,0x07,0x0D,0x19,0x31,0x21,0x01,0x01,0x01,0x01,0x01, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; #endif
6 仿真测试
7 参考资料