本帖最后由 Xflyan 于 2015-5-8 17:03 编辑
STM8默认CLK 是 2MHZ,你的中断周期相当于 1S,i == 61 才亮灯,相当于过1分钟才会亮..............
换这段代码试试
int main(void)
{
/* IO */
PD_DDR |= 0x04;
PD_CR1 |= 0x04;
PD_CR2 |= 0x04;
PD_ODR = 0x00;
/* TIM2 */
TIM2_PSCR = 0x06; /* 16MHZ / 8 / 64 = 31250HZ */
TIM2_ARRH = (unsigned char)(15625 >> 8);
TIM2_ARRH = (unsigned char)(15625);
TIM2_IER = 0x01;
TIM2_CR1 = 0x01;
_asm ("rim\n");
while (1) {
}
}
far interrupt void TIM2_UPD_OVF_IRQHandler (void)
{
PD_ODR ^= 0x04;
TIM2_SR1 = 0x00;
}
|