微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > stc15F204EA 0.96寸oled的使用IIC协议,显示图片和只讲屏幕点亮关闭可以,但显示汉字一直不成功,为什么?程序问题吗

stc15F204EA 0.96寸oled的使用IIC协议,显示图片和只讲屏幕点亮关闭可以,但显示汉字一直不成功,为什么?程序问题吗

时间:10-02 整理:3721RD 点击:
void delay(int ms)
{
   int ii,jj;
   if (ms<1) ms=1;
   for(ii=0;ii<ms;ii++)
     for(jj=0;jj<500;jj++);        
}
/****主函数*****/
void main(void)
{
OLED_Init();
delay(5);
while(1)
{
  OLED_ShowCN(3,0,1);
  OLED_ShowCN(21,0,2);
  delay(500);
//delay(500);
  //OLED_Fill(0xff);
  //delay(1000);
}
}
/*******************************************
//OLED: x,y -- 起始点坐标(x:0~127, y:0~7); N:汉字在codetab.h中的索引        ----OK
********************************************/
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++)
        {
                Write_IIC_Data(F16x16[adder]);
                adder += 1;
        }
        OLED_SetPos(x,y + 1);
        for(wm = 0;wm < 16;wm++)
        {
                Write_IIC_Data(F16x16[adder]);
                adder += 1;
        }
}/***************************16*16的点阵字体取模方式:共阴——列行式——逆向输出*********/
const unsigned char F16x16[] =                    
{
0x7F,0x8F,0xFF,0x00,0xDF,0xEF,0xF7,0xB7,0xB7,0x00,0xB7,0xB7,0xB7,0xB7,0xF7,0xFF,
0x7F,0x9F,0xE7,0xF8,0xF7,0xCF,0xFD,0xFD,0xFD,0x00,0xFD,0xFD,0xED,0xDD,0xE1,0xFF,//"炜",0
0x80,0x70,0x00,0xFF,0x20,0x10,0x08,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0x08,0x00,
0x80,0x60,0x18,0x07,0x08,0x30,0x02,0x02,0x02,0xFF,0x02,0x02,0x12,0x22,0x1E,0x00,//"炜",0
};
引脚设置没问题,程序能成功编译

Write_IIC_Data(F16x16[adder])中adder的值有没有问题,另外F16x16[]好像是两个字,第二个字是什么,程序好像应该能显示第二个字

恩,第一个炜字是共阳极取的,第二个是共阴极取的,我用来判断我取的是否有问题
程序中adder的值不是adder=32*N;N表示F16x16[]中的第几个汉字吗

