- 1 void GPIO_Configuration(void)
2 ^; X- G4 Y/ s - 2 {
* I3 L$ d, V+ v - 3 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
3 H9 y/ v8 m$ z# d! |8 i! ?& r: i - 4 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
! b9 X& Q2 K' l* x" A X - 5 - ^- d/ t( Y$ u' R, O
- 6 /* Configure ADC Channel as analog input */3 j/ } F5 X) r! m: E; e) K8 ]
- 7 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
) I% \5 P3 O4 d' P% u, D - 8 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
' K: X6 z* ]9 j& |8 M# W: e - 9 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
2 Y, f: _' n% t2 b4 G - 10 GPIO_Init(GPIOB, &GPIO_InitStructure);
6 \+ e! T0 q( a, o5 A - 11 ( ?& B9 F; F& n6 Y1 D/ T4 |. c
- 12 /*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
; `2 L; x! ^7 L+ x - 13 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;; I6 z2 f) i" B, Z% P3 R& k I4 ]
- 14 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;1 K8 |! z1 `! C! ?* c# Z
- 15 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;; f5 `0 l4 v3 I- y! o, R* a; T
- 16 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;: F7 y: ~7 \4 b1 p, [- m; J5 R
- 17 GPIO_Init(GPIOA, &GPIO_InitStructure);
/ H8 g* F! w6 |% O" V1 D - 18 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2);
. W% n, o' B$ C$ j; }: S - 19 % t% D B( f- l2 m5 G* I: j
- 20 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//9 C5 K6 k& Y# m2 X
- 21 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
! c. l' t# z! x: u3 N% f1 v - 22 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;4 E/ P2 {% S" s! a7 G
- 23 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; S) m. B( {/ A$ k& j7 R
- 24 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
2 J P* L! W) h5 A - 25 GPIO_Init(GPIOA, &GPIO_InitStructure); */
+ Y: m: L; k7 J/ y" u- O c - 26 & u' W& `' A6 Y
- 27 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_1 ;//
1 ~& V; }2 L3 \: n& F - 28 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
# o) Z) ?/ {& } - 29 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
9 u/ K1 N4 p c$ l6 y - 30 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;" ~3 }3 J- | n+ G& n& g- s2 _
- 31 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
' A6 q; x' a2 T - 32 GPIO_Init(GPIOA, &GPIO_InitStructure);
; ]4 w- G* C8 a - 33
2 \, ?& s% B; C - 34
; e1 ?" g+ E$ Q* U, u( Z, q# q5 l; C - 35
: e; O) c; l! ~ - 36 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//. O n; d. X6 I( G" m* a
- 37 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;# P9 [2 V5 |4 [' N3 u* b$ ]
- 38 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //外部电路上拉,设置为上拉* r4 t$ J& |: ?8 H
- 39 GPIO_Init(GPIOA, &GPIO_InitStructure); % D* \: s- V8 A/ l! e% U$ U
- 40 ( u' y! C+ G9 t/ v
- 41 - |( w/ E3 V4 H8 D3 r/ `
- 42 9 Q7 m# o9 M' |! `& z" L
- 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;//7 q; Y: A# p8 F; m) e( r
- 44 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;* H6 t/ K$ s' c0 a9 k# d
- 45 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
) E. K/ K3 r6 h! c' z - 46 GPIO_Init(GPIOA, &GPIO_InitStructure); # F! ?) U7 O4 z$ Z3 \4 Q3 K
- 47 }
2 a: S: f# z) ~& I+ J - ( R2 i, ?, }! C: \$ g* _
复制代码 0 Y# y4 ]5 t/ U& \' Z# M$ r' k
|