Timer-INT in C für das MM32 Board Light
//---------------------------------------------------------------------- // MM32 example Timer INT // MM32L073 // LED = B0 //---------------------------------------------------------------------- #include <stddef.h> #include <stdlib.h> #include "hardware.h" void initApplication() { // System timer initialization SysTick_Config(SystemCoreClock/100); // Enable GPIOB clock RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); // Configure PB0 GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); // Enable TIM16 clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE); // Timer configuration TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure; TIM_TimeBase_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBase_InitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBase_InitStructure.TIM_Period = 4800; TIM_TimeBase_InitStructure.TIM_Prescaler = 10000; TIM_TimeBaseInit(TIM16, &TIM_TimeBase_InitStructure); TIM_ITConfig(TIM16, TIM_IT_Update, ENABLE); // Enable timer TIM_Cmd(TIM16, ENABLE); // NVIC configuration NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM16_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03; NVIC_Init(&NVIC_InitStructure); } int main(void) { SystemInit(); initApplication(); while(1) { // Empty main loop } } void SysTick_Handler(void) { // Empty SysTick handler } void TIM16_IRQHandler(void) { static bool state=false; if (state) GPIO_ResetBits(GPIOB, GPIO_Pin_0); else GPIO_SetBits(GPIOB, GPIO_Pin_0); state=!state; TIM_ClearITPendingBit(TIM16, TIM_IT_Update); } //-----------------------------------------------------------------------------
Test
Nutzen sie die Schaltflächen Kompilieren, Linken und Brennen. Stellen Sie die nötigen Verbindungen auf dem Board mit den dafür vorgesehenen Patchkabeln her. Testen Sie die Anwendung.