初级会员
- 积分
- 176
- 金钱
- 176
- 注册时间
- 2014-4-14
- 在线时间
- 0 小时
|
5金钱
我就贴上几个初始化的函数把
#define OLED_CS_PORT GPIOC
#define OLED_CS_PIN GPIO_PIN_2
#define Set_OLED_CS GPIO_WriteHigh(OLED_CS_PORT,OLED_CS_PIN)
#define Clr_OLED_CS GPIO_WriteLow(OLED_CS_PORT,OLED_CS_PIN)
#define OLED_RS_PORT GPIOC
#define OLED_RS_PIN GPIO_PIN_3
#define Set_OLED_RS GPIO_WriteHigh(OLED_RS_PORT,OLED_RS_PIN)
#define Clr_OLED_RS GPIO_WriteLow(OLED_RS_PORT,OLED_RS_PIN)
#define OLED_WR_PORT GPIOC
#define OLED_WR_PIN GPIO_PIN_7
#define Set_OLED_WR GPIO_WriteHigh(OLED_WR_PORT,OLED_WR_PIN)
#define Clr_OLED_WR GPIO_WriteLow(OLED_WR_PORT,OLED_WR_PIN)
#define OLED_RD_PORT GPIOC
#define OLED_RD_PIN GPIO_PIN_5
#define Set_OLED_RD GPIO_WriteHigh(OLED_RD_PORT,OLED_RD_PIN)
#define Clr_OLED_RD GPIO_WriteLow(OLED_RD_PORT,OLED_RD_PIN)
#define OLED_REST_PORT GPIOC
#define OLED_REST_PIN GPIO_PIN_6
#define Set_OLED_REST GPIO_WriteHigh(OLED_REST_PORT,OLED_REST_PIN)
#define Clr_OLED_REST GPIO_WriteLow(OLED_REST_PORT,OLED_REST_PIN)
#define OLED_GPIO_DATA_PORT GPIOB
#define DATAOUT(DataValue) GPIO_Write(OLED_GPIO_DATA_PORT,DataValue);
#define OLED_CMD 0 //写命令
#define OLED_DATA 1 // 写数据
void main()
{
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
OLED_IOInit();
OLED_init();
OLED_ShowString(0,0, "0.96' OLED TEST");
OLED_Refresh_Gram();
while(1);
}
IO初始化
void OLED_IOInit()
{
GPIO_DeInit(GPIOB);
GPIO_Init(GPIOB, GPIO_PIN_ALL, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_DeInit(GPIOC);
GPIO_Init(GPIOC, GPIO_PIN_ALL, GPIO_MODE_OUT_PP_HIGH_FAST);
}
OLED写命令\数据
void OLED_WR_Byte(u8 dat,u8 cmd)
{
DATAOUT(dat);
if(cmd==1) {Set_OLED_RS;}
else {Clr_OLED_RS;}
Clr_OLED_CS;
Clr_OLED_WR;
Set_OLED_WR;
Set_OLED_CS;
Set_OLED_RS;
}
OLED初始化
void OLED_init()
{
Clr_OLED_REST;
delay1(50);
Set_OLED_REST;
OLED_WR_Byte(0xAE,OLED_CMD); //关闭显示
OLED_WR_Byte(0xD5,OLED_CMD); //设置时钟分频因子,震荡频率
OLED_WR_Byte(80,OLED_CMD); //【3:0】分频因子【7:4】震荡频率
OLED_WR_Byte(0xA8,OLED_CMD); //设置驱动路数
OLED_WR_Byte(0X3F,OLED_CMD); //默认0X3F(1/64)
OLED_WR_Byte(0xD3,OLED_CMD); //设置显示偏移
OLED_WR_Byte(0X00,OLED_CMD); //默认为0
OLED_WR_Byte(0x40,OLED_CMD); //设置显示开始行[5:0],行数
OLED_WR_Byte(0x8D,OLED_CMD); //电荷泵设置
OLED_WR_Byte(0x14,OLED_CMD); //bit2,开启/关闭
OLED_WR_Byte(0x20,OLED_CMD); //设置内存地址模式
OLED_WR_Byte(0x02,OLED_CMD); //[1:0],00列地址模式;01行地址模式;10,页地址模式;默认0;
OLED_WR_Byte(0xA1,OLED_CMD); //段重定义设置,bit0:0,0->0;1,0->127;
OLED_WR_Byte(0xC0,OLED_CMD); //设置COM扫描方向;bit3:0,?普通模式;1,?重定义模式 COM[N-1]->COM0;N:驱动路数
OLED_WR_Byte(0xDA,OLED_CMD); //设置COM硬件引脚配置
OLED_WR_Byte(0x12,OLED_CMD); //[5:4]配置
OLED_WR_Byte(0x81,OLED_CMD); //对比度设置
OLED_WR_Byte(0xEF,OLED_CMD); //1~255;默认0X7F (亮度设置,越大越亮)
OLED_WR_Byte(0xD9,OLED_CMD); //设置预充电周期
OLED_WR_Byte(0xf1,OLED_CMD); //[3:0],PHASE 1;[7:4],PHASE 2;
OLED_WR_Byte(0xDB,OLED_CMD); //设置VCOMH 电压倍率
OLED_WR_Byte(0x30,OLED_CMD); //[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc;
OLED_WR_Byte(0xA4,OLED_CMD); //全局开启显示;bit0:1,卡其;0,1关闭
OLED_WR_Byte(0xA6,OLED_CMD); //设置显示方式0:1,反向显示;0,正常显示
OLED_WR_Byte(0xAF,OLED_CMD); //开启显示
OLED_Clear();
}
个人分析是端口初始化或写命令\数据的函数不对,可不知道怎么改
|
|