- 1 void GPIO_Configuration(void)6 e7 }# g3 p3 X2 p
- 2 {! D+ u+ ?6 x% n8 F* q
- 3 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
% h- u9 V' h2 T1 q# z - 4 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);2 M- s5 c3 |2 n4 z" w
- 5 $ j" U3 |) i" E/ ]/ \4 W
- 6 /* Configure ADC Channel as analog input */% O4 @& W/ ^3 h( J, D8 S5 V5 Q0 M
- 7 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;( a- X6 m+ _; D2 |# L2 J
- 8 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
* F2 {( R; r4 P# [ J8 A* d - 9 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;6 ~/ i, P q: y! [
- 10 GPIO_Init(GPIOB, &GPIO_InitStructure);
/ ?2 S- V) }) D- v+ X% ~: `% z - 11
/ u% T1 Y+ K: l( l; U- G" T2 R: F" I$ L, E - 12 /*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;' _ [. k' R" F
- 13 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;. }7 }% p# F0 H
- 14 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
6 @9 ~6 L! f0 |4 p+ j - 15 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ e% w& d3 A+ d) s* N - 16 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
) b: M$ \* g/ b: ^! Q5 ]8 C% Y - 17 GPIO_Init(GPIOA, &GPIO_InitStructure); * b3 D% R. ^! `6 [% W% ~0 [
- 18 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2);( s" J3 `6 c$ R
- 19
. c# K. L$ q' k0 f - 20 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//
& o, `; A$ I; I$ w - 21 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
! d. }. g( S$ t+ y - 22 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;/ u& w" _# }. m1 C7 f
- 23 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;8 P9 Y Z0 D. }3 B
- 24 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;- W$ Y9 O1 F4 d3 A) D
- 25 GPIO_Init(GPIOA, &GPIO_InitStructure); */
! V( P- U& I6 h - 26
7 \2 O+ ]( }" I: @$ m3 z# y - 27 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_1 ;//
& G( J" ~* J9 y# D' d Q0 | - 28 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
' O: d& w1 `! F/ E0 h/ b - 29 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
8 i. C: c& f, c2 I: Q; n( e - 30 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;/ o: f9 n5 \4 E" D$ s& o2 y
- 31 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
$ V# n9 n2 R; n+ P" R - 32 GPIO_Init(GPIOA, &GPIO_InitStructure); ; c8 ~! ], S4 A5 |8 |8 E# }
- 33 $ t2 Q1 d( z& ~% S4 B6 d
- 34 , v, b# s: H5 F+ Y$ ?
- 35 . w# ?& ]( I! z- M9 R m% I
- 36 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;/// x" \% _1 b& R2 E
- 37 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
. Z j, x' x% J0 t% H1 p+ \, ?9 L2 Q( t - 38 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //外部电路上拉,设置为上拉
3 F- Z l$ W8 M( } - 39 GPIO_Init(GPIOA, &GPIO_InitStructure);
/ I% N W2 d' d/ ]* H6 o4 K& R* K0 \ - 40 9 b( P6 R2 k8 o5 z) N$ I
- 41
8 |. ?- k1 E; b - 42
* c8 q- R! t# z4 g: n - 43 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_7|GPIO_Pin_9|GPIO_Pin_10;//
5 e; Q1 E) |' _/ n9 M - 44 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;* w, C. S, Z; V0 x
- 45 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;$ m4 s6 M4 o3 v, F
- 46 GPIO_Init(GPIOA, &GPIO_InitStructure);
$ ]8 {9 m2 L) v, a3 |% r" l - 47 }! z' k2 }9 \. H" V
3 Z; i( H. Q" E( J" S0 L
复制代码 ) a) ~ o1 G/ [# V" Z
|