国庆假期即将结束,回顾这些天的休息调整,今天拿出来STM32G4 NUCLEO G431RB板子,结合之前工程资料,点点OLED屏。之前发了提问贴,谢谢各位网友的鼎力相助,Keil在线下载提示内部命令错误是Keil版本的原因导致,所以重新安装了5.28的版本,并安装了板极间支持包,底层标准接口动态库,然后很顺利的就实现了在线下载、调试。本来原计划9月份下旬点亮手中的OLED屏的,但是手头的OLED模块不知道什么原因,一接通G4NUCLEO31RB的VCC,模块的屏与FPC连接的地方烫手,然后拿到其他开发板上验证,确定是OLED模块已经短路破损,然后在淘宝上淘了一块OLED模块,今天拿出来来调试调试这个模块。3 k* t$ a6 Y9 \# d' `& J" @7 ~' x
模块是采用IIC的接口,所以结合基于STM2G431RB的原理图,将SCL连接上GPIOB8,SDA连接上GPIOB91 v$ y) g& |9 H2 p
( G1 s. l- ]5 i8 l% M 部分代码如下:
& X G/ m1 f2 u+ X- ?9 p
5 d) r: B8 s8 n" `6 m1 ~3 x7 e- void IIC_Start()" L# g7 r+ C1 Z3 @0 R% y |( D" G& E8 M
- {+ s' u0 ]1 ]2 N% ~
- 3 ]; Y$ s/ S' c9 G! L
- OLED_SCLK_Set() ;# G0 Q5 z% L i
- OLED_SDIN_Set();* n: { ^- s: p8 Q) w$ K9 {
- OLED_SDIN_Clr();. `7 S) \! H3 y# G& _1 `7 T
- OLED_SCLK_Clr();3 K X/ d& L8 N5 Z
- }
% Q5 R: k; ~8 `; n; n3 U - void IIC_Stop()
4 ^, y* Q+ V/ ?* z" m! [ - {4 a# w- U; |9 d( N2 P
- OLED_SCLK_Set() ;
) h- C3 i; l1 `- `! p$ x; I3 h - OLED_SDIN_Clr();; ^4 \4 ]) v# ]
- OLED_SDIN_Set();5 G4 X' p, l" P1 S
- }9 b8 a3 }& F' ?+ e, |) P
- void IIC_Wait_Ack()
. p& p, P' c' e0 a - {
2 l$ v& W3 L/ E. n/ O N5 L5 F - OLED_SCLK_Set() ;2 W) U* P% `# @+ c
- OLED_SCLK_Clr();; Z2 I1 s8 L2 ?) n7 U
- }; N7 e6 A# S/ A$ u- ?1 Z+ g, ]% F
- void Write_IIC_Byte(unsigned char IIC_Byte), c' C& I. y" G" [5 X( G" P
- {0 z$ a& T4 s2 Y& E
- unsigned char i;* t4 x$ p$ J8 U
- unsigned char m,da;
2 q9 n( B! `) h - da=IIC_Byte;: j9 e6 D& o2 I. F
- OLED_SCLK_Clr();
5 `+ _/ C. w% t - for(i=0;i<8;i++) : g5 ]7 l) x$ j3 s1 c/ x( W$ Z
- {
! s1 T6 U0 |$ C* s - m=da;
5 }8 d# Z3 ]) E4 B - m=m&0x80;, j* |. [$ r; s3 L# [
- if(m==0x80)$ {* t9 R! G1 s+ U) V5 Y
- {OLED_SDIN_Set();}0 P* V! Q) c# ^/ n6 b6 J! M, M4 }
- else OLED_SDIN_Clr();
8 h$ s; I8 ]' H0 ^5 ?6 \2 x9 F - da=da<<1;
C: f6 u( R- O+ B8 \, g, j - OLED_SCLK_Set();" w% \; k, M9 {3 z# V
- OLED_SCLK_Clr(); k' a' Z; K1 Q W- V
- }$ a0 H6 h& G3 [. \( H% E
- }
- E+ w5 [' K0 _( O& ^( i - void Write_IIC_Command(unsigned char IIC_Command)) y9 r! y0 n3 n% U. J# {
- {
( U$ \$ J1 ~# z" q - IIC_Start();
6 S; P# j8 ^* ~' {4 i* k - Write_IIC_Byte(0x78);
/ C4 {/ o: r; ?: y& j - IIC_Wait_Ack(); 7 N& Y5 X% X: P% d. \7 _, C K
- Write_IIC_Byte(0x00);
3 [7 P' ]( |% p9 l2 e - IIC_Wait_Ack(); & \* K9 p, b" D7 T4 [0 J/ O: e
- Write_IIC_Byte(IIC_Command); ' T8 V" L+ N Y, c { V
- IIC_Wait_Ack(); . u' z/ x) P: p4 U! T
- IIC_Stop();+ i1 U& ?: C B+ @8 l/ I* t
- }
5 p1 ], d) a- D# m) N! ] x - void Write_IIC_Data(unsigned char IIC_Data)( `: h& r9 |' T8 C0 ?1 m
- {5 a1 |4 f+ w* ?7 v% E! f d" I
- IIC_Start();1 C3 `/ l& y7 f& I8 J3 u' m
- Write_IIC_Byte(0x78);
; X; v- s. f/ n - IIC_Wait_Ack();
" K! X4 l4 i4 P E - Write_IIC_Byte(0x40);
8 H" W6 S$ y+ w - IIC_Wait_Ack(); , y% W8 E) i8 m; C0 L6 E
- Write_IIC_Byte(IIC_Data);7 h. R& k! P) j" e8 M- y$ I: a& w
- IIC_Wait_Ack(); . k& x. {8 L/ ~- x9 k
- IIC_Stop();
' _9 K2 {. ^9 L: G7 ]* N8 f$ D5 {1 y - }* |& U0 R3 D! w6 l* s0 q: @
- void OLED_WR_Byte(unsigned dat,unsigned cmd)
1 ~, e2 v4 A- @1 _ - {
; P9 _ _; m$ x9 Z - if(cmd)
# `% o" i# I& B! W - {' Q! `, V" I3 c! J$ f
- Write_IIC_Data(dat);# e% y7 V7 I& {, m8 z0 O
- }
: @- W, F- x9 [8 e5 p( T - else5 y9 S1 l) ~* l, K; k) z% L8 \# ?* w
- {0 r; C; T6 Y" O8 X
- Write_IIC_Command(dat);
# n0 F, G# f4 g/ y4 D - }
# R- L8 y9 E5 C1 I - }
' N% W' K6 Z, M2 }/ q) | - void OLED_Display_On(void). N* w) y A" M( K, C% h
- {' E( f% b- [0 b. O' t0 N! j
- OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC5 T7 {* _8 t3 s, h# ]8 O
- OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON8 p3 U2 F& j X; k; O" g" R$ L
- OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON1 \ \* G% c6 A* C
- } 3 }* K5 E& S) v w3 {1 j0 T0 K
- void OLED_Display_Off(void)
* U. J5 O' ?5 Y8 n% }3 y8 @ - {9 ?0 J8 V0 }% M
- OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC. s% W1 {, G7 i; Q) k
- OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF
* z7 Z+ [" h2 j/ s) K - OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF
( m+ G3 u5 Z* @4 i+ M - }
复制代码- void OLED_Clear(void) " y. W Q G6 H. H/ ]/ u& ]5 B1 A6 b# Z
- {
1 c0 p) j O( ]! }, K' L - u8 i,n;
$ M% B- `' {/ `' h7 T' b - for(i=0;i<8;i++) 2 n7 v5 Z1 F& r
- {
+ w3 [6 d9 s* y# a+ _: a8 z4 L! x - OLED_WR_Byte (0xb0+i,OLED_CMD);
& D. ~0 Q$ \% v5 W - OLED_WR_Byte (0x00,OLED_CMD);6 C( O. A6 N) w( B i
- OLED_WR_Byte (0x10,OLED_CMD); for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA); : M+ m% m, S m4 s! d" @8 n: _
- } * K7 x- k. l3 T; \% _ e
- }
: s) V6 i- \& m2 Q9 p - void OLED_On(void)
$ ?9 v+ L8 P* \. y' n - { 1 o. y1 I2 |8 Y6 U, z& n0 u& j
- u8 i,n;
1 j/ v* W3 z: L4 S& Q2 U - for(i=0;i<8;i++) ! X- F0 S7 j: X. T5 f# e- D
- {
: ^) v) T, V: s! y" z" T - OLED_WR_Byte (0xb0+i,OLED_CMD);
I" f5 K- \/ }* ]! _ - OLED_WR_Byte (0x00,OLED_CMD);
& I0 E0 W8 D1 R) N7 G6 d% L5 q - OLED_WR_Byte (0x10,OLED_CMD); for(n=0;n<128;n++)OLED_WR_Byte(1,OLED_DATA); ' O* N0 u: U7 }6 P; b
- }
9 ^! T7 ~* b+ f# G1 D B - }
2 ~! f: n' |( M$ Z- x - void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size)7 T" d# S! b# ]! F0 F: j$ w7 t& P
- { 4 n" w4 q1 s+ [3 ^) s* M7 ?2 ^1 U- a
- unsigned char c=0,i=0;
% v7 x1 o" ]( }* P/ W& h - c=chr-' ';
1 P T5 h' G9 ~; U; t - if(x>Max_Column-1){x=0;y=y+2;}
8 [2 x) C+ o. W - if(Char_Size ==16)+ v1 K4 C% T- Y# i4 y4 M
- {5 R; k9 o5 Q! c2 y* O
- OLED_Set_Pos(x,y);
* v% s' B+ _9 D" ~ - for(i=0;i<8;i++)
. {0 e" b4 E Y# D% y - OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);) E# {" |4 p; v$ y# W, _
- OLED_Set_Pos(x,y+1);! a# R7 w% M' x* i& d# r0 D
- for(i=0;i<8;i++)) w& ^. K6 ]' ^# {7 ^ Q/ ]( I) l
- OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);) ~5 }4 M6 U9 k0 ~$ J
- }
6 C+ k) V# c( Q9 v - else { / J! K* `8 X# ]
- OLED_Set_Pos(x,y);, V* X* Y( N, M6 X0 E/ ?3 [( w" E
- for(i=0;i<6;i++)
8 q J* b/ n/ N0 u5 B- a) a - OLED_WR_Byte(F6x8[c][i],OLED_DATA); u3 G2 Q" E( x% t+ V+ X) z
- }: _1 C1 j7 n5 E' }: J8 o
- }
! _$ z6 f! ~/ Q f1 |$ O - void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2)" k1 o5 ~! x, q8 |6 D3 c3 G5 o% m
- {
& O# ~ g2 a0 S! e7 i, B2 Q1 | - u8 t,temp;
2 n& ]) Z( e& q - u8 enshow=0;
4 ]% t5 D1 G( p: x4 S5 v. J' w" a" F - for(t=0;t<len;t++)( {5 k! z/ S G7 [+ H
- {
) [+ r) t6 s* p" ^! [ - temp=(num/oled_pow(10,len-t-1))%10;3 ^1 A% R% \- s& t6 n
- if(enshow==0&&t<(len-1))
. d: `2 \$ u7 e7 U0 O3 X/ \( O - {
2 y. J6 @$ F8 p2 T) I3 m T$ u - if(temp==0)
2 p, F& h r+ v3 v% M4 \4 D - {, i K& v$ l; x5 D3 W# D9 ?: R
- OLED_ShowChar(x+(size2/2)*t,y,' ',size2);9 ?7 ?9 i2 o0 @/ ?5 R* q, L
- continue;
( N e1 H& s$ H7 j$ Y! J( Q - }else enshow=1;
* t) j H1 v! y/ C -
8 o9 j& u6 E; D) K& l$ [3 O - }0 C1 W$ K1 ]7 U- J5 y' e# V
- OLED_ShowChar(x+(size2/2)*t,y,temp+'0',size2);
2 N, U9 j* x; Z" W - } ~1 X# f: w: l8 ~! v0 P& s( M; B
- } 5 y3 s" X3 M5 G q3 k* n
- void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size)
5 D; I( j* g F - {
) \& }2 a3 V+ D - unsigned char j=0;8 h7 N* @3 c% b& p% B0 g: |
- while (chr[j]!='\0')
8 P" Q1 R1 H0 V, g - { OLED_ShowChar(x,y,chr[j],Char_Size);. p- x9 @: [9 c9 X
- x+=8;9 I; z) \- D( Z
- if(x>120){x=0;y+=2;}, p2 b- N% T8 x( i+ ?
- j++;
. Y7 p7 E1 u. n9 S5 @' q% _! ~ - }
4 [, r( f3 I8 P5 g( t) p - }
% o& s, t* b9 I/ i
! k6 F7 K9 h7 J) R. A8 V- void OLED_ShowCHinese(u8 x,u8 y,u8 no)+ D; D; {0 G; h+ ]: q, i
- { % D. h9 G6 _, V* J0 i0 s& r
- u8 t,adder=0;" ^7 @+ j3 z0 ~, _* n4 ?) K4 [
- OLED_Set_Pos(x,y);
7 }- g0 v7 q: V/ D5 {! o/ h, v, s - for(t=0;t<16;t++)
" c' l7 J2 S" f3 ] |" e8 X - {
. ^% |0 ~& o5 q3 ?1 F - OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
d- d' m+ v6 P" l9 c - adder+=1;' D4 q; Y; `" T
- } : s, O$ U ]0 h8 w/ o
- OLED_Set_Pos(x,y+1);
+ y8 n3 J2 U# B1 R* n) L: K - for(t=0;t<16;t++)+ Y5 B# T0 N+ o h) G! R+ |- H
- { 0 h& Y( H# S, h7 b' M
- OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);6 ?, H, g3 H8 `* h/ t4 ~
- adder+=1;
" o ]3 E h7 c9 M0 f0 n* f* W - } " [4 n) u0 l" G, R; G
- }7 w' N& l q/ H3 v9 a) j
) q$ t+ K( ]2 t7 `- void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
1 h& J7 I5 ^! j# M7 V/ L- T" c0 E - {
- { }' K) e9 S, s - unsigned int j=0;
; Z5 U" n) k# A7 I( k/ Z* d. X, z - unsigned char x,y;, F# l, r& ?9 b2 f+ T& l
- ; q! ^0 G, {" r3 u' `0 Z
- if(y1%8==0) y=y1/8;
) j) z4 P4 \& C* {3 E! H) h - else y=y1/8+1;7 ^& I/ K; ^) e" i5 F) e/ H
- for(y=y0;y<y1;y++) t) q+ c% B0 B" ]9 p) Q& ^
- {
4 v. t8 j& G, |& J! \- s. }0 {5 Y - OLED_Set_Pos(x0,y);
% r" r# w6 }: D! T; |( @ - for(x=x0;x<x1;x++)
8 M6 q1 a9 g. z Y - { ) O% Q' s' j% ?5 D
- OLED_WR_Byte(BMP[j++],OLED_DATA);
* ] c% i' h4 h# \2 ]) Q& ?0 {! e - }) [) j9 \8 o6 H' ?
- }: f- i+ ~& u7 P2 J
- } " \9 k6 s# U% r# B
7 D) A7 R2 o7 V) N" r- void OLED_Init(void)
) [& S: h0 Q. O; _+ Z1 _2 _ - {
' E( F7 X. n$ c w6 Y - GPIO_InitTypeDef GPIO_InitStructure;
1 d+ g* _) L$ @) {; P2 v - - V0 s. F+ _3 I& T
- OLED_GPIO_CLK_ENABLE();
! ?; A$ ~; o& O, R: t P0 o - GPIO_InitStructure.Pin = GPIO_PIN_8|GPIO_PIN_9; 4 H- M% g, {9 p& w
- GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
* D1 U, g$ K( d. I- D7 y - GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
. Q3 u4 Z% R- Y9 m' r K* R - HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); 8 E8 T$ X2 F9 W% C! I' Y
- HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8|GPIO_PIN_9,GPIO_PIN_SET);- R1 r5 B1 x3 j& Z4 e" @
- HAL_Delay(200);
. ?1 l8 E( s- H5 a - OLED_WR_Byte(0xAE,OLED_CMD);
0 X7 r1 w5 s m3 \& {* _- s - //display off& L4 ^. R6 d' |' m( \7 i
- OLED_WR_Byte(0x00,OLED_CMD);//---set low column address+ \4 r; V. h/ _4 d
- OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
; \2 y1 r' E- Q. R2 k2 L - OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
$ `! U g) t2 V9 q+ s% |- J) y - OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
+ Q4 N& U/ ], i. z: V6 U: z - OLED_WR_Byte(0x81,OLED_CMD); // contract control2 E4 j r! B% Z6 w/ \
- OLED_WR_Byte(0xFF,OLED_CMD);//--128 " f% F) \1 B- p7 L5 A1 K/ r
- OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
3 M8 @% u, p, P, c+ { - OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
1 [) d) c- d( D v$ ?1 b7 e9 l5 b$ v - OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
1 `7 E2 {3 R! a: z; f - OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
. h1 d8 m* j( W - OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
: S3 s! L. H) e' j8 k - OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
2 K8 c |; S9 H# A4 r - OLED_WR_Byte(0x00,OLED_CMD);//6 ?* J, G7 b1 A$ v5 t0 G
- - ~- [/ j T( E
- OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
* Z5 Y4 L+ [8 o! B `1 f - OLED_WR_Byte(0x80,OLED_CMD);//
9 S$ @. r7 L @0 l& H$ n -
8 i" d( v2 L5 Q4 T1 w* D - OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off/ v# Q' r: C4 b; {# [4 `! N" s9 i
- OLED_WR_Byte(0x05,OLED_CMD);//
7 f4 P& j! w, h \8 r -
3 K5 l& B, B, X5 C _4 d7 j9 r* [% Q - OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period2 ^! I9 N) l3 |
- OLED_WR_Byte(0xF1,OLED_CMD);//+ x, ^, o# C2 u' ^; p
- % \ C q9 z# d$ a7 i) G# K6 g
- OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion' m5 l& x8 ?& ?9 j- L9 q
- OLED_WR_Byte(0x12,OLED_CMD);//7 l4 u% X0 q2 O
-
9 A H7 G5 {0 f8 K( y* G8 \ - OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh6 q' V1 F& {$ @8 C6 S4 b" ^, J2 u
- OLED_WR_Byte(0x30,OLED_CMD);//
& m8 o" H* g. c8 @7 K -
: k1 R2 V2 M# [: P8 m! l - OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable7 m# G) w( k* z
- OLED_WR_Byte(0x14,OLED_CMD);//
+ A2 v, C$ k* t - # W2 r! P2 D @# k" P" N
- OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
9 }* H8 I4 i, {+ b8 R$ W - }
复制代码- #ifndef __OLED_H3 }0 v& g Z; F; N$ k
- #define __OLED_H
, F* i+ a7 R. z# a8 v - #include "stdlib.h"
: s, s. f& U$ M6 K4 W - #include "stm32g4xx_nucleo.h"
) d0 M" p: E4 {+ Z1 s$ M - #define OLED_MODE 0
; w& o `0 U) W6 A$ m$ e - #define SIZE 8
1 E! P4 z: V$ t7 N5 h - #define XLevelL 0x00
, ?" i7 x3 q9 h! G& ^! M% H' u - #define XLevelH 0x104 w; s- ?% d' \3 i9 W1 }) h' B
- #define Max_Column 128
# [, @2 |( A6 B4 o/ L - #define Max_Row 64
: I' B8 j9 r, v, G4 q( e: c4 _# j - #define Brightness 0xFF
h& M3 }7 e6 a* i: ?4 m - #define X_WIDTH 128+ v6 w5 Q0 S# y& R5 p$ N
- #define Y_WIDTH 64
% n2 l- T5 J" @6 A0 A, Z' o0 J8 N - #define OLED_SCLK_Clr() HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET)//CLK, o" ?7 j& Y9 m, M0 I, j4 U, L
- #define OLED_SCLK_Set() HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET)- Z+ k( h7 X2 V4 p I7 Z2 Q' `
, l( e7 V9 _: S! E2 |( m, o- #define OLED_SDIN_Clr() HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET)//DIN
/ h9 \) d" z* g8 [9 y - #define OLED_SDIN_Set() HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET)) v$ c6 ^+ X5 P. s# s. z( D
7 V( W* O' _3 A# G# K- #define OLED_RST_Clr() GPIO_ResetBits(GPIOB,GPIO_PIN_11)//RES
$ g/ L4 Z: _% i9 a) d - #define OLED_RST_Set() GPIO_SetBits(GPIOB,GPIO_PIN_11) k0 i% J- f8 `/ Z0 e
-
- j+ C# c3 u! L1 k - #define OLED_CMD 08 I' H; J6 y3 i
- #define OLED_DATA 12 c" s* Q3 [) s% S
- #define OLED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
: v2 ]( m& i, M3 M6 W - #define OLED_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
; ]5 V, x6 `6 Y- z, U
2 X& H, S3 Y& U: o' [& M- void OLED_WR_Byte(unsigned dat,unsigned cmd); $ ?# h3 u/ H" B1 k7 S
- void OLED_Display_On(void);8 k$ ^& i, D/ K& ^$ |; Z G: N
- void OLED_Display_Off(void); f" ~3 Y6 e& Z! W$ a0 B3 `+ P
- void OLED_Init(void);' R$ k" _8 j- ]
- void OLED_Clear(void);/ c4 U2 ?$ z% ~- i4 O" _- [
- void OLED_DrawPoint(u8 x,u8 y,u8 t);
, X/ O# q8 o! Q7 V/ X: o2 h3 @ - void OLED_Fill(u8 x1,u8 y1,u8 x2,u8 y2,u8 dot);0 |0 w- a/ _6 w) c
- void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size);
1 ?& l. b/ D$ w0 Z - void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size); $ a, t- {% S+ _& l+ `: s( _
- void OLED_ShowString(u8 x,u8 y, u8 *p,u8 Char_Size);
% d5 m3 }4 q) u. h* N - void OLED_Set_Pos(unsigned char x, unsigned char y);) e) |& m5 B ?; ]; E2 @
- void OLED_ShowCHinese(u8 x,u8 y,u8 no);
h& l+ P4 ?+ i5 Q - void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]);( Q8 @ u; z, v9 a6 a! E
- void Delay_50ms(unsigned int Del_50ms);
' O8 p( z5 c$ R2 A. s - void Delay_1ms(unsigned int Del_1ms);
4 q& s2 O" s: w# Q! t+ S$ q - void fill_picture(unsigned char fill_Data);
/ ?& W$ M; q! B# k. i! Q - void Picture(void);
. w% R8 K% k3 T8 h T0 J - void IIC_Start(void);( _" q# M7 R$ V' Q }# j8 P: l# T
- void IIC_Stop(void);( B( q" O2 Z* U7 Y- }
- void Write_IIC_Command(unsigned char IIC_Command);6 k/ Z( g3 {' E. K+ n2 b* ]- C8 H
- void Write_IIC_Data(unsigned char IIC_Data);
* M7 C+ L V t- [8 t! C - void Write_IIC_Byte(unsigned char IIC_Byte);
, m, U% ?/ s, E. v$ W5 n - void Display_Battery_Level(void);2 ~5 G8 U, ?$ T: U6 X3 r* t+ L5 k
- void IIC_Wait_Ack(void);
z0 M( @2 h' J - #endif
复制代码- int main(void)1 P* d" N, n j
- {! E3 G5 ~: Z+ U3 {: n. b% m
- HAL_Init();
; x8 O+ h' I' k d - 9 D1 |# d0 a1 x% p/ L2 [
- OLED_Init();
6 b8 ?7 M: Q, U# T - OLED_Clear();
% k$ i7 X- u" `' J, a - SystemClock_Config();+ x5 v& c# L: h$ w/ z5 B. B
- {9 F7 `- g5 q$ D+ T% E; g- BSP_LED_Init(LED2);
" D% p& J, H5 t; w! U! X5 j - EXTI15_10_IRQHandler_Config();
4 b. H8 \9 q2 C; b - 9 w! J! V! d" R
- while(1) # | _, Z7 P7 S3 K' r
- {
' d/ a$ K9 R7 ? - OLED_ShowString(0,0,(unsigned char *)"STM32",16);
2 d/ I" {) y( p+ L! Z0 l( } - OLED_ShowCHinese(45,0,2);//- {8 J% ]$ T0 Q; ?4 Y) x; X
- OLED_ShowCHinese(63,0,3);//
3 c& d" v" b5 a _ - OLED_ShowCHinese(81,0,4);//
* Q. c/ J; S7 N$ K- k - OLED_ShowCHinese(99,0,5);//% X3 V# C) T+ j0 d8 F5 W* G
- OLED_ShowString(10,3,(unsigned char *)"stmcu.org.cn",16);
$ i0 E" H9 }; W% O' n7 P! G - OLED_ShowString(8,6,(unsigned char *)"STM32G431RBT6",16);. {3 z$ |: G P0 H$ C1 a k
- } , B; f2 `6 Q0 K+ {
- }8 P* w# a% X* V2 R, U
复制代码 编译、下载、测试,结果成功点亮OLED显示,效果如下图所示,本次分享就到这里,感谢社区平台,感谢各位网友的帮忙与支持。
+ c. ~4 }4 D) i& U* g
) ?6 v+ s9 }3 P/ ~4 X( D
) N2 R1 K: ] m1 D' C+ P
|