本帖最后由 zhseedling 于 2012-4-3 23:19 编辑
芯片是STM8S208RB,STVD+Cosmic专门写了个程序来测试。
问题是在定时器1的捕获比较中断中关不了总中断。
下面是测试过程。
#include "stm8s208rb.h"
void delay(unsigned int t);
unsigned int captureValue = 0,numberOfCapture = 0;
main()
{
/* CC1通道被配置为输入,IC1映射在TI1FP1上 */
TIM1_CCMR1 |= 0x01;
/* IC1PSC[1:0]被配置为11,即8分频 */
TIM1_CCMR1 |= (0x03 << 2);
/* 开捕获1中断 */
TIM1_IER |= 0x02;
/* 定时器开始计数 */
TIM1_CR1 |= 0x01;
/* 捕获使能 */
TIM1_CCER1 |= 0x01;
_asm("rim");
/* 时钟输出为fLSI */
CLK_CCOR |= 0x02;
/* 开启CCO时钟输出 */
CLK_CCOR |= 0x01;
while (1)
{
delay(100);
delay(100);
}
}
void delay(unsigned int t)
{
while(t--);
}
@far @interrupt void TIM1CC_IRQ(void)
{
// _asm("sim");
captureValue = (unsigned int)TIM1_CCR1H << 8;
captureValue |= TIM1_CCR1L;
numberOfCapture++;
}
接下来是仿真的图片
当跳出定时器函数的时候,总中断自动开了
然后我注释掉了关中断这条
结果进入中断服务程序总中断自动关闭了
然后又自动打开了。
当然,这也符合同时发生模式,可是这种实现方式也太低级了吧,出中断的时候打开中断。
下面是中断服务程序的汇编代码
main.c:39
_asm("sim");
0x8116 <TIM1CC_IRQ> 0x9B SIM SIM
main.c:40
captureValue = (unsigned int)TIM1_CCR1H << 8;
0x8117 <TIM1CC_IRQ+1> 0xC65265 LD A,0x5265 LD A,_TIM1_CCR1H
0x811a <TIM1CC_IRQ+4> 0x5F CLRW X CLRW X
0x811b <TIM1CC_IRQ+5> 0x97 LD XL,A LD XL,A
0x811c <TIM1CC_IRQ+6> 0x4F CLR A CLR A
0x811d <TIM1CC_IRQ+7> 0x02 RLWA X,A RLWA X,A
0x811e <TIM1CC_IRQ+8> 0xBF00 LDW 0x00,X LDW captureValue,X
main.c:41
captureValue |= TIM1_CCR1L;
0x8120 <TIM1CC_IRQ+10> 0xC65266 LD A,0x5266 LD A,_TIM1_CCR1L
0x8123 <TIM1CC_IRQ+13> 0x5F CLRW X CLRW X
0x8124 <TIM1CC_IRQ+14> 0x97 LD XL,A LD XL,A
0x8125 <TIM1CC_IRQ+15> 0x01 RRWA X,A RRWA X,A
0x8126 <TIM1CC_IRQ+16> 0xBA01 OR A,0x01 OR A,captureValue+1
0x8128 <TIM1CC_IRQ+18> 0x01 RRWA X,A RRWA X,A
0x8129 <TIM1CC_IRQ+19> 0xBA00 OR A,0x00 OR A,captureValue
0x812b <TIM1CC_IRQ+21> 0x01 RRWA X,A RRWA X,A
0x812c <TIM1CC_IRQ+22> 0xBF00 LDW 0x00,X LDW captureValue,X
main.c:42
numberOfCapture++;
0x812e <TIM1CC_IRQ+24> 0xBE02 LDW X,0x02 LDW X,numberOfCapture
0x8130 <TIM1CC_IRQ+26> 0x1C0001 ADDW X,#0x0001 ADDW X,#0x0001
0x8133 <TIM1CC_IRQ+29> 0xBF02 LDW 0x02,X LDW numberOfCapture,X
main.c:44
}
0x8135 <TIM1CC_IRQ+31> 0x80 IRET IRET |