按正常思路第二个炜字可以正常显示,但实际一直黑屏,以下这个显示图片的就能正常运行,那么oled屏自身应该没问题吧
#include "reg52.h"
#define high 1
#define low 0
/*************Pin Define***************/
sbit SCL=P1^2;
sbit SDA=P1^3;
#define   uchar unsigned char
#define   uint unsigned int
uint        Value,A1,A2,A3;
sfr       P5=0xc8;
/****************************************************/
void Initial_LY096BG30(); //初始化显示屏
void Delay_50ms(unsigned int Del_50ms);
void Delay_1ms(unsigned int Del_1ms);
void fill_picture(unsigned char fill_Data);//
void Picture_1();
void IIC_Start();
void IIC_Stop();
void Write_IIC_Command(unsigned char IIC_Command);//写入协议的命令                                                                  
void Write_IIC_Data(unsigned char IIC_Data);
void Write_IIC_Byte(unsigned char IIC_Byte);
/***********************Initial code*********************/
void Initial_LY096BG30()
{
        Write_IIC_Command(0xAE);   //display off
        Write_IIC_Command(0x20);        //Set Memory Addressing Mode       
        Write_IIC_Command(0x10);        //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
        Write_IIC_Command(0xb0);        //Set Page Start Address for Page Addressing Mode,0-7
        Write_IIC_Command(0xc8);        //Set COM Output Scan Direction
        Write_IIC_Command(0x00);//---set low column address        低列的起始地址
        Write_IIC_Command(0x10);//---set high column address 高列的起始地址
        Write_IIC_Command(0x40);//--set start line address         开始行地址
        Write_IIC_Command(0x81);//--set contrast control register  对比控制寄存器
        Write_IIC_Command(0x7f);
        Write_IIC_Command(0xa1);//--set segment re-map 0 to 127 设置段再现0到127
        Write_IIC_Command(0xa6);//--set normal display
        Write_IIC_Command(0xa8);//--set multiplex ratio(1 to 64)  设置多路复用率(1到64)
        Write_IIC_Command(0x3F);//
        Write_IIC_Command(0xa4);//0xa4,Output follows RAM content;0xa5,Output ignores RAM content
        Write_IIC_Command(0xd3);//-set display offset
        Write_IIC_Command(0x00);//-not offset
        Write_IIC_Command(0xd5);//--set display clock divide ratio/oscillator frequency
        Write_IIC_Command(0xf0);//--set divide ratio
        Write_IIC_Command(0xd9);//--set pre-charge period
        Write_IIC_Command(0x22); //
        Write_IIC_Command(0xda);//--set com pins hardware configuration
        Write_IIC_Command(0x12);
        Write_IIC_Command(0xdb);//--set vcomh
        Write_IIC_Command(0x20);//0x20,0.77xVcc
        Write_IIC_Command(0x8d);//--set DC-DC enable
        Write_IIC_Command(0x14);//
        Write_IIC_Command(0xaf);//--turn on oled panel
}
/***********************Picture Code**************************/
unsigned char code show1[]=
{
0X08,0X20,0X06,0X20,0X40,0X7E,0X31,0X80,0X00,0X02,0X00,0X7E,0X7F,0X42,0X49,0X42,
0X49,0X7E,0X49,0X42,0X49,0X7E,0X49,0X42,0X7F,0X42,0X00,0X7E,0X00,0X02,0X00,0X00,//"温",0
0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,
0x0C,0xFE,0xFE,0x0C,0x08,0x20,0x60,0xFE,0xFE,0x60,0x20,0x00,0x00,0x00,0x78,0x48,
0xFE,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xFE,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xFF,0xFF,0x00,0x00,0xFE,0xFF,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xFF,0xFE,0x00,0x00,0x00,0x00,0xC0,0xC0,
0xC0,0x00,0x00,0x00,0x00,0xFE,0xFF,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0xFF,0xFE,0x00,0x00,0xFE,0xFF,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xFF,
0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x0C,
0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0xFF,0xFF,0x00,0x00,0x00,0x00,0xE1,0xE1,
0xE1,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,
0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1F,0x0F,0x00,0x00,0x0F,0x1F,0x18,
0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
0x1F,0x0F,0x00,0x00,0x0F,0x1F,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1F,
0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE2,0x92,0x8A,0x86,0x00,0x00,0x7C,0x82,0x82,0x82,0x7C,
0x00,0xFE,0x00,0x82,0x92,0xAA,0xC6,0x00,0x00,0xC0,0xC0,0x00,0x7C,0x82,0x82,0x82,
0x7C,0x00,0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0xC0,0xC0,0x00,0x7C,0x82,0x82,0x82,
0x7C,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x24,0xA4,0x2E,0x24,0xE4,0x24,0x2E,0xA4,0x24,0x00,0x00,0x00,0xF8,0x4A,0x4C,
0x48,0xF8,0x48,0x4C,0x4A,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,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,0x20,0x10,0x10,
0x10,0x10,0x20,0xC0,0x00,0x00,0xC0,0x20,0x10,0x10,0x10,0x10,0x20,0xC0,0x00,0x00,
0x00,0x12,0x0A,0x07,0x02,0x7F,0x02,0x07,0x0A,0x12,0x00,0x00,0x00,0x0B,0x0A,0x0A,
0x0A,0x7F,0x0A,0x0A,0x0A,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x40,0x40,
0x40,0x50,0x20,0x5F,0x80,0x00,0x1F,0x20,0x40,0x40,0x40,0x50,0x20,0x5F,0x80,0x00,
};
/**********************************************
//IIC Start
**********************************************/
void IIC_Start()
{
   SCL = high;
   //Delay_us(1);               
   SDA = high;
   //Delay_us(1);
   SDA = low;
  // Delay_us(1);
   SCL = low;
  // Delay_us(1);
}
/**********************************************
//IIC Stop
**********************************************/
void IIC_Stop()
{
   SCL = low;
   //Delay_us(1);
   SDA = low;
   //Delay_us(1);
   SCL = high;
   //Delay_us(1);
   SDA = high;
   //Delay_us(1);
}
/**********************************************
// IIC Write byte
**********************************************/
void Write_IIC_Byte(unsigned char IIC_Byte)
{
        unsigned char i;
        for(i=0;i<8;i++)               
        {
                if(IIC_Byte & 0x80)                //1?0?
                SDA=high;
                else
                SDA=low;
                //Delay_us(1);
                SCL=high;
                //Delay_us(1);
                SCL=low;
                //Delay_us(1);
                IIC_Byte<<=1;                        //loop
        }
        SDA=1;
        //Delay_us(1);
        SCL=1;
        //Delay_us(1);
        SCL=0;
        //Delay_us(1);
}
/**********************************************
// IIC Write Command
**********************************************/
void Write_IIC_Command(unsigned char IIC_Command)
{
   IIC_Start();
   Write_IIC_Byte(0x78);            //Slave address,SA0=0
   Write_IIC_Byte(0x00);                        //write command
   Write_IIC_Byte(IIC_Command);
   IIC_Stop();
}
/**********************************************
// IIC Write Data
**********************************************/
void Write_IIC_Data(unsigned char IIC_Data)
{
   IIC_Start();
   Write_IIC_Byte(0x78);                       
   Write_IIC_Byte(0x40);                        //write data
   Write_IIC_Byte(IIC_Data);
   IIC_Stop();
}
/********************************************
// fill_Picture         怎样的对应关系
********************************************/
void fill_picture(unsigned char fill_Data)
{
        unsigned char m,n;
        for(m=0;m<8;m++)
        {
                Write_IIC_Command(0xb0+m);                //page0-page1
                Write_IIC_Command(0x00);                //low column start address
                Write_IIC_Command(0x10);                //high column start address
                for(n=0;n<128;n++)
                        {
                                Write_IIC_Data(fill_Data);
                        }
        }
}
/******************************************
// picture
******************************************/
void picture_1()
{
  unsigned char x,y;
  unsigned int i=0;
  for(y=0;y<8;y++)
    {
      Write_IIC_Command(0xb0+y);
      Write_IIC_Command(0x00);
      Write_IIC_Command(0x10);
      for(x=0;x<128;x++)
        {
          Write_IIC_Data(show1[i++]);//将show[1]中显示完
        }
    }
}
/********************picture**********************/
void picture_2()
{
  unsigned char x,y;
  unsigned int i=0;
  for(Value=0;Value<1000;Value++)
    {
      A1=Value/100;
      A2=(Value-A1*100)/10;
      A3=Value-A1*100-A2*10;
      for(y=0;y<2;y++)
     {
        Write_IIC_Command(0XB0+y); //纵向页
        Write_IIC_Command(0X20);      //横向离左部边缘开始的距离
        Write_IIC_Command(0X10);      //10--17横向第0到第七个字
        for(x=0;x<8;x++)          //横向像素
        {
           Write_IIC_Data(show1[x+y*8+A1*16]);
        }
     }
     for(y=0;y<2;y++)
     {
       Write_IIC_Command(0XB0+y);//纵向页
       Write_IIC_Command(0X20);      //横向离左部边缘开始的距离
       Write_IIC_Command(0X11);  //10--17横向第0到第七个字
       for(x=0;x<8;x++)          //横向像素
        {
          Write_IIC_Data(show1[x+y*8+A2*16]);
        }
     }
    for(y=0;y<2;y++)
     {
       Write_IIC_Command(0XB0+y);//纵向页
       Write_IIC_Command(0X20);      //横向离左部边缘开始的距离
       Write_IIC_Command(0X12);  //10--17横向第0到第七个字
       for(x=0;x<8;x++)          //横向像素
        {
         Write_IIC_Data(show1[x+y*8+A3*16]);
        }
     }
  Delay_50ms(3);
}
}
/***********************Delay****************************************/
void Delay_50ms(unsigned int Del_50ms)                //
{
        unsigned int m;
        for(;Del_50ms>0;Del_50ms--)
                for(m=6245;m>0;m--);
}
void Delay_1ms(unsigned int Del_1ms)                //
{
        unsigned char j;
        while(Del_1ms--)
        {       
                for(j=0;j<123;j++);
        }
}
/*******************************Main*******************************/
void main(void)
{
                        //
        Initial_LY096BG30();
        Delay_1ms(5);
        while(1)
        {
                fill_picture(0xff);        Delay_50ms(25);//满屏点亮
                fill_picture(0xf0);        Delay_50ms(25);//
                Picture_1();                Delay_50ms(25);
        //        Picture_2();                Delay_50ms(25);
        }
}

