帮我看一下程序呗?我想用mega16做秒数的计时器,总是不对,谢谢了
时间:10-02
整理:3721RD
点击:
#include <iom16v.h>
#include <macros.h>
int n=0;
void timer0_init(void)
{
TCCR0 = 0x00;
TCNT0 = 0x06;
OCR0 = 0xFA;
TCCR0 = 0x03;
}
#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
TCNT0 = 0x06;
n++;
if(n==1000)
{
n=0;
DDRC=0X00;
}
}
void init_devices(void)
{
CLI();
timer0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x01;
SEI();
}
void main(void)
{
char dis[10]={0xF9,0xC0,0xB5,0xE5,0xCC,0x6D,0x7D,0xC1,0xFD,0xED};
char COM[4]={0x78,0xB8,0xD8,0xE8};
int i = 0;
int b=1;
init_devices();
DDRD = 0xFF;
DDRC = 0xFF;
for(b=1;b<10;b++)
{
for(i=0;i<10;i++)
{ PORTD=COM[1];
DDRC = 0xFF;
PORTC=dis[b];
PORTD=COM[0];
DDRC = 0xFF;
PORTC = dis[i];
}
}
}
#include <macros.h>
int n=0;
void timer0_init(void)
{
TCCR0 = 0x00;
TCNT0 = 0x06;
OCR0 = 0xFA;
TCCR0 = 0x03;
}
#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
TCNT0 = 0x06;
n++;
if(n==1000)
{
n=0;
DDRC=0X00;
}
}
void init_devices(void)
{
CLI();
timer0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x01;
SEI();
}
void main(void)
{
char dis[10]={0xF9,0xC0,0xB5,0xE5,0xCC,0x6D,0x7D,0xC1,0xFD,0xED};
char COM[4]={0x78,0xB8,0xD8,0xE8};
int i = 0;
int b=1;
init_devices();
DDRD = 0xFF;
DDRC = 0xFF;
for(b=1;b<10;b++)
{
for(i=0;i<10;i++)
{ PORTD=COM[1];
DDRC = 0xFF;
PORTC=dis[b];
PORTD=COM[0];
DDRC = 0xFF;
PORTC = dis[i];
}
}
}
是时间不准还是就没有计时呢