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

CORTEX-M0 探索板流水灯~~

[复制链接]
dspapi 发布时间:2014-3-3 20:33
 //----------------------------------------------------------        ( u* a8 i$ s: Q, w# D
 void Delay(uint32_t temp)                                                                                                                                        //¼òµ¥µÄÑÓʱº¯Êý£¬ÓÃÓÚ°´¼üÏû¶¶) O( Q1 A( B- A9 M8 P( T& I) L
{/ u( A# n- A3 `. s; ^9 }( G
  for(; temp != 0; temp--);
+ Q2 o* [# M; f3 Z4 h2 I" R0 ?* {- E' R4 r5 V, C9 H2 L+ O
       
  ]4 C. I3 b$ }- [//----------------------------------------------------------
3 Q: X! j. Z" P* N5 A3 F3 h& ]! _//----------------------------------------------------------& B% S& s- i# G# L5 Q% f- O+ W
unsigned long i;3 b* c: n$ r$ S7 F  H
 . P9 B* N' {" U" C
int main(void)6 A8 k7 e" u/ A( O6 n" @- x
{. r4 _( J% |7 x/ d9 ~/ `4 `" i
        unsigned int j;
0 k' M! A, p% k4 {" X' L  /*!< At this stage the microcontroller clock setting is already configured, 
9 C9 x% s# _  _/ `0 i- b( ?       this is done through SystemInit() function which is called from startup. X) |* g7 k+ s/ P6 v
       file (startup_stm32f0xx.s) before to branch to application main.+ J, H" P; I$ H" d+ u1 }
       To reconfigure the default setting of SystemInit() function, refer to6 d& _/ C$ c7 z8 m* {$ a2 g
       system_stm32f0xx.c file
8 K3 N$ O2 x/ `% o. d2 |% w     */
# O3 \( G& a: b5 q& n 
5 N4 H+ o# S  Z1 x& y# ^4 F  /* GPIOC Periph clock enable */) b$ R6 I- @' K/ A0 Z" l9 \
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);! C. h. k7 b- Y4 g4 _, z' D
 . c! N6 P7 o- ^/ ?/ p/ A
  /* Configure PC8 and PC9 in output pushpull mode */6 W  M# e, j! G. ]" ]- z, c
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
  x* \3 b5 D- ^/ n6 k2 O  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;7 h. `8 v/ i/ M
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;. b9 X' u$ G& ?) z; P
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
7 E9 ?+ P* I4 l$ }* P$ b  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;* X  C3 {. n+ x) Q9 O: P) f" `
  GPIO_Init(GPIOC, &GPIO_InitStructure);
+ Y; o9 W& `) z4 w        # j! v* v+ B6 @% s  u# v- a
//----------------------------------------------------------2 t$ k( W4 U( L2 f
 
5 E- n1 a5 c4 f' V9 Y3 Q        //Ê×ÏȶÔkey½øÐгõʼ»¯£¬Ò²¾ÍÊÇÉèÖÃGPIO µÄģʽ* {$ p" l* t7 V$ O, {( m5 z
//        GPIO_InitTypeDef GPIO_InitStructure;                                                                                        //µ÷ÓÃIO¶¨ÒåµÄ½á¹¹Ìå; H; x+ |8 `" U
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);                                //ʹÄܰ´¼üIOµÄʱÖÓ
. a/ p6 J7 v7 F! w' S  GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_1 ;                                                                //ÉèÖÃÁ¬½Ó°´¼üµÄIO¶Ë¿Ú' C, `% g) D5 ]0 @3 D
  GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_IN;                                                                //ÉèÖö˿ÚΪÊäÈëģʽ6 \& {- Y5 l" D. R4 t* a. g
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;                                        //ÉèÖÃËÙ¶ÈΪµÚÈý¼¶
' b3 N* W7 x( f  GPIO_InitStructure.GPIO_PuPd         = GPIO_PuPd_UP;                                                                //ÉÏÀ­ÊäÈë$ f! v: n! U" j$ m, c/ j
  GPIO_Init(GPIOA, &GPIO_InitStructure);                                                                                        //°ÑÉèÖõIJÎÊýÓõ½½á¹¹Ìå0 n5 _& r; g- d  B- }& ], T
 
- o! k# d, v7 t3 ?  b 3 k: |6 @0 t" W. P
 , n  q! V4 g: D% P/ j& w( G
  /* To achieve GPIO toggling maximum frequency, the following  sequence is mandatory. / R6 u1 f& h; M$ U
     You can monitor PC8 and PC9 on the scope to measure the output signal. 
8 M' z# J2 G/ r* A) r     If you need to fine tune this frequency, you can add more GPIO set/reset 2 N# @* q7 R# T4 C
     cycles to minimize more the infinite loop timing.( j9 Z5 A$ k* B  c* S- u
     This code needs to be compiled with high speed optimization option.  */
; ^- P" y# }$ r+ M  _8 x; ] % K9 m" Z; T$ ]1 V, x8 _
        while (1)5 a0 ^! J& r3 z: K+ [
  {
4 @; ]1 E+ z9 V6 H5 H    5 W4 ]# m, ?" c' ^5 c+ Q( E
           if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 ) 
7 @4 k0 _5 y% K; w          {           & R7 ?# M2 y, H
    /* Set PC8 and PC9 */
' R# e6 M' K$ ^" F6 }9 ^0 L  O8 I                for(j=0;jBSRR |= (0x20BRR |= (0x400>>j);        " }5 r( L) G3 a  {$ p
                         Delay(5000000);! O4 p+ q  @" C
                        }- k& ^8 e& }* z2 u% a% b& h
                        % C" O7 a% w, e4 w) m3 a
                }; O- X) y6 x$ n6 M
        else
9 V0 a9 F# E; [* ?                {           # Q! q: v) n" ~" x' U7 f
    /* Set PC9 */( H8 K$ h( E' I' M( u8 m( |
 - e% C3 w; ]  z5 i5 r  m. j
    GPIOC->BSRR |= 0x0200;
1 O; [4 A5 j5 D+ K) }2 Y. a3 }                Delay(1000000);                9 q4 a7 C, {# W/ I% H
 . }$ X1 M5 p0 h9 b9 g( Q4 i
    /* Reset PC9 */
* ^) N$ X: }6 W% q4 e# A2 @               
7 M- ^/ k0 C2 \$ [3 Y8 `6 d                GPIOC->BRR |= 0x0200;/ _! r/ e$ M- J8 t
                Delay(1000000);          g) H- g. X% ~' v( v( Z" p2 P
                        : Y; u9 O1 T% x+ a& K" Z
                };
* F( J( }4 W/ d+ Y 
- ~$ m2 A: h  g* p4 X 2 y8 p- A0 f4 E) J2 V2 B8 Z
  }. }# e: h/ g' ^/ Y5 }; t/ 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 手机版