打印

【新手求助】OLED显示问题:每行只能显示一个汉字

[复制链接]
4241|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
goonfly|  楼主 | 2011-1-13 13:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近买了块OLED的屏幕,结果调试的时候总是每行只能写一个汉字,写两个或者更多的话就花屏。
调试了两天了,总是不行,也找不到原因。
程序是参考 买屏幕时店家附送的例程。单片机是C8051F310。OLED的驱动芯片是SH1101A ,C86端已经接到VCC上的了。谢谢大家!!!

以下是程序:

#include <c8051f310.h>                       // SFR declarations
#include <intrins.h>

#define DAT P2
#define uchar unsigned char
#define uint unsigned int
#define NOP() _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()  

sbit W_R=P1^6;
sbit DC=P1^5;
sbit CS=P1^7;
sbit RES=P3^1;
sbit R_D=P3^2;

unsigned char code num0[16]={0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00};
unsigned char code hz0[32]={0x00,0x00,0x00,0x00,0x1F,0xFF,0x80,0x00,0x60,0x00,0x07,0xC0,0x44,0x40,0x44,0x40,0x44,0x40,0x44,0x40,0x47,0xC0,0x40,0x02,0x40,0x01,0x7F,0xFE,0x00,0x00,0x00,0x00};
unsigned char code xing[32]={0x01,0x00,0x02,0x00,0x0C,0x00,0x3F,0xFE,0xE0,0x00,0x50,0x00,0x15,0x7E,0x15,0x44,0x95,0x44,0x75,0x44,0x55,0x44,0x15,0x44,0x15,0x7E,0x10,0x00,0x10,0x00,0x00,0x00};   
unsigned char code xi[32]={0x00,0x00,0x00,0x04,0x00,0x1C,0x3F,0x80,0x2A,0xBC,0x2A,0x82,0x6A,0x82,0xAA,0xA2,0x2A,0x9A,0x2A,0x82,0x2A,0x82,0x3F,0x8E,0x00,0x00,0x00,0x10,0x00,0x0C,0x00,0x00};
unsigned char code zhong[32]={0x00,0x00,0x00,0x00,0x3F,0xE0,0x10,0x40,0x10,0x40,0x10,0x40,0x10,0x40,0xFF,0xFF,0x10,0x40,0x10,0x40,0x10,0x40,0x10,0x40,0x3F,0xE0,0x10,0x00,0x00,0x00,0x00,0x00};
unsigned char code xin[32]={0x00,0x20,0x01,0xC0,0x00,0x00,0x00,0x00,0x0F,0xFC,0x00,0x02,0x80,0x02,0x40,0x02,0x38,0x02,0x10,0x02,0x00,0x02,0x02,0x1E,0x01,0x00,0x00,0xE0,0x00,0x40,0x00,0x00};
unsigned char code bu[32]={0x40,0x00,0x57,0xAF,0x55,0x6A,0x55,0x2A,0xF5,0x2A,0x55,0x6A,0x57,0xAF,0x00,0x00,0x40,0x00,0x57,0xAF,0x55,0x6A,0xF5,0x2A,0x55,0x2A,0x55,0x6A,0x47,0xAF,0x00,0x00};


void delay1ms();
void delay1us();
void delaynms(int n);

//------------------------------------------------------------------//
void WriteCommand(uchar com);
void WriteData(uchar dat);
void ini_oled(void);
void esbusini(void);

void protinit(void)
{
//  P0SKIP=0xFF;
//  P1SKIP=0x1F;
XBR0=0x00;
XBR1=0x40;
P0MDOUT=0xFF;
P1MDOUT=0xFF;
P2MDOUT=0xFF;
P3MDOUT=0xFF;
}
//----------------------------------------------------------------
void delay1ms()
{
uchar i,j;
for(i=0;i<10;i++)
for(j=0;j<33;j++)
;   
}
void delaynms(int n)
{
int i;
for(i=0;i<n;i++)
delay1ms();
}

void delay1us()
{
uchar i;
for(i=0;i<5;i++);
}

