// ****************************************************************************************** // Project : STM32VLDISCOVERY Sample Program (STM32F100RB) // Program Name : // Programer : // Create date : Version 1.0 H24.10.01 // History : // Laungage : Atollic TrueSTDIO C Launguage // ****************************************************************************************** // Description // On board LED : PC8, PC9 // // ****************************************************************************************** #include #include "stm32f10x.h" void wait(void); int main(void) { unsigned int LEDlst=0; // ******************* // 1.Initialize // ******************* // (1)Define APB2(peripheral clock enable register) RCC->APB2ENR = 0x000C; // APB2ENR[2-3]:IOPAEN,IOPBEN I/O port A,B clock enable // Set and cleared by software. 0: I/O portn clock disabled, 1:I/O portn clock enabled // (2)Define I/O Port A GPIOA->CRL = 0x11111111; // Port configuration register low (GPIOn[0-7]) GPIOA->CRH = 0x11111111; // Port configuration register high(GPIOn[8-15]) // CNF=00: General purpose output push-pull, MODE=01:Output mode, max speed 10 MHz // GPIOA->IDR // Port input data register (Read Only) IDR[31-16]:Reserved,@IDR[15-0]:Port output data GPIOA->ODR = 0x00000000; // Port output data register ODR[31-16]:Reserved,@ODR[15-0]:Port output data // GPIOA->BSRR // Port bit set/reset registe // GPIOA->BRR // Port bit reset register // GPIOA->LCKR // Port configuration lock register // (3)Define I/O Port B GPIOB->CRL = 0x11111111; // Port configuration register low (GPIOn[0-7]) GPIOB->CRH = 0x11111111; // Port configuration register high(GPIOn[8-15]) // CNF=00: General purpose output push-pull, MODE=01:Output mode, max speed 10 MHz // GPIOB->IDR // Port input data register (Read Only) IDR[31-16]:Reserved,@IDR[15-0]:Port output data GPIOB->ODR = 0x00000000; // Port output data register ODR[31-16]:Reserved,@ODR[15-0]:Port output data // GPIOB->BSRR // Port bit set/reset registe // GPIOB->BRR // Port bit reset register // GPIOB->LCKR // Port configuration lock register // ******************* // 2.Program main // ******************* LEDlst = 1; while(1){ if(LEDlst == 1){ LEDlst = 2; }else if(LEDlst > 127){ LEDlst = 1; }else{ LEDlst = LEDlst * 2; } GPIOA->ODR = LEDlst | (LEDlst << 8); GPIOB->ODR = LEDlst | (LEDlst << 8); wait(); } } //**************************************************************************** // Function Name : wait // Title : // Input : // Output : // Description : //**************************************************************************** void wait() { unsigned int lp,lp1; for(lp=0;lp<2000;lp++) for(lp1=0;lp1<100;lp1++){}; }