main.c

来自「avr的I/O、串口、定时器/计数器、外部中断、LCD等的例程」· C语言 代码 · 共 44 行

C
44
字号
#include <avr/io.h> 
#include <avr/interrupt.h> 
#include <avr/signal.h> 
#define uchar unsigned char 
#define uint unsigned int 

static uchar g_bCount=0; 
static uchar abc=0; 

SIGNAL(SIG_OVERFLOW1)
{ 
   	TCNT1 = 0x85ee;
   //if(++g_bCount >16) 
   //{ 
      if(abc==0) 
      {
		PORTA = 0XFF;
		abc=1;
		} 
      else 
      {
		PORTA = 0;
		abc=0;
		} 
   //g_bCount = 0; 
   //} 
} 

int main(void) 
{    
   DDRA = 0XFF; 
   PORTA = 0; 
   OCR1A = 0x7a12;
   OCR1B = 0x7a12;
   TCCR1A=0x00; //普通模式
   TCCR1B=0x04; //256分频
   TCNT1=0x85ee;
   TIMSK = 0x04;
   sei();
   while(1) 
   { 
   } 
}

⌨️ 快捷键说明

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