- 1 void GPIO_Configuration(void)" h8 h4 L+ n, D# F% j
- 2 {
9 K2 Z5 y1 r' s2 ?' ` - 3 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); ; J! m" J9 R6 i1 I* G
- 4 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);9 L2 X+ Q& Q1 Z+ b9 O) I6 z+ U
- 5 s6 G6 H$ A0 O$ m# ^, U
- 6 /* Configure ADC Channel as analog input *// i2 M7 x5 G5 \5 G, R- {+ m
- 7 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;' _8 @& f- Z6 b
- 8 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
- S& Y n: P' c5 J# K - 9 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;( u2 W) a$ ^: z& \ L( z
- 10 GPIO_Init(GPIOB, &GPIO_InitStructure);
: ?5 W1 M6 M* p! U, ?9 u - 11
; y2 i& b" b: M! v3 ~7 S - 12 /*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- Z# ]% P: Q5 s - 13 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
! o1 A$ E3 t _! o! O" i+ [ - 14 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
% J5 C) i9 J- _6 U* c7 [& D - 15 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
8 _# p/ b. W9 Y - 16 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
1 ^! q C) J) Z; Y2 w - 17 GPIO_Init(GPIOA, &GPIO_InitStructure);
z' [6 f% L! i( L - 18 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2);1 w- P, h; d' R' ? K* z# T
- 19
6 p& ^1 S. E6 @! g& |+ Z/ C# x - 20 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//
/ [; @" K0 l/ X4 Y7 d& C+ g4 E - 21 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
, \0 L1 T# u0 t* Z - 22 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;1 a$ c8 c9 a( }3 h) j
- 23 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;% x5 j# Y* C4 x& n# c+ q5 T9 ~! S. a3 Y6 k
- 24 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
$ n8 V0 F- h: ~9 W+ T4 { - 25 GPIO_Init(GPIOA, &GPIO_InitStructure); */
. m4 Z* t7 m% e- d/ Y - 26 # o* e: A! O8 r
- 27 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_1 ;//
4 O8 ?/ h& [! @: R+ r# [$ B8 s9 G& w - 28 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
" c4 G& q- f' |0 m4 D5 H1 I - 29 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
S% X/ m2 u5 H+ v2 a1 W4 G - 30 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;4 i: n& J7 I2 p- x" v! l
- 31 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;$ u/ w* V" L+ m' e
- 32 GPIO_Init(GPIOA, &GPIO_InitStructure);
. {: @9 }, \; G- G - 33 ! o4 }; |6 t+ x. r3 E
- 34 ' }( k ~9 y8 r- ?4 x
- 35 4 L5 w' B' G4 _1 ?' \. S; W
- 36 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//
! \6 ~- G3 q+ S! f5 ?5 _# N0 ~ d8 B - 37 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;" w q w! c) V$ |. b6 F% c
- 38 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //外部电路上拉,设置为上拉
. `+ E( D1 j6 i( v2 p1 _ - 39 GPIO_Init(GPIOA, &GPIO_InitStructure);
" z4 k6 U5 F) C - 40
' `2 Y9 M1 X4 Y0 E6 b3 U - 41
: v: W8 L$ l! P( O' V5 ` - 42
0 [9 b% \$ ?+ f) x' g3 {, z - 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;//
, i3 t2 S) q' r9 ~1 B, ]( C* p - 44 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
' I% k1 \% z. M3 g. Y - 45 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
, w% {1 ? W8 q% o - 46 GPIO_Init(GPIOA, &GPIO_InitStructure);
T5 Z. h _) e' u& N0 ^ - 47 }- e% D5 G" t& @% b8 m
- 5 t/ {, \9 w( f% i
复制代码
% C( o6 j8 a8 E' R' m! ?0 m/ u9 Z3 |4 J |