📄 main.c
字号:
/* Includes ------------------------------------------------------------------*/
#include <stdio.h> /* standard I/O .h-file */
#include "stm32f10x.h"
#include "stm32_eval.h"
#include "led.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
//#define TEST_LED LED_ALL
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
void LEDInit(void);
void Delay(unsigned int ticks);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
int i;
/* System Clocks Configuration */
RCC_Configuration();
/* Configure the GPIO ports */
GPIO_Configuration();
/* Configure USART #2 */
USART_Configuration();
printf("\n\r-- Basic 4LED Project V1.0 --\n\r");
printf("\n\r-- EM-STM3210C --\n\r");
printf("\n\r-- 7 sections of numerical code tubes test --\n\r");
#ifdef TEST_LED
/* Test the 7 sections of numerical code tubes. */
LED_CHIP_SEL(TEST_LED);
while (1)
{
SEVEN_LED_DISPLAY(ZERO);
Delay(800);
SEVEN_LED_DISPLAY(ONE);
Delay(800);
SEVEN_LED_DISPLAY(TWO);
Delay(800);
SEVEN_LED_DISPLAY(THREE);
Delay(800);
SEVEN_LED_DISPLAY(FOUR);
Delay(800);
SEVEN_LED_DISPLAY(FIVE);
Delay(800);
SEVEN_LED_DISPLAY(SIX);
Delay(800);
SEVEN_LED_DISPLAY(SEVEN);
Delay(800);
SEVEN_LED_DISPLAY(EIGHT);
Delay(800);
SEVEN_LED_DISPLAY(NINE);
Delay(800);
}
#else
while (1)
{
for (i = 200; i > 0; i--)
{
LED_CHIP_SEL(LED_ONE);
SEVEN_LED_DISPLAY(ONE);
Delay(1);
LED_CHIP_SEL(LED_TWO);
SEVEN_LED_DISPLAY(TWO);
Delay(1);
LED_CHIP_SEL(LED_THREE);
SEVEN_LED_DISPLAY(THREE);
Delay(1);
LED_CHIP_SEL(LED_FOUR);
SEVEN_LED_DISPLAY(FOUR);
Delay(1);
}
for (i = 200; i > 0; i--)
{
LED_CHIP_SEL(LED_ONE);
SEVEN_LED_DISPLAY(FIVE);
Delay(1);
LED_CHIP_SEL(LED_TWO);
SEVEN_LED_DISPLAY(SIX);
Delay(1);
LED_CHIP_SEL(LED_THREE);
SEVEN_LED_DISPLAY(SEVEN);
Delay(1);
LED_CHIP_SEL(LED_FOUR);
SEVEN_LED_DISPLAY(EIGHT);
Delay(1);
}
}
#endif
}
/**
* @brief Configures the different system clocks.
* @param None
* @retval None
*/
void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
initialize the PLL and update the SystemFrequency variable. */
SystemInit();
/* Enable GPIOC and GPIOE clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOE, ENABLE);
}
/**
* @brief Configures the different GPIO ports.
* @param None
* @retval None
*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure PC.02 PC.03 PC.05 PC.07 as Push-pull output ---------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_5 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure PE.08...15 as Push-pull output ----------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 \
| GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 \
| GPIO_Pin_14 | GPIO_Pin_15; \
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* LED is off by default */
SEVEN_LED_Off();
}
/**
* @brief Configures the USART.
* @param None
* @retval None
*/
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- 1 Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
STM_EVAL_COMInit(COM1, &USART_InitStructure);
}
/**
* @brief Delay about ticks ms.
* @param ticks
* @retval None
*/
void Delay(unsigned int ticks)
{
int i, j;
for (i = ticks; i > 0; i--)
for (j = 10000; j > 0; j--);
}
/**
* @brief Redefine fputc function.
* @param ...
* @retval ...
*/
int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(EVAL_COM1, (u8) ch);
/* Loop until the end of transmission */
while(USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TXE) == RESET)
{
}
return ch;
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
/************* (C) COPYRIGHT 2009 Wuhan R&D Center, Embest *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -