话不多说 本人的项目中设计到了OLED显示一些花里胡哨的东西 来和大家一起分享一下成果 (已经调试直接用)
- void WriteCmd(unsigned char I2C_Command)
- {
- write_i2c(OLED_DEV_ADDR,0x00, I2C_Command);
- }
- void WriteDat(unsigned char I2C_Data)
- {
- write_i2c(OLED_DEV_ADDR,0x40, I2C_Data);
- }
- void OLED_SetPos(unsigned char x, unsigned char y)
- {
- WriteCmd(0xb0+y);
- WriteCmd(((x&0xf0)>>4)|0x10);
- WriteCmd((x&0x0f)|0x01);
- }
- void OLED_Fill(unsigned char fill_Data)
- {
- unsigned char m,n;
- for(m=0;m<8;m++)
- {
- WriteCmd(0xb0+m); //page0-page1
- WriteCmd(0x00); //low column start address
- WriteCmd(0x10); //high column start address
- for(n=0;n<128;n++)
- {
- WriteDat(fill_Data);
- }
- }
- }
- void OLED_CLS(void)
- {
- OLED_Fill(0x00);
- }
- void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize)
- {
- unsigned char c = 0,i = 0,j = 0;
- switch(TextSize)
- {
- case 1:
- {
- while(ch[j] != '\0')
- {
- c = ch[j] - 32;
- if(x > 126)
- {
- x = 0;
- y++;
- }
- OLED_SetPos(x,y);
- for(i=0;i<6;i++)
- WriteDat(F6x8[c][i]);
- x += 6;
- j++;
- }
- }break;
- case 2:
- {
- while(ch[j] != '\0')
- {
- c = ch[j] - 32;
- if(x > 120)
- {
- x = 0;
- y++;
- }
- OLED_SetPos(x,y);
- for(i=0;i<8;i++)
- WriteDat(F8X16[c*16+i]);
- OLED_SetPos(x,y+1);
- for(i=0;i<8;i++)
- WriteDat(F8X16[c*16+i+8]);
- x += 8;
- j++;
- }
- }break;
- }
- }
- void OLED_ShowCN(unsigned char x, unsigned char y, unsigned char N)
- {
- unsigned char wm=0;
- unsigned int adder=32*N;
- OLED_SetPos(x , y);
- for(wm = 0;wm < 16;wm++)
- {
- WriteDat(F16x16[adder]);
- adder += 1;
- }
- OLED_SetPos(x,y + 1);
- for(wm = 0;wm < 16;wm++)
- {
- WriteDat(F16x16[adder]);
- adder += 1;
- }
- }
- void OLED_DrawBMP(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char BMP[])
- {
- unsigned int j=0;
- unsigned char x,y;
- if(y1%8==0)
- y = y1/8;
- else
- y = y1/8 + 1;
- for(y=y0;y<y1;y++)
- {
- OLED_SetPos(x0,y);
- for(x=x0;x<x1;x++)
- {
- WriteDat(BMP[j++]);
- }
- }
- }
- void OLED_ShowChar(u8 x, u8 y, u8 chr,u8 size)
- {
- unsigned char c = 0, i = 0;
- c = chr - ' '; //μÃμ½Æ«òÆoóμÄÖμ
- if(x > 128 - 1)
- {
- x = 0;
- y = y + 2;
- }
- if(size == 0)
- {
- OLED_SetPos(x, y);
- for(i = 0; i < 8; i++)
- WriteDat(F8X16[c * 16 + i]);
- OLED_SetPos(x, y + 1);
- for(i = 0; i < 8; i++)
- WriteDat(F8X16[c * 16 + i + 8]);
- }
- else
- {
- OLED_SetPos(x, y + 1);
- for(i = 0; i < 6; i++)
- WriteDat(F6x8[c][i]);
- }
- }
- void OLED_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 size)
- {
- u8 t,temp;
- u8 enshow = 0;
- 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 + (size / 2)*t, y, ' ',size);
- continue;
- }
- else enshow = 1;
- }
- OLED_ShowChar(x + (size / 2)*t, y, temp + '0',size);
- }
- }
复制代码
这一个函数 :void OLED_DrawBMP(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char BMP[]); 是用来显示图片的
这就需要用到工具 请百度搜索下载“ 9. Image2Lcd 2.9” 和工具“ PCtoLCD2002完美版 ”
首先下载一张图片打开将其转化为BMP格式
打开Image2Lcd 工具导入图片点击保存。
打开PCtoLCD2002 配置如
然后导入BMP图片得到字符串即可
全部资料51hei下载地址:
Hardwareddata.7z
(1.55 MB, 下载次数: 35)
|