[N32WB031_STB开发板测评]+OLED屏显示驱动
<div class='showpostmsg'> 本帖最后由 jinglixixi 于 2023-5-6 09:30 编辑<p>N32WB031开发板是一款近于最小系统型的开发板,为它配置一个小巧的显示屏可以更好地与其体型相匹配。这里所驱动的是一款I2C接口的准双色OLED显示屏,其特点是占用引脚资源少,显示信息量也相等比较多,其显示分辨率为64*128像素点,其显示效果如下图所示。</p>
<p></p>
<p>OLED屏与开发板的连接关系为:</p>
<p>SCL---PB4</p>
<p>SDA---PB5</p>
<p>以GPIO口输出高低电平的语句定义为:</p>
<p>#define SCL_high GPIO_SetBits(GPIOB, GPIO_PIN_4)</p>
<p>#define SCL_low GPIO_ResetBits(GPIOB, GPIO_PIN_4)</p>
<p>#define SDA_high GPIO_SetBits(GPIOB, GPIO_PIN_5)</p>
<p>#define SDA_low GPIO_ResetBits(GPIOB, GPIO_PIN_5)</p>
<p>使用GPIO口模拟I2C方式启动和停止信号的函数为:</p>
<pre>
<code class="language-cpp">void IIC_Start()
{
SCL_high;
SDA_high;
SDA_low;
SCL_low;
}
void IIC_Stop()
{
SCL_low;
SDA_low;
SCL_high;
SDA_high;
}
</code></pre>
<p> 实现应答等待的函数是:</p>
<pre>
<code class="language-cpp">void IIC_Wait_Ack()
{
SCL_high;
SCL_low;
}
</code></pre>
<p>模拟I2C方式发送字节数据的函数内容是:</p>
<pre>
<code class="language-cpp">void Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
unsigned char m,da;
da=IIC_Byte;
SCL_low;
for(i=0;i<8;i++)
{
m=da;
m=m&0x80;
if(m==0x80)
{
SDA_high;
}
elseSDA_low;
da=da<<1;
SCL_high;
SCL_low;
}
}
</code></pre>
<p>实现指令和数据发送函数是:</p>
<pre>
<code class="language-cpp">void Write_IIC_Command(unsigned char IIC_Command)
{
IIC_Start();
Write_IIC_Byte(0x78);
IIC_Wait_Ack();
Write_IIC_Byte(0x00);
IIC_Wait_Ack();
Write_IIC_Byte(IIC_Command);
IIC_Wait_Ack();
IIC_Stop();
}
void Write_IIC_Data(unsigned char IIC_Data)
{
IIC_Start();
Write_IIC_Byte(0x78);
IIC_Wait_Ack();
Write_IIC_Byte(0x40);
IIC_Wait_Ack();
Write_IIC_Byte(IIC_Data);
IIC_Wait_Ack();
IIC_Stop();
}
void OLED_WR_Byte(unsigned dat,unsigned cmd)
{
if(cmd)
{
Write_IIC_Data(dat);
}
else
{
Write_IIC_Command(dat);
}
}
</code></pre>
<p>实现图示效果的主程序为:</p>
<pre>
<code class="language-cpp">int main(void)
{
OLED_gpio();
OLED_Init();
OLED_Clear();
OLED_ShowString(20,0,"N32WB031",16);
OLED_ShowString(20,4,"jinglixixi",16);
while(1);
}
</code></pre>
<p>这样就完成了OLED屏的显示驱动,后面再有显示的任务就可以交它来完成了。</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> 这显示屏挺好的,有没有试验一下硬件I2C呀。 lugl4313820 发表于 2023-5-6 17:54
这显示屏挺好的,有没有试验一下硬件I2C呀。
<p>尚且没有!</p>
页:
[1]