📄 timer1.c
字号:
#define EXT_TIMER1_GLOBALS
#include "includes.h"
/************************************************************
Function Name: T2Init
Function: Timer0 initial
Paramenter: None
Return value: None
Author: Chen yuan zhen May.30.2008
*************************************************************/
void T1Set0p5ms(void)
{
TCNT1 = 0;
OCR1A = 63; /* 0.5ms*/
}
/************************************************************
Function Name: T2Init
Function: Timer0 initial
Paramenter: None
Return value: None
Author: Chen yuan zhen May.30.2008
*************************************************************/
void T1Set2ms(void)
{
TCNT1 = 0;
OCR1A = 255; /* 2ms*/
}
/************************************************************
Function Name: T2Init
Function: Timer0 initial
Paramenter: None
Return value: None
Author: Chen yuan zhen May.30.2008
*************************************************************/
void T1Set8p7ms(void)
{
TCNT1 = 0;
OCR1A = 1200; /* 8.75ms*/
}
/************************************************************
Function Name: T2Init
Function: Timer0 initial
Paramenter: None
Return value: None
Author: Chen yuan zhen May.30.2008
*************************************************************/
void T1Set17p5ms(void)
{
TCNT1 = 0;
OCR1A = 2240; /*17.5ms*/
}
/************************************************************
Function Name: T2Init
Function: Timer0 initial
Paramenter: None
Return value: None
Author: Chen yuan zhen May.30.2008
*************************************************************/
void T1Init(void)
{
OCR1A = 63; /* 0.5ms*/
TCNT1 = 0;
TCCR1B = 8; /*CTC模式*/
TIMSK1 |= (1<<OCIE1A); /*中断允许*/
}
/************************************************************
Function Name: T2Start
Function: Timer0 start
Paramenter: None
Return value: None
Author: Chen yuan zhen May.30.2008
*************************************************************/
void T1Start(void)
{
TCNT1 = 0;
TCCR1B |= 0x03; /*设置定时器的分频值为64分频并开始*/
}
/************************************************************
Function Name: T2Close
Function: Timer0 close
Paramenter: None
Return value: None
Author: Chen yuan zhen May.30.2008
*************************************************************/
void T1Close(void)
{
TCCR1A &= 0xF8; /*关闭定时器*/
}
/************************************************************
Function Name: SIGNAL(TIMER0_COMPA_vect)
Function: Timer0 interrupt
Paramenter: TIMER0_COMPA_vect
Return value: None
Author: Chen yuan zhen May.30.2008
*************************************************************/
SIGNAL(TIMER1_COMPA_vect)
{
unsigned char static PwmCtrTimeCounter=1;
switch(PwmCtrTimeCounter)
{
case 1:
{
PwmStepCounter=0;
TurnOnPwm();
T1Set0p5ms();
break;
}
case 2:
{
PwmStepCounter=0;
TrueStepCount=0;
T1Set2ms( );
T0Start( ); //开始
break;
}
case 3:
{
T0Close( );
PwmStepCounter=0;
ClrPwmPort( );
if(IS_AD_INPUT && (!RUN_FLAG))
{
AD_FLAG=1;
T1Set17p5ms( );
PwmCtrTimeCounter=0;
}
else
{
AD_FLAG=0;
T1Set8p7ms( );
}
FuctionProcess();
break;
}
case 4:
{
PwmCtrTimeCounter=0;
FuctionProcess();
break;
}
default:
{
PwmCtrTimeCounter=0;
break;
}
}
PwmCtrTimeCounter++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -