这次要测试的是驱动OLED12864显示屏。OLED12864模块使用的是IIC接口,SDA接RF4引脚,SCL接RF5引脚,电源为3.3V。IIC时序使用软件模拟,采用强制读写模式。
1.iic.h文件
#ifndef __IIC_H
#define __IIC_H
#include
#include "system_config.h"
#define IIC_SCL(status) if(status)
PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_5);
else
PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_5)
#define IIC_SDA_OUT(status) if(status)
PLIB_PORTS_PinSet(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_4);
else
PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_F, PORTS_BIT_POS_4)
#define DELAY_US asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop");
asm("nop");asm("nop");asm("nop"); asm("nop")
void IIC_Init(void);
void IIC_Start(void);
void IIC_Stop(void);
void IIC_Send_Byte(uint8_t data);
void DelayMs(uint32_t msDelay );
void DelayUs(uint32_t usDelay );
2.iic.c文件
#include "iic.h"
void IIC_Start(void)//产生启动时序
{
IIC_SCL(0);
DelayUs(2);
IIC_SDA_OUT(1);
DelayUs(2);
IIC_SCL(1);
DelayUs(2);
IIC_SDA_OUT(0);
DelayUs(2);
IIC_SCL(0);
DelayUs(2);
}
void IIC_Stop(void)//产生停止时序
{
IIC_SCL(0);
DelayUs(2);
IIC_SDA_OUT(0);
DelayUs(2);
IIC_SCL(1);
DelayUs(2);
IIC_SDA_OUT(1);
DelayUs(2);
}
3.oled.c:OLED初始化与驱动程序
void OLED_Write_CMD(uint8_t oled_cmd)//写命令函数
{
IIC_Start();
IIC_Send_Byte(0x78);//模块地址
IIC_SCL(0);
DelayUs(2);
IIC_SCL(1);
DelayUs(2);
IIC_SCL(0);
DelayUs(2);//跳过应答位
IIC_Send_Byte(0x00);//写命令
IIC_SCL(0);
DelayUs(2);
IIC_SCL(1);
DelayUs(2);
IIC_SCL(0);
DelayUs(2);//跳过应答位
IIC_Send_Byte(oled_cmd);//命令值
IIC_Stop();
}
4.app.c:显示“1234”.
#include "app.h"
#include "oled.h"
#include "iic.h"
#include "bsp.h"
APP_DATA appData;
void APP_Initialize ( void )
{
appData.state = APP_STATE_INIT;
}
void APP_Tasks ( void )
{
switch ( appData.state )
{
case APP_STATE_INIT:
{
DelayMs(100);
OLED_Init();
OLED_Clear();
appData.state = APP_STATE_SERVICE_TASKS;
break;
}
case APP_STATE_SERVICE_TASKS:
{
OLED_Show_Char0816((16 + 1), 0,0); //"1"
OLED_Show_Char0816((16 + 2), 0,8); //"2"
OLED_Show_Char0816((16 + 3), 0,16);//"3"
OLED_Show_Char0816((16 + 4), 0,24);//"4"
DelayMs(1000);
break;
}
}
}
5.显示效果
-
显示屏
+关注
关注
28文章
4448浏览量
74113 -
OLED12864
+关注
关注
1文章
6浏览量
9066
发布评论请先 登录
相关推荐
评论