搜索
bottom↓
回复: 12

PIC PICC 的奇怪问题

[复制链接]

出0入22汤圆

发表于 2010-9-19 17:28:50 | 显示全部楼层 |阅读模式
今天发现一个奇怪的问题。
使用PIC16F722  这个IC出来没多久 ,需要使用PICC 9.65的编译器。

程序用SIM仿真发现总是在中断中跑,于是我关了GIE 同时查看特殊功能寄存器,发现不可能进中断,

在中断中通过判断标准位
进了这个
if(TMR2IE&TMR2IF)// PWM TIME INT    CHANGE DUTY
      {TMR2IF=0;
       TMR2IE=0;
         CCPR2L=PWM_duty;
      }

可是这个怎么可能一直在中断中跑。

还有哪位知道Startup.as这个文件有没有必要要。怎么去掉。我非常的怀疑是它在搞鬼

同事也怀疑编译器的问题 。

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2010-9-19 19:14:09 | 显示全部楼层
PWM中断模式下的中断标志位是楼主写的那个吗?

出0入22汤圆

 楼主| 发表于 2010-9-20 09:18:44 | 显示全部楼层
楼上的 ,即使不是也不会出现这样的现象。


后来调试发现 问题出在这里


T0CS=0;

这个东西无论你以什么方式置0 都会出现问题。不操作这一位就正常了。

出0入0汤圆

发表于 2010-9-20 09:38:12 | 显示全部楼层
"后来调试发现 问题出在这里 "

this example demonstrates two things:

1) what you think is wrong may not be wrong: you were adamant about the problem being in the isr when in fact it is somewhere else. it brings to question a) your approach / thought process; and b) your credibility.
2) many times, you have to help others help you. in this case, posting your complete code would have been helpful.

"这个东西无论你以什么方式置0 都会出现问题。不操作这一位就正常了。"

maybe you should look into the datasheet to see what it does and what its default (POR/Reset) values are and see if that's consistent with what you want to do.

programming is not a trial-and-error process, unless you want to remain clueless.

出0入22汤圆

 楼主| 发表于 2010-9-20 10:04:53 | 显示全部楼层
楼上 。哈哈  我英文不是很好 。


通过注释发现 TOCS 不能置1,。
该位复位是1,TO做外部计数器,现在我需要做定时器,不然我也不会去管他。


DATASHEET上没有关于这位操作的特别说明,以前也用过很多次,都没有发现问题 ,

我不敢坚信是编译器的问题,但是现在通过了解,我无法找到别的地方的问题。


另有谁知道这段代码是什么含义,


PICC的启动文件中的 。

; jump to start
        movlw        start >>8
        movwf        PCLATH
        goto        start & 0x7FF | (reset_vec & not 0x7FF)



        psect        init
start
_exit

出0入22汤圆

 楼主| 发表于 2010-9-20 11:58:39 | 显示全部楼层
还是不死心 ,重新开了个项目,很简单的 。

#include "Main_heard.h"

void main(void)
{
//T0IF=0;
  T0IE=1;//open int  need alawys open
  PSA=0; PS1=0;  PS0=0;
  T0CS=0;
TMR0=0;
  
PEIE=1;
GIE=1;
while(1);
}


/****************ISR******************************/
static void interrupt ISR(void)                        // Here be interrupt function - the name is unimportant.
{
  if(T0IE&T0IF)// SYSTEMTICK 4.096MS int  need scan led an count or decount
       {T0IF=0;

         }

if(RBIE&RBIF)//partB int need scan key
        {RBIF=0;

         }

if(TMR1GIE&TMR1GIF)//ccp INT  read perid
        {TMR1GIF=0;

        }

if(TMR2IE&TMR2IF)// PWM TIME INT    CHANGE DUTY
      {TMR2IE=0;
      //
      }

}

以上为全部源代码 。


发现只要T0溢出,以后怎么搞都逛if(TMR2IE&TMR2IF)// .


实在是很郁闷。

怎么会出这样的事呢 ?

出0入0汤圆

发表于 2010-9-20 12:17:44 | 显示全部楼层
试试把 & 改成 &&

出0入22汤圆

 楼主| 发表于 2010-9-20 12:51:37 | 显示全部楼层
楼上正解。



请问,为什么会这样。

难道是将TMR2IE所在的寄存器(8BIT)全部和另外一个的一起做按位于,

