
//---------------------------------------------------------- void Delay(uint32_t temp) //¼òµ¥µÄÑÓʱº¯Êý£¬ÓÃÓÚ°´¼üÏû¶¶ {- P2 q" k, q1 C, D/ R0 i3 v for(; temp != 0; temp--); } //---------------------------------------------------------- //---------------------------------------------------------- unsigned long i; % I2 R8 _7 F8 ]) I, R1 T2 K int main(void) {$ u0 g+ I. A& w5 O# T unsigned int j;$ P4 L7 G) ?) E% G/ L9 @) S /*!< At this stage the microcontroller clock setting is already configured, / q% y4 H w% s- u+ r9 G" } 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" x& ~8 U( m4 \- D6 l K! R2 e; [ system_stm32f0xx.c file/ C; x+ _* Q; z; i& H */ , h3 y1 f0 d, z/ m0 p& m" ]7 _. B5 x /* GPIOC Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);- q! U" W" }2 `6 Z3 w$ n 2 S$ }& E7 r0 X /* Configure PC8 and PC9 in output pushpull mode */( ?9 L7 x, n( x3 `0 v5 F/ C GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;9 Z+ g6 k+ c6 m1 M6 A GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;; }" i: n) q3 j* b GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;2 t# L* _( K+ K0 _" y- `. | GPIO_Init(GPIOC, &GPIO_InitStructure); //----------------------------------------------------------1 {7 [: a. Y" I( L 6 x7 a4 Y- Y; W) D8 C //Ê×ÏȶÔkey½øÐгõʼ»¯£¬Ò²¾ÍÊÇÉèÖÃGPIO µÄģʽ // GPIO_InitTypeDef GPIO_InitStructure; //µ÷ÓÃIO¶¨ÒåµÄ½á¹¹Ìå RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //ʹÄܰ´¼üIOµÄʱÖÓ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; //ÉèÖÃÁ¬½Ó°´¼üµÄIO¶Ë¿Ú GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //ÉèÖö˿ÚΪÊäÈëģʽ0 | u" {1 {9 f/ x& o7 [ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; //ÉèÖÃËÙ¶ÈΪµÚÈý¼¶) B3 |9 Y; o+ j9 Z! }5 v5 K9 I GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //ÉÏÀÊäÈë GPIO_Init(GPIOA, &GPIO_InitStructure); //°ÑÉèÖõIJÎÊýÓõ½½á¹¹Ìå * m/ U# s8 s2 {. `9 p7 F4 v " s# @. t0 B& G4 K0 f /* To achieve GPIO toggling maximum frequency, the following sequence is mandatory. You can monitor PC8 and PC9 on the scope to measure the output signal. 5 O8 P% E) A+ q9 S; s+ w) L& | If you need to fine tune this frequency, you can add more GPIO set/reset cycles to minimize more the infinite loop timing.* {4 j1 g( U& G# x. }) h$ L2 M1 f This code needs to be compiled with high speed optimization option. */ M# k6 Q) N7 g) B$ ^ while (1)" }8 L g# g2 {8 h' V% {( m" n {& G0 t" `1 n& z8 f# \( }$ S 5 Z. Z9 h5 a5 L" U+ r) I/ M if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 ) { : @+ U+ v: W; g1 A& f3 } /* Set PC8 and PC9 */ for(j=0;jBSRR |= (0x20BRR |= (0x400>>j); Delay(5000000);' t6 Q1 u5 W( t2 m6 \ }& T" M1 T( p" U. X+ A } else { * g7 {0 o5 U# \: [* p2 Z /* Set PC9 */ GPIOC->BSRR |= 0x0200; Delay(1000000); 6 }5 Y$ E0 U) j( j) ^ /* Reset PC9 */ GPIOC->BRR |= 0x0200;6 V3 J% l* L1 {: i: Q' U( a Delay(1000000); 9 O9 X+ S/ E9 O* u5 }5 Y T };% d/ A( K8 H5 k$ _ : w$ l3 t, p' A& l; A- C! A- n }% D4 ]5 x/ o5 S" F5 n; g+ t! H4 P } |
RE:CORTEX-M0 探索板流水灯~~