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

CORTEX-M0 探索板流水灯~~

[复制链接]
dspapi 发布时间:2014-3-3 20:33
 //----------------------------------------------------------        ) B+ @* D- N  w- b& U
 void Delay(uint32_t temp)                                                                                                                                        //¼òµ¥µÄÑÓʱº¯Êý£¬ÓÃÓÚ°´¼üÏû¶¶! `* A5 z2 c  W7 {4 m. w0 z
{
: F$ _/ w0 M, {& x, r; b/ J  for(; temp != 0; temp--);/ J( H) i' f; x+ V
} 
! e9 v4 ]! L/ u1 a        3 H7 b- x0 I! j* ?" J
//----------------------------------------------------------
- h3 L# L4 R/ F//----------------------------------------------------------
8 w4 d! m5 @' W3 e$ c& ]unsigned long i;+ |5 F( E8 h/ _: k
   a; Z0 O" ^0 F- z. t4 j+ }
int main(void)$ ^1 U9 W- f3 a8 ?3 t9 f/ t
{/ t( g( e9 s; Y, W
        unsigned int j;
; P- f' n. c. v. v1 D* W( s+ P% B  /*!< At this stage the microcontroller clock setting is already configured, 7 o4 I% A5 }( q/ f( R
       this is done through SystemInit() function which is called from startup$ |$ w# h4 E- \! w0 l
       file (startup_stm32f0xx.s) before to branch to application main.$ k/ x4 J0 `, C- }& y5 `
       To reconfigure the default setting of SystemInit() function, refer to% X4 J6 V3 d! Z, c) @! l4 o
       system_stm32f0xx.c file
" v: i: U/ `' A     */* n% D4 h4 S6 T) I
 
7 D$ _1 U$ [+ ~5 T, d% Z  /* GPIOC Periph clock enable */
& @* P; u4 V& g+ x; d  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);% [; \1 z' K3 m  o/ |% m
 
+ Q# N6 P# L! O9 t# n  /* Configure PC8 and PC9 in output pushpull mode */
, b! K1 K2 t  ?0 j: l& U  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;7 s5 x4 R: b# G; k# w' [# e% h
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
! K* O4 v( }% M1 `  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
( W. P2 R' c9 B/ M2 q  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
1 A) k( \8 W) H9 G  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
% D' w* S+ ]% M  GPIO_Init(GPIOC, &GPIO_InitStructure);3 @" _2 d9 q- Y
        $ e1 w8 u+ q8 }: v4 q6 Z7 s
//----------------------------------------------------------
, N  \* X9 m& `( c" l" e* z 1 H3 s" l0 j4 j/ X5 r4 G* F1 c1 g
        //Ê×ÏȶÔkey½øÐгõʼ»¯£¬Ò²¾ÍÊÇÉèÖÃGPIO µÄģʽ1 L0 ?$ U' Q5 U( I2 F, \  z0 q
//        GPIO_InitTypeDef GPIO_InitStructure;                                                                                        //µ÷ÓÃIO¶¨ÒåµÄ½á¹¹Ìå* N9 A/ G  _1 \6 V6 U
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);                                //ʹÄܰ´¼üIOµÄʱÖÓ
0 ~2 Z7 L: q  v2 w( g/ O  GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_1 ;                                                                //ÉèÖÃÁ¬½Ó°´¼üµÄIO¶Ë¿Ú9 K. w+ o8 W. Y( S
  GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_IN;                                                                //ÉèÖö˿ÚΪÊäÈëģʽ
3 m: n% U/ f  k' z/ l( S$ Z! \  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;                                        //ÉèÖÃËÙ¶ÈΪµÚÈý¼¶
: R- P" i$ ^4 p7 h! H- Y  GPIO_InitStructure.GPIO_PuPd         = GPIO_PuPd_UP;                                                                //ÉÏÀ­ÊäÈë+ F( X; z% j+ W% S
  GPIO_Init(GPIOA, &GPIO_InitStructure);                                                                                        //°ÑÉèÖõIJÎÊýÓõ½½á¹¹Ìå
6 j7 Y: @7 D8 [' x& L2 V   J2 n. h: w" c  `
 - l1 @4 ]- v1 l
 " ?( m5 e) x) C0 H6 h
  /* To achieve GPIO toggling maximum frequency, the following  sequence is mandatory. % g* S# n! G* n2 E: {# `* h* q
     You can monitor PC8 and PC9 on the scope to measure the output signal. # p3 x3 R- J5 F( D$ x
     If you need to fine tune this frequency, you can add more GPIO set/reset   ^' |, f7 P# c" a
     cycles to minimize more the infinite loop timing.
" k) j* a0 F+ P7 j( Y     This code needs to be compiled with high speed optimization option.  */
: k* ?0 d/ I- L9 v3 Z( n: n 
8 }- v! B7 J2 y        while (1)1 b) y' _$ k! U. y) L& N
  {
  m( o( a- ]# H6 P    # K5 t8 e: k  Y
           if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 ) - g* S+ j8 S$ z" x( z! B
          {           
- J6 T% Y2 o2 h& I    /* Set PC8 and PC9 */
3 t  O( o7 P$ x3 c- j, X2 u                for(j=0;jBSRR |= (0x20BRR |= (0x400>>j);        0 j/ Y* d  G9 c, Z. K( A) \
                         Delay(5000000);
3 C# ]; v- Q" c8 j5 i8 U                        }8 u. G+ [# i6 d) T, j. L0 ^
                        ! n. G+ s4 q. @8 K+ W1 T) [! N
                }7 d$ \- M- L, y, T
        else1 X: ^7 O/ R& b, V* _
                {           3 y$ N2 |  s: ], O
    /* Set PC9 */
. A* a# F+ g- p/ q 
) i6 q" o: o5 ~5 D8 P; u    GPIOC->BSRR |= 0x0200;( T& G  I: H1 \
                Delay(1000000);                + q7 _8 `+ D: w3 `8 j
 " I- G' ^" Y5 l' G: e5 R3 g8 K
    /* Reset PC9 */8 }; W9 Y, j5 g" j+ S7 p4 E7 l
               
5 W! _6 h6 k  J- G                GPIOC->BRR |= 0x0200;! h. k8 o5 _& r  R0 l9 g
                Delay(1000000);        ( [" p# f2 }: _7 l/ ]- d& t% l1 n
                       
2 w2 ^) M5 ~& k+ y                };
6 |) r; I& b5 R# Q" s- h 
9 m5 x0 Z) P! T  U+ [& {5 s 
( v! ]1 f- {2 S( E0 B  X; u: o6 N  }
! \2 s) v6 e: G/ a7 @' g# 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 手机版