timer0._c

来自「详细介绍M8两版间通讯」· _C 代码 · 共 29 行

_C
29
字号
#include <iom8v.h>
#include <macros.h>
extern void spark(unsigned char pos,unsigned char num);
unsigned char LedNum[8]={9,8,7,6,5,4,3,2};
#pragma interrupt_handler timer0:10
void timer0(void)
  {
   static unsigned char cPos=0;
   static unsigned char cTimes=0;
   cTimes++;
   if (cTimes==3)
      {
	   cTimes=0;
	   cPos++;
	   }
   cPos&=0b00001111;
   spark(cPos,LedNum[cPos]);   
   }
void timer0_init(void)
  {
   TIMSK|=0x01;
   TCCR0=0x03;//分频系数256
   TCNT0=0x10;
   /*定时中断时间间隔:
   					  TimeInterval=(256-预置数值)*分频系数/主频
	注意开启中断
	SEI();
	*/
	} 

⌨️ 快捷键说明

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