#include<iostm8s103k3.h>
#include <intrinsics.h>
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
void delay(u16 n)
{
u16 i,j;
while(n --)
{
for(i = 0;i < 32;i ++)
for(j = 0;j < 10;j ++);
}
}
void Clk_Config(void)
{
CLK_CKDIVR= 0x00; //系统时钟1 分频
while(!(CLK_ICKR & 0x02)); //等待HSI 准备好
}
void Io_Config(void)
{
PD_DDR |= 0x10; //PD4 设置为输出
PD_CR1 |= 0x10; //推挽输出
PD_CR2 &= ~0x10; //输出高电平
}
void Tim4_Init(void)
{
TIM4_PSCR = 6; //64 分频得到250KHZ 的定时器时钟,
定时器加1 就是4us
TIM4_ARR = 0xfa; //1ms 中断一次
TIM4_IER_UIE = 1; //更新中断使能
TIM4_CR1_ARPE = 1; //预装载使能
TIM4_CR1_CEN = 1; //启动计数器
}
int main( void )
{
Clk_Config();
Io_Config();
Tim4_Init();
__enable_interrupt();
while(1){}
}
#pragma vector = TIM4_OVR_UIF_vector
__interrupt __root void TIM4_UIF_HANDLER(void)
{
static u16 i;
i++;
if(i == 1000)
{
i = 0;
PD_ODR_ODR4=~PD_ODR_ODR4;
} TIM4_SR_UIF =0;
}
注意
Error[Li006]: duplicate definitions for "_interrupt_25"; in "C:\Users\ibm-thinkpad\Desktop\stotem\Debug\Obj\main.o", and
"C:\Users\ibm-thinkpad\Desktop\stotem\Debug\Obj\stm8s_it.o"
大师们解惑下啊
|