Код: Выделить всё
#include "stm32f10x.h"
uint16_t i;
void TIM13_IRQHandler(void){
if(((TIM13->SR & 0x1) != 0) & ((TIM13->DIER & 0x1) != 0)){
TIM13->SR &= ~0x1;
if(i < 1000){
i++;
} else {
i = 0;
}
TIM13->CCR1 = 0x384;
GPIOC->BSRR = 0x200;
}
}
int main(void){
//---------Setup Clock--------------------------------------------------------------
RCC->CR |= 0x10000; //enable HSE (16 bit)
while((RCC->CR & 0x20000) == 0) {} //wait till HSE is ready (17 bit)
RCC->CFGR &= ~0x73FFFFF; //clear CFGR bits (all not reserved bits)
RCC->CFGR |= 0x130000; //PLL source = PREDIV1 (16 bit)
//HSE / 2 = 4 MHz (17 bit)
//4 * 6 = 24 MHz (18 - 21 bits)
RCC->CR |= 0x1000000; //enable PLL (24 bit)
while((RCC->CR & 0x2000000) == 0) {} //wait till PLL is ready (25 bit)
RCC->CFGR &= ~0x3; //clear SW bits (0, 1 bits)
RCC->CFGR |= 0x2; //select PLL as system clock (1 bit)
while((RCC->CFGR & 0xC) != 0x8) {} //wait till PLL is used (2, 3 bits)
//------------------------------------------------
RCC->APB2ENR |= 0x11; //Clock port C and enable Alternate Functions
GPIOC->CRH |= 0xB; //Pin 8, Mode AF Push pull, 50 mHz
GPIOC->CRH |= 0x20; //Pin 9, Mode outPP, 2mHz
RCC->APB1ENR |= 0x80; //Clock TIMER13
TIM13->PSC = 0; //Prescaler
TIM13->CR1 = 0x80; //Count up, division - 0, Edge-aligned mode, Auto-reload preload enable
TIM13->ARR = 0x3E8; //Count do 1000;
TIM13->CCMR1 = 0x68; //Output Compare 1 preload enable, PWM mode 1
TIM13->CCR1 = 0x1; //1 - pulse duration
TIM13->CCER = 0x3; //Capture/Compare 1 output enable, polarity - OC1 active low
TIM13->DIER = 0x1; //Update interrupt enable
NVIC_EnableIRQ(TIM13_IRQn); //Allow interrupt for timer13
TIM13->CR1 |= 0x1; //Start timer
while(1){
__NOP();
}
}


