|
7段数码管显示数字1-9
#include <Reg51.h>
char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //0-9
void disp_7seg(long int num);
void delay(int n)
{
{
int x,y;
for(x=n;x>0;x--)
for(y=255;y>0;y--);
}
}
void main()
{
while(1)
{
disp_7seg(123456789);
}
}
void disp_7seg(long int num)
{
P1 = 0xFD;//1
P2 = table[num/100000000];
delay(200);
P1 = 0xFB;//2
P2 = table[num%100000000/10000000];
delay(200);
P1 = 0xF7;//3
P2 = table[num%10000000/1000000];
delay(200);
P1 = 0xFE;//4
P2 = table[num%1000000/100000];
delay(200);
P1 = 0xFD;//5
P2 = table[num%100000/10000];
delay(200);
P1 = 0xFB;//6
P2 = table[num%10000/1000];
delay(200);
P1 = 0xF7;//7
P2 = table[num%1000/100];
delay(200);
P1 = 0xFE;//8
P2 = table[num%100/10];
delay(200);
P1 = 0xFD;//9
P2 = table[num%10];
delay(200);
}
|
|