#include "reg51.h"
#define uchar unsigned char
uchar display_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar time[8]={2,0,1,2,1,1,4,5};
//uchar time[3]={0,0,0};
void delay(void)
{
uchar i;
for(i=250;i>0;i--);
}
void display()
{
P2=0x80;
P0=display_code[time[0]];
delay();
P2=0x00;
P2=0x40;
P0=display_code[time[1]];
delay();
P2=0x00;
P2=0x20;
P0=display_code[time[2]];
delay();
P2=0x00;
P2=0x10;
P0=display_code[time[3]];
delay();
P2=0x00;
P2=0x08;
P0=display_code[time[4]];
delay();
P2=0x00;
P2=0x04;
P0=display_code[time[5]];
delay();
P2=0x00;
P2=0x02;
P0=display_code[time[6]];
delay();
P2=0x00;
P2=0x01;
P0=display_code[time[7]];
delay();
P2=0x00;
}
void main(void)
{
uchar i;
while(1)
{
for(i=0;i<100;i++)
{
display();
}
}
}
大神,感谢您的回答,但是最后一个8呢......(失意体前屈)
按照这样的接法,再加一个2位一体的数码管。比如位选接P30,另外段选接到P1。于是有:
P3=0x01;
P0=display_code[time[7]];
delay();
P3=0x00;
就可以了。