/******************************************************************************************/ // /******************************************************************************************/ typedef struct typCHAR_12 { unsigned char Index[1]; unsigned char Msk[16]; }; /******************************************************************************************/ // /******************************************************************************************/ struct typCHAR_12 code CHAR_12[]={ //16*8 字符 "1",0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x1F,0x10,0x10,0x00, "2",0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x14,0x12,0x11,0x10,0x18,0x00, "3",0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x0C,0x10,0x10,0x10,0x11,0x0E,0x00, "4",0x00,0x80,0x40,0x20,0xF8,0x00,0x00,0x00,0x00,0x03,0x02,0x12,0x1F,0x12,0x12,0x00, "5",0x00,0xF8,0x88,0x48,0x48,0x48,0x88,0x00,0x00,0x0C,0x10,0x10,0x10,0x10,0x0F,0x00, "6",0x00,0xE0,0x10,0x88,0x88,0x98,0x00,0x00,0x00,0x0F,0x11,0x10,0x10,0x10,0x0F,0x00, "7",0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00, "8",0x00,0x70,0x88,0x88,0x88,0x88,0x70,0x00,0x00,0x0E,0x11,0x10,0x10,0x11,0x0E,0x00, "9",0x00,0xF0,0x08,0x08,0x08,0x90,0xE0,0x00,0x00,0x00,0x19,0x11,0x11,0x08,0x07,0x00, "0",0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x07,0x08,0x10,0x10,0x08,0x07,0x00, ".",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00, "a",0x00,0x20,0x90,0x50,0x50,0xE0,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x07,0x04,0x00, "b",0x02,0xFE,0x20,0x10,0x10,0x10,0xE0,0x00,0x00,0x07,0x04,0x04,0x04,0x04,0x03,0x00, "c",0x00,0xC0,0x20,0x10,0x10,0x10,0x20,0x00,0x00,0x01,0x02,0x04,0x04,0x04,0x02,0x00, "d",0x00,0xE0,0x10,0x10,0x10,0x12,0xFE,0x00,0x00,0x03,0x04,0x04,0x04,0x02,0x07,0x04, "e",0x00,0xE0,0x50,0x50,0x50,0x50,0x60,0x00,0x00,0x03,0x04,0x04,0x04,0x04,0x02,0x00, "f",0x00,0x10,0x10,0xFC,0x12,0x12,0x06,0x00,0x00,0x04,0x04,0x07,0x04,0x04,0x00,0x00, "g",0x00,0xB0,0x48,0x48,0x48,0x38,0x08,0x00,0x00,0x06,0x09,0x09,0x09,0x09,0x06,0x00, "h",0x02,0xFE,0x20,0x10,0x10,0x10,0xE0,0x00,0x04,0x07,0x04,0x00,0x00,0x04,0x07,0x04, "i",0x00,0x10,0x16,0xF6,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x07,0x04,0x04,0x00,0x00, "k",0x02,0xFE,0x80,0x40,0xB0,0x10,0x10,0x00,0x04,0x07,0x04,0x00,0x05,0x06,0x04,0x00, "l",0x00,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x07,0x04,0x04,0x00,0x00, "m",0x10,0xF0,0x10,0xF0,0x10,0xE0,0x00,0x00,0x04,0x07,0x00,0x07,0x00,0x07,0x04,0x00, "n",0x10,0xF0,0x20,0x10,0x10,0x10,0xE0,0x00,0x04,0x07,0x04,0x00,0x00,0x04,0x07,0x04, "o",0x00,0xC0,0x20,0x10,0x10,0x20,0xC0,0x00,0x00,0x01,0x02,0x04,0x04,0x02,0x01,0x00, "p",0x08,0xF8,0x10,0x08,0x08,0x08,0xF0,0x00,0x08,0x0F,0x0A,0x02,0x02,0x02,0x01,0x00, "q",0x00,0xF0,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x01,0x02,0x02,0x02,0x09,0x0F,0x08, "r",0x10,0x10,0xF0,0x20,0x10,0x10,0x30,0x00,0x04,0x04,0x07,0x04,0x04,0x00,0x00,0x00, "s",0x00,0x60,0x90,0x90,0x90,0x30,0x00,0x00,0x00,0x06,0x04,0x04,0x04,0x03,0x00,0x00, "t",0x00,0x10,0x10,0xFC,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x03,0x04,0x04,0x00,0x00, "u",0x10,0xF0,0x00,0x00,0x00,0x10,0xF0,0x00,0x00,0x03,0x04,0x04,0x04,0x02,0x07,0x04, "v",0x10,0x30,0xD0,0x00,0x00,0xD0,0x30,0x10,0x00,0x00,0x01,0x06,0x01,0x00,0x00,0x00, "w",0x10,0xF0,0x00,0xF0,0x00,0xF0,0x10,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00, "x",0x00,0x10,0x30,0xC0,0xD0,0x30,0x10,0x00,0x00,0x04,0x06,0x05,0x01,0x06,0x04,0x00, "y",0x08,0x18,0xE8,0x00,0x80,0x68,0x18,0x08,0x08,0x08,0x08,0x07,0x01,0x00,0x00,0x00, "z",0x00,0x30,0x10,0x90,0x50,0x30,0x10,0x00,0x00,0x04,0x06,0x05,0x04,0x04,0x06,0x00, "_",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x00, "/",0x00,0x00,0x00,0xE0,0x18,0x07,0x00,0x00,0x00,0x0C,0x03,0x00,0x00,0x00,0x00,0x00, ":",0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00, " ",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ">",0x00,0x00,0x40,0x40,0x80,0x80,0x00,0x00,0x01,0x01,0x05,0x05,0x03,0x03,0x01,0x01, "<",0x00,0xFC,0x07,0x07,0x04,0xF8,0x00,0x00,0x10,0x9F,0xF0,0x90,0xF0,0x9F,0x10,0x00, "O",0xF8,0x04,0x02,0x02,0x02,0x04,0xF8,0x00,0x01,0x02,0x04,0x04,0x04,0x02,0x01,0x00, "N",0x00,0x02,0xFE,0x0E,0x70,0x82,0xFE,0x02,0x00,0x04,0x07,0x04,0x00,0x03,0x07,0x00, "D",0x00,0x02,0xFE,0x02,0x02,0x02,0x04,0xF8,0x00,0x04,0x07,0x04,0x04,0x04,0x02,0x01, "S",0x00,0x78,0x04,0x04,0x04,0xF8,0x00,0x00,0x7F,0xFF,0xEF,0xC7,0xEF,0xFF,0x7F,0x00, "C",0x00,0xF0,0x08,0x08,0x08,0x08,0x38,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x10,0x00, "%",0xE0,0x50,0xE0,0x90,0x68,0x14,0x0A,0x00,0x00,0x31,0x0C,0x03,0x0E,0x11,0x0E,0x00, "+",0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x01,0x01,0x01, "-",0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ";",0x00,0x00,0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x08,0x04,0x02,0x01,0x00 }; /******************************************************************************************/ //
/*=====================OLED部分开始=====================*/ /**/ /******************************************************************************************/ // OLED清屏模块 /******************************************************************************************/ void clear_prog() { unsigned char i,j; for(i=0;i<8;i++) { wr_command(0xb0+i); //页面地址设置 wr_command(0x0); //列地址设置 wr_command(0x10); //列地址设置 for( j=0; j<128; j++) { //RAM清"0" wr_data(0x0); gui_disp_buf[j] =0; } } } /******************************************************************************************/
/******************************************************************************************/ // 显示字符 /******************************************************************************************/ void dprintf_CHAR12 (unsigned char line,column,unsigned char str[20],color) { unsigned char i=0,c1,ulen; ulen = (unsigned char)sprintf(dispbuff,"%s",str); while(i<ulen) { c1 = dispbuff; for(jj=0;jj<sizeof(CHAR_12)/sizeof(CHAR_12[0]);jj++)//寻找字库 { if(c1 == CHAR_12[jj].Index[0]) break; } display_prog(line,column,3,color); column++;
i++; } }
/******************************************************************************************/ // /******************************************************************************************/ void wr_command(unsigned char data com) //写命令(0-128 行)子程序 { EA = 0; D_C = 0; // D_C=0,数据送至指令寄存器 CS1_LOW; //Chip select _nop_(); _nop_(); P0 = com; _nop_(); //用此NOP代替读状态 _nop_(); //用此NOP代替读状态 r_w = 0; _nop_(); _nop_(); r_w = 1; _nop_(); _nop_(); CS1_HIGH; //Chip select _nop_(); _nop_(); EA=1; } /******************************************************************************************/ // /******************************************************************************************/ void wr_data(unsigned char data dat) //写数据(65-128 行)子程序 { EA=0; D_C = 1; //D_C=1,数据送至RAM CS1_LOW; //Chip select _nop_(); _nop_(); P0 = dat; _nop_(); //用此NOP代替读状态 _nop_(); //用此NOP代替读状态
r_w = 0; _nop_(); _nop_(); r_w = 1; _nop_(); _nop_(); CS1_HIGH; //Chip select _nop_(); _nop_(); EA=1; }
/******************************************************************************************/ // /******************************************************************************************/ // void oled_display(unsigned char picture[]) //{ // unsigned char j; // for(page=0;page<8;page++) // { // wr_command(176+page); //set page address
// wr_command(0x00); //set low address
// wr_command(0x10); //set higher address
// for(j=0;j<128;j++) // { // wr_data(picture[j+page*128]); // } // } //} /* void show_picture(unsigned char picture[]) { uchar j; for(page=0;page<8;page++) {
wr_command(0xb0+page); //set page address
wr_command(0x00); //set low address
wr_command(0x10); //set higher address
for(j=0;j<16;j++)//picture is 58*64 { wr_data(picture[j+page*16]); } } } */ /****************************************************************************************** // OLED初始化函数 ******************************************************************************************/ void init_oled() //初始化 { unsigned char i; en = 1; r_w = 1; RST_LOW ; for(i=0;i<100;i++); RST_HIGH ; for(i=0;i<100;i++); wr_command(0xAE); //Display off wr_command(0xAD); //Internal DC-DC off wr_command(0x8A); // Second byte wr_command(0xA8); //MUX Ratio wr_command(0x3F); //64 duty wr_command(0xD3); //Display offset wr_command(0x00); //Second byte wr_command(0x40); //Start line wr_command(0xA0); //Segment remap //a0 wr_command(0xC8); //COM remap wr_command(0xA6); //Set normal/inverse display (0xA6:Normal display) wr_command(0xA4); //Set entire display on/off (0xA4:Normal display) wr_command(0x81); //Contrast setting wr_command(0x5c); //Second byte 5c wr_command(0xD5); //Frame rate wr_command(0x60); // 85 Hz wr_command(0xD8); //Mode setting wr_command(0x00); //Mono mode wr_command(0xD9); //Set Pre-charge period wr_command(0x84); // Second byte wr_command(0xAF); //Display on }
/****************************************************************************************** ** ** ** ******************************************************************************************/ |