Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PIC15F1516微控制器中的定时器逻辑_C_Timer_Embedded_Microcontroller_Pic - Fatal编程技术网

PIC15F1516微控制器中的定时器逻辑

PIC15F1516微控制器中的定时器逻辑,c,timer,embedded,microcontroller,pic,C,Timer,Embedded,Microcontroller,Pic,我正在使用PIC15F1516微控制器,并在没有任何文档的情况下进行反向工程以理解代码。我无法理解在main.c中实现的计时器和逻辑的用法 Timer0RegValue=64536.0 预标量=1 延迟=((65536-Timer0RegValue)*(预标量*4))/Fosc=0.001秒 我可以理解,在主函数中,计时器是用1mSec的值更新的,但是,我无法得到ProcessTenthSec()和ProcessTwelfthSec()将执行多少时间 void TMR1_Initia

我正在使用PIC15F1516微控制器,并在没有任何文档的情况下进行反向工程以理解代码。我无法理解在main.c中实现的计时器和逻辑的用法

  • Timer0RegValue=64536.0
  • 预标量=1
  • 延迟=((65536-Timer0RegValue)*(预标量*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();
        }
    }
}
void TMR1\u初始化(void)
{
//将计时器设置为GUI中选择的选项
//T1CKPS 1:1;T1OSCEN禁用;NT1同步;TMR1CS FOSC/4;TMR1ON禁用;
T1CON=0x00;
//T1GSS T1G;TMR1GE已禁用;T1GTM已禁用;T1GPOL低;T1GGO_n完成;T1GSPM已禁用;
T1GCON=0x00;
//TMR1H 252;
TMR1H=0xFC;
//TMR1L 24;
TMR1L=0x18;
//加载TMR值以重新加载变量
//6396=0xFC18
//延迟=((65536-Timer0RegValue)*(预标量*4))/Fosc;
//延迟=((65536-6396)*(1*4))/500000;
//延迟=

timer1ReloadVal=(TMR1H具体来说,您对什么感到困惑?似乎
Fosc
不是4mhz,因为
TENTH_secu\u RELOAD
不是100。
TMR1H