|
发表于 2008-10-17 16:39:08
|
显示全部楼层
先点亮位,再输出段,则可!以前的版本是不分顺序输出也可以的,但现在不行,可以说更严谨!
#include <avr/io.h>
#include <util/delay.h>
#define uchar unsigned char
#define uint unsigned int
uchar table[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x7,0x7F,0x6F,
//0 1 2 3 4 5 6 7 8 9
//A b C d E F
0x77,0X7C,0x39,0x5e,0x79,0x71};
/* 数码管段选信号接 PORTC PC0
数码管位选信号接 PORTC PC1
*/
void Port_init()
{
DDRD=0XFF;
PORTD=0XFF;
// DDRB=0XFF;
// PORTB=0XFF;
DDRC=_BV(DDC0)|_BV(DDC1);
PORTC=0XC0;
}
void DELAY(int us)
{
uint i;
for(i=0;i<us;i++)
{
_delay_us(50);
}
}
int main()
{
uchar i;
Port_init();
while(1)
{
for(i=0;i<8;i++)
{
PORTD=0XFF;
asm("nop");
PORTD&=~_BV(i);
PORTC|=_BV(PC1);
asm("nop");
PORTC&=~_BV(PC1);
asm("nop");
PORTD=table;
asm("nop");
PORTC|=_BV(PC0);
asm("nop");
PORTC&=~_BV(PC0);
DELAY(100);
}
}
return 0;
}
本贴被 xqqtang 编辑过,最后修改时间:2008-10-17,16:43:28. |
|