初学AVR,请教大湿一个数码管动态显示器设计的问题
时间:10-02
整理:3721RD
点击:
问题1:time_counter为什么要自加到40,在晶振为4MHZ时自加一次时间怎样算啊?
问题2:在void display(void)函数里最后为什么要PORTC =0xff关闭所有数码管,直接更不吗,我删除后的确不行,是什么原因
#include <mega16.h>
#include <delay.h>
char time[3];
char dis_buff[6];
flash char led_7[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x7F,0x6F};
bit point_on;
flash char position[6]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
char time_counter;
void time_to_disbuffer(void)
{
char i,j=0;
for(i=0;i<2;i++)
{
dis_buff[j++] = time % 10;
dis_buff[j++] = time / 10;
}
}
void display(void)
{
char i;
for(i=0;i<=5;i++)
{
PORTA = led_7[dis_buff];
if (point_on && (i==2||i==4)) PORTA |= 0x80;
PORTC = position;
delay_ms(2);
PORTC =0xff;
}
}
void main()
{
PORTA=0x00; //初始化POTA
DDRA=0xFF;
PORTC=0x3F; //0011 1111
DDRC=0x3F; //0011 1111,PORT0-PORT5输入
time[2] = 23;
time[1] = 58;
time[0] = 55;
time_to_disbuffer();
while(1)
{
display();
if(++time_counter >=40)
{
time_counter = 0;
point_on=~point_on;
if(++time[0]>=60)
{
time[0] = 0;
if(++time[1]>=60)
{
time[1] = 0;
if(++time[2]>=24) time[2] = 0;
}
time_to_disbuffer();
}
delay_ms(13);
}
}
}
问题2:在void display(void)函数里最后为什么要PORTC =0xff关闭所有数码管,直接更不吗,我删除后的确不行,是什么原因
#include <mega16.h>
#include <delay.h>
char time[3];
char dis_buff[6];
flash char led_7[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x7F,0x6F};
bit point_on;
flash char position[6]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
char time_counter;
void time_to_disbuffer(void)
{
char i,j=0;
for(i=0;i<2;i++)
{
dis_buff[j++] = time % 10;
dis_buff[j++] = time / 10;
}
}
void display(void)
{
char i;
for(i=0;i<=5;i++)
{
PORTA = led_7[dis_buff];
if (point_on && (i==2||i==4)) PORTA |= 0x80;
PORTC = position;
delay_ms(2);
PORTC =0xff;
}
}
void main()
{
PORTA=0x00; //初始化POTA
DDRA=0xFF;
PORTC=0x3F; //0011 1111
DDRC=0x3F; //0011 1111,PORT0-PORT5输入
time[2] = 23;
time[1] = 58;
time[0] = 55;
time_to_disbuffer();
while(1)
{
display();
if(++time_counter >=40)
{
time_counter = 0;
point_on=~point_on;
if(++time[0]>=60)
{
time[0] = 0;
if(++time[1]>=60)
{
time[1] = 0;
if(++time[2]>=24) time[2] = 0;
}
time_to_disbuffer();
}
delay_ms(13);
}
}
}