/******************************************************************************* * Function Name : BACKUP_IRQHandler * Description : This function handles BACKUP global interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void BACKUP_IRQHandler(void) { uint32_t tmp; vuint32_t i, j; if (BKP_RTC_GetFlagStatus(BKP_RTC_FLAG_ALRF) == SET) { if (STOPModeStatus) { /* Wake-up from STOP mode is handled by an RTC Alarm */ /* Disable SLEEPONEXIT mode */ tmp = SCB->SCR; tmp &= ~SCB_SCR_SLEEPONEXIT_Msk; SCB->SCR = tmp; STOPModeStatus = 0; } else /* RTC Alarm handling */ if (AlarmSetStatus) { for (i = 0; i < 5; i++) { PORT_SetBits(LEDs_PORT, LEDs_PINs); for (j = 0; j < 300000; j++) { } PORT_ResetBits(LEDs_PORT, LEDs_PINs); for (j = 0; j < 300000; j++) { } } } } if (BKP_RTC_GetFlagStatus(BKP_RTC_FLAG_SECF) == SET) { BKP_RTC_ITConfig(BKP_RTC_IT_SECF, DISABLE); /* If counter is equal to 86339: one day was elapsed */ tmp = BKP_RTC_GetCounter(); if ((tmp / 3600 == 23) && (((tmp % 3600) / 60) == 59) && (((tmp % 3600) % 60) == 59)) { /* Wait until last write operation on RTC registers has finished */ BKP_RTC_WaitForUpdate(); /* Reset counter value */ BKP_RTC_SetCounter(0); /* Wait until last write operation on RTC registers has finished */ BKP_RTC_WaitForUpdate(); /* Increment the date */ Date_Update(); } BKP_RTC_ITConfig(BKP_RTC_IT_SECF, ENABLE); } }
//================================================================================== void LoadLED_Reg(uint8_t R1,uint8_t anod) { uint8_t R0; REG_EN; for(R0=0;R0<8;++R0) { if(R1 & 1) PORT_SetBits(MDR_PORTB, PORT_Pin_10); else PORT_ResetBits(MDR_PORTB, PORT_Pin_10); R1 >>= 1; PORT_ResetBits(MDR_PORTB, PORT_Pin_8); __nop(); __nop(); PORT_SetBits(MDR_PORTB, PORT_Pin_8); } R1=1<<anod; for(R0=0;R0<8;++R0) { if(R1 & 1) PORT_ResetBits(MDR_PORTB, PORT_Pin_10); else PORT_SetBits(MDR_PORTB, PORT_Pin_10); R1 >>= 1; PORT_ResetBits(MDR_PORTB, PORT_Pin_8); __nop(); __nop(); PORT_SetBits(MDR_PORTB, PORT_Pin_8); } REG_DIS; }
/** * @brief Turns selected LED Off. * @param LED_Num: Specifies the Led to be set off. * This parameter can be one of following parameters: * @arg LED1 * @arg LED2 * @retval None */ void LEDOff(uint32_t LED_Num) { PORT_ResetBits(MDR_PORTD, LED_Num); }
void prvSetupHardware( void ) { PORT_InitTypeDef PORT_InitStructure; UART_InitTypeDef UART_InitStructure; //SSP_InitTypeDef SPI_InitStructure; TIMER_CntInitTypeDef sTIM_CntInit; // TIMER_ChnInitTypeDef sTIM_ChnInit; //CLK /* Enable HSE clock oscillator */ RST_CLK_HSEconfig(RST_CLK_HSE_ON); while(RST_CLK_HSEstatus() == ERROR); RST_CLK_CPUclkSelection(RST_CLK_CPUclkCPU_C3); MDR_RST_CLK -> CPU_CLOCK |= 2;//CPU_C1 set HSE RST_CLK_HSIcmd(DISABLE); /* Enable the RTCHSE clock on all ports */ RST_CLK_PCLKcmd(ALL_PORTS_CLK, ENABLE); PORT_StructInit(&PORT_InitStructure);//reset struct /************************ LCD Initialization *************************/ /* Configure PORTA pins for data transfer to/from LCD */ PORT_InitStructure.PORT_Pin = LCD_DATA_BUS_8; PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_Init(MDR_PORTA, &PORT_InitStructure); /* Configure PORTE pin4 and pin5 for LCD crystals control */ PORT_InitStructure.PORT_Pin = KS0108_CS1 | KS0108_CS2 | KS0108_RS; PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_Init(MDR_PORTE, &PORT_InitStructure); PORT_Init(MDR_PORTE, &PORT_InitStructure); PORT_InitStructure.PORT_Pin = KS0108_EN | KS0108_RW | KS0108_RES; PORT_Init(MDR_PORTC, &PORT_InitStructure); PORT_SetBits(MDR_PORTA, LCD_DATA_BUS_8); PORT_SetBits(MDR_PORTE, KS0108_CS1 | KS0108_CS2 | KS0108_RS); PORT_SetBits(MDR_PORTC, KS0108_EN | KS0108_RW | KS0108_RES); //Timer1 // TIMER1 RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER1,ENABLE); /* Reset all TIMER1 settings */ TIMER_DeInit(MDR_TIMER1); TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1); /* TIM1 configuration ------------------------------------------------*/ /* Initializes the TIMERx Counter ------------------------------------*/ sTIM_CntInit.TIMER_IniCounter = 0; sTIM_CntInit.TIMER_Prescaler = 150;// sTIM_CntInit.TIMER_Period = 82; sTIM_CntInit.TIMER_CounterMode = TIMER_CntMode_ClkFixedDir; sTIM_CntInit.TIMER_CounterDirection = TIMER_CntDir_Up; sTIM_CntInit.TIMER_EventSource = TIMER_EvSrc_None; sTIM_CntInit.TIMER_FilterSampling = TIMER_FDTS_TIMER_CLK_div_1; sTIM_CntInit.TIMER_ARR_UpdateMode = TIMER_ARR_Update_Immediately; sTIM_CntInit.TIMER_ETR_FilterConf = TIMER_Filter_1FF_at_TIMER_CLK; sTIM_CntInit.TIMER_ETR_Prescaler = TIMER_ETR_Prescaler_None; sTIM_CntInit.TIMER_ETR_Polarity = TIMER_ETRPolarity_NonInverted; sTIM_CntInit.TIMER_BRK_Polarity = TIMER_BRKPolarity_NonInverted; TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit); NVIC_EnableIRQ(Timer1_IRQn); TIMER_ITConfig(MDR_TIMER1,TIMER_STATUS_CNT_ARR, ENABLE); /* TMR1 enable */ TIMER_Cmd (MDR_TIMER1,ENABLE); // TIMER2 RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER2,ENABLE); /* Reset all TIMER1 settings */ TIMER_DeInit(MDR_TIMER2); TIMER_BRGInit(MDR_TIMER2,TIMER_HCLKdiv1); /* TIM2 configuration ------------------------------------------------*/ /* Initializes the TIMERx Counter ------------------------------------*/ sTIM_CntInit.TIMER_IniCounter = 0; sTIM_CntInit.TIMER_Prescaler = 0xf;// sTIM_CntInit.TIMER_Period = 0xffff; sTIM_CntInit.TIMER_CounterMode = TIMER_CntMode_ClkFixedDir; sTIM_CntInit.TIMER_CounterDirection = TIMER_CntDir_Up; sTIM_CntInit.TIMER_EventSource = TIMER_EvSrc_None; sTIM_CntInit.TIMER_FilterSampling = TIMER_FDTS_TIMER_CLK_div_1; sTIM_CntInit.TIMER_ARR_UpdateMode = TIMER_ARR_Update_Immediately; sTIM_CntInit.TIMER_ETR_FilterConf = TIMER_Filter_1FF_at_TIMER_CLK; sTIM_CntInit.TIMER_ETR_Prescaler = TIMER_ETR_Prescaler_None; sTIM_CntInit.TIMER_ETR_Polarity = TIMER_ETRPolarity_NonInverted; sTIM_CntInit.TIMER_BRK_Polarity = TIMER_BRKPolarity_NonInverted; TIMER_CntInit (MDR_TIMER2,&sTIM_CntInit); NVIC_EnableIRQ(Timer2_IRQn); TIMER_ITConfig(MDR_TIMER2,TIMER_STATUS_CNT_ARR, ENABLE); /* TMR2 enable */ TIMER_Cmd (MDR_TIMER2,ENABLE); // TIMER3 RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER3,ENABLE); /* Reset all TIMER3 settings */ TIMER_DeInit(MDR_TIMER3); TIMER_BRGInit(MDR_TIMER3,TIMER_HCLKdiv1); /* TIM3 configuration ------------------------------------------------*/ /* Initializes the TIMERx Counter ------------------------------------*/ sTIM_CntInit.TIMER_IniCounter = 0; sTIM_CntInit.TIMER_Prescaler = 0; sTIM_CntInit.TIMER_Period = 0xFFFF; sTIM_CntInit.TIMER_CounterMode = TIMER_CntMode_EvtFixedDir; sTIM_CntInit.TIMER_CounterDirection = TIMER_CntDir_Up; sTIM_CntInit.TIMER_EventSource = TIMER_EvSrc_CH1; sTIM_CntInit.TIMER_FilterSampling = TIMER_FDTS_TIMER_CLK_div_1; sTIM_CntInit.TIMER_ARR_UpdateMode = TIMER_ARR_Update_Immediately; sTIM_CntInit.TIMER_ETR_FilterConf = TIMER_Filter_1FF_at_TIMER_CLK; sTIM_CntInit.TIMER_ETR_Prescaler = TIMER_ETR_Prescaler_None; sTIM_CntInit.TIMER_ETR_Polarity = TIMER_ETRPolarity_NonInverted; sTIM_CntInit.TIMER_BRK_Polarity = TIMER_BRKPolarity_NonInverted; TIMER_CntInit (MDR_TIMER3,&sTIM_CntInit); // NVIC_EnableIRQ(Timer3_IRQn); // TIMER_ITConfig(MDR_TIMER3,TIMER_STATUS_CNT_ARR, ENABLE); /* Enable TIMER3 */ TIMER_Cmd(MDR_TIMER3,ENABLE); /************************ UART1 Initialization *************************/ PORT_StructInit(&PORT_InitStructure);//reset struct PORT_InitStructure.PORT_Pin = PORT_Pin_12|PORT_Pin_13;//RX TX PORT_InitStructure.PORT_FUNC = PORT_FUNC_OVERRID; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW; PORT_Init(MDR_PORTE, &PORT_InitStructure); PORT_InitStructure.PORT_Pin = PORT_Pin_14;//EN RS485 PORT_InitStructure.PORT_OE =PORT_OE_OUT; PORT_InitStructure.PORT_PD = PORT_PD_OPEN; PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_Init(MDR_PORTE, &PORT_InitStructure); RS485_TX_OFF; //UART1 RST_CLK_PCLKcmd(RST_CLK_PCLK_UART1,ENABLE); /* Set the HCLK division factor = 1 for UART1,UART2*/ UART_BRGInit(MDR_UART1, UART_HCLKdiv1); UART_DeInit(MDR_UART1); /* Disable interrupt on UART1 */ NVIC_DisableIRQ(UART1_IRQn); /* Initialize UART_InitStructure */ UART_InitStructure.UART_BaudRate = 38400; UART_InitStructure.UART_WordLength = UART_WordLength8b; UART_InitStructure.UART_StopBits = UART_StopBits1;//PKDU2 niobyi UART_InitStructure.UART_Parity = UART_Parity_No; UART_InitStructure.UART_FIFOMode = UART_FIFO_OFF; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RXE | UART_HardwareFlowControl_TXE; /* Configure UART1 parameters*/ UART_Init(MDR_UART1,&UART_InitStructure); NVIC_EnableIRQ(UART1_IRQn); UART_ITConfig(MDR_UART1,UART_IT_RX, ENABLE); /* Enables UART1 peripheral */ UART_Cmd(MDR_UART1,ENABLE); //PORT /************************ Joystick Initialization *************************/ /* Configure PORTC pins 10..14 for input to handle joystick events */ PORT_StructInit(&PORT_InitStructure);//reset struct PORT_InitStructure.PORT_Pin = ( PORT_Pin_10 | PORT_Pin_11 | PORT_Pin_12 | PORT_Pin_13 | PORT_Pin_14 ); PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_InitStructure.PORT_SPEED = PORT_OUTPUT_OFF; PORT_Init( MDR_PORTC, &PORT_InitStructure ); /************************ LEDs Initialization *************************/ PORT_StructInit( &PORT_InitStructure );//reset struct /* Configure PORTD pins 10..14 for output to switch LEDs on/off */ PORT_InitStructure.PORT_Pin = LEDs_PINs; PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW; PORT_Init( MDR_PORTD, &PORT_InitStructure ); /* All LEDs switch off */ PORT_ResetBits(MDR_PORTD, LEDs_PINs); }
//==============================================================// // Select LCD (LCD0, LCD1) // Hardware-specific function //==============================================================// void LcdSelect(uint8_t lcd) { (lcd==LCD0) ? PORT_SetBits(MDR_PORTE, 1<<LCD_SEL) : PORT_ResetBits(MDR_PORTE, 1<<LCD_SEL); LcdDelayUs(20); }
/******************************************************************************* * Function Name : Demo_Init * Description : Initializes the demonstration application * Input : None * Output : None * Return : None *******************************************************************************/ void Demo_Init(void) { ClockConfigure(); /************************ LCD Initialization *************************/ /* Configure LCD_DATA_PORT for data transfer to/from LCD */ PortInitStructure.PORT_Pin = LCD_DATA_BAS_8_0; PortInitStructure.PORT_FUNC = PORT_FUNC_PORT; PortInitStructure.PORT_OE = PORT_OE_IN; PortInitStructure.PORT_SPEED = PORT_SPEED_SLOW; PortInitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_Init(LCD_DATA_PORT_0, &PortInitStructure); PortInitStructure.PORT_Pin = LCD_DATA_BAS_8_1; PORT_Init(LCD_DATA_PORT_1, &PortInitStructure); /* Configure LCD_RD_WR_PORT for read/write control */ /* Switch LCD into data output mode */ PORT_SetBits(LCD_RD_WR_PORT, LCD_RD_WR_PIN); PortInitStructure.PORT_Pin = LCD_RD_WR_PIN; PortInitStructure.PORT_OE = PORT_OE_OUT; PORT_Init(LCD_RD_WR_PORT, &PortInitStructure); /* Configure LCD_CLOCK_PORT for CLOCK signal control*/ /* Set LCD CLOCK signal to its initial value (0) */ PORT_ResetBits(LCD_CLOCK_PORT, LCD_CLOCK_PIN); PortInitStructure.PORT_Pin = LCD_CLOCK_PIN; PortInitStructure.PORT_SPEED = PORT_SPEED_FAST; PORT_Init(LCD_CLOCK_PORT, &PortInitStructure); /* Configure LCD_CRYSTAL_PORT for LCD crystal control */ /* De-select both LCD crystals*/ PORT_ResetBits(LCD_CRYSTAL_PORT, LCD_CRYSTAL_PINs); PortInitStructure.PORT_Pin = LCD_CRYSTAL_PINs; PortInitStructure.PORT_SPEED = PORT_SPEED_SLOW; PORT_Init(LCD_CRYSTAL_PORT, &PortInitStructure); /* Configure LCD_CMD_DATA_PORT for data/command mode switching */ PortInitStructure.PORT_Pin = LCD_CMD_DATA_PIN; PORT_Init(LCD_CMD_DATA_PORT, &PortInitStructure); /* Configure LCD_RESET_PORT for RESET signal control */ /* Zeroing LCD RES signal (initial state) */ PORT_ResetBits(LCD_RESET_PORT, LCD_RESET_PIN); PortInitStructure.PORT_Pin = LCD_RESET_PIN; PortInitStructure.PORT_SPEED = PORT_SPEED_FAST; PORT_Init(LCD_RESET_PORT, &PortInitStructure); LCD_INIT(); /************************ Joystick Initialization *************************/ /* Configure SEL_PORT for input to handle joystick event SEL */ PortInitStructure.PORT_Pin = SEL_PIN; PortInitStructure.PORT_OE = PORT_OE_IN; PortInitStructure.PORT_FUNC = PORT_FUNC_PORT; PortInitStructure.PORT_SPEED = PORT_SPEED_SLOW; PORT_Init(SEL_PORT, &PortInitStructure); /* Configure UP_PORT for input to handle joystick event UP */ PortInitStructure.PORT_Pin = UP_PIN; PORT_Init(UP_PORT, &PortInitStructure); /* Configure DOWN_PORT for input to handle joystick event DOWN */ PortInitStructure.PORT_Pin = DOWN_PIN; PORT_Init(DOWN_PORT, &PortInitStructure); /* Configure LEFT_PORT for input to handle joystick event LEFT */ PortInitStructure.PORT_Pin = LEFT_PIN; PORT_Init(LEFT_PORT, &PortInitStructure); /* Configure RIGHT_PORT for input to handle joystick event RIGHT */ PortInitStructure.PORT_Pin = RIGHT_PIN; PORT_Init(RIGHT_PORT, &PortInitStructure); /************************ LEDs Initialization *************************/ /* Configure LEDs_PORT for output to switch LEDs on/off */ PortInitStructure.PORT_Pin = LEDs_PINs; PortInitStructure.PORT_OE = PORT_OE_OUT; PortInitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_Init(LEDs_PORT, &PortInitStructure); /* All LEDs switch off */ PORT_ResetBits(LEDs_PORT, LEDs_PINs); }