123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747 |
- #include "board.h"
- #define SPI_BUFFER_SIZE 5
- static const uint16_t nixieCathodeMap[4][10] = {
- {0x8000, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000},
- {0x2000, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000},
- {0x0800, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400},
- {0x0200, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100}
- };
- static uint8_t tubesBuffer[SPI_BUFFER_SIZE] = {0};
- static void _show_digits(const uint32_t digits);
- static void GPIO_Init(void);
- static void DMA_Init(void);
- static void I2C1_Init(void);
- static void SPI1_Init(void);
- static void TIM1_Init(void);
- static void TIM3_Init(void);
- static void TIM14_Init(void);
- static void TIM16_Init(void);
- static void TIM17_Init(void);
- static void USART1_UART_Init(void);
- void Board_Init(void)
- {
-
- RCC->APBENR1 = (RCC_APBENR1_PWREN | RCC_APBENR1_I2C1EN | RCC_APBENR1_TIM3EN);
- RCC->APBENR2 = (RCC_APBENR2_SYSCFGEN | RCC_APBENR2_SPI1EN | RCC_APBENR2_TIM1EN);
-
- RCC->IOPENR = (RCC_IOPENR_GPIOAEN | RCC_IOPENR_GPIOBEN | RCC_IOPENR_GPIOCEN);
-
-
- NVIC_SetPriority(RCC_IRQn, 0);
- NVIC_EnableIRQ(RCC_IRQn);
-
- SystemClock_Config();
-
- SCB->SCR &= ~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
-
- SCB->SCR &= ~((uint32_t)SCB_SCR_SLEEPONEXIT_Msk);
-
- GPIO_Init();
- DMA_Init();
- I2C1_Init();
- SPI1_Init();
-
-
-
- DMA1_Channel1->CMAR = (uint32_t)&tubesBuffer;
-
- DMA1_Channel1->CPAR = (uint32_t)&(SPI1->DR);
-
- DMA1_Channel1->CNDTR = SPI_BUFFER_SIZE;
-
- SPI1->CR1 |= SPI_CR1_SPE;
- Flag.SPI_TX_End = 1;
-
- TUBE_PWR_ON;
-
-
- TIM1_Init();
- TIM3_Init();
-
- TIM14_Init();
-
-
-
- }
- void showDigits(tube4_t dig)
- {
- static uint32_t old_dig = 0;
- uint8_t st = 0, ov = FADE_START;
- if (old_dig != dig.u32) {
- while (ov < FADE_STOP) {
- if (st == 0) {
-
- st = 1;
- _show_digits(dig.u32);
- ov += FADE_STEP;
- tdelay_ms(ov);
- } else {
-
- st = 0;
- _show_digits(old_dig);
- tdelay_ms(FADE_STOP - ov);
- }
- }
- old_dig = dig.u32;
- }
- }
- static void _show_digits(const uint32_t digits)
- {
- tube4_t dig;
- dig.u32 = digits;
-
- tubesBuffer[0] = 0;
- tubesBuffer[1] = 0;
- tubesBuffer[2] = 0;
- tubesBuffer[3] = 0;
- tubesBuffer[4] = 0;
-
- int i;
- for (i=0; i<4; i++) {
- if (dig.ar[i] > 9) {
- if (dig.ar[i] != 0xf) {
- dig.ar[i] = 0;
- }
- }
- }
-
- while (Flag.SPI_TX_End == 0);
- Flag.SPI_TX_End = 0;
-
- tubesBuffer[0] = (uint8_t)(nixieCathodeMap[Tube_E][dig.s8.tE] >> 8);
- tubesBuffer[1] = (uint8_t)((nixieCathodeMap[Tube_E][dig.s8.tE]) | (nixieCathodeMap[Tube_D][dig.s8.tD] >> 8));
- tubesBuffer[2] = (uint8_t)((nixieCathodeMap[Tube_D][dig.s8.tD]) | (nixieCathodeMap[Tube_B][dig.s8.tB] >> 8));
- tubesBuffer[3] = (uint8_t)((nixieCathodeMap[Tube_B][dig.s8.tB]) | (nixieCathodeMap[Tube_A][dig.s8.tA] >> 8));
- tubesBuffer[4] = (uint8_t)(nixieCathodeMap[Tube_A][dig.s8.tA]);
-
- DMA1_Channel1->CCR |= DMA_CCR_EN;
-
- for (i=0; i<4; i++) {
- if (dig.ar[i] == 0xf) {
- tube_PowerOff((tube_pos_t)i);
- } else {
- tube_PowerOn((tube_pos_t)i);
- }
- }
- }
- void tube_PowerOn(tube_pos_t tube)
- {
- switch (tube) {
- case Tube_A:
- TUBE_A_ON;
- break;
- case Tube_B:
- TUBE_B_ON;
- break;
- case Tube_D:
- TUBE_D_ON;
- break;
- case Tube_E:
- TUBE_E_ON;
- break;
- case Tube_All:
- TUBE_ALL_ON;
- break;
-
- default:
- break;
- }
- }
- void tube_PowerOff(tube_pos_t tube)
- {
- switch (tube) {
- case Tube_A:
- TUBE_A_OFF;
- break;
- case Tube_B:
- TUBE_B_OFF;
- break;
- case Tube_D:
- TUBE_D_OFF;
- break;
- case Tube_E:
- TUBE_E_OFF;
- break;
- case Tube_All:
- TUBE_ALL_OFF;
- break;
-
- default:
- break;
- }
- }
- void tube_BrightLevel(tube_pos_t tube, uint8_t bright)
- {
- switch (tube) {
- case Tube_A:
- TUBE_A_BRIGHT(bright);
- break;
- case Tube_B:
- TUBE_B_BRIGHT(bright);
- break;
- case Tube_C:
- TUBE_C_BRIGHT(bright);
- break;
- case Tube_D:
- TUBE_D_BRIGHT(bright);
- break;
- case Tube_E:
- TUBE_E_BRIGHT(bright);
- break;
- case Tube_All:
- TUBES_BRIGHT(bright);
- break;
-
- default:
- break;
- }
- }
- void SystemClock_Config(void)
- {
-
- RCC->CR |= RCC_CR_HSION;
- while((RCC->CR & RCC_CR_HSIRDY) == 0);
-
-
- RCC->PLLCFGR = (RCC_PLLCFGR_PLLSRC_HSI | RCC_PLLCFGR_PLLM_0 | (9 << RCC_PLLCFGR_PLLN_Pos) | RCC_PLLCFGR_PLLR_1);
- RCC->PLLCFGR |= RCC_PLLCFGR_PLLREN;
- RCC->CR |= RCC_CR_PLLON;
- while((RCC->CR & RCC_CR_PLLRDY) == 0);
-
- RCC->CFGR &= RCC_CFGR_SW;
- RCC->CFGR |= RCC_CFGR_SW_1;
- while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_1);
-
- SystemCoreClock = 24000000;
-
- RCC->CCIPR &= ~(RCC_CCIPR_I2C1SEL);
- RCC->CCIPR |= RCC_CCIPR_I2C1SEL_1;
- }
- static void GPIO_Init(void)
- {
-
-
- EXTI->IMR1 |= EXTI_IMR1_IM14;
-
-
-
- EXTI->FTSR1 = EXTI_FTSR1_FT14;
-
- EXTI->EXTICR[3] = EXTI_EXTICR4_EXTI14_1;
-
- NVIC_SetPriority(EXTI4_15_IRQn, 0);
- NVIC_EnableIRQ(EXTI4_15_IRQn);
-
- GPIO_SetPinMode(IRQ_GPIO_Port, IRQ_Pin, GPIO_MODE_IN);
- GPIO_SetPinPull(IRQ_GPIO_Port, IRQ_Pin, GPIO_PUPDR_UP);
-
- GPIO_SetPinMode(LC0_GPIO_Port, LC0_Pin, GPIO_MODE_OUT);
- GPIO_SetPinSpeed(LC0_GPIO_Port, LC0_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(LC0_GPIO_Port, LC0_Pin, GPIO_PUPDR_DW);
- GPIO_SetPinMode(LC1_GPIO_Port, LC1_Pin, GPIO_MODE_OUT);
- GPIO_SetPinSpeed(LC1_GPIO_Port, LC1_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(LC1_GPIO_Port, LC1_Pin, GPIO_PUPDR_DW);
- GPIO_SetPinMode(LC2_GPIO_Port, LC2_Pin, GPIO_MODE_OUT);
- GPIO_SetPinSpeed(LC2_GPIO_Port, LC2_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(LC2_GPIO_Port, LC2_Pin, GPIO_PUPDR_DW);
- GPIO_SetPinMode(LC3_GPIO_Port, LC3_Pin, GPIO_MODE_OUT);
- GPIO_SetPinSpeed(LC3_GPIO_Port, LC3_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(LC3_GPIO_Port, LC3_Pin, GPIO_PUPDR_DW);
-
- GPIO_SetPinMode(SHDN_GPIO_Port, SHDN_Pin, GPIO_MODE_OUT);
- GPIO_SetPinSpeed(SHDN_GPIO_Port, SHDN_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(SHDN_GPIO_Port, SHDN_Pin, GPIO_PUPDR_DW);
-
- GPIO_SetPinMode(Latch_GPIO_Port, Latch_Pin, GPIO_MODE_OUT);
- GPIO_SetPinOutputType(Latch_GPIO_Port, Latch_Pin, GPIO_OTYPE_OD);
- GPIO_SetPinSpeed(Latch_GPIO_Port, Latch_Pin, GPIO_OSPEED_HI);
-
- GPIO_SetPinMode(UART_EN_GPIO_Port, UART_EN_Pin, GPIO_MODE_OUT);
-
- GPIO_SetPinPull(UART_ST_GPIO_Port, UART_ST_Pin, GPIO_PUPDR_UP);
- GPIO_SetPinMode(UART_ST_GPIO_Port, UART_ST_Pin, GPIO_MODE_IN);
-
- GPIO_SetPinPull(BTN1_GPIO_Port, BTN1_Pin, GPIO_PUPDR_UP);
- GPIO_SetPinMode(BTN1_GPIO_Port, BTN1_Pin, GPIO_MODE_IN);
- GPIO_SetPinPull(BTN2_GPIO_Port, BTN2_Pin, GPIO_PUPDR_UP);
- GPIO_SetPinMode(BTN2_GPIO_Port, BTN2_Pin, GPIO_MODE_IN);
- GPIO_SetPinPull(BTN3_GPIO_Port, BTN3_Pin, GPIO_PUPDR_UP);
- GPIO_SetPinMode(BTN3_GPIO_Port, BTN3_Pin, GPIO_MODE_IN);
- GPIO_SetPinPull(BTN4_GPIO_Port, BTN4_Pin, GPIO_PUPDR_UP);
- GPIO_SetPinMode(BTN4_GPIO_Port, BTN4_Pin, GPIO_MODE_IN);
- }
- static void DMA_Init(void)
- {
-
- RCC->AHBENR |= RCC_AHBENR_DMA1EN;
-
-
-
-
- NVIC_SetPriority(DMA1_Channel1_IRQn, 0);
- NVIC_EnableIRQ(DMA1_Channel1_IRQn);
-
- NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0);
- NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
- }
- static void I2C1_Init(void)
- {
-
- GPIO_SetPinMode(GPIOB, GPIO_PIN_8, GPIO_MODE_AFF);
- GPIO_SetPinOutputType(GPIOB, GPIO_PIN_8, GPIO_OTYPE_OD);
- GPIO_SetPinSpeed(GPIOB, GPIO_PIN_8, GPIO_OSPEED_HI);
- GPIO_SetPinPull(GPIOB, GPIO_PIN_8, GPIO_PUPDR_UP);
- GPIO_SetAFPin_8_15(GPIOB, GPIO_PIN_8, GPIO_AF_6);
- GPIO_SetPinMode(GPIOB, GPIO_PIN_9, GPIO_MODE_AFF);
- GPIO_SetPinOutputType(GPIOB, GPIO_PIN_9, GPIO_OTYPE_OD);
- GPIO_SetPinSpeed(GPIOB, GPIO_PIN_9, GPIO_OSPEED_HI);
- GPIO_SetPinPull(GPIOB, GPIO_PIN_9, GPIO_PUPDR_UP);
- GPIO_SetAFPin_8_15(GPIOB, GPIO_PIN_9, GPIO_AF_6);
-
-
- DMA1_Channel2->CCR = (DMA_CCR_PL_0 | DMA_CCR_MINC | DMA_CCR_TEIE | DMA_CCR_TCIE);
-
- DMAMUX1_Channel1->CCR = 10;
-
- DMA1_Channel3->CCR = (DMA_CCR_PL_0 | DMA_CCR_MINC| DMA_CCR_DIR | DMA_CCR_TEIE | DMA_CCR_TCIE);
-
- DMAMUX1_Channel2->CCR = 11;
-
- I2C1->TIMINGR = 0x0010061A;
- I2C1->CR2 = I2C_CR2_AUTOEND;
- I2C1->CR1 = I2C_CR1_PE;
- }
- static void SPI1_Init(void)
- {
-
- GPIO_SetPinMode(GPIOB, GPIO_PIN_3, GPIO_MODE_AFF);
- GPIO_SetPinOutputType(GPIOB, GPIO_PIN_3, GPIO_OTYPE_OD);
- GPIO_SetPinSpeed(GPIOB, GPIO_PIN_3, GPIO_OSPEED_HI);
- GPIO_SetPinMode(GPIOB, GPIO_PIN_5, GPIO_MODE_AFF);
- GPIO_SetPinOutputType(GPIOB, GPIO_PIN_5, GPIO_OTYPE_OD);
- GPIO_SetPinSpeed(GPIOB, GPIO_PIN_5, GPIO_OSPEED_HI);
-
-
- DMA1_Channel1->CCR = (DMA_CCR_PL_1 | DMA_CCR_MINC | DMA_CCR_CIRC | DMA_CCR_TEIE | DMA_CCR_DIR | DMA_CCR_TCIE);
-
- DMAMUX1_Channel0->CCR = 0x11;
-
- NVIC_SetPriority(SPI1_IRQn, 0);
- NVIC_EnableIRQ(SPI1_IRQn);
-
- SPI1->CR1 = (SPI_CR1_MSTR | SPI_CR1_BR_1 | SPI_CR1_BR_0 | SPI_CR1_SSM | SPI_CR1_SSI);
- SPI1->CR2 = (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0 | SPI_CR2_TXDMAEN | SPI_CR2_FRXTH);
- }
- static void TIM1_Init(void)
- {
-
- TIM1->PSC = TIM1_PSC;
- TIM1->ARR = TIM1_ARR;
- TIM1->CR1 = TIM_CR1_ARPE;
-
- TIM1->CCR1 = PWM_TUBE_INIT_VAL;
- TIM1->CCR2 = PWM_LED_INIT_VAL;
- TIM1->CCR3 = PWM_LED_INIT_VAL;
- TIM1->CCR4 = PWM_LED_INIT_VAL;
-
- TIM1->CCMR1 = (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC1PE | TIM_CCMR1_OC2PE);
- TIM1->CCMR2 = (TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC3PE | TIM_CCMR2_OC4PE);
-
-
- TIM1->BDTR = TIM_BDTR_MOE;
- TIM1->EGR = TIM_EGR_UG;
-
- TIM1->CCER = (TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E);
-
- TIM1->CR1 |= TIM_CR1_CEN;
-
- GPIO_SetPinMode(PWM_1_GPIO_Port, PWM_1_Pin, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(PWM_1_GPIO_Port, PWM_1_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(PWM_1_GPIO_Port, PWM_1_Pin, GPIO_PUPDR_DW);
- GPIO_SetAFPin_8_15(PWM_1_GPIO_Port, PWM_1_Pin, GPIO_AF_2);
- GPIO_SetPinMode(PWM_R_GPIO_Port, PWM_R_Pin, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(PWM_R_GPIO_Port, PWM_R_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(PWM_R_GPIO_Port, PWM_R_Pin, GPIO_PUPDR_DW);
- GPIO_SetAFPin_8_15(PWM_R_GPIO_Port, PWM_R_Pin, GPIO_AF_2);
- GPIO_SetPinMode(PWM_B_GPIO_Port, PWM_B_Pin, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(PWM_B_GPIO_Port, PWM_B_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(PWM_B_GPIO_Port, PWM_B_Pin, GPIO_PUPDR_DW);
- GPIO_SetAFPin_8_15(PWM_B_GPIO_Port, PWM_B_Pin, GPIO_AF_2);
- GPIO_SetPinMode(PWM_G_GPIO_Port, PWM_G_Pin, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(PWM_G_GPIO_Port, PWM_G_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(PWM_G_GPIO_Port, PWM_G_Pin, GPIO_PUPDR_DW);
- GPIO_SetAFPin_8_15(PWM_G_GPIO_Port, PWM_G_Pin, GPIO_AF_2);
- }
- static void TIM3_Init(void)
- {
-
- TIM3->PSC = TIM3_PSC;
- TIM3->ARR = TIM3_ARR;
- TIM3->CR1 = TIM_CR1_ARPE;
-
- TIM3->CCR1 = PWM_TUBE_INIT_VAL;
- TIM3->CCR2 = PWM_TUBE_INIT_VAL;
- TIM3->CCR3 = PWM_TUBE_INIT_VAL;
- TIM3->CCR4 = PWM_TUBE_INIT_VAL;
-
- TIM3->CCMR1 = (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC1PE | TIM_CCMR1_OC2PE);
- TIM3->CCMR2 = (TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC3PE | TIM_CCMR2_OC4PE);
-
- TIM3->EGR = TIM_EGR_UG;
-
- TIM3->CCER = (TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E);
-
- TIM3->CR1 |= TIM_CR1_CEN;
-
- GPIO_SetPinMode(PWM_5_GPIO_Port, PWM_5_Pin, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(PWM_5_GPIO_Port, PWM_5_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(PWM_5_GPIO_Port, PWM_5_Pin, GPIO_PUPDR_DW);
- GPIO_SetAFPin_0_7(PWM_5_GPIO_Port, PWM_5_Pin, GPIO_AF_1);
- GPIO_SetPinMode(PWM_4_GPIO_Port, PWM_4_Pin, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(PWM_4_GPIO_Port, PWM_4_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(PWM_4_GPIO_Port, PWM_4_Pin, GPIO_PUPDR_DW);
- GPIO_SetAFPin_0_7(PWM_4_GPIO_Port, PWM_4_Pin, GPIO_AF_1);
- GPIO_SetPinMode(PWM_3_GPIO_Port, PWM_3_Pin, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(PWM_3_GPIO_Port, PWM_3_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(PWM_3_GPIO_Port, PWM_3_Pin, GPIO_PUPDR_DW);
- GPIO_SetAFPin_0_7(PWM_3_GPIO_Port, PWM_3_Pin, GPIO_AF_1);
- GPIO_SetPinMode(PWM_2_GPIO_Port, PWM_2_Pin, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(PWM_2_GPIO_Port, PWM_2_Pin, GPIO_OSPEED_HI);
- GPIO_SetPinPull(PWM_2_GPIO_Port, PWM_2_Pin, GPIO_PUPDR_DW);
- GPIO_SetAFPin_0_7(PWM_2_GPIO_Port, PWM_2_Pin, GPIO_AF_1);
- }
- static void TIM14_Init(void)
- {
-
- RCC->APBENR2 |= RCC_APBENR2_TIM14EN;
-
- NVIC_SetPriority(TIM14_IRQn, 0);
- NVIC_EnableIRQ(TIM14_IRQn);
-
- TIM14->PSC = TIM14_PSC;
- TIM14->ARR = TIM14_ARR;
-
- TIM14->CR1 = (TIM_CR1_ARPE);
-
- TIM14->CCMR1 = (TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1PE);
-
- TIM14->CCER = TIM_CCER_CC1E;
-
- TIM14->CCR1 = TIM14_PULSE_VAL;
-
- TIM14->DIER = (TIM_DIER_UIE | TIM_DIER_CC1IE);
-
- }
- void Blink_Start(void)
- {
-
-
-
- TIM14->SR |= TIM_SR_UIF;
- TIM14->SR |= TIM_SR_CC1IF;
-
- TIM14->CNT = 0;
-
- TIM14->CR1 |= TIM_CR1_CEN;
- }
- void Blink_Stop(void)
- {
-
- TIM14->CR1 &= ~(TIM_CR1_CEN);
-
- if (Flag.Blink_1 != 0) {
- TUBE_A_ON;
- }
- if (Flag.Blink_2 != 0) {
- TUBE_B_ON;
- }
- if (Flag.Blink_3 != 0) {
- TUBE_C_ON;
- }
- if (Flag.Blink_4 != 0) {
- TUBE_D_ON;
- }
- if (Flag.Blink_5 != 0) {
- TUBE_E_ON;
- }
-
- Flag.Blink_1 = 0;
- Flag.Blink_2 = 0;
- Flag.Blink_3 = 0;
- Flag.Blink_4 = 0;
- Flag.Blink_5 = 0;
- }
- static void TIM16_Init(void)
- {
-
- RCC->APBENR2 |= RCC_APBENR2_TIM16EN;
-
- NVIC_SetPriority(TIM16_IRQn, 0);
- NVIC_EnableIRQ(TIM16_IRQn);
-
- TIM16->PSC = TIM16_PSC;
- TIM16->ARR = TIM16_ARR;
- TIM16->CR1 = TIM_CR1_ARPE;
-
-
-
- TIM16->CCMR1 = (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1PE);
-
- TIM16->SR |= TIM_SR_UIF;
- TIM16->BDTR = TIM_BDTR_MOE;
- TIM16->EGR = TIM_EGR_UG;
-
- TIM16->CCER = TIM_CCER_CC1E;
-
- TIM16->CR1 |= TIM_CR1_CEN;
-
- TIM16->DIER = TIM_DIER_UIE;
- }
- static void TIM17_Init(void)
- {
-
- RCC->APBENR2 |= RCC_APBENR2_TIM17EN;
-
- NVIC_SetPriority(TIM17_IRQn, 0);
- NVIC_EnableIRQ(TIM17_IRQn);
-
- TIM17->PSC = TIM17_PSC;
- TIM17->ARR = TIM17_ARR;
- TIM17->CR1 = TIM_CR1_ARPE;
-
-
-
- TIM17->CCMR1 = (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1PE);
-
- TIM17->SR |= TIM_SR_UIF;
- TIM17->BDTR = TIM_BDTR_MOE;
- TIM17->EGR = TIM_EGR_UG;
-
- TIM17->CCER = TIM_CCER_CC1E;
-
- TIM17->CR1 |= TIM_CR1_CEN;
-
- TIM17->DIER = TIM_DIER_UIE;
- }
- static void USART1_UART_Init(void)
- {
-
- RCC->APBENR2 |= RCC_APBENR2_USART1EN;
-
- GPIO_SetPinMode(GPIOB, GPIO_PIN_6, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(GPIOB, GPIO_PIN_6, GPIO_OSPEED_HI);
- GPIO_SetPinMode(GPIOB, GPIO_PIN_7, GPIO_MODE_AFF);
- GPIO_SetPinSpeed(GPIOB, GPIO_PIN_7, GPIO_OSPEED_HI);
-
- NVIC_SetPriority(USART1_IRQn, 0);
- NVIC_EnableIRQ(USART1_IRQn);
- USART1->CR1 |= (USART_CR1_TE |USART_CR1_RE);
- USART1->BRR = 138;
-
- USART1->CR1 |= USART_CR1_UE;
-
- while((!(USART1->ISR & USART_ISR_TEACK)) || (!(USART1->ISR & USART_ISR_REACK)))
- {
- }
- }
|