
//---------------------------------------------------------- . w# V! l( V0 t _$ y void Delay(uint32_t temp) //¼òµ¥µÄÑÓʱº¯Êý£¬ÓÃÓÚ°´¼üÏû¶¶$ I3 L# B& u( W( e2 R. E1 |8 F {- o7 W; l/ u ~7 ]1 t/ U- R for(; temp != 0; temp--); } //---------------------------------------------------------- //----------------------------------------------------------; @9 k/ o* k# X, ~: x unsigned long i;! B+ q# b6 m2 t7 _ int main(void)1 R& [3 [. Q" b {; g4 s) ^# O4 a6 ~8 q unsigned int j;; g* N5 H8 J( W& }0 g) R2 g) W( y1 W /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup4 M5 c% Q4 g' q& ?" V4 U file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */- t+ x3 C3 Q& ?' Z# U: |+ X; U /* GPIOC Periph clock enable */9 c1 k+ h! ?, C$ s- Y RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Configure PC8 and PC9 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;4 ~5 W. z# I1 M! W' w `4 Z! Y* O GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;4 y5 ~$ m7 _; w GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;! u! c/ z9 Z! t2 r3 c1 x GPIO_Init(GPIOC, &GPIO_InitStructure);7 `/ N/ _' d, q6 o# _ //---------------------------------------------------------- % N& p' x5 ?( M- `. b% s7 n9 o //Ê×ÏȶÔkey½øÐгõʼ»¯£¬Ò²¾ÍÊÇÉèÖÃGPIO µÄģʽ // GPIO_InitTypeDef GPIO_InitStructure; //µ÷ÓÃIO¶¨ÒåµÄ½á¹¹Ìå RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //ʹÄܰ´¼üIOµÄʱÖÓ5 Z4 j% x" c& d2 F7 [7 F GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; //ÉèÖÃÁ¬½Ó°´¼üµÄIO¶Ë¿Ú GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //ÉèÖö˿ÚΪÊäÈëģʽ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; //ÉèÖÃËÙ¶ÈΪµÚÈý¼¶/ ]* G2 s( I& i" i: S8 [ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //ÉÏÀÊäÈë/ N' F9 z7 ?& y, m3 M) T* n/ {. u GPIO_Init(GPIOA, &GPIO_InitStructure); //°ÑÉèÖõIJÎÊýÓõ½½á¹¹Ìå1 R3 G) K0 v/ \7 t8 J ( T5 B f% c0 E2 q! o 6 _- _$ r- _2 L/ o0 A3 K( q /* 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. If you need to fine tune this frequency, you can add more GPIO set/reset - ^3 M( B; d$ G" F- y8 m cycles to minimize more the infinite loop timing.) V4 a0 l6 R) o+ m- l This code needs to be compiled with high speed optimization option. */- M/ s+ y. J. v& y M8 e7 y. s. [ ' I# t0 X% J( a- R while (1) {! j& `- n8 n x% \ , I- ?; L) b8 ?" B, U' D2 X/ \# U if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 0 ) . G& A7 a" c: i6 n. M c/ R5 c { /* Set PC8 and PC9 */: X3 ]0 Q$ l/ r. B for(j=0;jBSRR |= (0x20BRR |= (0x400>>j); U/ r" I, e, H2 m Delay(5000000);4 a/ Z# g0 h- a( v! e5 _0 R8 z } + o! D- S! U- y% y8 h# D, A s2 C } else { /* Set PC9 */8 D* N2 G( r9 u0 Y GPIOC->BSRR |= 0x0200; Delay(1000000); 3 G. b& B+ v+ x- N9 h " E8 n) X: j. F0 O8 \ /* Reset PC9 */ GPIOC->BRR |= 0x0200; Delay(1000000); ) X ]: C8 a2 a9 ^$ P8 n) H }; 8 n( b" j9 \/ X. w* n3 ?) @9 g } } |
RE:CORTEX-M0 探索板流水灯~~