今天发现一个奇怪的问题。
使用PIC16F722 这个IC出来没多久 ,需要使用PICC 9.65的编译器。
程序用SIM仿真发现总是在中断中跑,于是我关了GIE 同时查看特殊功能寄存器,发现不可能进中断,
在中断中通过判断标准位
进了这个
if(TMR2IE&TMR2IF)// PWM TIME INT CHANGE DUTY
{TMR2IF=0;
TMR2IE=0;
CCPR2L=PWM_duty;
}
可是这个怎么可能一直在中断中跑。
还有哪位知道Startup.as这个文件有没有必要要。怎么去掉。我非常的怀疑是它在搞鬼
同事也怀疑编译器的问题 。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
========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.
一周热门 更多>