#include <STM8L151K4.h>
static unsigned short s_Cnt = 10000;
_Bool LED @PB_ODR:4;
_Bool LED1 @PB_ODR:3;
void PortInit(void)
{
PB_CR1 = (1<<4)|(1<<3);
PB_CR2 &= ~((1<<4)|(1<<3));
PB_DDR = (1<<4)|(1<<3);
LED = 1;
LED1 = 0;
}
void Timer1Init(void)
{
TIM1_IER = 0x00;
TIM1_CR1 = (1<<7); //自动重载使能
TIM1_EGR = 0x01; //产生更新事件
TIM1_PSCRH = 0x1F; //分频
TIM1_PSCRL = 0x3F;
TIM1_ARRH = 0x00; //最大限度
TIM1_ARRL = 0x00;
TIM1_CR1 |=0x01; //使能计数
TIM1_IER = 0x01; //
}
@far @interrupt void Timer1OverISR(void) //0.5ms
{
TIM1_SR1 = 0x00;
LED1 = ~LED1;
if (s_Cnt != 0)
{
s_Cnt--;
}
}
main(void)
{
static unsigned char num = 0;
_asm("sim");
PortInit();
CLK_CKDIVR = 0x00; //不分频
CLK_ICKCR = (1<<0) | (1<<4);
while ((CLK_ICKCR&(1<<1)) == 0);
CLK_PCKENR1 = 0xFF;
CLK_PCKENR2 = 0x3F;
//CLK_ICKCR |= (1<<2);
//while ((CLK_ICKCR&(1<<3)) == 0);
_asm("rim");
while(1)
{
switch (num)
{
case 0:
num++;
s_Cnt = 10000;
LED = 0;
TIM1_IER = 0x00;
//TIM1_CR1 = (1<<7); //自动重载使能
TIM1_EGR = 0x01; //产生更新事件
TIM1_PSCRH = 0x00; //
TIM1_PSCRL = 0x00;
TIM1_ARRH = 0x1F; //最大限度
TIM1_ARRL = 0x40;
TIM1_CR1 |=0x01; //使能计数
TIM1_IER = 0x01; //
break;
case 1:
if (s_Cnt == 0)
{
num = 2;
}
break;
case 2:
num++;
s_Cnt = 52000;
TIM1_IER = 0x00;
//TIM1_CR1 = (1<<7); //自动重载使能
TIM1_EGR = 0x01; //产生更新事件
TIM1_PSCRH = 0x00; //分频
TIM1_PSCRL = 0x00;
TIM1_ARRH = 0x00; //最大限度
TIM1_ARRL = 10;
TIM1_CR1 |=0x01; //使能计数
TIM1_IER = 0x01;
break;
case 3:
LED = 1;
if (s_Cnt == 0)
{
num = 0;
}
break;
}
}
} |