帮忙看看AVR单片机ATMEGA128A定时器1中断程序,我想实现数码管秒表的显示,
#include"iom16v.h"#include"macros.h"//数组声明并定义在存储数据区code//0~9#pragrmadata:codeunsigned...
#include "iom16v.h"
#include "macros.h"
//数组声明并定义在存储数据区code
//0~9
#pragrma data:code
unsigned char const Number[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,};
//A~F
#pragrma data:code
unsigned char const Alpha[]={0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,};
#pragma interrupt_handler Second_Ir:9
unsigned int Second;
//声明中断
void delay(unsigned long x)
{
int i,j;
for(j=0;j<x;j++)
for(i=0;i<1000;i++);
}
void Second_Ir()
{
TCNT1H=0X57; //高八位重新赋值
TCNT1L=0X3F; //低八位重新赋值
if(Second==60) Second=0;
Second++;
}
void main()
{
int i;
unsigned char Ten=0,One=0; //建立变量
DDRA=0XFF;
PORTA=0XFF;
DDRC=0XFF;
PORTC=0X3F;
TCCR1B|=BIT(2); //分频设置为256;0x40
TCNT1H=0x57; //初值高八位
TCNT1L=0x3F; //初值低八位
TIMSK|=0x04; //定时器1中断溢出使能
SREG|=BIT(7); //全局中断使能使能
while(1)
{
PORTC=~BIT(6);
PORTA=~Number[Second/10];
delay(1);
PORTC=~BIT(7);
PORTA=~Number[Second%10];
delay(1);
}
}
时间运行很快,好像没用的定时器一样,而且还显示的是倒计时。。求大神帮忙。 展开
#include "macros.h"
//数组声明并定义在存储数据区code
//0~9
#pragrma data:code
unsigned char const Number[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,};
//A~F
#pragrma data:code
unsigned char const Alpha[]={0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,};
#pragma interrupt_handler Second_Ir:9
unsigned int Second;
//声明中断
void delay(unsigned long x)
{
int i,j;
for(j=0;j<x;j++)
for(i=0;i<1000;i++);
}
void Second_Ir()
{
TCNT1H=0X57; //高八位重新赋值
TCNT1L=0X3F; //低八位重新赋值
if(Second==60) Second=0;
Second++;
}
void main()
{
int i;
unsigned char Ten=0,One=0; //建立变量
DDRA=0XFF;
PORTA=0XFF;
DDRC=0XFF;
PORTC=0X3F;
TCCR1B|=BIT(2); //分频设置为256;0x40
TCNT1H=0x57; //初值高八位
TCNT1L=0x3F; //初值低八位
TIMSK|=0x04; //定时器1中断溢出使能
SREG|=BIT(7); //全局中断使能使能
while(1)
{
PORTC=~BIT(6);
PORTA=~Number[Second/10];
delay(1);
PORTC=~BIT(7);
PORTA=~Number[Second%10];
delay(1);
}
}
时间运行很快,好像没用的定时器一样,而且还显示的是倒计时。。求大神帮忙。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询