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

📄 timer1.c

📁 dsPIC30F4011 + CLCD 4*16ch (flexible pin I/O) >> MPLAB Project files >> C30-compile
💻 C
字号:
#include  <p30f4011.h>  
#include  "..\h\timer1.h"
#include  "..\h\keypad.h"  //  --> 粗У亚峄猫摇 keypad.h

volatile struct timer1STATUS Timer1;
volatile struct ScheduleSTATUS Schedule1;

void initial_Timer1(void)
{
    TMR1 = 0;				// clear timer 1
    PR1 = 0x0270;			// interrupt every  ? ms  卵т凌浯椁庸枪

    T1CONbits.TCKPS = 3;
    T1CONbits.TON   = 1;

    IFS0bits.T1IF = 0;		// clr interrupt flag
    IEC0bits.T1IE = 1;		// set interrupt enable bit
    
    Timer1.Count = 0;
    Keypad.Tick = 0;
    Keypad.keyFlag = 0;
    Schedule1.Task1 = 0;
}

unsigned char setSchedualTime_Timer1(unsigned char timeSet)
{
    if(timeSet)
    {
       Schedule1.Stop = timeSet;
    }
return 1;
}

unsigned char Task1FlagCheck(unsigned char CheckIN)
{
    if(CheckIN){
        if((Timer1.Count == CheckIN)&&(Schedule1.Task1==1)){Schedule1.Task1=0; return 1;}
        else return 0;
    }

    if((CheckIN==0)) Schedule1.Task1=0;

    return 0;
}

void Service_Task1(void)
{
    Timer1.Count++;    
    if(Timer1.Count > Schedule1.Stop){ 
        Timer1.Count = 0;
        Schedule1.Task1=1;
        LATEbits.LATE4 ^= 0x01;	   //Toggle LED's PORT_E4        
    }   
}

void Service_KeypAD(void)
{
    Keypad.Tick++;
    if((Keypad.Tick == 50)||(Keypad.Tick == 100)){ 
        Keypad.keyFlag = 1;
    }else if(Keypad.Tick > 100){
        Keypad.Tick = 0;
    }else{
        Keypad.keyFlag = 0;
    }
}

// interrupt service routine for Timer1
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void) 
{
    // Time Schedual = 100 , compare with " Task1FlagCheck(50)"
    Service_Task1();      // Control service Task1
    // Alway 50 Tick
    Service_KeypAD();     // Control service Keypad
	IFS0bits.T1IF = 0;	  // clear interrupt flag
}

⌨️ 快捷键说明

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