?? timer1.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 + -