- 1 void GPIO_Configuration(void)* f" D$ K, H @ L
- 2 {
0 [$ K6 p/ _* @, M - 3 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); . y# ?0 V" p. l% ~7 g
- 4 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);" V3 \- m, G$ Q% y7 p- N4 j
- 5 2 U5 \; `1 x5 g j- ^7 z/ Q4 A
- 6 /* Configure ADC Channel as analog input */
* |, a9 ]. r4 S( J) W - 7 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;8 P* R1 U3 L! E9 g+ q
- 8 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;; Y5 ~ g( Z, m9 v
- 9 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
& [5 x- o2 L4 Y: T) c% ^3 d - 10 GPIO_Init(GPIOB, &GPIO_InitStructure);, e; D4 K/ b5 ` f6 |
- 11 8 g7 f% U4 A& U- l$ h+ i
- 12 /*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
& b0 l) d& h3 \ - 13 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
! q. q' s9 m6 o4 l% m; P+ w - 14 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ Q$ p) W+ e% n) d3 _9 v - 15 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
7 l9 M, S. Y g7 }* ]6 ?- J) e' [ - 16 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
& G% R* U3 w2 W9 V5 Q - 17 GPIO_Init(GPIOA, &GPIO_InitStructure); " N& c, o5 }. ^' Q; {
- 18 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2);
2 G$ i& G9 m1 S - 19 7 Q# M4 b, i7 w/ t$ C- \
- 20 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//
5 D/ c7 a% ^1 S2 w$ } - 21 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;3 B2 n! Y) [0 O( H1 @; q
- 22 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
( c2 P; Q/ s, e" i. N% i2 \4 D- Q - 23 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;2 ?8 v( A$ m; ]' r9 W* Y }
- 24 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
; t& w; [ a3 \ L1 G - 25 GPIO_Init(GPIOA, &GPIO_InitStructure); */ , ?, Y4 V2 x8 o; C& q
- 26
9 {# \! {: y/ G6 Y- v - 27 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_1 ;//) X- E8 ?5 G' t2 C) ^ `
- 28 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;2 y }: }/ d* M7 t
- 29 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;; \) T. k Q7 K5 t& }+ s
- 30 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;: @) T7 h- z1 ?% T" T# [: M: N
- 31 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;- ]8 W! {$ `/ N. U6 L M
- 32 GPIO_Init(GPIOA, &GPIO_InitStructure); 2 X8 c4 Z5 P6 R) [
- 33
7 f2 u5 d/ c5 X# c, K9 C - 34 : h, h! W& }3 t3 [
- 35
6 k x; `4 w9 f1 z4 h3 g8 p - 36 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//; b6 d/ S, z$ q1 |' C! i- [! ~
- 37 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;! A3 e0 X7 H1 |+ a/ \! V
- 38 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //外部电路上拉,设置为上拉5 k5 ^7 K, M5 m. r* D" v
- 39 GPIO_Init(GPIOA, &GPIO_InitStructure); / h& K" M- D/ M9 C4 a d- f+ G
- 40 / z' s7 A: s3 Y
- 41
( K8 o9 g" c- T3 h* l/ w O( ~ - 42 4 D# {) Q: ~9 \7 G) e; \
- 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;//
t" ~7 O q2 s; ?, V R - 44 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
/ r& }8 X1 O9 H& |1 X - 45 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
$ f2 g) L3 t% g9 }* x- O# r7 ~ - 46 GPIO_Init(GPIOA, &GPIO_InitStructure); + b2 L4 @1 k8 ~4 d1 g
- 47 }
3 L; m: `2 O; F) }; Q9 F
: q( f& F5 _) `/ D
复制代码 & S' m& ~4 `: R
|