这款开发板上有个OLED显示器,对调试板卡来说非常好用,这里首先把这个显示器驱动起来,显示器为I2C接口,论坛里有人已经成功驱动过了,相信应该不是很难。I2C驱动、OLED驱动,再加字库就OK了。show显示效果,祝大家国庆、中秋双节快乐!
只要之前接触过OLED,相信驱动起来都不是很难,这里不啰嗦了,直接上代码:首先搭建I2C接口配置,可参考例程
stc_i2c_init_t stcI2cInit;
stc_clk_freq_t stcClkFreq;
/* Initialize I2C port*/
PORT_SetFunc(I2C2_SCL_PORT, I2C2_SCL_PIN, Func_I2c2_Scl, Disable);
PORT_SetFunc(I2C2_SDA_PORT, I2C2_SDA_PIN, Func_I2c2_Sda, Disable);
/* Enable I2C Peripheral*/
PWC_Fcg1PeriphClockCmd(PWC_FCG1_PERIPH_I2C2, Enable);
I2C_DeInit(I2C_CH);
/* Get system clock frequency */
CLK_GetClockFreq(&stcClkFreq);
MEM_ZERO_STRUCT(stcI2cInit);
stcI2cInit.enI2cMode = I2cMaster;
stcI2cInit.u32Pclk3 = stcClkFreq.pclk3Freq;
stcI2cInit.u32Baudrate = 400000ul;
stcI2cInit.u32SclTime = 0ul;
I2C_Init(I2C_CH, &stcI2cInit);
I2C_Cmd(I2C_CH, Enable);
写数据 uint32_t u32TimeOut = TIMEOUT;
while(u32Size--)
{
/* Wait tx buffer empty */
u32TimeOut = TIMEOUT;
while(Reset == I2C_GetStatus(I2C_CH, I2C_SR_TEMPTYF))
{
if(0ul == (u32TimeOut--))
{
break;
}
}
/* Send one byte data */
I2C_SendData(I2C_CH, Data);
/* Wait transfer end*/
u32TimeOut = TIMEOUT;
while(Reset == I2C_GetStatus(I2C_CH, I2C_SR_TENDF))
{
if(0ul == (u32TimeOut--))
{
break;
}
}
/* Check ACK */
u32TimeOut = TIMEOUT;
while(Set == I2C_GetStatus(I2C_CH, I2C_SR_NACKDETECTF))
{
if(0ul == (u32TimeOut--))
{
break;
}
}
}
uint32_t u32TimeOut = TIMEOUT;
/* Wait tx buffer empty */
while(Reset == I2C_GetStatus(I2C_CH, I2C_SR_TEMPTYF))
{
if(0ul == (u32TimeOut--))
{
break;
}
}
/* Send I2C address */
I2C_SendData(I2C_CH, u8Adr);
if(!(u8Adr & 0x01u))
{
/* If in master transfer process, Need wait transfer end*/
uint32_t u32TimeOut = TIMEOUT;
while(Reset == I2C_GetStatus(I2C_CH, I2C_SR_TENDF))
{
if(0ul == (u32TimeOut--))
{
break;
}
}
}
/* Check ACK */
u32TimeOut = TIMEOUT;
while(Set == I2C_GetStatus(I2C_CH, I2C_SR_NACKDETECTF))
{
if(0ul == (u32TimeOut--))
{
break;
}
}
uint32_t u32TimeOut = TIMEOUT;
en_flag_status_t enFlagBusy = Reset;
en_flag_status_t enFlagStartf = Reset;
/* generate start or restart signal */
if(!u8Start)
{
/* Wait I2C bus idle */
while(Set == I2C_GetStatus(I2C_CH, I2C_SR_BUSY))
{
if(0ul == (u32TimeOut--))
{
break;
}
}
I2C_GenerateStart(I2C_CH, Enable);
}
else
{
/* Clear start status flag */
I2C_ClearStatus(I2C_CH, I2C_CLR_STARTFCLR);
/* Send restart condition */
I2C_GenerateReStart(I2C_CH , Enable);
}
/* Judge if start success*/
u32TimeOut = TIMEOUT;
while(1)
{
enFlagBusy = I2C_GetStatus(I2C_CH, I2C_SR_BUSY);
enFlagStartf = I2C_GetStatus(I2C_CH, I2C_SR_STARTF);
if(enFlagBusy && enFlagStartf)
{
break;
}
if(0ul == (u32TimeOut--))
{
break;
}
}
代码还不少,直接上传文件,最后调用OLED_Process show 效果!
|