Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f37x.h"
- #include "defines.h"
- #include "tm_stm32f37x_usart.h"
- void TM_USART_Init(USART_TypeDef* USARTx, TM_USART_PinsPack_t pinspack, uint32_t baudrate);
- void InitTimer(void)
- {
- TIM_TimeBaseInitTypeDef base_timer;
- TIM_TimeBaseStructInit(&base_timer);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
- base_timer.TIM_Prescaler = 36000 - 1;
- base_timer.TIM_Period = 2000;
- TIM_TimeBaseInit(TIM6, &base_timer);
- TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);
- TIM_Cmd(TIM6, ENABLE);
- NVIC_EnableIRQ(TIM6_DAC1_IRQn);
- }
- void InitPort(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Ðàçðåøèòü òàêòèðîâàíèå GPIOx */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- /* Êîíôèãóðèðîâàíèå íîæêè PA7, òóäà ïîäêëþ÷åí ñâåòîäèîä */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- return;
- }
- int main(void)
- {
- uint8_t c;
- InitPort();
- InitTimer();
- TM_USART_Init(USART2, TM_USART_PinsPack_2, 115200);
- GPIO_SetBits(GPIOA, GPIO_Pin_7); //ñâåòîäèîä ãîðèò
- TM_USART_Puts(USART2, "STM32F37xx switcher v1.0\r");
- TM_USART_Puts(USART2, "Please, press '1' or '0'\n\r");
- while (1)
- {
- c = TM_USART_Getc(USART1);
- switch (c) {
- case '1':
- GPIO_SetBits(GPIOA, GPIO_Pin_7); //ñâåòîäèîä ãîðèò
- TM_USART_Puts(USART2, "LED is on\n\r");
- TIM_Cmd(TIM6, DISABLE);
- break;
- case '0':
- GPIO_ResetBits(GPIOA, GPIO_Pin_7); //ñâåòîäèîä íå ãîðèò
- TM_USART_Puts(USART2, "LED is off\n\r");
- TIM_Cmd(TIM6, DISABLE);
- break;
- }
- }
- }
- void TIM6_DAC1_IRQHandler(void)
- {
- if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET)
- {
- GPIOA->ODR ^= GPIO_Pin_7; //ïåðåêëþ÷àåì âûõîä ñâåòîäèîäà
- TM_USART_Puts(USART2, "Hi, i am STM32F373 :)\n\r");
- TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement