timer.c
来自「ATMEGA8-timer-学习AVR的朋友们挺多的」· C语言 代码 · 共 60 行
C
60 行
//:rc:8M
//ic atmegal 8l
#include <avr/io.h>
#include <avr/interrupt.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char timer=0;
void delay(unsigned int x)
{
while(x)x--;
}
SIGNAL(SIG_OVERFLOW1)
{
TCNT1=61712;
timer++;
if(timer>=150) //〈256 //改变时间
{
PORTB=0x01^PORTB; //改变引脚
timer=0;
}
}
int main (void)
{
DDRB=0xff;
PORTB=0Xff;//1111,1111
sei();
TCCR1A=0X00;
TCCR1B=(1<<CS10);
TIMSK|=(1<<TOIE1);
TCNT1=61712;
while(1)
{
}
return (0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?