| 本人是新手。请各位高手指点一下。我所用的芯片是F28035,然后我想用定时器0做一个延时函数,让程序延时200Ms,但是又不想用到中断。因为直接用循环的delay()函数时间不准确,所以想用定时器来实现一个200ms的延时,但是又不用中断。望各位高手不吝赐教!!谢谢! |
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
| 本人是新手。请各位高手指点一下。我所用的芯片是F28035,然后我想用定时器0做一个延时函数,让程序延时200Ms,但是又不想用到中断。因为直接用循环的delay()函数时间不准确,所以想用定时器来实现一个200ms的延时,但是又不用中断。望各位高手不吝赐教!!谢谢! |
void CpuTimer_Delay(VU16 k)//这个只是配置了定时器的时间,没有实现延时功能
{
VU16 count;
count=k;
InitCpuTimers();//初始化定时器
ConfigCpuTimer(&CpuTimer0,60,1000); //定时1ms;Configure CPU-Timer 0, 1, and 2 to interrupt every second:
CpuTimer0Regs.TCR.bit.TSS=0;//当TSS=0时,启动或重启定时器0
while(count!=0)
{
CpuTimer0.InterruptCount++;
count--;
}
CpuTimer0Regs.TCR.bit.TSS=1;//定时器停止计数
}
这样写对吗?CpuTimer0.InterruptCount++;这个是不是应该在中断服务程序中使用。
void CpuTimer_Delay(VU16 k)//这个只是配置了定时器的时间,没有实现延时功能
{
VU16 count;
count=k;
InitCpuTimers();//初始化定时器
ConfigCpuTimer(&CpuTimer0,60,1000); //定时1ms;Configure CPU-Timer 0, 1, and 2 to interrupt every second:
CpuTimer0Regs.TCR.bit.TSS=0;//当TSS=0时,启动或重启定时器0
while(count!=0)
{
CpuTimer0.InterruptCount++;
count--;
}
CpuTimer0Regs.TCR.bit.TSS=1;//定时器停止计数
}
这样写对吗?CpuTimer0.InterruptCount++;这个是不是应该在中断服务程序中使用。