[编程]

AVR单片机定时器中断问题!!!

[复制链接]
2922|1
手机看帖
扫描二维码
随时随地手机跟帖
寇大白|  楼主 | 2017-2-6 10:56 | 显示全部楼层 |阅读模式
求大神帮忙看下这个定时1s的程序为什么不能执行啊?先谢谢了
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
#pragma interrupt_handler time1_isr:9

const SEG_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};//共阴极数码管码表
uchar i;
uchar table[2];

void delay()
{
uchar a;
for(a=300;a>0;a--);
}
/*显示函数*/
void display()
{
/*显示十位*/
PORTC =SEG_CODE[table[0]];
PORTD &=~BIT(0);
delay();
PORTD |=BIT(0);
/*显示个位*/
PORTC =SEG_CODE[table[1]];
PORTD &=~BIT(1);
delay();
PORTD |=BIT(1);

}

/*端口初始化*/
void ini()
{
DDRC=0XFF;
PORTC=0XFF;

DDRD=0XFF;
PORTD=0XFF;
}

/*8MHZ晶振,定时器初始化*/
void time1_init()
{
TCCR1B |=0X04;//256分频率
TCNT1H=0x85;
TCNT1L=0xed;
TIMSK |=BIT(2);
SREG |=BIT(2);
}

void main()
{
ini();
time1_init();
while(1)
{
  table[0]=i%10;
  table[1]=i/10;
  display();
}

}

void time1_isr()
{
flag=1;
TCNT1H=0x85;
TCNT1L=0xed;
i++;
if(i==60)
{
  i=0;
}
}



相关帖子

feixiangspring| | 2017-3-12 21:38 | 显示全部楼层
你的中断标志位TIFR寄存器怎么没设置,你把这个寄存器TOV1使能试试,不然就算是计数溢出了也不会响应中断服务函数的,,

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