显示出错,6X8显示没问题 8X16只能显示下面半部分 求助, 显示程序应该没问题??
void OLED_SPI_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
//---------------
#define OLED_SCL_L GPIO_ResetBits(GPIOA,GPIO_Pin_7)
#define OLED_SCL_H GPIO_SetBits(GPIOA,GPIO_Pin_7)
#define OLED_SDA_L GPIO_ResetBits(GPIOA,GPIO_Pin_6)
#define OLED_SDA_H GPIO_SetBits(GPIOA,GPIO_Pin_6)
#define OLED_RST_L GPIO_ResetBits(GPIOA,GPIO_Pin_5)
#define OLED_RST_H GPIO_SetBits(GPIOA,GPIO_Pin_5)
#define OLED_DC_L GPIO_ResetBits(GPIOA,GPIO_Pin_4)
#define OLED_DC_H GPIO_SetBits(GPIOA,GPIO_Pin_4)
#define XLevelL 0x00
#define XLevelH 0x10
#define XLevel ((XLevelH&0x0F)*16+XLevelL)
#define Max_Column 128
#define Max_Row 64
#define Brightness 0xCF
#define X_WIDTH 128
#define Y_WIDTH 64
void OLED_WrDat(uint8_t data)
{
uint8_t i=8;
//LCD_CS=0;;
OLED_DC_H;
OLED_SCL_L;
//asm("nop");
while(i--)
{
if(data&0x80){OLED_SDA_H;}
else{OLED_SDA_L;}
OLED_SCL_H;
//asm("nop");;
//asm("nop");
OLED_SCL_L;
data<<=1;
}
//LCD_CS=1;
}
void OLED_WrCmd(uint8_t cmd)
{
uint8_t i=8;
//LCD_CS=0;;
OLED_DC_L;
OLED_SCL_L;
//asm("nop");
while(i--)
{
if(cmd&0x80){OLED_SDA_H;}
else{OLED_SDA_L;}
OLED_SCL_H;
//asm("nop");
//asm("nop");
OLED_SCL_L;
cmd<<=1;;
}
}
void OLED_Set_Pos(uint8_t x, uint8_t y)
{
OLED_WrCmd(0xb0+(y>>3));
OLED_WrCmd(((x&0xf0)>>4)|0x10);
OLED_WrCmd((x&0x0f)|0x01);
}
void OLED_Fill(uint8_t bmp_data)
{
uint8_t y,x;
for(y=0;y<8;y++)
{
OLED_WrCmd(0xb0+y);
OLED_WrCmd(0x01);
OLED_WrCmd(0x10);
for(x=0;x<X_WIDTH;x++)
OLED_WrDat(bmp_data);
}
}
void OLED_CLS(void)
{
uint8_t y,x;
for(y=0;y<8;y++)
{
OLED_WrCmd(0xb0+y);
OLED_WrCmd(0x01);
OLED_WrCmd(0x10);
for(x=0;x<X_WIDTH;x++)
OLED_WrDat(0);
}
}
void OLED_DLY_ms(uint16_t ms)
{
uint16_t a;
while(ms)
{
a=1335; //1335
while(a--);
ms--;
}
return;
}
void OLED_Init(void)
{
OLED_SPI_Init();
OLED_SCL_H;
//LCD_CS=1;
OLED_RST_L;
OLED_DLY_ms(50);
OLED_RST_H;
OLED_WrCmd(0xae);
OLED_WrCmd(0x00);
OLED_WrCmd(0x10);
OLED_WrCmd(0x40);
OLED_WrCmd(0x81);
OLED_WrCmd(0xcf);
OLED_WrCmd(0xa1);
OLED_WrCmd(0xc8);
OLED_WrCmd(0xa6);
OLED_WrCmd(0xa8);
OLED_WrCmd(0x3f);
OLED_WrCmd(0xd3);
OLED_WrCmd(0x00);//-not offset
OLED_WrCmd(0xd5);
OLED_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
OLED_WrCmd(0xd9);
OLED_WrCmd(0xf1);
OLED_WrCmd(0xda);
OLED_WrCmd(0x12);
OLED_WrCmd(0xdb);//--set vcomh
OLED_WrCmd(0x40);//Set VCOM Deselect Level
OLED_WrCmd(0x20);
OLED_WrCmd(0x02);//
OLED_WrCmd(0x8d);
OLED_WrCmd(0x14);
OLED_WrCmd(0xa4);
OLED_WrCmd(0xa6);
OLED_WrCmd(0xaf);
OLED_Fill(0x00);
}
/*==============================================================
void OLED_PutPixel(u8 x,u8 y)
定点
==============================================================*/
void OLED_PutPixel(uint8_t x,uint8_t y)
{
uint8_t data1;
// OLED_Set_Pos(x,y);
data1 = 0x01<<(y%8);
OLED_WrCmd(0xb0+(y>>3));
OLED_WrCmd(((x&0xf0)>>4)|0x10);
OLED_WrCmd((x&0x0f)|0x00);
OLED_WrDat(data1);
}
/*========================================
void OLED_P6x8Char(char x,char y,char ch);
6X8字符
========================================*/
void OLED_P6x8Char(uint8_t x,uint8_t y,char ch)
{
char c=0,i=0;
c =ch-32;
if(x>122)
{
x=0;
y++;
}
OLED_Set_Pos(x,y);
for(i=0;i<6;i++)
{
OLED_WrDat(F6x8[c]);
}
}
//6X8字符串
void OLED_P6x8Str(uint8_t x,uint8_t y,uint8_t ch[])
{
uint8_t c=0,i=0,j=0;
while (ch[j]!=' ')
{
c =ch[j]-32;
if(x>126){x=0;y++;}
OLED_Set_Pos(x,y);
for(i=0;i<6;i++)
OLED_WrDat(F6x8[c]);
x+=6;
j++;
}
}
/*===========================================
void OLED_P8x16Char(u8 x,u8 y,char ch);
8X16字符
===============================================*/
void OLED_P8x16Char(uint8_t x,uint8_t y,char ch)
{
char c=0,i=0;
c =ch-32;
if(x>120)
{
x=0;
y++;
}
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
{
OLED_WrDat(F8X16[(c<<4)+i]);
}
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
{
OLED_WrDat(F8X16[(c<<4)+i+8]);
}
}
//8X16字符串
void OLED_P8x16Str(uint8_t x,uint8_t y,uint8_t ch[])
{
uint8_t c=0,i=0,j=0;
while (ch[j]!=' ')
{
c =ch[j]-32;
if(x>120){x=0;y++;}
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WrDat(F8X16[c*16+i]);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WrDat(F8X16[c*16+i+8]);
x+=8;
j++;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
另外你的显示机制我不是很了解,你的void OLED_P8x16Char(uint8_t x,uint8_t y,char ch)中
OLED_Set_Pos(x,y+1); 另一半显示的起点是不是有问题,为什么y+1呢?而不是y+8
一周热门 更多>