这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» 活动中心» 板卡试用» STM32F0+SPI+0.96 OLED

共7条 1/1 1 跳转至

STM32F0+SPI+0.96 OLED

菜鸟
2018-11-29 18:37:30 打赏

拿出板卡,一股正版的气息铺面而来...

创建库函数版工程模板

Stm32F0的标准库不好找,放个链接

https://www.st.com/content/st_com/zh/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32048.html#getsoftware-scroll

然后创建模板,日常操作,截几个关键的图吧


image.png

这是必须的一些文件,勿忘,还有

image.png


然后我考虑用cubemx试试,但是感觉不太好用,可能是因为注释太多了吧。。。

移植OLED驱动程序

效果如下

1543487197243752.png

主程序如下


image.png


部分驱动程序如下


#include "oled.h" #include "oledfont.h" #include "stm32f0xx.h" #include "delay.h" void OLED_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE); GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;//ÍÆÍìÊä³ö GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_SetBits(GPIOB,GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); } void OLED_Init(void) { OLED_RST_Set(); delay_ms(100); OLED_RST_Clr(); delay_ms(100); OLED_RST_Set(); OLED_WR_Byte(0xAE,OLED_CMD);//Set display off OLED_WR_Byte(0x00,OLED_CMD);//set low column address OLED_WR_Byte(0x10,OLED_CMD);//set high column address OLED_WR_Byte(0x40,OLED_CMD);//set start line address Set Mapping RAM Display Start Line (0x00~0x3F) OLED_WR_Byte(0x81,OLED_CMD);//Set contrast control OLED_WR_Byte(0xCF,OLED_CMD);//Select1-256 OLED_WR_Byte(0xA4,OLED_CMD);//Disable entire display OLED_WR_Byte(0xA6,OLED_CMD);//Set normal display OLED_WR_Byte(0xAF,OLED_CMD);//Set display on OLED_WR_Byte(0x20,OLED_CMD);//Set memory addressing mode OLED_WR_Byte(0x02,OLED_CMD);//Set page addressing mode OLED_WR_Byte(0xA1,OLED_CMD);//Disable segment re-map OLED_WR_Byte(0xA8,OLED_CMD);//Set multiplex ratio OLED_WR_Byte(0x3F,OLED_CMD);//1/64 duty OLED_WR_Byte(0xC8,OLED_CMD);//Set normal mode scan OLED_WR_Byte(0xD3,OLED_CMD);//Set display offset OLED_WR_Byte(0x00,OLED_CMD);//No offset OLED_WR_Byte(0xDA,OLED_CMD);//Set COM pins hardware configuration OLED_WR_Byte(0x12,OLED_CMD);//Alternative COM pin configuration OLED_WR_Byte(0xD5,OLED_CMD);//Set display clock clock divide OLED_WR_Byte(0x80,OLED_CMD);//100 frames/s OLED_WR_Byte(0xD9,OLED_CMD);//Set pre-charge period OLED_WR_Byte(0xF1,OLED_CMD);//Set pre-charge as 15 clocks,discharge as 1 clock OLED_WR_Byte(0xDB,OLED_CMD);//Set Vcomh deselect level OLED_WR_Byte(0x40,OLED_CMD);//~0.77xVcc OLED_WR_Byte(0x8D,OLED_CMD);//Set DCDC OLED_WR_Byte(0x14,OLED_CMD);//Enable DCDC (0x10 disable) OLED_Clear(0); OLED_Set_Address(0,0); } /................中间省略................./ void OLED_WR_Byte(uint8_t DATA,uint8_t CMD) { uint8_t i; OLED_CS_Clr(); if(CMD) {OLED_DC_Set();} else OLED_DC_Clr(); for(i=0;i<8;i++) { OLED_SCLK_Clr(); if(DATA&0x80) {OLED_SDIN_Set();} else OLED_SDIN_Clr(); OLED_SCLK_Set(); DATA<<=1; } OLED_CS_Set(); OLED_DC_Set(); } void OLED_Set_Address(uint8_t column,uint8_t page) { OLED_WR_Byte(OLED_PAGE_Address+page,OLED_CMD); OLED_WR_Byte(OLED_LINE_Address_L+column%16,OLED_CMD); OLED_WR_Byte(OLED_LINE_Address_H+column/16,OLED_CMD); } void OLED_ShowString(u8 x,u8 y,u8 *chr) { unsigned char j=0; while (chr[j]!='\0') { OLED_ShowChar(x,y,chr[j]); x+=8; if(x>120){x=0;y+=2;} j++; } }

驱动代码网盘链接

https://pan.baidu.com/s/1adV97nYilo4b7PikCFnqBA


现在就做了这么多,因为F0的板子大家很少用,程序都得从F1的移植,所以有点麻烦

先就这么多吧,告辞










关键词: STM32F0 OLED

管理员
2018-11-30 14:55:14 打赏
2楼

楼主棒棒哒


助工
2018-12-01 08:37:49 打赏
3楼

加油加油


高工
2018-12-06 14:34:09 打赏
4楼

很棒~期待楼主的新帖~


院士
2018-12-15 21:19:07 打赏
5楼

显示的效果挺不错的,点赞。


专家
2022-01-21 10:47:21 打赏
6楼

谢谢分享


高工
2022-01-21 10:50:58 打赏
7楼

感谢分享,学习学习


共7条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]