/*-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------*/
void WriteCommand(uchar com)
{
CS=1;
DC=0;
W_R=0;
R_D=1;
CS=0;
delaynms(1);
DAT=com;
delaynms(1);
W_R=1;
CS=1;
}
void WriteData(uchar dat)
{
CS=1;
DC=1;
W_R=0;
R_D=1;
CS=0;
  delaynms(1);
DAT=dat;
  delaynms(1);
W_R=1;
CS=1;
}
void esbusini(void)
{
unsigned char i=100;
while(--i)_nop_();//延时5uS以上
RES=1;
RES=0;
while(--i)_nop_();//延时5uS以上
RES=1;
}
void ini_dis(void)
{
uchar i,j;
for(i=0;i<8;i++)
{
WriteCommand (0xb0+i);    //设置显示位置—行
WriteCommand (0x02);      //设置显示位置—列低地址
WriteCommand (0x10);      //设置显示位置—列高地址
for(j=0;j<128;j++)
WriteData(0x00);        //屏幕显示,全亮
}
}
void ini_oled(void)
{
esbusini();
// Lower Column Address
WriteCommand(0x00); /* Set Lower Column Address */
// High Column Address
WriteCommand(0x10); /* Set Higher Column Address*/
// Display Start Line
WriteCommand(0x40); /* Set Display Start Line */
// Contrast Control Register
WriteCommand(0x81); /* Set Contrast Control */
WriteCommand(0x2f); /* 0 ~ 255 0x1f*/
// Re-map
WriteCommand(0xA1); /* [A0]:column address 0 is map  
to SEG0 , [A1]: columnaddress 131 is map to SEG0*/  
// Entire Display ON/OFF
WriteCommand(0xA4); /* A4=ON */
// Normal or Inverse Display
WriteCommand(0XA6); /* Normal Display*/
// Multiplex Ratio
WriteCommand(0xA8); /* Set Multiplex Ratio */
WriteCommand(0x3f); /* Set to 36 Mux*/
// Set DC-DC
WriteCommand(0xAD); /* Set DC-DC */
WriteCommand(0x8A); /* 8B=ON, 8A=Off */
// Display ON/OFF
WriteCommand(0xAE); /* AF=ON , AE=OFF*/
// Display Offset
WriteCommand(0xD3); /* Set Display Offset */
WriteCommand(0x00); /* No offset */
// Display Clock Divide
WriteCommand(0xD5); /* Set Clock Divide */
WriteCommand(0x20); /* Set to 80Hz */
// Area Color Mode
WriteCommand(0xD8); /* Set Area Color On or Off*/
WriteCommand(0x00); /* Mono Mode */
// COM Pins Hardware Configuration
WriteCommand(0xDA); /* Set Pins HardwareConfiguration */
WriteCommand(0x12);
// VCOMH
WriteCommand(0xDB); /* Set VCOMH */
WriteCommand(0x00);
// VP
WriteCommand(0xD9); /* Set VP */
WriteCommand(0x22); /* P1=2 , P2=2 */
WriteCommand(0xc0);//配置成标准应用
ini_dis();
}
void displayoff(void)
{
    WriteCommand(0xAD); // Set DC-DC  
WriteCommand(0x8A); // 8B=ON, 8A=Off  
   WriteCommand(0xAE);  
}
void displayon(void)
{
WriteCommand(0xAD); // Set DC-DC  
WriteCommand(0x8B); // 8B=ON, 8A=Off  
   WriteCommand(0xAF);  
}

void dish(uchar x,uchar y,uchar *c)
{
uchar i;

WriteCommand (0xb7-(y<<1));    //设置显示位置—行
if(x%2)
WriteCommand (0x0a);
else
WriteCommand (0x02);
WriteCommand (0x10+(x>>1));
for(i=0;i<=31;i=i+2)
{
WriteData(*(c+i));
}
delaynms(200);  
WriteCommand (0xb7-(y<<1)-1);    //设置显示位置—行
if(x%2)
WriteCommand (0x0a);
else
WriteCommand (0x02);
WriteCommand (0x10+(x>>1));
for(i=1;i<=31;i=i+2)
{
WriteData(*(c+i));
}
delaynms(200);  


}


//----------------------------------------------------------------
void main (void)
{
int i;
PCA0MD &= ~0x40;                          
OSCICN |= 0x03;                           
protinit();
delaynms(150);
ini_oled();
delaynms(150);
displayon();

dish(1,0,xing);  
dish(1,1,xi);  
dish(1,2,zhong);
dish(1,3,xin);

while(1)
{
}
}

相关帖子

沙发
goonfly|  楼主 | 2011-1-13 13:59 | 只看该作者
我测试了下端口电压,正常显示时SH1101A的VDD1和VDD2是2.4V,VPP是6V。
闪烁时 VDD1和VDD2是1.4V,VPP是3.6V。

买的人家电路开发板,结果人家的是3.3V和6.33V。

悲剧啊,找不到原因。。。
1# goonfly

使用特权

评论回复
板凳
goonfly|  楼主 | 2011-1-13 21:51 | 只看该作者
问题解决,感谢大家!
问题解决了,原因是板子给OLED供电不足,分给OLED的电流不够,单独给OLED上电后,问题就解决了。

使用特权

评论回复
地板
vilinx| | 2011-2-8 10:50 | 只看该作者
能否留下你的联系方式,我也想玩OLED,我的QQ:467013407

使用特权

评论回复
5
china_fog| | 2011-2-9 21:24 | 只看该作者
OLED的屏有没有相关链接,买几块来玩玩

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

5

帖子

0

粉丝