OLED_ShowCN(3,0,1);
  OLED_ShowCN(21,0,2);
看程序参数,第一个应该可以显示字符数组里的第二个字,第二个应该显示全0xff,或全0x00,或乱码,现在是OLED_ShowCN(3,0,1);这个能不能显示出汉字

还是不行,用该程序框架,我让oled亮一会灭一会可以如下:
/****主函数*****/
void main(void)
{
OLED_Init();
delay(5);
//OLED_CLS();
while(1)
{
  OLED_CLS();
  delay(500);
  OLED_Fill(0xff);
  delay(1000);
}
}
当汉字显示还是不行:如下
/****主函数*****/
void main(void)
{
OLED_Init();
delay(5);
//OLED_CLS();
while(1)
{
OLED_ShowCN(3,0,0);
OLED_ShowCN(21,0,1);
delay(500);
}
}
/*******************************************
//OLED: x,y -- 起始点坐标(x:0~127, y:0~7); N:汉字在codetab.h中的索引        ----OK
********************************************/
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++)
        {
                Write_IIC_Data(F16x16[adder]);
                adder += 1;
        }
        OLED_SetPos(x,y + 1);
        for(wm = 0;wm < 16;wm++)
        {
                Write_IIC_Data(F16x16[adder]);
                adder += 1;
        }
}
/***************************16*16的点阵字体取模方式:共阴——列行式——逆向输出*********/
const unsigned char F16x16[] =                    
{
0x80,0x70,0x00,0xFF,0x20,0x10,0x08,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0x08,0x00,
0x80,0x60,0x18,0x07,0x08,0x30,0x02,0x02,0x02,0xFF,0x02,0x02,0x12,0x22,0x1E,0x00,//"炜",0
0x00,0x20,0x22,0x2C,0x20,0x20,0xE0,0x3F,0x20,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,
0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x00,0x01,0x46,0x80,0x40,0x3F,0x00,0x00,0x00,/*"为",0*/
0x00,0x02,0x02,0x02,0x02,0x02,0x02,0xE2,0x22,0x12,0x0A,0x06,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"了",1*/
0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,/*"生",2*/
0x10,0x60,0x02,0x8C,0x00,0x20,0x24,0x24,0x24,0xFE,0x22,0x23,0x22,0x20,0x20,0x00,
0x04,0x04,0x7E,0x01,0x00,0x00,0xFE,0x42,0x42,0x43,0x42,0x42,0xFE,0x00,0x00,0x00,/*"活",3*/
0x00,0x80,0x60,0xF8,0x07,0x40,0x40,0x40,0x40,0x40,0xFF,0x40,0x40,0x40,0x40,0x00,
0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*"什",4*/
0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0xC0,0x30,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x20,0x70,0x28,0x24,0x22,0x21,0x20,0x20,0x24,0x28,0x30,0x60,0x00,0x00,/*"么",5*/
0x20,0x24,0x24,0xA4,0x7F,0x24,0x34,0x28,0x26,0x20,0xFE,0x02,0x22,0xDA,0x06,0x00,
0x04,0x02,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0xFF,0x08,0x10,0x08,0x07,0x00,/*"都",6*/
//0x80,0x60,0xF8,0x07,0x88,0x88,0xFF,0x88,0x88,0x20,0xD8,0x17,0x10,0xF0,0x10,0x00,
//0x00,0x00,0xFF,0x00,0x3F,0x10,0x10,0x10,0x9F,0x40,0x37,0x08,0x36,0x41,0x80,0x00,/*"做",7*/
};

