国庆假期即将结束,回顾这些天的休息调整,今天拿出来STM32G4 NUCLEO G431RB板子,结合之前工程资料,点点OLED屏。之前发了提问贴,谢谢各位网友的鼎力相助,Keil在线下载提示内部命令错误是Keil版本的原因导致,所以重新安装了5.28的版本,并安装了板极间支持包,底层标准接口动态库,然后很顺利的就实现了在线下载、调试。本来原计划9月份下旬点亮手中的OLED屏的,但是手头的OLED模块不知道什么原因,一接通G4NUCLEO31RB的VCC,模块的屏与FPC连接的地方烫手,然后拿到其他开发板上验证,确定是OLED模块已经短路破损,然后在淘宝上淘了一块OLED模块,今天拿出来来调试调试这个模块。
& ~1 s4 k4 h3 o$ m9 {5 L0 } v 模块是采用IIC的接口,所以结合基于STM2G431RB的原理图,将SCL连接上GPIOB8,SDA连接上GPIOB9! Y, Z! W% ~6 S. a( j5 G% Z& m8 E g$ K
7 ?( [0 n3 X/ S. ^/ K" V 部分代码如下:
( b& |! ]9 i, s6 b
: L7 t% G) }9 p, P+ p- void IIC_Start()
" X { J4 L, Z; [8 B% m% _/ F2 } - {, s6 |/ s/ ]8 o: H6 k
) x) e, w$ ~6 q- OLED_SCLK_Set() ;
+ j4 ]0 H8 f# s" H - OLED_SDIN_Set();. P# b, w4 S+ }& e
- OLED_SDIN_Clr();
: y% ?& h0 R. ] - OLED_SCLK_Clr();6 ~9 R1 k/ H5 R& L7 O0 ?. o6 `
- }
7 @9 {! p6 u# D - void IIC_Stop()
; R& J1 |" o' w' m - {
8 B5 E* r& m9 w8 V5 i* s - OLED_SCLK_Set() ;
. r9 x3 a" i1 \$ d5 p - OLED_SDIN_Clr();( N4 k$ I! t' A$ G1 p
- OLED_SDIN_Set();7 Q3 A% }' \% @" K
- }
& d" i# |# Z( }. E - void IIC_Wait_Ack()
, k7 c* j2 F- Z2 J$ q8 `4 }: V$ | - {
' {7 Z! v/ f' }* h" r9 \% I* v; N( ] - OLED_SCLK_Set() ;
% p3 K. O2 L4 L% t8 E - OLED_SCLK_Clr();+ K4 R- B* x. Y1 {
- }
9 e+ D* V5 x2 }# i; \0 L - void Write_IIC_Byte(unsigned char IIC_Byte)5 J/ r8 u1 V7 f& W# J& Q. V
- {7 W+ x0 }, F5 c4 k1 r9 ]
- unsigned char i;
: P5 c# @: r+ x ~0 C; _ - unsigned char m,da;
( ^1 n& F1 Z: O) [5 I& p) _ - da=IIC_Byte;% j; E! S' N: @0 l+ W
- OLED_SCLK_Clr();2 L+ F0 J. Y6 b }6 S
- for(i=0;i<8;i++) ' u( W8 @/ O' _$ S0 t8 ^
- {
; M' p1 e% \/ H - m=da;
: V( x5 c* j7 ]5 J6 S - m=m&0x80;' I& B; ?7 K; v# r0 ^
- if(m==0x80)
K+ t6 ]! H/ X7 B - {OLED_SDIN_Set();}$ D$ G) d1 O4 h) h
- else OLED_SDIN_Clr();6 `1 p" Z2 K7 `# ^# X d. [
- da=da<<1;' M! B' W5 V3 g6 O5 ^5 `; q
- OLED_SCLK_Set();/ u0 @# B3 _. I' D4 b
- OLED_SCLK_Clr();# T2 E1 t1 h) M; }
- }
2 ?" k+ m* X4 T( T: B; ~* d! h( J - }
# b q5 p4 A5 v! D5 P; Z9 X& k; r - void Write_IIC_Command(unsigned char IIC_Command)* A6 u9 `5 a* W4 X& U1 c" V" c
- {
% e* Q I. z" S7 s - IIC_Start();
& `4 \& q, D8 o" I3 ~* t0 M3 g2 o - Write_IIC_Byte(0x78);
2 W. g& K L) Y# D* A- m6 z - IIC_Wait_Ack();
* a8 s# k- v! @& P8 ^3 l - Write_IIC_Byte(0x00); " N5 m+ t9 N, Y. L8 V4 R/ \, w4 ^
- IIC_Wait_Ack();
: d |* K3 m7 E5 ` - Write_IIC_Byte(IIC_Command); ( U. z3 }- t# u# R# i: K
- IIC_Wait_Ack(); 8 G( N& r6 C0 W% i
- IIC_Stop();
1 i j, \: k! X1 J7 z) ]5 p1 m - }
% c, U3 ?/ Q) @ - void Write_IIC_Data(unsigned char IIC_Data)
% K& n+ N6 p% B9 C* o" L3 D8 b - {* M/ Q/ b' x( H& Q' }8 }) |( }
- IIC_Start();
6 ?$ g, d1 O" {$ c - Write_IIC_Byte(0x78);
7 \0 _/ ^! P: {* f; v$ e - IIC_Wait_Ack();
9 h5 y' E! b4 W9 W Y% x% I/ P8 E* X1 Z - Write_IIC_Byte(0x40);' F" F3 k" i1 D N. H+ l4 X! O/ w# i
- IIC_Wait_Ack(); * s0 r A, G! G7 l; C
- Write_IIC_Byte(IIC_Data);
! F Z% I: @$ b+ |' E6 q - IIC_Wait_Ack();
0 F9 S i" e9 F; x: \ - IIC_Stop();8 h( D* Z, w. P( a- a1 l
- }
1 @0 X5 b9 h# V/ l p5 P% k - void OLED_WR_Byte(unsigned dat,unsigned cmd)
8 g( W& h S( W - {
- r) ^- {) t* U2 L - if(cmd). R+ q, V* L" Y7 k0 U
- {' q( G2 ]! T: ?1 ?9 p5 e L( K- K
- Write_IIC_Data(dat);
! f* _( Y& |. F) ~' \% z - }/ q' K" W' s: J1 b8 s2 L& r( {, e
- else& p& Z% S: H3 |% O7 m3 b% I: X
- {6 o% }$ u) s1 [# U! w4 Z
- Write_IIC_Command(dat); # `: _2 x& ~4 i
- }6 U k1 F" t4 e% t/ M
- }# Q" V, @- E( h- @9 J
- void OLED_Display_On(void); o6 _! u& G( F& g
- {( K" A! u; i! u5 M
- OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC
+ y& ` L5 X w) y" n - OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON; G2 p, y% M% S% f
- OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON& _4 [0 h8 ?5 {2 F6 D( `
- }
: N* Y6 `/ P: l - void OLED_Display_Off(void)0 V# j1 @% s7 ]
- {
) u8 t( A$ T# C9 J - OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC
- |: A$ s3 V6 u! V6 N% o) W - OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF
5 |8 C& H0 Q* h3 A - OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF" B7 [6 x# p8 [9 B/ a% u
- }
复制代码- void OLED_Clear(void) . z/ S2 S+ y2 o+ |: N7 M. j0 g) U
- { I0 B: B0 H; B( W
- u8 i,n; M0 _4 E7 }* A0 U4 l) G7 V4 Y
- for(i=0;i<8;i++)
- d# F; O5 p4 r$ Z - {
w2 F, H. m0 H; Z! U - OLED_WR_Byte (0xb0+i,OLED_CMD);
; U: `, c) d0 e& B9 S% A' F - OLED_WR_Byte (0x00,OLED_CMD);
6 @) d2 Y! d( \* U [- G - OLED_WR_Byte (0x10,OLED_CMD); for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
2 w; [/ ]# g. F! \1 W( R - }
$ p$ o: Z3 _& N7 |& C( _+ l$ R - } b: X/ |9 v6 x' q2 V5 p; C8 J
- void OLED_On(void) 7 W9 }. d6 e" |; Q1 s! a r$ G3 H
- {
c( h6 E/ @& P! Q2 s - u8 i,n; 9 R5 \1 `9 z0 G8 s7 K- h$ B
- for(i=0;i<8;i++)
8 C, C. a ^7 w/ ?0 D/ F - {
4 l/ }5 X, C# A. l) _2 L - OLED_WR_Byte (0xb0+i,OLED_CMD);
2 B M+ l' K/ E% m: L - OLED_WR_Byte (0x00,OLED_CMD);
. z" D# T g" P* V7 e$ w5 k$ o - OLED_WR_Byte (0x10,OLED_CMD); for(n=0;n<128;n++)OLED_WR_Byte(1,OLED_DATA); ) L" w, [1 g/ g; X& }- P; k" o0 T$ g
- }
# y9 }4 |( S% j/ P) @ - }
7 m/ I# B! z; ~/ o m - void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size)6 x& M- @" h0 `
- {
( o/ A' D! e/ P/ C/ h) h* T( l - unsigned char c=0,i=0;
" Z D' K" t8 m# A' A - c=chr-' ';
* R$ w4 z* e5 g' t/ _; g- g8 ] - if(x>Max_Column-1){x=0;y=y+2;}. o- ~" B0 V9 B4 g
- if(Char_Size ==16)
/ W' h& r( v7 L - {
; {& I1 o/ Z! {8 {9 R( e - OLED_Set_Pos(x,y); 3 [& F5 P: t# \& o2 x% w
- for(i=0;i<8;i++)
; n! i6 v" @+ w7 o& L3 o - OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
) v2 W ~! D: z% P: W' N - OLED_Set_Pos(x,y+1);
; [4 z* {2 i' f - for(i=0;i<8;i++)
0 v5 W4 ~& M0 U* [- f3 n# x! L - OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA); W! T, g3 {' }# t; `* A0 X( D
- }/ o, k/ K$ G5 w! @) F
- else { 4 c0 N8 O6 u! Z
- OLED_Set_Pos(x,y);. M; N' l" O2 @7 T# {! k
- for(i=0;i<6;i++)$ R. O/ c$ b) X9 C+ _$ E: M
- OLED_WR_Byte(F6x8[c][i],OLED_DATA); % z `' f8 V2 n0 c6 Y
- }
/ `4 G' G& }. J7 x) C - }( }0 m) ]( S/ o/ {
- void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2): t2 T' X- H O. j; v9 N
- { 1 l6 S2 Q7 f" c' R+ p* W2 O* [
- u8 t,temp;
+ }! u( z* F' z - u8 enshow=0;
) `. d% O" J3 m' ?& | - for(t=0;t<len;t++)8 Z2 |9 s6 R7 B* T: _
- {
1 x& X2 L1 q3 }" J; J/ V5 {3 ]0 y - temp=(num/oled_pow(10,len-t-1))%10;
$ B7 F# \7 b2 M9 `) {+ A3 D - if(enshow==0&&t<(len-1))
6 m$ f0 B* E4 m- a% r/ M% [2 p( g - {
, v- k( u7 f* f5 [ - if(temp==0)
( v! n1 e& `- L8 ? - {
9 h+ R% w& [* Y: ? - OLED_ShowChar(x+(size2/2)*t,y,' ',size2);
( f5 K/ w: B8 A+ U - continue;
1 A3 @. h' ^' `' c# X: }' Y, ]( f - }else enshow=1;
7 ]( T' k/ t: O4 n( b! q9 F7 t - & s, e8 ~- U$ R1 f9 J5 g8 z8 F
- }# B0 H Z8 u) m! V/ m2 W
- OLED_ShowChar(x+(size2/2)*t,y,temp+'0',size2);
- U' b+ z- v n; v! \6 U6 _# m, r - }! ~8 ~5 \8 F: H! N4 ?8 i% d
- }
- n. Y1 x( m% K7 n, T0 r8 [8 Z - void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size)7 E' h% B" w+ Y, D2 X2 {9 w
- {9 Z. j( y( ], \
- unsigned char j=0;' H, k. W; B9 ]/ Z: [, d9 p7 U
- while (chr[j]!='\0')/ v: B( t9 E! s! s2 Q7 l
- { OLED_ShowChar(x,y,chr[j],Char_Size);
$ e/ Y5 n$ } y' y* V9 R0 B9 h6 t - x+=8;- a) X1 W8 f( `* I4 L/ y
- if(x>120){x=0;y+=2;}
9 U: l) @! P* O1 G. v r, m - j++;
( j# P. x, C' u7 B2 E) R# E4 u - }
6 t X- o2 _' Q7 x4 X8 K - }
- u+ _- t- N: r9 X - + ]! f' L% _! x. q: k
- void OLED_ShowCHinese(u8 x,u8 y,u8 no)! e5 ^% r. x# L! @6 f
- {
% B/ V7 s8 \$ r; A6 w - u8 t,adder=0;
$ e3 r# M, t( |- |$ v3 ^ - OLED_Set_Pos(x,y); " b/ Q% y% ]7 w5 J; R
- for(t=0;t<16;t++)/ a7 t9 X! w/ ^: E# o
- {
, ~; J. W" b b - OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);& ?+ M3 A6 S9 Q* [9 m
- adder+=1;: d6 |2 M2 l, x& T. ]/ ]
- } + c" R/ E8 W) d5 h9 _6 R
- OLED_Set_Pos(x,y+1); 2 H1 V! Z5 C6 T/ Y, s8 X' i
- for(t=0;t<16;t++)
3 R5 ?* v. P; n- F( P - {
! M1 D6 h" t, @; W+ N - OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);/ a# w4 ]8 M2 Y0 ?1 O, E3 }- n
- adder+=1;, s9 p* F ]0 N% V `9 }# }( T
- } . |8 k# p. z1 g0 N/ o Y, Y$ e
- }' Q+ H) }8 y' D4 Y- P; z! g
2 P, d2 B( e R- ^4 v) p% \& p- void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
3 b1 g, ]0 w$ V5 Z8 q - {
, |9 L; Y) ~. k0 R- j1 E - unsigned int j=0;: K4 E4 K X. ~5 Y! F
- unsigned char x,y;
4 e1 N0 y$ j1 i9 D* p& a - ( }4 H" p0 w( G# C: s
- if(y1%8==0) y=y1/8;
, R7 g, q4 Q$ u3 B - else y=y1/8+1;
5 n* E- v5 S+ e1 _2 v - for(y=y0;y<y1;y++)
; V0 y: `% U* ?1 C% z0 ] - {
7 B" e9 v# L; B) B5 z3 U - OLED_Set_Pos(x0,y);
" s! t3 R9 I# ~, m1 K0 |# Y - for(x=x0;x<x1;x++)0 w5 B9 g. N4 w p ^: S e$ [
- {
& J' t. c+ f5 g# X5 a( I, J: d - OLED_WR_Byte(BMP[j++],OLED_DATA);
. N. i1 I& t0 } - }
7 \: G$ q, K. d1 p - }6 H# O- G% o5 g) q6 K" g: k* L7 w. O
- }
& F8 X* A4 [ `8 m+ C5 ?! [( n' C
9 g- g5 x" ^1 H3 Q- void OLED_Init(void)& C, V6 T1 i- d; N5 F2 r2 P
- { 5 s( K9 s" O: F& i5 M* D3 A
- GPIO_InitTypeDef GPIO_InitStructure;
" ^, W% {9 I- [5 o; k/ d - $ |$ ~- ]4 B6 l* Z3 S+ C$ L7 W
- OLED_GPIO_CLK_ENABLE();
( ]. G+ ?1 h" ? {3 }$ t' Q - GPIO_InitStructure.Pin = GPIO_PIN_8|GPIO_PIN_9;
. w8 Q& W( R" i& x- U% l - GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;# N- v% {7 D; i. N9 k2 y
- GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
( s8 q. [: @3 A- ]4 Y( H - HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); 9 ]2 ]: z# z2 {6 k& A
- HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8|GPIO_PIN_9,GPIO_PIN_SET);: n2 u* D$ K% B: |
- HAL_Delay(200);
7 ~5 }) \" X! [1 e1 }/ ? - OLED_WR_Byte(0xAE,OLED_CMD);; A- ^1 {' e, n3 S9 x! K$ s( w: n; U
- //display off% P- D/ A" P/ v' U
- OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
1 I: N: J$ D% w9 ~$ n3 ? - OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
/ A6 b2 D: r8 G - OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
& H1 Y- C1 `4 y/ i3 x - OLED_WR_Byte(0xB0,OLED_CMD);//--set page address# S, Z3 u; `2 y+ `" h$ W- @
- OLED_WR_Byte(0x81,OLED_CMD); // contract control; n) H9 ?) e ~* }" n
- OLED_WR_Byte(0xFF,OLED_CMD);//--128
- y3 h: z# F% e, d( L- { - OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap 0 a- B& V: i7 \9 a& y% I* T
- OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse5 r5 u3 e1 r0 A' G
- OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)+ [1 T' q; \% N' N# i" I5 f9 S
- OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
6 G* M- K: Z# M% y - OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
/ h% A) u2 i$ S2 r2 W - OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
. h; r' M4 v o! _: H" A2 t! p - OLED_WR_Byte(0x00,OLED_CMD);// {, j ]. o( S0 w4 ?6 ^4 d
- " [& G# H5 h! ~, u( V' C4 b
- OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
2 ? t# T; p- \& a - OLED_WR_Byte(0x80,OLED_CMD);//
: e. \4 e* E4 j0 Z$ z -
/ T1 C V4 y( n/ c0 J' F, ] - OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
) T5 H# F' i; Q6 \& z0 a - OLED_WR_Byte(0x05,OLED_CMD);//
2 i$ t3 S3 p P! g -
' O" R4 A9 @! S- `8 N, `7 |: | - OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
6 A6 g( @7 j- T9 W0 q3 M - OLED_WR_Byte(0xF1,OLED_CMD);//
# D' ^: @/ V. i! Y z - 8 c1 |# p' y5 |2 p- X, [4 l
- OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
- P, s/ d/ e, @2 H - OLED_WR_Byte(0x12,OLED_CMD);//
+ Y! x$ d3 X, v7 K* D" c* }; K -
4 e( z+ ?6 V% x7 ~! S% \- T - OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh' i( R1 _1 j5 ]. l _, D7 A
- OLED_WR_Byte(0x30,OLED_CMD);//
' C8 i0 t! L- A; ^* e1 l0 D -
! C) r. {5 p3 R3 M# c - OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
4 ~1 l, j# g) ? _! J/ }7 X" V! i/ y - OLED_WR_Byte(0x14,OLED_CMD);//
2 P3 Z" y0 [: o - 6 v" U" j/ R2 N$ D/ A3 z
- OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
: ^4 `, l& | I0 u8 v, Q/ t - }
复制代码- #ifndef __OLED_H
6 i( z+ d" a5 F4 e+ l - #define __OLED_H 6 p4 b" B, c0 i8 s3 e
- #include "stdlib.h"* j3 _* f# {" I9 M9 B. @4 b
- #include "stm32g4xx_nucleo.h"6 \* F5 t5 o/ M6 p X% G, x/ \% h
- #define OLED_MODE 00 ?) f1 [7 w4 Q. [; r: t( `+ c
- #define SIZE 8
: K4 d- {6 X7 \ - #define XLevelL 0x00
8 O; y) u! v. B& d+ w - #define XLevelH 0x10
. V8 }9 ~; V* d9 b - #define Max_Column 128
' c' {1 P; u6 ?0 d2 ?9 v - #define Max_Row 64
; Y$ F6 K+ C* {4 Z7 T" J% X - #define Brightness 0xFF
7 f5 V8 J3 w2 x, t* I5 t - #define X_WIDTH 128. ]! k+ \1 Z+ m4 ] Q7 |' M6 W; S
- #define Y_WIDTH 64
* X; J7 v! ?6 E - #define OLED_SCLK_Clr() HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET)//CLK" q) w! n. [6 Z4 J* w0 H
- #define OLED_SCLK_Set() HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET)
$ `, |, X" v5 \
, m, x; Z# @) u4 F- #define OLED_SDIN_Clr() HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET)//DIN
8 x- O8 L! Q9 h% i - #define OLED_SDIN_Set() HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET)
. L5 v. v9 r6 G" s) p4 c* C% R. j
. p( V6 `' n4 D8 s* ~; c# ^, ` Z- #define OLED_RST_Clr() GPIO_ResetBits(GPIOB,GPIO_PIN_11)//RES% N4 |, d. a9 a3 o
- #define OLED_RST_Set() GPIO_SetBits(GPIOB,GPIO_PIN_11)( @2 w/ i' D2 w$ c
- 9 y. m2 L8 w1 {; a+ w& c
- #define OLED_CMD 0
/ i: k8 x1 m2 S' X3 t3 J - #define OLED_DATA 1; m2 P6 M; J- @$ N' {
- #define OLED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() ! x+ A# w" X6 @) n3 Z
- #define OLED_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
' W( \7 ^% b& Z9 m/ P) f m
$ _; z6 Q& O( O, R0 K4 [! O* \- void OLED_WR_Byte(unsigned dat,unsigned cmd); 5 B# L P, J7 X% R9 Z, l" u* f
- void OLED_Display_On(void);
* N7 _/ d* e5 N2 y; i6 z# b - void OLED_Display_Off(void);
4 y$ p; a8 j o" h7 _ - void OLED_Init(void);
& Y! {, L6 a( r/ W' M - void OLED_Clear(void);
; n/ V3 j0 \. ]% M0 h$ S - void OLED_DrawPoint(u8 x,u8 y,u8 t);
& m$ P* i" O5 r4 ]0 T$ y - void OLED_Fill(u8 x1,u8 y1,u8 x2,u8 y2,u8 dot);! G: i+ v! O: f8 I
- void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size);
8 V/ f# R' ^2 L+ A% `; g/ X - void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size);
) X/ i: ~9 H' h. o2 w: O - void OLED_ShowString(u8 x,u8 y, u8 *p,u8 Char_Size);
' g( O. @% P0 e9 `. R, t - void OLED_Set_Pos(unsigned char x, unsigned char y);
) P. P1 A8 e3 b. _: M+ p4 R, K - void OLED_ShowCHinese(u8 x,u8 y,u8 no);
" A! }, a# A# y1 J - void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]);0 r& |: o! P; g- I
- void Delay_50ms(unsigned int Del_50ms);" X# J2 E1 j3 \0 _0 d
- void Delay_1ms(unsigned int Del_1ms);3 I% K) U. ]3 a' ^
- void fill_picture(unsigned char fill_Data);; r7 v$ Y" y1 g/ t
- void Picture(void);) K5 A8 A5 [, y$ J
- void IIC_Start(void);/ V; C# ^- m9 _+ ~9 s& p
- void IIC_Stop(void);1 S. X5 n# Y9 P+ p1 o8 A+ x$ O, t
- void Write_IIC_Command(unsigned char IIC_Command);
" z9 o1 C# u0 g) ? - void Write_IIC_Data(unsigned char IIC_Data);/ m8 `9 j4 T( g
- void Write_IIC_Byte(unsigned char IIC_Byte);1 b* N, k* L, v0 d5 s& e5 _ w: D! I
- void Display_Battery_Level(void);
( V: d! D$ K3 E" z$ f$ m - void IIC_Wait_Ack(void);
. R3 U, S. D" o# J# x6 o - #endif
复制代码- int main(void). r# U& ]. f0 v& L0 i+ {
- {9 M9 K# o& o9 f, M
- HAL_Init();; a2 ]* k! j, g6 a
- # |1 N- @9 S0 m8 p
- OLED_Init();& @: O6 S* Z" V& B6 o( w
- OLED_Clear();
/ Z; F$ J' l" [4 O* ]. o - SystemClock_Config();
9 z# U M: D+ D' i: g5 V
* c% k. g+ b- H! i" Y- BSP_LED_Init(LED2);( g- C4 v4 m& A7 P
- EXTI15_10_IRQHandler_Config();
" R4 x6 a! X* w$ Z+ a' ]; [ - : R' \- a; y K" A. I4 ^
- while(1) + B' Q! Q' [) d' x4 t* \
- {
) G/ v- K9 X# F - OLED_ShowString(0,0,(unsigned char *)"STM32",16);
8 ]* j+ y/ g; D$ w9 S8 F0 S - OLED_ShowCHinese(45,0,2);//
- o$ l) ?9 @. N7 T: D: j: T9 z# G - OLED_ShowCHinese(63,0,3);//
4 c0 w7 E2 c9 `1 u% k3 v, E5 h - OLED_ShowCHinese(81,0,4);//
1 [+ L8 i9 w8 J% z! } - OLED_ShowCHinese(99,0,5);//
' m% ]1 {1 N0 V5 ?6 v8 I* m% P. P - OLED_ShowString(10,3,(unsigned char *)"stmcu.org.cn",16);
! \. r, X6 g6 n; j - OLED_ShowString(8,6,(unsigned char *)"STM32G431RBT6",16);
7 Z, U7 U( \9 K$ D - } 9 _' ~: t0 b/ F2 Z
- }
/ o3 F: s" P0 m+ _7 @
复制代码 编译、下载、测试,结果成功点亮OLED显示,效果如下图所示,本次分享就到这里,感谢社区平台,感谢各位网友的帮忙与支持。
6 ^% B W3 n/ ^' j0 K9 p8 X, O9 q" h1 |& y3 _2 n% ^
1 _1 k! q. k" R( h! g0 X5 R! o |