⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 This is full set of procedures used to communicate with any GSM module for SMS sending/receiving (
💻 C
字号:
/*
 *  FILE:
 *     timer.c (rev. 1.1 - 11.05.2007)
 *
 *  PROJECT:
 *     GSM Communication Module
 *
 *  DESCRIPTION:
 *     See "timer.h" for description
 *
*/

#include "types.h"
#include "timer.h"
#include "gsm-link.h"

U8  volatile TMR_SMS;       // Timer for SMS processor (resolution: 0.1 sec)
U8  volatile TMR_GSM;       // Timer for GSM phone response timeout (resolution: 0.1 sec)

U16 TMR_System;             // System Timer (1 ms)
U8  TMR_Slow;               // System slow Timer (0.1 sec)

// Initialize and start timer
void TMR_Init(void) {
    TMR_System=0; TMR_Slow=100;
    TMR_GSM=0;
    TCCR2=0x0E;             // Configure Timer 2: prescaler=256, CTC mode
    OCR2=TMR_Val;           // Configure MAX value for timer 2
    TCNT2=0;                // Clear timer 2 counter
    TIMSK|=0x10;            // Enable timer 2 compare match interrupt
}

// Timer 2 compare match ISR
#pragma vector=TIMER2_COMP_vect
__interrupt void Timer2OutCompare(void) {
    U8 i;
    TMR_System++;
    if (TMR_Slow==0) {
        // Slow timer routine (invoked every 0.1 sec.)
        TMR_Slow=100;
        if (TMR_SMS) TMR_SMS--;
        if (TMR_GSM) {
            TMR_GSM--;
            // If end GSM timeout timer expire
            if (TMR_GSM==0) GSM_EndOfPacket();
        }
    }
    else TMR_Slow--;
}

// Hardware delay (resolution: 1 ms)
void TMR_Delay(U16 delay) {
    __disable_interrupt();
    TMR_System=0;
    __enable_interrupt();
    while(TMR_System<delay);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -