Oled implements animation display - basketball boy

Oled implements animation display - basketball boy

Oled display module, using char definition to clear the interface will cause snowflakes on the screen; if char i, j; is signed, it means from -128 to 127, which will cause some numbers to be swallowed, use int or unsigned char (meaning none symbol)

Equipment: 51 development board and 0.96-inch 4-pin OLED display module.

To put it bluntly, the animation display is to separate the GIF image into a frame-by-frame picture, and displaying a picture is similar to displaying a picture.

Step 1: Extract and separate images. Gifsplitter is recommended.

insert image description here

Step 2: Reduce the image quality, change the picture to bmp format, and adjust the size to 128×64 (you can adjust it in the software or use the Windows drawing application). The details are as follows:

insert image description here

Step 3: Take the modulus of the picture (the most cumbersome step, where is the one-click modulo software, I am eager to tell you) I am using CopyLeft Bu Horse2000 here, and it is recommended to use PCtolCD

insert image description here

insert image description here
insert image description here

After taking the modulus, add the array to it. The specific code is as follows:

#include "reg52.h"
#include "intrins.h"

sbit scl = P0^1;
sbit sda = P0^3;


void IIC_Start()
{
    
    
    scl = 0;
    sda = 1;
    scl = 1;
    _nop_();
    sda = 0;
    _nop_();
}

void IIC_Stop()
{
    
    
    scl = 0;
    sda = 0;
    scl = 1;
    _nop_();
    sda = 1;
    _nop_();
}

char IIC_ACK()
{
    
    
    char flag;
    sda = 1;//就在时钟脉冲9期间释放数据线
    _nop_();
    scl = 1;
    _nop_();
    flag = sda;
    _nop_();
    scl = 0;
    _nop_();

    return flag;
}

void IIC_Send_Byte(char dataSend)
{
    
    
    int i;

    for(i = 0; i<8; i++) {
    
    
        scl = 0;//scl拉低,让sda做好数据准备
        sda = dataSend & 0x80;//1000 0000获得dataSend的最高位,给sda
        _nop_();//发送数据建立时间
        scl = 1;//scl拉高开始发送
        _nop_();//数据发送时间
        scl = 0;//发送完毕拉低
        _nop_();//
        dataSend = dataSend << 1;
    }
}

void Oled_Write_Cmd(char dataCmd)
{
    
    
    //	1. start()
    IIC_Start();
    //
    //	2. 写入从机地址  b0111 1000 0x78
    IIC_Send_Byte(0x78);
    //	3. ACK
    IIC_ACK();
    //	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
    IIC_Send_Byte(0x00);
    //	5. ACK
    IIC_ACK();
    //6. 写入指令/数据
    IIC_Send_Byte(dataCmd);
    //7. ACK
    IIC_ACK();
    //8. STOP
    IIC_Stop();
}

void Oled_Write_Data(char dataData)
{
    
    
    //	1. start()
    IIC_Start();
    //
    //	2. 写入从机地址  b0111 1000 0x78
    IIC_Send_Byte(0x78);
    //	3. ACK
    IIC_ACK();
    //	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
    IIC_Send_Byte(0x40);
    //	5. ACK
    IIC_ACK();
    ///6. 写入指令/数据
    IIC_Send_Byte(dataData);
    //7. ACK
    IIC_ACK();
    //8. STOP
    IIC_Stop();
}


void Oled_Init(void) {
    
    
    Oled_Write_Cmd(0xAE);//--display off
    Oled_Write_Cmd(0x00);//---set low column address
    Oled_Write_Cmd(0x10);//---set high column address
    Oled_Write_Cmd(0x40);//--set start line address
    Oled_Write_Cmd(0xB0);//--set page address
    Oled_Write_Cmd(0x81); // contract control
    Oled_Write_Cmd(0xFF);//--128
    Oled_Write_Cmd(0xA1);//set segment remap
    Oled_Write_Cmd(0xA6);//--normal / reverse
    Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
    Oled_Write_Cmd(0x3F);//--1/32 duty
    Oled_Write_Cmd(0xC8);//Com scan direction
    Oled_Write_Cmd(0xD3);//-set display offset
    Oled_Write_Cmd(0x00);//

    Oled_Write_Cmd(0xD5);//set osc division
    Oled_Write_Cmd(0x80);//
    
    Oled_Write_Cmd(0xD8);//set area color mode off
    Oled_Write_Cmd(0x05);//
    
    Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
    Oled_Write_Cmd(0xF1);//
    
    Oled_Write_Cmd(0xDA);//set com pin configuartion
    Oled_Write_Cmd(0x12);//
    
    Oled_Write_Cmd(0xDB);//set Vcomh
    Oled_Write_Cmd(0x30);//
    
    Oled_Write_Cmd(0x8D);//set charge pump enable
    Oled_Write_Cmd(0x14);//
    
    Oled_Write_Cmd(0xAF);//--turn on oled panel
}

void Oled_Clear(void) {
    
    
    int i,j;
    Oled_Write_Cmd (0x20);                    //set memory addressing mode
    Oled_Write_Cmd (0x02);                    //page addressing mode

    for(i=0; i<8; i++) {
    
    
        Oled_Write_Cmd(0xB0+i);               //ÉèÖÃÒ³µØÖ·£¨0~7£©
        Oled_Write_Cmd(0x00);                 //ÉèÖÃÏÔʾλÖáªÁе͵ØÖ·
        Oled_Write_Cmd(0x10);                 //ÉèÖÃÏÔʾλÖáªÁиߵØÖ·
        for(j=0; j<128; j++) {
    
    
            Oled_Write_Data(0);
        }
    }
}






void Oled_Show_Image(unsigned char *image) {
    
    
    unsigned char i;
    unsigned int j;

    for(i=0; i<8; i++) {
    
    
        Oled_Write_Cmd(0xB0+i); //page0 ——page7
    
        Oled_Write_Cmd(0x00); //每个page从第0列开始
        Oled_Write_Cmd(0x10);
    
        for(j=128*i; j<128*(i+1); j++) {
    
    
            Oled_Write_Data(image[j]);
        }
    }
}
void main()
{
    
    
    //1. OLED初始化
    Oled_Init();
    //2. 选择一个位置
    //2.1 确认页寻址模式
    Oled_Write_Cmd(0x20);
    Oled_Write_Cmd(0x02);
    Oled_Clear();
    //Oled_Show_Image(bmpImager);
    while(1) {
    
    //取模代码太多就不写出来了

        Oled_Show_Image(bmpImager41);
        _nop_();
        Oled_Show_Image(bmpImager42);
        _nop_();
        Oled_Show_Image(bmpImager43);
        _nop_();
        Oled_Show_Image(bmpImager44);
        _nop_();
        Oled_Show_Image(bmpImager45);
        _nop_();
        Oled_Show_Image(bmpImager46);
        _nop_();
    }

}

This code will cause some problems with Oled’s display frame rate. It should be due to too many delay functions, code redundancy or other problems. Welcome to communicate and solve.
Effect demo

study

Guess you like

Origin blog.csdn.net/weixin_54882070/article/details/129717803