- /******************** (C) COPYRIGHT 2012 WildFire Team **************************
8 F( M" K9 l0 Z0 ^& b: G9 B9 B
/ g4 N) o. k& l, ]! S% a- **********************************************************************************/1 I* x9 L/ }0 C" M8 }
- #include "stm32f10x.h"
# k d8 J l" F! r7 U - #include "stm32f10x_conf.h "
# B0 E [' w7 F- l6 O3 ?( _
9 z5 d5 A `2 o! D- void Delay(__IO u32 nCount);1 U/ C+ b! z3 i' ^( O9 r! S6 g. _) e C$ s
- void TIM4_EIR_Init(void);9 B' x% e+ ]& A" C
- void PA8_INIT(void); N7 t- G. }$ X9 {
9 B7 U$ G# T8 M) W1 N4 z- uint16_t COUNT = 0;) |& S8 J% w0 n5 X
- 3 j4 _4 y* r9 n. M- a2 `% @" C" ]4 a
- int main(void)2 D0 l' L. @7 B- y& o5 R
- { 7 ?' X u2 S% R6 k8 m$ }/ H) m
- PA8_INIT();
8 g; z4 @$ y4 @5 u5 j4 f3 I' V$ C% q - TIM4_EIR_Init();
/ r- n) @8 O" s( T - while (1)
- j$ c. }7 S/ P - { , b/ l0 A+ r4 `5 q
- TIM_SetCounter(TIM4, 0); // CLEAR6 x; e3 _7 L$ Y( N4 L
-
% A1 \. m' D7 N! ^# t) s - Delay(200);
2 C; z* h0 V& ^4 N - GPIO_SetBits(GPIOA, GPIO_Pin_8);
( Z- I/ w0 j" W; g+ ]: s - Delay(200);- \9 ~' ?. n) y) g9 i4 e$ r7 {
- GPIO_ResetBits(GPIOA, GPIO_Pin_8);! k( J, x8 e. O$ B! D2 u3 u
- Delay(200);. Q# R4 K2 l' [ k! }) I/ S7 e
- GPIO_SetBits(GPIOA, GPIO_Pin_8);
/ }) t) D4 Z# v2 n9 D3 I - Delay(200);
* W, I3 ^3 y8 K* o7 i# ? - GPIO_ResetBits(GPIOA, GPIO_Pin_8);
4 a" x* {; u9 X) |+ h) P5 G; X# [ - Delay(200);: C/ }- U+ `) |/ x# U
- GPIO_SetBits(GPIOA, GPIO_Pin_8);
4 C- U; ^# k: J$ l: H) R - Delay(200);3 _( x' I! T; k* l; y; r) p
- GPIO_ResetBits(GPIOA, GPIO_Pin_8);) s6 E/ X5 S4 U5 D! ~' `
- Delay(200);
1 ?- |& f* Z6 V! S2 n; _! r - GPIO_SetBits(GPIOA, GPIO_Pin_8);
$ h/ r* I6 m# m* P9 M9 F$ A5 s - Delay(200);
( i+ U/ G7 I5 u- {& F! J - GPIO_ResetBits(GPIOA, GPIO_Pin_8);" A2 _8 c8 p( j/ _/ t1 x% D
- % k9 A6 q2 k2 t3 S
-
% }7 r- y! j" g' D+ b; s) ^6 { - COUNT=TIM_GetCounter(TIM4);9 v" T; j9 {) |7 ^
- TIM_SetCounter(TIM4, 0); // CLEAR
$ t8 X4 q5 J Z/ X: I - COUNT=TIM_GetCounter(TIM4);
, k( ?8 G* e* [, T' r - TIM_SetCounter(TIM4, 0); // CLEAR 9 h: [' G# \) \2 p; \
- }
v; I. C2 S8 @5 J1 y - }
; A9 k* `6 K+ n4 X% @1 b4 }% G1 } - & D1 N# s, u9 |
- void Delay(__IO u32 nCount) //简单的延时函数. `8 ]/ V$ }' V; Z" B
- {, k7 N. n5 J h! n7 I# S4 Z# P$ W
- for(; nCount != 0; nCount--);; c1 d" j5 u" L; ]
- }
) U" s) y* O* D2 K# k. P4 ^ - * ?1 v0 ^; c- a
-
# w# m& Z9 B+ |# q2 j. P - /*
! G" R c0 `' P) B: F% N - void TIM4_EIR_Init(void): `8 x8 m* u( C. w. B" {8 m
- {
5 r8 r6 M( t6 r5 w - GPIO_InitTypeDef GPIO_InitStructure;
, o( D! _" l# q- i; d - TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
. x2 e: b% A3 s -
1 }. B* `0 l; ~7 Z* X - RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);' \ C$ n8 `0 E) {, b! ~
-
: N" V# x" s$ n ]' h - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);7 I2 I0 u D/ u5 Z2 w
- 0 ^8 a2 L+ N8 s4 ?6 G& y* L0 X
- //Config PE0 为浮空输入 , H: I- o3 d0 Y% ~2 M3 }9 f/ q- g
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
% }- R" i9 t5 y - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 7 {. I: [+ t& ]/ R. D( J. |
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; * y- y& F) f) o A
- GPIO_Init(GPIOE, &GPIO_InitStructure);
) a4 {8 X/ o* U; i
* a) z0 I5 L% [* ]3 x* P- TIM_DeInit(TIM4);8 d- p' b% I {) X: C! G
- TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
0 r# t* R4 t2 u- } - TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
9 X* ?0 m5 Y% F5 o) f - TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; & Y; r* J- `5 w/ W F
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 1 D% d. K* X- F; i$ |8 n0 M2 P
- TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); // Time base configuration
]0 V, Q* E/ a& q2 T/ Q -
$ n" M% f8 M* \- G2 p6 u6 E9 N - TIM_ETRClockMode2Config(TIM4, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);
! ]$ |3 e3 l/ p( U9 O5 n - TIM_SetCounter(TIM4, 0); 5 s/ I4 k# b. h. ]3 b
- TIM_Cmd(TIM4, ENABLE);
: N: A2 ^; j- y1 e( \ - 6 E. l6 ]% l) ]9 k
- }3 K/ _1 U( W! O. M4 y/ j% ?
- */
, ^. k9 P7 l9 c: [ - void TIM4_EIR_Init(void)* s( J) H4 X3 g6 T# b! v
- {) J9 _7 T, f9 I4 B
- & k6 C* r$ p0 R6 D. J) t% D0 u/ ~
- GPIO_InitTypeDef GPIO_InitStructure;
2 U3 R- p2 H: B, b$ b - TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
# R/ j- I( L* w' ] - ///////////////////////////////////////////////////////////////////////////// & e5 J( Z$ Z1 P) d- {; l
- /* RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);0 I' d: N: Y4 |9 _6 J( N4 u" B' `( D C
- 7 J g4 b4 {* w/ L/ n0 @
- TIM_CounterModeConfig(TIM3,TIM_CounterMode_Up);
4 R7 y- y7 B6 K! { - TIM_SetAutoreload(TIM4,9);
7 w* w- X$ y# P, ?3 l* A0 ^9 b - 7 J/ h- k1 h- s, U6 P k
- TIM_TIxExternalClockConfig(TIM4,TIM_TIxExternalCLK1Source_TI2,TIM_ICPolarity_Rising,0);
' \7 }2 ^, |' O- R' h - , q5 W: F7 g" |9 Y/ I: M
- TIM_Cmd(TIM4,ENABLE);8 ~! }( |1 |' z6 b3 R
- TIM_ITConfig(TIM4,TIM_IT_CC2|TIM_IT_Update,ENABLE);. u; E. d# y: I3 [- o
- */- F" l* T+ `1 i3 f& J% C; o
- /////////////////////////////////////////////////////////////////////////////
; W2 _ P$ x4 h: k9 P& t - RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);4 E, `: g7 F/ T# U. _& v- y' a
- * @" W, S Z- U, ~2 {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); q7 _# Z0 N; L" `4 ~+ l
8 X3 l; n# p- G# R- //Config PE0 为浮空输入
& K% l- T, W1 k - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; $ Z( w0 ^8 T3 f
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
3 Z) y- ]2 `2 r) m# r7 f5 Z - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 1 W0 @; @) S4 { D% V
- GPIO_Init(GPIOE, &GPIO_InitStructure);
4 @. K8 A/ f* M
" ~ H( `& e# T! e9 h5 y7 ^- TIM_DeInit(TIM4);4 a! ~3 c% M9 i) g; u
- TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
* r/ z# D. l9 T d( s4 s - TIM_TimeBaseStructure.TIM_Period = 0xFFFF; $ p/ d2 E8 {. @# J" r$ j5 f
- TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; ' C4 V! \% P+ d' u- I
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
! s& p( d1 Z3 S4 }& W - TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); // Time base configuration
! `+ V3 T2 \" p" ^- A+ m! z - ( O) J8 y5 M) F3 A: ` a N
- TIM_ETRClockMode2Config(TIM4, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 10);
9 T$ B1 F3 A2 i+ d) d8 S6 t# p - TIM_SetCounter(TIM4, 0);
. U# k7 P& f3 h1 { - TIM_Cmd(TIM4, ENABLE); ; o) ]) X: m: d. O1 y. r
~* l# f1 V/ R+ f$ H* l; J-
5 e. }9 D) j R9 |$ A2 F - }
- k. ?0 n% N$ R2 x6 q! n - void PA8_INIT(void)# w* r: P! z( T4 Q" P3 M& h$ q
- { % N: F4 r* o( P8 r* R$ R
- /*定义一个GPIO_InitTypeDef类型的结构体*/' [' ?. E, }& `6 V6 f1 ~4 D0 @8 o0 @
- GPIO_InitTypeDef GPIO_InitStructure;. Y4 A5 O2 ^3 b; T$ N
6 }& N! e& p$ X" |" N- /*开启GPIOA的外设时钟*/# b' t {0 g# \, L
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); ! z+ V$ k) d5 B, y8 ^
5 b7 T- P# X' w8 n- /*选择要控制的GPIOA8引脚*/ % K8 Y8 G* L7 s o2 i M N) s
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;+ T6 b5 H# J0 t
- 9 h# { G+ |- E$ \. g2 s U1 d6 W
- /*设置引脚模式为通用推挽输出*/% J. N) ^ P! k% t' ]) R5 `
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 2 P6 a6 b- g- w
- 0 S& b5 K( T0 A& W. s; S+ x
- /*设置引脚速率为50MHz */ & S9 x, y- R5 Q A x
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; % T" B" c9 @% `. L! p$ t
- : a2 ^; M2 o3 z' V- F1 `9 S
- /*调用库函数,初始化GPIOA*/ T6 @6 u3 ?/ q% Y7 q/ d
- GPIO_Init(GPIOA, &GPIO_InitStructure);
+ {8 O# m) V6 G
d( a9 A0 R' W2 U. F7 w: P- /* 关闭所有led灯 */
' t' L" t( i1 t M/ A$ V - GPIO_SetBits(GPIOA, GPIO_Pin_8); 9 [/ ^3 O1 Y% Q! R" g& A
- }
* {5 |3 t) o' P# g. n7 ]
* U6 |5 _# G8 J8 c$ [4 W8 o- / P# T* h. ]; @; _( f, Y) s0 O
8 p- E/ B9 r/ v5 y$ N( U: U! G7 W- /******************* (C) COPYRIGHT 2012 WildFire Team *****END OF FILE************/
- ^1 {' s ^4 |4 ]
复制代码 7 l! o, q- Q5 t/ ^! k% A
, C* w% S! P8 N
|