中科昊芯Start_DSC28034PNT 使用OLED显示图片
上次测验使用DELAY_US();函数有问题,所以这次测试OLED12864选择使用自己编写的延时函数,成功点亮OLED屏幕。
本次测试主要目的是将下边图片,通过OLED显示出来。
显示结果:
代码如下:
main.c文件:
#include "dsc_config.h"
#include <syscalls.h>
#include "IQmathLib.h"
#include "IIC_OLED.h"
unsigned char fox[8][128]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,0x7F,0xBF,0xBF,0xBF,0xBF,0xDF,0x9F,
0x9F,0x1F,0x0F,0x2F,0x0F,0x07,0x63,0x63,0x69,0xF1,0xF1,0x31,0x1D,0x1C,0x11,0x19,
0x19,0x1D,0x91,0xB1,0xC3,0xE3,0xE7,0xC7,0xC7,0xF7,0xEF,0xEF,0xEF,0x6F,0x6F,0x6F,
0x6F,0x6F,0x5F,0x5F,0x5F,0x5F,0xDF,0x8F,0x97,0x87,0x27,0x33,0x33,0x3B,0x23,0x33,
0x33,0x73,0xE3,0x27,0x27,0x0F,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF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0xC6,0xD6,0xD5,0xD5,0xC5,0xD9,0xD3,
0xC3,0xCB,0xE7,0xCF,0xDF,0xDF,0xDF,0xDF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};
int main(void)
{
InitSysCtrl();
DINT;
InitPieCtrl();
IER=0x0000;
IFR=0x0000;
InitPieVectTable();
OLED_Init();
while(1){
OLED_ShowBMP(0,0,8,128,fox);
}
return 0;
}
IIC_OLED.h文件:
#ifndef __IIC_OLED_H
#define __IIC_OLED_H
#include "dsc_config.h"
#define OLED_SIZE_13 1
#define OLED_SIZE_096 0
extern void delay_Xus(Uint16 X);
void IICA_Init(void);
void IIC_Start(void);
void IIC_Stop(void);
void IIC_Send_Byte(unsigned char txd);
unsigned char IIC_Read_Byte(unsigned char ack);
unsigned char IIC_Wait_Ack(void);
void IIC_Ack(void);
void IIC_NAck(void);
extern void OLED_WriteCommand(unsigned char Command);
extern void OLED_WriteData(unsigned char Data);
extern void OLED_Init(void);
extern void OLED_Clear(void);
extern void OLED_ShowBMP(Uint16 Line0, Uint16 Column0, Uint16 Line1, Uint16 Column1, unsigned char BMP[]);
#endif
IIC_OLED.c文件:
#include "IIC_OLED.h"
#define IIC_SCL_SETH (GpioDataRegs.GPBSET.bit.GPIO33=1)
#define IIC_SCL_SETL (GpioDataRegs.GPBCLEAR.bit.GPIO33=1)
#define IIC_SDA_SETH (GpioDataRegs.GPBSET.bit.GPIO32=1)
#define IIC_SDA_SETL (GpioDataRegs.GPBCLEAR.bit.GPIO32=1)
#define READ_SDA (GpioDataRegs.GPBDAT.bit.GPIO32)
void delay_Xus(Uint16 X)
{
static Uint16 i=0;
while(X--)
{
for(i=0;i<1;i++){}
}
}
void OLED_WriteCommand(unsigned char Command)
{
IIC_Start();
IIC_Send_Byte(0x78);
IIC_NAck();
IIC_Send_Byte(0x00);
IIC_NAck();
IIC_Send_Byte(Command);
IIC_NAck();
IIC_Stop();
}
void OLED_WriteData(unsigned char Data)
{
IIC_Start();
IIC_Send_Byte(0x78);
IIC_NAck();
IIC_Send_Byte(0x40);
IIC_NAck();
IIC_Send_Byte(Data);
IIC_NAck();
IIC_Stop();
}
void OLED_SetCursor(unsigned char Y, unsigned char X)
{
if(OLED_SIZE_13==1)
{
OLED_WriteCommand(0xB0 | Y);
OLED_WriteCommand(0x10 | (((X+2) & 0xF0) >> 4));
OLED_WriteCommand(0x00 | ((X+2) & 0x0F));
}
if(OLED_SIZE_096==1)
{
OLED_WriteCommand(0xB0 | Y);
OLED_WriteCommand(0x10 | ((X & 0xF0) >> 4));
OLED_WriteCommand(0x00 | (X & 0x0F));
}
}
void OLED_Clear(void)
{
unsigned char i, j;
for (j = 0; j < 8; j++)
{
OLED_SetCursor(j, 0);
for(i = 0; i < 128; i++)
{
OLED_WriteData(0x00);
}
}
}
void OLED_ShowBMP(Uint16 Line0, Uint16 Column0, Uint16 Line1, Uint16 Column1, unsigned char BMP[])
{
Uint16 j=0;
Uint16 Column,Line;
for(Line=Line0;Line<Line1;Line++)
{
OLED_SetCursor(Line,Column0);
for(Column=Column0;Column<Column1;Column++)
{
OLED_WriteData(BMP[j++]);
}
}
}
void OLED_Init(void)
{
IICA_Init();
unsigned int i, j;
for (i = 0; i < 1000; i++)
{
for (j = 0; j < 1000; j++);
}
OLED_WriteCommand(0xAE);
OLED_WriteCommand(0x20);
OLED_WriteCommand(0x02);
OLED_WriteCommand(0x00);
OLED_WriteCommand(0x40);
OLED_WriteCommand(0xB0);
OLED_WriteCommand(0xD5);
OLED_WriteCommand(0x80);
OLED_WriteCommand(0xA8);
OLED_WriteCommand(0x3F);
OLED_WriteCommand(0xD3);
OLED_WriteCommand(0x00);
OLED_WriteCommand(0xA1);
OLED_WriteCommand(0xC8);
OLED_WriteCommand(0xDA);
OLED_WriteCommand(0x12);
OLED_WriteCommand(0x81);
OLED_WriteCommand(0xCF);
OLED_WriteCommand(0xD9);
OLED_WriteCommand(0xF1);
OLED_WriteCommand(0xDB);
OLED_WriteCommand(0x30);
OLED_WriteCommand(0xA4);
OLED_WriteCommand(0xA6);
OLED_WriteCommand(0x8D);
OLED_WriteCommand(0x14);
OLED_WriteCommand(0xAF);
OLED_Clear();
}
void IICA_Init(void)
{
EALLOW;
SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;
GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO32 = 1;
GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 0;
GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 2;
GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO33 = 1;
GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 0;
GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 2;
EDIS;
}
void SDA_OUT(void)
{
EALLOW;
GpioCtrlRegs.GPBDIR.bit.GPIO32=1;
EDIS;
}
void SDA_IN(void)
{
EALLOW;
GpioCtrlRegs.GPBDIR.bit.GPIO32=0;
EDIS;
}
void IIC_Start(void)
{
SDA_OUT();
IIC_SDA_SETH;
IIC_SCL_SETH;
delay_Xus(5);
IIC_SDA_SETL;
delay_Xus(6);
IIC_SCL_SETL;
}
void IIC_Stop(void)
{
SDA_OUT();
IIC_SCL_SETL;
IIC_SDA_SETL;
IIC_SCL_SETH;
delay_Xus(6);
IIC_SDA_SETH;
delay_Xus(6);
}
unsigned char IIC_Wait_Ack(void)
{
unsigned char tempTime=0;
IIC_SDA_SETH;
delay_Xus(1);
SDA_IN();
IIC_SCL_SETH;
delay_Xus(1);
while(READ_SDA)
{
tempTime++;
if(tempTime>250)
{
IIC_Stop();
return 1;
}
}
IIC_SCL_SETL;
return 0;
}
void IIC_Ack(void)
{
IIC_SCL_SETL;
SDA_OUT();
IIC_SDA_SETL;
delay_Xus(2);
IIC_SCL_SETH;
delay_Xus(5);
IIC_SCL_SETL;
}
void IIC_NAck(void)
{
IIC_SCL_SETL;
SDA_OUT();
IIC_SDA_SETH;
delay_Xus(2);
IIC_SCL_SETH;
delay_Xus(5);
IIC_SCL_SETL;
}
void IIC_Send_Byte(unsigned char txd)
{
unsigned char t;
SDA_OUT();
IIC_SCL_SETL;
for(t=0;t<8;t++)
{
if((txd&0x80)>0)
IIC_SDA_SETH;
else
IIC_SDA_SETL;
txd<<=1;
delay_Xus(2);
IIC_SCL_SETH;
delay_Xus(2);
IIC_SCL_SETL;
delay_Xus(2);
}
}
unsigned char IIC_Read_Byte(unsigned char ack)
{
unsigned char i,receive=0;
SDA_IN();
for(i=0;i<8;i++ )
{
IIC_SCL_SETL;
delay_Xus(2);
IIC_SCL_SETH;
receive<<=1;
if(READ_SDA)receive++;
delay_Xus(1);
}
if (!ack)
IIC_NAck();
else
IIC_Ack();
return receive;
}
显示其他图片,只用更新数组内容就可以。