
//---------------------------------------------------------- void Delay(uint32_t temp) //¼òµ¥µÄÑÓʱº¯Êý£¬ÓÃÓÚ°´¼üÏû¶¶ {. `0 T g" Z+ w for(; temp != 0; temp--);" t" C: P7 n! X0 U } : L# }2 C* x/ x z( o% e2 A ( b: U- J9 K/ q //---------------------------------------------------------- //----------------------------------------------------------) a8 c+ b# b1 X2 m2 M3 w& w unsigned long i;! c8 R% _! j. t' f' o0 ^ 6 Q' [# b; [+ ]/ p2 D# \ int main(void) {, N, M4 ]% [8 l" M unsigned int j;& Z" `/ b- D7 O _0 B& n5 G# k /*!< At this stage the microcontroller clock setting is already configured, " K6 E. i8 k3 W/ q6 ?/ K this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file* u/ h4 m9 p3 n8 t */4 E) R8 J C+ ^+ E( {. b) L /* GPIOC Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); S, A& |9 F+ c, C- F; f. Q /* Configure PC8 and PC9 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; E1 o" a7 a x3 ~/ N GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;6 @5 X- Q( ?# B. }8 g GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;$ H2 h u/ H4 `) c GPIO_Init(GPIOC, &GPIO_InitStructure); & k% X, ^' x5 o. o //---------------------------------------------------------- |: B% v" i/ u7 i; q //Ê×ÏȶÔkey½øÐгõʼ»¯£¬Ò²¾ÍÊÇÉèÖÃGPIO µÄģʽ // GPIO_InitTypeDef GPIO_InitStructure; //µ÷ÓÃIO¶¨ÒåµÄ½á¹¹Ìå5 K- ]) Y' e5 x& `& I2 e" p RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //ʹÄܰ´¼üIOµÄʱÖÓ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; //ÉèÖÃÁ¬½Ó°´¼üµÄIO¶Ë¿Ú7 y) n) k" `& O; ?+ G" o( c GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //ÉèÖö˿ÚΪÊäÈëģʽ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; //ÉèÖÃËÙ¶ÈΪµÚÈý¼¶ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //ÉÏÀÊäÈë( ^5 J6 L# X: ^+ U' S) V2 ~+ d GPIO_Init(GPIOA, &GPIO_InitStructure); //°ÑÉèÖõIJÎÊýÓõ½½á¹¹Ìå 1 q! c2 q. P+ F /* To achieve GPIO toggling maximum frequency, the following sequence is mandatory. * X% t6 I+ q( T' k4 E You can monitor PC8 and PC9 on the scope to measure the output signal. If you need to fine tune this frequency, you can add more GPIO set/reset # M- a( ]& w9 m+ \2 S6 R" x! C cycles to minimize more the infinite loop timing.$ _0 W0 h) {* m4 O0 q; G This code needs to be compiled with high speed optimization option. */ while (1), m I, W; L! K( f; H+ T4 R {: L# Y- s0 t; F4 U3 Q: Y . Q X" G4 |* b if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 ) { /* Set PC8 and PC9 */# z F% K2 @3 v' h" i) W for(j=0;jBSRR |= (0x20BRR |= (0x400>>j); / w6 f y: k [( R, g3 b" A: | Delay(5000000); }8 N( [$ d; L' A [9 l% h }) P, t' u% u; i else { 2 O P) O+ u0 b6 I7 w /* Set PC9 */ , U! \' E- Z4 `( o; C2 W GPIOC->BSRR |= 0x0200; Delay(1000000); d6 _1 X2 F4 E5 S9 X5 r# K! @6 b /* Reset PC9 */* `% w; D+ s# s: {4 b$ o o2 u ' v3 X* N* d; }( t; e GPIOC->BRR |= 0x0200; Delay(1000000); }; } } |
RE:CORTEX-M0 探索板流水灯~~