timer.c~

来自「按键是比较复杂。可以用状态机表示。 每10mS执行一次键盘扫描任务 0、无」· C~ 代码 · 共 37 行

C~
37
字号
#include "timer.h"#include <avr/io.h>#include <avr/interrupt.h>volatile unsigned char ftimer2ms_ok, ftimer10ms_ok, ftimer1s_ok;unsigned char timer1s_count;void timer_init(void){        TCCR0 = (1<<WGM01)|(1<<CS02);   /* CTC, 256分频 */        TCNT0 = 0;        OCR0 = (FOSC/N/500-1);          /* 2ms, 500Hz */                /* CTC, 1024分频, 注意分频设置与T/C0不同 */        TCCR2 = (1<<WGM01)|(1<<CS02)|(1<<CS01)|(1<<CS00);        TCNT2 = 0;        OCR2 = (FOSC/1024/100-1);       /* 10ms, 100Hz */				TIMSK = (1<<OCIE0)|(1<<OCIE2);}ISR(TIMER0_COMP_vect){        ftimer2ms_ok = 1;}ISR(TIMER2_COMP_vect){        ftimer10ms_ok = 1;        if(++timer1s_count >= 100)        {                timer1s_count = 0;				ftimer1s_ok = 1;        }}

⌨️ 快捷键说明

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