📄 timer128.c
字号:
sbi(TCCR1A,COMC1);
cbi(TCCR1A,COMC0);
}
void timer1PWMAOff(void)
{
// turn off channel A (OC1A) PWM output
// set OC1A (OutputCompare action) to none
cbi(TCCR1A,COMA1);
cbi(TCCR1A,COMA0);
}
void timer1PWMBOff(void)
{
// turn off channel B (OC1B) PWM output
// set OC1B (OutputCompare action) to none
cbi(TCCR1A,COMB1);
cbi(TCCR1A,COMB0);
}
void timer1PWMCOff(void)
{
// turn off channel C (OC1C) PWM output
// set OC1C (OutputCompare action) to none
cbi(TCCR1A,COMC1);
cbi(TCCR1A,COMC0);
}
void timer1PWMASet(u16 pwmDuty)
{
// set PWM (output compare) duty for channel A
// this PWM output is generated on OC1A pin
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
// pwmDuty should be in the range 0-511 for 9bit PWM
// pwmDuty should be in the range 0-1023 for 10bit PWM
outp( (pwmDuty>>8), OCR1AH); // set the high 8bits of OCR1A
outp( (pwmDuty&0x00FF), OCR1AL); // set the low 8bits of OCR1A
}
void timer1PWMBSet(u16 pwmDuty)
{
// set PWM (output compare) duty for channel B
// this PWM output is generated on OC1B pin
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
// pwmDuty should be in the range 0-511 for 9bit PWM
// pwmDuty should be in the range 0-1023 for 10bit PWM
outp( (pwmDuty>>8), OCR1BH); // set the high 8bits of OCR1B
outp( (pwmDuty&0x00FF), OCR1BL); // set the low 8bits of OCR1B
}
void timer1PWMCSet(u16 pwmDuty)
{
// set PWM (output compare) duty for channel C
// this PWM output is generated on OC1C pin
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
// pwmDuty should be in the range 0-511 for 9bit PWM
// pwmDuty should be in the range 0-1023 for 10bit PWM
outp( (pwmDuty>>8), OCR1CH); // set the high 8bits of OCR1C
outp( (pwmDuty&0x00FF), OCR1CL); // set the low 8bits of OCR1C
}
void timer3PWMInit(u08 bitRes)
{
// configures timer1 for use with PWM output
// on pins OC3A, OC3B, and OC3C
// enable Timer3 as 8,9,10bit PWM
if(bitRes == 9)
{ // 9bit mode
sbi(TCCR3A,WGMA1);
cbi(TCCR3A,WGMA0);
}
else if( bitRes == 10 )
{ // 10bit mode
sbi(TCCR3A,WGMA1);
sbi(TCCR3A,WGMA0);
}
else
{ // default 8bit mode
cbi(TCCR3A,WGMA1);
sbi(TCCR3A,WGMA0);
}
// set clear-timer-on-compare-match
//cbi(TCCR3B,CTC1);
// clear output compare value A
outb(OCR3AH, 0);
outb(OCR3AL, 0);
// clear output compare value B
outb(OCR3BH, 0);
outb(OCR3BL, 0);
// clear output compare value B
outb(OCR3CH, 0);
outb(OCR3CL, 0);
}
void timer3PWMInitICR(u16 topcount)
{
// set PWM mode with ICR top-count
cbi(TCCR3A,WGM30);
sbi(TCCR3A,WGM31);
sbi(TCCR3B,WGM32);
sbi(TCCR3B,WGM33);
// set top count value
ICR3H = (u08)(topcount>>8);
ICR3L = (u08)topcount;
// clear output compare value A
outb(OCR3AH, 0);
outb(OCR3AL, 0);
// clear output compare value B
outb(OCR3BH, 0);
outb(OCR3BL, 0);
// clear output compare value C
outb(OCR3CH, 0);
outb(OCR3CL, 0);
}
void timer3PWMOff(void)
{
// turn off PWM mode on Timer3
cbi(TCCR3A,WGMA1);
cbi(TCCR3A,WGMA0);
// clear (disable) clear-timer-on-compare-match
//cbi(TCCR3B,CTC1);
// set OC3A/B/C (OutputCompare action) to none
timer3PWMAOff();
timer3PWMBOff();
timer3PWMCOff();
}
void timer3PWMAOn(void)
{
// turn on channel A (OC3A) PWM output
// set OC3A as non-inverted PWM
sbi(TCCR3A,COMA1);
cbi(TCCR3A,COMA0);
}
void timer3PWMBOn(void)
{
// turn on channel B (OC3B) PWM output
// set OC3B as non-inverted PWM
sbi(TCCR3A,COMB1);
cbi(TCCR3A,COMB0);
}
void timer3PWMCOn(void)
{
// turn on channel C (OC3C) PWM output
// set OC3C as non-inverted PWM
sbi(TCCR3A,COMC1);
cbi(TCCR3A,COMC0);
}
void timer3PWMAOff(void)
{
// turn off channel A (OC3A) PWM output
// set OC3A (OutputCompare action) to none
cbi(TCCR3A,COMA1);
cbi(TCCR3A,COMA0);
}
void timer3PWMBOff(void)
{
// turn off channel B (OC3B) PWM output
// set OC3B (OutputCompare action) to none
cbi(TCCR3A,COMB1);
cbi(TCCR3A,COMB0);
}
void timer3PWMCOff(void)
{
// turn off channel C (OC3C) PWM output
// set OC3C (OutputCompare action) to none
cbi(TCCR3A,COMC1);
cbi(TCCR3A,COMC0);
}
void timer3PWMASet(u16 pwmDuty)
{
// set PWM (output compare) duty for channel A
// this PWM output is generated on OC3A pin
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
// pwmDuty should be in the range 0-511 for 9bit PWM
// pwmDuty should be in the range 0-1023 for 10bit PWM
outp( (pwmDuty>>8), OCR3AH); // set the high 8bits of OCR3A
outp( (pwmDuty&0x00FF), OCR3AL); // set the low 8bits of OCR3A
}
void timer3PWMBSet(u16 pwmDuty)
{
// set PWM (output compare) duty for channel B
// this PWM output is generated on OC3B pin
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
// pwmDuty should be in the range 0-511 for 9bit PWM
// pwmDuty should be in the range 0-1023 for 10bit PWM
outp( (pwmDuty>>8), OCR3BH); // set the high 8bits of OCR3B
outp( (pwmDuty&0x00FF), OCR3BL); // set the low 8bits of OCR3B
}
void timer3PWMCSet(u16 pwmDuty)
{
// set PWM (output compare) duty for channel B
// this PWM output is generated on OC3C pin
// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM
// pwmDuty should be in the range 0-511 for 9bit PWM
// pwmDuty should be in the range 0-1023 for 10bit PWM
outp( (pwmDuty>>8), OCR3CH); // set the high 8bits of OCR3C
outp( (pwmDuty&0x00FF), OCR3CL); // set the low 8bits of OCR3C
}
//! Interrupt handler for tcnt0 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW0)
{
Timer0Reg0++; // increment low-order counter
if(!Timer0Reg0) // if low-order counter rollover
Timer0Reg1++; // increment high-order counter
// if a user function is defined, execute it too
if(TimerIntFunc[TIMER0OVERFLOW_INT])
TimerIntFunc[TIMER0OVERFLOW_INT]();
}
//! Interrupt handler for Timer1 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW1)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1OVERFLOW_INT])
TimerIntFunc[TIMER1OVERFLOW_INT]();
}
//! Interrupt handler for Timer2 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW2)
{
Timer2Reg0++; // increment low-order counter
if(!Timer2Reg0) // if low-order counter rollover
Timer2Reg1++; // increment high-order counter
// increment pause counter
TimerPauseReg++;
// if a user function is defined, execute it
if(TimerIntFunc[TIMER2OVERFLOW_INT])
TimerIntFunc[TIMER2OVERFLOW_INT]();
}
//! Interrupt handler for Timer3 overflow interrupt
TIMER_INTERRUPT_HANDLER(SIG_OVERFLOW3)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER3OVERFLOW_INT])
TimerIntFunc[TIMER3OVERFLOW_INT]();
}
//! Interrupt handler for OutputCompare0 match (OC0) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE0)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER0OUTCOMPARE_INT])
TimerIntFunc[TIMER0OUTCOMPARE_INT]();
}
//! Interrupt handler for OutputCompare1A match (OC1A) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1A)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1OUTCOMPAREA_INT])
TimerIntFunc[TIMER1OUTCOMPAREA_INT]();
}
//! Interrupt handler for OutputCompare1B match (OC1B) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1B)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1OUTCOMPAREB_INT])
TimerIntFunc[TIMER1OUTCOMPAREB_INT]();
}
//! Interrupt handler for OutputCompare1C match (OC1C) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE1C)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1OUTCOMPAREC_INT])
TimerIntFunc[TIMER1OUTCOMPAREC_INT]();
}
//! Interrupt handler for InputCapture1(IC1) interrupt
TIMER_INTERRUPT_HANDLER(SIG_INPUT_CAPTURE1)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER1INPUTCAPTURE_INT])
TimerIntFunc[TIMER1INPUTCAPTURE_INT]();
}
//! Interrupt handler for OutputCompare2 match (OC2) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE2)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER2OUTCOMPARE_INT])
TimerIntFunc[TIMER2OUTCOMPARE_INT]();
}
//! Interrupt handler for OutputCompare3A match (OC3A) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE3A)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER3OUTCOMPAREA_INT])
TimerIntFunc[TIMER3OUTCOMPAREA_INT]();
}
//! Interrupt handler for OutputCompare3B match (OC3B) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE3B)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER3OUTCOMPAREB_INT])
TimerIntFunc[TIMER3OUTCOMPAREB_INT]();
}
//! Interrupt handler for OutputCompare3C match (OC3C) interrupt
TIMER_INTERRUPT_HANDLER(SIG_OUTPUT_COMPARE3C)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER3OUTCOMPAREC_INT])
TimerIntFunc[TIMER3OUTCOMPAREC_INT]();
}
//! Interrupt handler for InputCapture3 (IC3) interrupt
TIMER_INTERRUPT_HANDLER(SIG_INPUT_CAPTURE3)
{
// if a user function is defined, execute it
if(TimerIntFunc[TIMER3INPUTCAPTURE_INT])
TimerIntFunc[TIMER3INPUTCAPTURE_INT]();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -