发表于《上本书!AVRGCC》
16年8个月前IP:未同步
219015
2楼
AVR 天天练!定时器0!


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

static uint c;

void init(void);

void delay(uint s)
{
    uint i,j;
    for(i=0;i<s;i++)
    for(j=0;j<300;j++);
    

}
int main(void)
{
    init();
DDRB=0xff;
PORTB=0xff;



    while(1)
    {
        if(c==5)
        {
        c=0;
        PORTB ^=0xff;
        }

    }
}

void init(void)
{

sei();//开全局中断
TCCR0 |=(1<<CS02);;//系统时钟256分频
TCNT0=0x01;//初值
TIMSK=0x01;//打开T/C中断屏蔽寄存器
}


SIGNAL(SIG_OVERFLOW0)
{
TCNT0=0x01;    
c++;

}
评论
文号 / 219015

十步芳草
名片发私信
学术分 0
总主题 29 帖总回复 174 楼拥有证书:笔友
注册于 2006/03/11 14:30:50最后登录 2020/06/09 19:53:53
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:0

个人简介

暂未填写
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的