看看你取的字模和LCD显示的方向是否一致,或是你的描点函数有问题

还是不行,用该程序框架,我让oled亮一会灭一会可以如下:
/****主函数*****/
void main(void)
{
OLED_Init();
delay(5);
//OLED_CLS();
while(1)
{
  OLED_CLS();
  delay(500);
  OLED_Fill(0xff);
  delay(1000);
}
}
当汉字显示还是不行:如下
/****主函数*****/
void main(void)
{
OLED_Init();
delay(5);
//OLED_CLS();
while(1)
{
OLED_ShowCN(3,0,0);
OLED_ShowCN(21,0,1);
delay(500);
}
}
/*******************************************
//OLED: x,y -- 起始点坐标(x:0~127, y:0~7); N:汉字在codetab.h中的索引        ----OK
********************************************/
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++)
        {
                Write_IIC_Data(F16x16[adder]);
                adder += 1;
        }
        OLED_SetPos(x,y + 1);
        for(wm = 0;wm < 16;wm++)
        {
                Write_IIC_Data(F16x16[adder]);
                adder += 1;
        }
}
/***************************16*16的点阵字体取模方式:共阴——列行式——逆向输出*********/
const unsigned char F16x16[] =                    
{
0x80,0x70,0x00,0xFF,0x20,0x10,0x08,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0x08,0x00,
0x80,0x60,0x18,0x07,0x08,0x30,0x02,0x02,0x02,0xFF,0x02,0x02,0x12,0x22,0x1E,0x00,//"炜",0
0x00,0x20,0x22,0x2C,0x20,0x20,0xE0,0x3F,0x20,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,
0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x00,0x01,0x46,0x80,0x40,0x3F,0x00,0x00,0x00,/*"为",0*/
0x00,0x02,0x02,0x02,0x02,0x02,0x02,0xE2,0x22,0x12,0x0A,0x06,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"了",1*/
0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,/*"生",2*/
0x10,0x60,0x02,0x8C,0x00,0x20,0x24,0x24,0x24,0xFE,0x22,0x23,0x22,0x20,0x20,0x00,
0x04,0x04,0x7E,0x01,0x00,0x00,0xFE,0x42,0x42,0x43,0x42,0x42,0xFE,0x00,0x00,0x00,/*"活",3*/
0x00,0x80,0x60,0xF8,0x07,0x40,0x40,0x40,0x40,0x40,0xFF,0x40,0x40,0x40,0x40,0x00,
0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*"什",4*/
0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0xC0,0x30,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x20,0x70,0x28,0x24,0x22,0x21,0x20,0x20,0x24,0x28,0x30,0x60,0x00,0x00,/*"么",5*/
0x20,0x24,0x24,0xA4,0x7F,0x24,0x34,0x28,0x26,0x20,0xFE,0x02,0x22,0xDA,0x06,0x00,
0x04,0x02,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0xFF,0x08,0x10,0x08,0x07,0x00,/*"都",6*/
//0x80,0x60,0xF8,0x07,0x88,0x88,0xFF,0x88,0x88,0x20,0xD8,0x17,0x10,0xF0,0x10,0x00,
//0x00,0x00,0xFF,0x00,0x3F,0x10,0x10,0x10,0x9F,0x40,0x37,0x08,0x36,0x41,0x80,0x00,/*"做",7*/
};

