#include "p24hj128gp506.h"
#include "delay.h"
#include "Generic.h"
#include "incap.h"
#include "ports.h"
#include "timer.h"
#include "delay.h"
ulong ax=0;
void __attribute__((interrupt,auto_psv)) _T3Interrupt(void)
{
WriteTimer3(0X0000);
mPORTDToggleBits(IOPORT_BIT_0);
IFS0bits.T3IF = 0;
}
void T3_Init(void)
{
ConfigIntTimer3(T3_INT_PRIOR_1& T3_INT_ON);
OpenTimer3(T3_ON & T3_GATE_OFF & T3_IDLE_STOP &
T3_PS_1_1 &T3_SOURCE_INT, 40000);
}
int main(void)
{
mPORTDOutputConfig(IOPORT_BIT_0);
mPORTDSetBits(IOPORT_BIT_0);
osc_init();
T3_Init();
while(1)
{
;
}
return 0;
}
用32位模式延时1S的程序如下:
#include "p24hj128gp506.h"
#include "delay.h"
#include "Generic.h"
#include "incap.h"
#include "ports.h"
#include "timer.h"
#include "delay.h"
ulong ax=0;
void __attribute__((interrupt,auto_psv)) _T3Interrupt(void)
{
// WriteTimer3(0X0000);
mPORTDToggleBits(IOPORT_BIT_0);
IFS0bits.T3IF = 0;
}
void T3_Init(void)
{
ConfigIntTimer23(T3_INT_PRIOR_1& T3_INT_ON);
OpenTimer23(T2_ON & T2_GATE_OFF & T2_IDLE_STOP &
T2_PS_1_1 &T2_SOURCE_INT, 0x02625a00);
}
int main(void)
{
mPORTDOutputConfig(IOPORT_BIT_0);
mPORTDSetBits(IOPORT_BIT_0);
osc_init();
T3_Init();
while(1)
{
;
}
return 0;
}
如果要设置成8分频,则 OpenTimer23(T2_ON & T2_GATE_OFF & T2_IDLE_STOP &
T2_PS_1_8 &T2_SOURCE_INT, 0x02625a00);
这样,延时为8S,可以看出,32位的定时器和分频模式的使用,最大的延时时间为:
65536*65536*25*256*0.000000001=27487s
如果采用更小的时钟频率,则延时的时间更长!
文章评论(0条评论)
登录后参与讨论