拿出板卡,一股正版的气息铺面而来...
创建库函数版工程模板
Stm32F0的标准库不好找,放个链接
然后创建模板,日常操作,截几个关键的图吧
这是必须的一些文件,勿忘,还有
然后我考虑用cubemx试试,但是感觉不太好用,可能是因为注释太多了吧。。。
移植OLED驱动程序
效果如下
主程序如下
部分驱动程序如下
#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的移植,所以有点麻烦
先就这么多吧,告辞