可是在以前的编译器中基本所有都是&。

出0入0汤圆

发表于 2010-9-21 00:25:53 | 显示全部楼层
可能这个编译器要求严格一些吧,不要太在意这些,另,写程序最好正规些,可以少走弯路,呵呵

出0入0汤圆

发表于 2010-9-21 00:42:40 | 显示全部楼层
"发现只要T0溢出,以后怎么搞都逛if(TMR2IE&TMR2IF)// .
     {TMR2IE=0; "

because you turned on PEIE, which made TMR2IE possible (which could have been accidentally set) and tmr2 starts to run so you go into it from time to time.

to try it, you can explicitly clear TMR2IE.

another mistake you made is that you never cleared TMR2IF so the isr is stuck processing TMR2 overflow. what you should have done is to clear TMR2IF in the isr, not TMR2IE.

出0入0汤圆

发表于 2010-9-21 06:43:07 | 显示全部楼层
I ran the following code:

========code=========

#include <htc.h>
//#include "Main_heard.h"
#include "gpio.h"

__CONFIG(BORDIS & MCLRDIS & PWRTDIS & WDTDIS & HS & LVPDIS);
__CONFIG(IESODIS & FCMDIS & DEBUGDIS & BORV21);

#define LED_PORT                        PORTC                        //led indicators on portc
#define LED_DDR                                TRISC
#define LED_TMR0                        (1<<0)                        //flip'd if tmr0 interrupt is serviced
#define LED_TMR1                        (1<<1)                        //flip'd if tmr1 interrupt is serviced
#define LED_TMR2                        (1<<2)                        //flip'd if tmr2 interrupt is serviced
void main(void) {

        ANSEL=0x00;                                                                //all pins gpio
        ANSELH=0x00;
        IRCF2=1, IRCF1=1, IRCF0=0;                                //running at 4mhz
        //T0IF=0;
        T0IE=1;//open int  need alawys open  
        PSA=0; PS1=0;  PS0=0;
        T0CS=0;
        TMR0=0;
   
        PEIE=1;
        GIE=1;
       
        IO_CLR(LED_PORT, LED_TMR0 | LED_TMR1 | LED_TMR2);        //led_tmr0/1/2 driven to low
        IO_OUT(LED_DDR, LED_TMR0 | LED_TMR1 | LED_TMR2);        //led_tmr0/1/2 as output

        while(1)
                continue;
}


/****************ISR******************************/
static void interrupt ISR(void)         // Here be interrupt function - the name is unimportant.
{
        if (T0IE&T0IF)// SYSTEMTICK 4.096MS int  need scan led an count or decount  
                {T0IF=0;
                IO_FLP(LED_PORT, LED_TMR0);                //flip led_tmr0
        }

        if (RBIE&RBIF)//partB int need scan key  
                {RBIF=0;
        }
  
        if (TMR1IE&TMR1IF)//ccp INT  read perid
                {TMR1IF=0;
                IO_FLP(LED_PORT, LED_TMR1);                //flip led_tmr1
        }

        if (TMR2IE&TMR2IF)// PWM TIME INT    CHANGE DUTY
                {TMR2IE=0;                                                 //should reset the flag, not the interrupt enabling bit
                IO_FLP(LED_PORT, LED_TMR2);                //flip led_tmr2
        }
}
==========end code=============

it has three indicators, portc.0, portc.1, and portc.2 (on a 16F886), designated as tmr0/1/2 interrupt indicators: when tmr0 interrupt is serviced, LED_TMR0 (portc.0) is flip'd, and so on and so forth.

when I ran the code, the only thing flip'd is portc.0 (=LED_TMR0). that means the only interrupt service being executed is the one related to T0IF, as expected.

出0入22汤圆

 楼主| 发表于 2010-9-23 11:31:44 | 显示全部楼层
谢谢楼上的回答,,,

理论上TMR2IF 等都是标志位  应该是按位与,,,,
而且楼上也证明是正确的。

所以说很大的可能是编译器的问题 。本人使用的是PICC9.65版本。目前好像还只有这 一个版本支持722

出0入0汤圆

发表于 2010-9-23 12:39:41 | 显示全部楼层
和_谐得不好,总有些怪异的问题,坛里有9.8的,bug比较少
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-30 19:39

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表