资深版主
 
- 积分
- 11476
- 金钱
- 11476
- 注册时间
- 2014-4-1
- 在线时间
- 1297 小时
|

楼主 |
发表于 2021-6-2 16:41:28
|
显示全部楼层
本帖最后由 xuande 于 2021-6-3 08:52 编辑
完整程序如下:
//Configure PB8 as output:
RCC -> AHB1ENR |= 1 << 1; //Enable clock of GPIOB.
GPIOB -> MODER &= ~( 0x3 << 16 ) ; //PB8 as AF mode.
GPIOB -> MODER |= 2 << 16;
GPIOB -> AFR[1] |= 3 << 0; //PB8 as AF3 (TIM10).
//Configure TIM10.
RCC -> APB2ENR |= ( 1 << 17 ); //Enable clock of TIM10.
TIM10 -> CCMR1 |= 6 << 4; //Ch1 as PWM mode 1 mode.
TIM10 -> CCER |= 1 << 0; //Ch1 output enabled.
TIM10 -> PSC = 83; //脉冲宽度为 1mS 。
TIM10 -> CCR1 = 2000;
//测试程序。
while (1)
{
TIM10 -> CNT = 0;
TIM10 -> CR1 |= 1 << 0; //启动定时器。
while ( !( TIM10 -> SR & ( 1 << 1 ) ) ); //等待脉冲结束。
TIM10 -> CR1 &= ~( 1 << 0 ); //Disable TIM10.
TIM10 -> SR &= ~( 3 << 1 ); //Clear flag.
for ( i=0; i<0x20000; i++ );
}
|
|