yucheng_xiao 发表于 2008-7-23 21:43:47

proteus 仿真数码管动态扫描的问题

今天用proteus仿真M16对数码管的动态扫描程序,发现只能点亮第二个数码管,我将点亮延时时间延长后能明显看到第一个第二个数码管间或的点亮,但缩短延时时间后,发现只能点亮第二个管子,程序是参考《深入浅出AVR单片机》里的程序,不知道是哪出了问题,望哪位兄台指点一下!
proteus 图如下
点击此处下载 ourdev_356470.rar(文件大小:27K) (原文件名:proteus.rar)

程序如下
//ICC-AVR application builder : 2008-7-23 上午 07:12:47
// Target : M16
// Crystal: 8.0000Mhz

#include <iom16v.h>
#include <macros.h>


void port_init(void)
{
PORTA = 0xc0;
DDRA= 0xc0;
PORTB = 0x00;
DDRB= 0xFF;
PORTC = 0x00; //m103 output only
DDRC= 0x00;
PORTD = 0x00;
DDRD= 0x00;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();

MCUCR = 0x00;
GICR= 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}

void delay_ms(unsigned int time)
{
unsigned char n;
while(time>0)
{
        for(n=1; n<187; n++)
        {
       NOP();
        }
time--;
}
}

const unsigned char DisTab[]=
{
0xfc,0x60,0xda,0xf2,0x66,
0xb6,0xbe,0xe0,0xfe,0xf6,
0xee,0x3e,0x9c,0x7a,0x9e,
0x8e,0xce,0x1c,0x6e,0x7c,
0x0a,0x10,0x02
};

void main(void)
{
init_devices();
//unsigned char counter=0;
while(1)
{


PORTB = DisTab;
PORTA = 0b10111111;    //驱动数码管2
delay_ms(3);
PORTA = 0b11111111;    //数码管熄灭

PORTB = DisTab;
PORTA = 0b01111111;    //驱动数码管1
delay_ms(3);


//counter++;
//if(counter>16)
//counter = 0;
delay_ms(10);

}
}

luoxiaoyuan 发表于 2009-6-14 19:46:18

PORTA = 0b10111111;    //驱动数码管2
PORTB = DisTab;
//PORTA = 0b10111111;    //驱动数码管2
delay_ms(3);
PORTA = 0b11111111;    //数码管熄灭
   
PORTA = 0b01111111;    //驱动数码管1
PORTB = DisTab;
//PORTA = 0b01111111;    //驱动数码管1
delay_ms(3);
注意:proteus仿真时要, 先开位,再开端
页: [1]
查看完整版本: proteus 仿真数码管动态扫描的问题