你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

CORTEX-M0 探索板流水灯~~

[复制链接]
dspapi 发布时间:2014-3-3 20:33
 //----------------------------------------------------------       
3 A& s. T4 [/ I; |2 s2 [: `3 w void Delay(uint32_t temp)                                                                                                                                        //¼òµ¥µÄÑÓʱº¯Êý£¬ÓÃÓÚ°´¼üÏû¶¶
$ D, p2 W" ?  c  `- A/ W{
4 x8 L( Z5 v1 X  f! N# U/ p. {3 B  for(; temp != 0; temp--);
! m* x$ d1 L$ E/ \! {$ [} " P& C9 ^( T5 D
        % r: L5 _- u# s; D' ~' `0 W
//----------------------------------------------------------
1 b+ T. P0 e: c4 m* W' y! i6 C//----------------------------------------------------------' z+ R- T% a+ Y3 p1 q) t' L
unsigned long i;
& d" G/ `. ^7 x% t. _: k 
2 }. z3 t% x# f0 P) l: Hint main(void)
1 W' x( ?, i* [$ w9 g{
( X8 h6 \7 [: ~: W3 ]4 d2 l        unsigned int j;
, ^) N& k- h/ p; N7 O2 x) O' l  /*!< At this stage the microcontroller clock setting is already configured, 
' g7 [8 }; T8 H0 z& z" p. n# ~- b       this is done through SystemInit() function which is called from startup" R& t6 v. V" i- u! ~9 \3 F
       file (startup_stm32f0xx.s) before to branch to application main.
0 ]6 ]( t4 |! X9 i' g6 e9 _! ?0 b       To reconfigure the default setting of SystemInit() function, refer to
! e0 U# Z5 R( Z' G) [( E       system_stm32f0xx.c file2 G3 [* _0 s) l$ t- N- q3 j
     *// u5 @' V. F$ f; V$ e& p! r& [
 
8 x) X6 _( t/ b  /* GPIOC Periph clock enable */
+ X; \9 k" X% e  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);) [- ]) T' z6 p: u) _; a+ h
 9 r; H- {" v! T
  /* Configure PC8 and PC9 in output pushpull mode */0 K0 k' m4 |( ?
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;: P# R1 ^7 K. V4 @! D, {
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;6 E  f1 z  `: c* v) \
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;; ~1 Z1 }7 {/ z( j8 U) l1 {
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;7 l/ u' d' f6 ]/ D# ^: q
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ ]0 H8 `! @1 X% S7 R  GPIO_Init(GPIOC, &GPIO_InitStructure);+ v+ r; |( {9 i- X4 p# u% I
          k" [) Q# k6 q- k' R
//----------------------------------------------------------( ?- n( H( [* a( X# j* _3 ~
 ( b, t' s8 j7 A( ]  \
        //Ê×ÏȶÔkey½øÐгõʼ»¯£¬Ò²¾ÍÊÇÉèÖÃGPIO µÄģʽ5 ^" {& I* c: g& D0 q6 i/ j
//        GPIO_InitTypeDef GPIO_InitStructure;                                                                                        //µ÷ÓÃIO¶¨ÒåµÄ½á¹¹Ìå: r( P8 t, v- k1 c
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);                                //ʹÄܰ´¼üIOµÄʱÖÓ
) `, s( |$ t" E: Q# p: L! `  GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_1 ;                                                                //ÉèÖÃÁ¬½Ó°´¼üµÄIO¶Ë¿Ú
- o5 n1 x0 a- U: l% s- J  GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_IN;                                                                //ÉèÖö˿ÚΪÊäÈëģʽ
' G" j# H9 R: T/ O  p" z* H  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;                                        //ÉèÖÃËÙ¶ÈΪµÚÈý¼¶
# W1 {" H( x5 r  GPIO_InitStructure.GPIO_PuPd         = GPIO_PuPd_UP;                                                                //ÉÏÀ­ÊäÈë
& g' ?8 G) F) O6 u+ e; \. a, t  GPIO_Init(GPIOA, &GPIO_InitStructure);                                                                                        //°ÑÉèÖõIJÎÊýÓõ½½á¹¹Ìå
6 d) k% n7 B' A- w% U 
4 S0 R9 |2 }) K 3 x  S' a. _, C9 g( z
 ! R1 n7 q3 E& ^1 b0 h- l7 I: ]
  /* To achieve GPIO toggling maximum frequency, the following  sequence is mandatory. 8 H- k2 L# D- r1 z$ P* P! ?
     You can monitor PC8 and PC9 on the scope to measure the output signal. 
5 z6 F7 V1 s" a/ }) \) {     If you need to fine tune this frequency, you can add more GPIO set/reset   X) d: G& O2 }: d% o0 x
     cycles to minimize more the infinite loop timing.
4 O$ v# E( B0 P. U% Y' R9 G     This code needs to be compiled with high speed optimization option.  */$ ]1 r$ T' h  h
 , u3 T9 t7 c. F# V( J2 }
        while (1)& r! e- w7 D: R! T, Q6 H" n
  {
: u  Y! _3 S' Q. L& A    1 G3 e) o; G# b
           if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 ) # J4 V- m2 y4 P! n  h
          {           1 M0 |/ X, f( _3 q
    /* Set PC8 and PC9 */
8 I4 q9 ^% x* v4 S% p                for(j=0;jBSRR |= (0x20BRR |= (0x400>>j);        2 y; B, N& f$ v) t' w% q9 J. L
                         Delay(5000000);
% V. _: i/ Z& W( B                        }
6 @4 @& x3 O, e! @; g                        ) ^) v" t/ z) X, H, [% ~
                }
* g- s5 F8 J* H/ S, L: z4 A% C        else
$ [4 c' D1 k7 {* F3 F                {           + H; T* h' I" ]; ^' z
    /* Set PC9 */! l) t- Q9 u  K
 
& ?3 `# _$ ~( l, B    GPIOC->BSRR |= 0x0200;
$ Y/ Q# L4 \/ s& s# I                Delay(1000000);                1 c- x2 D* z9 h
 ' }) T# X1 ?8 s: W& S0 ^- ?) T
    /* Reset PC9 */9 u) v8 b" Q  |/ U) W" D
                # j$ S7 C2 i$ L" \& g0 b+ F
                GPIOC->BRR |= 0x0200;
% D% w* A) k+ x9 G                Delay(1000000);        1 p) S9 ?7 D% m0 e0 `! ^
                        ! J: H3 \4 y2 Z6 E
                };
/ f0 T, X2 X* N+ o/ B1 p 
- a, _) B4 I3 M+ d 
  }/ t" @' J; E3 V  }5 t6 J* `+ O( _: V% {2 L
}
赞 收藏 评论1 发布时间:2014-3-3 20:33

举报

1个回答
沐紫 回答时间:2014-3-18 13:14:54

RE:CORTEX-M0 探索板流水灯~~

for STM32F030?
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版