//外部脉冲输入端T2CK,输入4个高脉冲(外置按键控制),将使_LATD7控制的LED反转!
//但是发现在中断服务子程序中,IF标志不能清除。希望高手指点一二!
#include <p30f6014A.h>
_FOSC(CSW_FSCM_OFF & XT_PLL4);
_FWDT(WDT_OFF);
_FBORPOR(MCLR_EN & PBOR_OFF);
_FGS(CODE_PROT_OFF);
#define fcy 7372800
unsigned int ch1=0,ch2=0,ch3=0,jp=0;
void init(void)
{
INTCON1=0;
INTCON2=0;
IEC0=0;
IEC1=0;
IEC2=0;
T2CON=0;
TMR2=0;
PR2=8;
//记录4次
_T2IF=0;
_T2IP=5;
_T2IE=1;
T2CON=0x8002;
//开启TON
;1:1分频; 外部时钟
_LATD7=1;
TRISD=0;
ch1=0,
ch2=0,
ch3=0;
}
void __attribute__((__interrupt__,auto_psv)) _T2Interrupt(void)
{
_T2IE=0;
ch2=TMR2;
_T2IF=0;
_LATD7=!_LATD7;
ch3=TMR2;
_T2IE=1;
}
int main()
{
init();
while(1)
{
jp++;
ch1=TMR2;
jp--;
}
return 0;
} |