我也是刚学习这个的,,取的字模都是按设定,共阴——列行式——逆向输出,描点函数指的是这个吗
/*******************************************
//OLED: x,y -- 起始点坐标(x:0~127, y:0~7); N:汉字在codetab.h中的索引        ----OK
********************************************/
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++)
        {
                Write_IIC_Data(F16x16[adder]);
                adder += 1;
        }
        OLED_SetPos(x,y + 1);
        for(wm = 0;wm < 16;wm++)
        {
                Write_IIC_Data(F16x16[adder]);
                adder += 1;
        }
}
用的也都是网上能获取的例程拿来用的,图片能显示,汉字就不能显示很困惑

没看到这个代码OLED_SetPos(x , y);,或者直接用 Write_IIC_Command(0xb0+y);来代替,有可能地址设置出错,显示汉字前先清屏,这样除非显示全空,不然总会有点东西显示。另外unsigned int  adder=32*N;,建议改为unsigned int  adder=32*(N-1);,数组起始应该是0。

/*******************************************
//OLED设置起始坐标
********************************************/
void OLED_SetPos(unsigned char x, unsigned char y)
{
        Write_IIC_Command(0xb0+y);
        Write_IIC_Command(((x&0xf0)>>4)|0x10);
        Write_IIC_Command((x&0x0f)|0x01);
}
//unsigned int  adder=32*N;改为unsigned int  adder=32*(N-1);不就是将N 从0开始取,变为从1开始取吗

最好把显示地址固定,直接写死,比如屏幕的最左上角为显示起点,现在查问题,能固定的参数最好都固定了。至于N,只是在于你如何定义而已,如果定义N =0为数组中第一个汉字,那就不需要做N-1,如果定义N=1为数组第一个汉字,那就应该要做N-1了

谢谢你的建议,改了另一个例程,能够成功显示了,问了懂的朋友,说是oled中的函数有问题,相信日后会慢慢把问题找出来

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top