- 1 void GPIO_Configuration(void)
1 `. w% i1 \/ N) m8 z - 2 {7 r& s* ^0 {$ }, ~. S, m9 d# u
- 3 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
1 t7 |, `3 }) e. p/ Z$ G5 I - 4 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
7 o" h# P; O/ x2 x3 U - 5
) p: y. N' `. c A- h& Y* t0 n - 6 /* Configure ADC Channel as analog input */* b) y; C# z/ Y5 O, l+ q [8 Z" q
- 7 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
; s7 Z! {; d+ k; E+ c - 8 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
- u' q( s% M8 D - 9 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
0 R& W+ j& O9 J% N4 V' H/ a - 10 GPIO_Init(GPIOB, &GPIO_InitStructure);
J% F2 `9 G% ]* H - 11 ) G- q# n( L7 |/ x
- 12 /*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
+ x( t6 D$ Z# y0 Y/ v - 13 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;# H C+ G: W; ~2 ? \
- 14 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; \. O# T) R; A( M+ B" [, Q, ~
- 15 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
, a% `" r O K- J O - 16 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;. F+ @3 Z% x0 `$ b! |* L
- 17 GPIO_Init(GPIOA, &GPIO_InitStructure);
% Y0 v9 A, X8 n) E5 I2 O& R8 s - 18 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2);& n! P$ L) E; o: m! R
- 19
0 j- c$ {% w0 S9 i/ Q: w) G - 20 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//
8 Z! L2 ^- k5 m8 Y5 f1 K0 b+ }, K - 21 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;3 s# W% U+ s" _
- 22 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;0 ~: [3 p. ]% a N+ W! x
- 23 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;% K4 y& M9 J% e% X, j
- 24 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;+ S( t8 y, x1 g* E* t5 l2 U
- 25 GPIO_Init(GPIOA, &GPIO_InitStructure); */ % l5 d v) @8 j0 `) d: w
- 26 ( Q! `0 \. V( ]3 f. `
- 27 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_1 ;//
5 A$ _5 l; v; L4 X; v% R - 28 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
/ ]* h1 U, O0 \. g! L+ e& ?* M- ~& \ - 29 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
( m3 t1 |+ [+ K/ c q/ ^ - 30 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
6 v% H, w, T, p - 31 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;0 N8 C7 V1 U: r, z. q5 ^
- 32 GPIO_Init(GPIOA, &GPIO_InitStructure);
: ^+ @ {2 L" w5 }4 Z$ O$ i - 33
- j2 t Q- m& b5 Z - 34 / R0 w4 u6 i* J1 X3 B0 Z
- 35
/ \6 B; v/ x+ Q' ^9 j4 K# N1 _! v4 t - 36 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//
, e" \% ^) ]/ m- F - 37 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
o$ \' i3 B4 l i2 | - 38 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //外部电路上拉,设置为上拉
4 I* k2 X( V4 ^ A+ o3 q+ b# ] - 39 GPIO_Init(GPIOA, &GPIO_InitStructure); ; |. L4 z3 `( T) h+ ?! U
- 40 - B i) M& m9 [# t, J+ X
- 41 / z' o' I r) E6 R8 N. N, M2 g8 h
- 42
' F. a5 @/ \ v _ - 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;//
* R% n' z7 a, K$ l9 c - 44 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
' q! A2 C Z2 p2 \& N6 H$ p1 g W - 45 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;* S9 Y! A9 C# }$ q2 u: d
- 46 GPIO_Init(GPIOA, &GPIO_InitStructure);
8 Z. W2 u% f6 w, S9 U - 47 }
; l L8 q& ]7 r- J) W
& k5 t7 E3 B6 p9 I" n4 W+ p1 B
复制代码 1 D! L$ I- h: z9 Q
|