- 1 void GPIO_Configuration(void)
`9 [, i% p' c7 d/ ?4 U5 h0 E, } - 2 {
i: M# ^ s7 Q# \: n - 3 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); 9 f: @) w9 d' d# N% r. j8 \6 ^! @
- 4 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);# u, R1 \& z& s$ s- I7 S% P! d6 Q0 }
- 5 - {/ \) T2 ?' I: P+ S
- 6 /* Configure ADC Channel as analog input */. d8 `. C5 z0 Y, k/ x. G" T
- 7 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
- x& y" I S8 e - 8 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;# C! k8 \' s5 B' u" u' X) _) F
- 9 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;! B% L, X: x# S7 T5 `% J( @' H& Y
- 10 GPIO_Init(GPIOB, &GPIO_InitStructure);
" `# ~4 N/ o% U+ Q! ^ - 11
( t3 P* c$ c5 t' I7 Z$ l; o& h - 12 /*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
" ?) Q2 a, I# ^4 j3 _ - 13 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;: a# ?5 w- L1 h% Z8 S r
- 14 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;6 j# s6 o1 f/ ~7 y2 Q z7 r7 w
- 15 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;% r0 ^1 X7 i8 h8 T# a: V7 C' |
- 16 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;5 N: v8 q, }: y, {6 T
- 17 GPIO_Init(GPIOA, &GPIO_InitStructure);
c- q- n+ }, g# Y( `2 V& P - 18 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_2);% e% o) j; G0 U8 L0 w8 T
- 19
! w9 Z) g7 g0 x, ~# u - 20 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//. v6 q8 ?( Q, |/ |4 T- }
- 21 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ m: l) \ R0 a+ w' } - 22 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
x1 y+ V1 |; J ] - 23 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;; V; Y( P6 F5 P/ a
- 24 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;; B# `# W# W9 z" f* M; a
- 25 GPIO_Init(GPIOA, &GPIO_InitStructure); */
0 ?6 Y6 o2 K6 Y. h9 b - 26 " W& |6 N/ h0 f i7 `
- 27 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_1 ;//
A. t6 y7 P; S, @ - 28 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
% F& ~- k) d: i2 R$ v - 29 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;$ ~' l7 |$ D! C2 q/ Y, j$ y
- 30 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
# _/ E0 [" R$ y - 31 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;" B1 u5 p( o; {5 ^1 b, b
- 32 GPIO_Init(GPIOA, &GPIO_InitStructure); , e" m. a/ J1 R Y/ }
- 33
* `) a- x& `1 b - 34 / I# x4 c% \* J5 h6 \
- 35 - F0 C5 P" I8 [$ I& H9 f- R% `" Q5 D
- 36 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//* o7 m( p& l" I$ |0 l
- 37 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;' V! z' w/ Q/ }/ V
- 38 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //外部电路上拉,设置为上拉
- H+ m9 b( e6 {/ C7 X, V( b% ^ w - 39 GPIO_Init(GPIOA, &GPIO_InitStructure); 0 ?& \" T/ U& u8 `
- 40 # L5 @. [ |7 Q' E
- 41 ' ~5 I: q% r, V6 j- i
- 42
5 T0 o3 B, x: z. K2 e3 _ - 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;//9 I2 T" {5 z8 F0 D( z
- 44 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;5 | y& W& |' r2 o( f% X; X( h5 l
- 45 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;5 @6 E2 q! q! {- f! k' @& @
- 46 GPIO_Init(GPIOA, &GPIO_InitStructure); + w4 p4 z7 ?# i' a' Z9 n2 R
- 47 }' u) s6 F, X; H6 Z* z
- / M% Q/ C+ l* ^7 S
复制代码
, s2 t8 F N- A8 G. u |