智能车制作

标题: 很简单的定时器中断问题,就是搞不出来,不知道哪里错了 [打印本页]

作者: justing88    时间: 2009-11-5 22:24
标题: 很简单的定时器中断问题,就是搞不出来,不知道哪里错了
本帖最后由 chenrunshe_007 于 2010-1-13 17:50 编辑

在最终程序调试窗口中可以发现:中断时可以进去的,m的数值也是可以加上去的,但是就是感觉中断中的if语句不做。而且B寄存器当中的数值一直是在FF和55这两个数值之间变化。。。不知道是什么原因。还望过路人热心解答。
  1. #include <hidef.h>      /* common defines and macros */
  2. #include "derivative.h"      /* derivative-specific definitions */

  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. uchar Pulsecnt;
  6. uchar  m=0;   

  7. #pragma CODE_SEG NON_BANKED

  8. interrupt 16 void Time_Over(void)
  9. {
  10.   m++;                               //进入一次中断,m加一
  11.   if(m==5)                          //进入5次,则
  12.   {
  13.     DDRB=0XFF;
  14.     Pulsecnt=~Pulsecnt;   //进入后,B口取反
  15.     PORTB=Pulsecnt;
  16.     m=0;
  17.   }
  18.   TFLG2_TOF=1;         //每次都将标志位清零
  19. }
  20.   
  21. #pragma CODE_SEG DEFAULT

  22. void main(void)
  23. {
  24.   /* put your own code here */  
  25.    EnableInterrupts;
  26.    TIOS=0x00;                       //设置输入的通道工作为输入捕捉
  27.    TSCR2=0x87;                     //设置定时器溢出中断,并且分频系数为128
  28.    TIE=0x01;                          //允许中断
  29.    TFLG2_TOF=1;                   //定时器溢出中断标志位清零
  30.    TCNT=65535-30000;         //设置初始值
  31.    TSCR1_TEN=1;                  //开定时器
  32.    Pulsecnt=0xF0;                 //设置变量为0xf0,最终输出给B口
  33.    DDRB=0XFF;                   //设置B口为输出方式
  34.    PORTB=Pulsecnt;        //设置初始值B

  35.   for(;;)
  36. {
  37.      _FEED_COP(); /* feeds the dog */
  38. } /* loop forever */
  39.    /* please make sure that you never leave main */
  40. }
复制代码

作者: 50833713    时间: 2009-11-6 10:15
提示: 作者被禁止或删除 内容自动屏蔽
作者: justing88    时间: 2009-11-7 12:26
现在已经成功了,谢谢提醒啊!!错在一个很变态的处理上面
作者: chenrunshe_007    时间: 2009-11-16 17:20
现在已经成功了,谢谢提醒啊!!错在一个很变态的处理上面
justing88 发表于 2009-11-7 12:26

形容得有点说的有点wretched
作者: chenrunshe_007    时间: 2009-11-16 17:21
编辑过看起来就是爽
作者: justing88    时间: 2010-1-13 15:05
回复 5# chenrunshe_007


    谢谢啊!今后都编辑了!!最近有重新开始了…………哈哈
作者: lfllcy    时间: 2010-3-16 23:46
谢谢分享经验!




欢迎光临 智能车制作 (http://111.231.132.190/) Powered by Discuz! X3.2