stm8s103f3 stm8s903k3 stm8s105s4 与这三款 单片机兼容的都可以生成代码 下面是用定时器1生成的定时1000us的程序:
#include
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
void delay_ms(uchar ms)
{
uchar i,j;
while(ms--)
{
for(i=4;i!=0;i--)
for(j=100;j!=0;j--);
}
}
void timer_Init(void)
{
TIM1_PSCRH = 0;
TIM1_PSCRL = 1; //(1+1)分频为1M
TIM1_ARRH = 0x3;
TIM1_ARRL = 0xE8; //每1000us中断一次
TIM1_IER = 0x01; //允许更新中断
TIM1_CR1 = 0x01; //计数器使能,开始计数
}
void main(void)
{
asm("sim"); //关总中断
timer_Init();
asm("rim"); //开总中断
while(1)
{
asm("nop");
}
}
#pragma vector = TIM1_OVR_UIF_vector
__interrupt void TIM1_OVR_UIF(void)
{
TIM1_SR1_UIF = 0;
//add your code here
}
最后感谢作者,所有权归作者所有!
7
|
|
|
|
很不错,又可以偷懒了
|
|
|
|
|
太强了呵呵
|
|
|
|
|