c - PIC15F1516 微控制器中使用的定时器逻辑
问题描述
我正在使用 PIC15F1516 微控制器,并进行逆向工程以在没有任何文档的情况下理解代码。我无法理解 main.c 中实现的计时器和逻辑的使用
- Timer0RegValue = 64536.0
- 预标量 = 1
- 延迟 = ( (65536-Timer0RegValue)*(Prescalar*4) ) / Fosc = 0.001 秒
我可以理解在主函数中计时器的值更新为 1mSec,但是,在 ProcessTenthSec() 和 ProcessTwelfthSec() 将执行多少时间后我无法获得?
void TMR1_Initialize(void)
{
//Set the Timer to the options selected in the GUI
//T1CKPS 1:1; T1OSCEN disabled; nT1SYNC synchronize; TMR1CS FOSC/4; TMR1ON disabled;
T1CON = 0x00;
//T1GSS T1G; TMR1GE disabled; T1GTM disabled; T1GPOL low; T1GGO_nDONE done; T1GSPM disabled;
T1GCON = 0x00;
//TMR1H 252;
TMR1H = 0xFC;
//TMR1L 24;
TMR1L = 0x18;
// Load the TMR value to reload variable
// 6396= 0xFC18
// Delay = ( (65536-Timer0RegValue)*(Prescalar*4) ) / Fosc;
// Delay = ( (65536-6396)*(1*4) ) / 500000;
// Delay =
timer1ReloadVal=(TMR1H << 8) | TMR1L;
// Clearing IF flag before enabling the interrupt.
PIR1bits.TMR1IF = 0;
// Enabling TMR1 interrupt.
//PIE1bits.TMR1IE = 1;
// Set Default Interrupt Handler
//TMR1_SetInterruptHandler(TMR1_DefaultInterruptHandler);
// Start TMR1
//TMR1_StartTimer();
}
#define TENTH_SEC_RELOAD 156
#define TWELFTH_SEC_RELOAD 130
void main(void)
{
// initialize the device
SYSTEM_Initialize();
// When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
// Use the following macros to:
// Enable the Global Interrupts
INTERRUPT_GlobalInterruptEnable();
// Enable the Peripheral Interrupts
INTERRUPT_PeripheralInterruptEnable();
byTenthSec = TENTH_SEC_RELOAD
byTwelfthSec = TWELFTH_SEC_RELOAD
while (1)
{
if(PIR1bits.TMR1IF)
{
T1CONbits.TMR1ON = 0;
//TMR1H 252;
TMR1H = 0xFC;
//TMR1L 24;
TMR1L = 0x18;
T1CONbits.TMR1ON = 1;
PIR1bits.TMR1IF = 0;
if(--byTenthSec == 0)
{
byTenthSec = TENTH_SEC_RELOAD;
ProcessTenthSec();
}
if(--byTwelfthSec == 0)
{
if(byTwelfthFix--)
{
byTwelfthSec = TWELFTH_SEC_RELOAD ;
}
else
{
byTwelfthFix = 3;
byTwelfthSec = TWELFTH_SEC_RELOAD + 1;
}
ProcessTwelfthSec();
}
}
//if an ADC conversion is in progress do a low priority task
if(uHiPriTasks.HighPriority)
{
if(uHiPriTasks.One)
Function1();
else if(uHiPriTasks.Two)
Function2();
else if(uHiPriTasks.Three)
Function3();
else if(uHiPriTasks.four)
Function4();
else if(uHiPriTasks.five)
Function4();
}
if(uWatchdog.byWatchdog == WDT_ALL_TASKS_COMPLETE)
{
//reset the watchdog task structure
uWatchdog.byWatchdog = 0;
//restart the watchdog timer
CLRWDT();
}
}
}
解决方案
推荐阅读
- python - Python 和 JSON - 直接与项目交互
- c# - MVVM 模式中的去抖动事件/命令
- php - 警告:为过滤器上的 foreach() 提供的参数无效
- python - 从屏幕管理器屏幕问题向字段传递值
- java - 用于treeAnno的tomcat 9 context.xml中的JDBC URL问题
- javascript - 如何避免与 React hooks 相关的范围问题
- json - 新项目角
- c++ - 如何收听 Windows 当前正在播放的声音?
- java - 线段和圆之间交点的 LibGDX 坐标
- c++ - 如何正确地将字符串转换为 std::chrono::system_clock::time_point?