#include "stm32f4xx.h" #include "LCD2x16.c" void main (void){ RCC->AHB1ENR |= 0x01 + 0x10; // Clock for PortA, E RCC->APB1ENR |= 0x01; // Clock for Timer2 LCD_init(); // init LCD GPIOA->MODER |= 0x00000008; // all inputs but: PA1 => AF mode GPIOA->AFR[0] |= 0x00000010; // select AF1 (TIM2) for PA01 -> TIM2_CH2 LCD_string("Timer2:", 0x00); // display title string TIM2->CCMR1 |= 0x0100; // Ch. 2 as TI2 TIM2->SMCR |= 0x0007; // Ext. clk mode 1 TIM2->SMCR |= 0x0060; // TI2FP2 as ext. clock TIM2->CR1 |= 0x0001; // enable counting while (1) { LCD_uInt32(TIM2->CNT,0x40,1); // write position to LCD for (int i = 0; i<100000; i++) {}; // waste some time if (GPIOE->IDR & 0x01) TIM2->CNT = 0; // reset counter if (GPIOE->IDR & 0x02) TIM2->CR1 |= 0x01; // enable counter if (GPIOE->IDR & 0x04) TIM2->CR1 &= ~0x01; // disable counter }; }