我按照手册写好初始化,SPI写数据和一系列命令函数和写数据函数,但最后OLED的显示只有全亮和全灭能够显示,若是要显示符号就会不全,或是说让16*8的区域显示全亮也会缺。换了标准源码就能正常显示,一开始我以为是字库问题,换来换去都不行,,
这是主函数,我随便写点的
void main()
{
oled_init();
oled_clear();
// oled_put_char_8x16(1,0,'B');
// oled_put_char_8x16(2,0,'B');
while(1)
{
Delay(500);
oled_clear();
Delay(500);
oled_full();
Delay(500);
oled_clear();
Delay(500);
oled_put_char_8x16(1,0,'A');
Delay(500);
oled_put_char_8x16(2,0,'B');
Delay(500);
oled_put_char_8x16(3,0,'C');
Delay(500);
oled_put_char_8x16(4,0,'D');
}
}
这是OLED的命令部分
#include "OLED.h"
#include "character.h"
extern const unsigned char code CHARACTERS_8X16[][16];
void oled_reset()
{
OLED_RESET=0;
Delay(50);
OLED_RESET=1;
}
void oled_send_command(unsigned char Command)
{
u8 i=0;
SPI_CS=0;
OLED_DC=0;
spi_read_write(Command);
SPI_CS=1;
OLED_DC=1;
}
void oled_send_Data(unsigned char Data)
{
SPI_CS=0;
OLED_DC=1;
spi_read_write(Data);
SPI_CS=1;
oled_DC=1;
}
void oled_set_position(unsigned char x, unsigned char y)
{
oled_send_command(0xb0 + y); //起始页地址
oled_send_command((x & 0x0f) | 0x00); //起始列地址的低四位
oled_send_command(((x & 0xf0) >> 4) | 0x10);//起始列地址的高四位
}
void oled_init(void)
{
oled_send_command(0xAF);//关闭显示
oled_send_command(0x00);//起始列设置地址低四位(00h~0Fh)
oled_send_command(0x10);//起始列设置地址高四位(10h~1Fh)
oled_send_command(0x40);//起始行设置,设置RAM的起始行(40h~74h)
oled_send_command(0x20); // 设置内存寻址模式
oled_send_command(0x00); // 页面寻址模式:水平地址模式
// oled_send_command(0x01); // 垂直地址模式
// oled_send_command(0x10); // 页地址模式
oled_send_command(0xA8);
oled_send_command(0x3F);
oled_send_command(0xD3);
oled_send_command(0x00);
oled_send_command(0xA1);
oled_send_command(0xC8);
oled_send_command(0xDA);
oled_send_command(0x02);
oled_send_command(0x81);
oled_send_command(0x7F);
oled_send_command(0xA4);
oled_send_command(0xA6);
oled_send_command(0xD5);
oled_send_command(0x80);
oled_send_command(0xD9);
oled_send_command(0xF1); // 将预充电设置为15个时钟并将其放电设置为1个时钟
oled_send_command(0x8D);//使能电荷泵稳压器(8DH)
oled_send_command(0x14);//模式14H
oled_send_command(0xAF);//打开屏幕
oled_set_position(0,0);//起始位置0页0列
}
void oled_clear(void)
{
/水平地址模式/
oled_send_command(0x21);//起始列与终止列地址编写
oled_send_command(0x00);
oled_send_command(0x7F);
oled_send_command(0x22);//起始页与终止页地址编写
oled_send_command(0x00);
oled_send_command(0x07);
for(y=0;y<(OLED_HEIGHT >> 3);y++)
{
for(x=0;x<OLED_WIDTH;x++)
{
oled_send_Data(0x00);
}
}
/*****END*****/
}
void oled_full(void)
{
unsigned char y, x;
/水平地址模式/
oled_send_command(0x21);//起始列与终止列地址编写
oled_send_command(0x00);
oled_send_command(0x7F);
oled_send_command(0x22);
oled_send_command(0x00);
oled_send_command(0x07);
for(y=0;y<(OLED_HEIGHT >> 3);y++)
{
for(x=0;x<OLED_WIDTH;x++)
{
oled_send_Data(0xFF);
}
}
}
void oled_put_char_8x16(u8 x, u8 y, char character)//宽度8(8列);高度16(2页)的模块输入
{
u8 i;
// set column
oled_send_command(0x21);//起始列和终止列的地址编写
oled_send_command(x * 0x08);
oled_send_command(0x07 + x * 0x08);
// set page
oled_send_command(0x22);//起始页和终止页的地址编写
oled_send_command(y * 2);
oled_send_command(0x01+ y * 2);
for(i=0; i<16; i++)
}
基本就这样的了,逻辑上没有问题我感觉,难道说是要延时读取数据这种操作吗,之前写IIC的时候好像有这种操作,但这太细节我还不会看