|
显示0到9的数码管代码
#include <Reg52.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,z;
for(x=n;x>0;x--)
for(y=255;y>0;y--)
for(z=255;z>0;z--);
}
void main()
{
while(1)
{
disp_7seg(123456789);
}
}
void disp_7seg(long int num)
{
P1 = 0xFE;//1111 1110;????????
P2 = table[num/1000000000]; //?? num???,??1000????????????,????????
delay(1);
P1 = 0xFD;//1111 1101;?????
P2 = table[num/100000000]; //?? num???,??1000????????????,????????
delay(1);
P1 = 0xFB;//1111 1011;????????
P2 = table[num%100000000/10000000];//2, %?????
delay(1);
P1 = 0xF7;//1111 0111;????????
P2 = table[num%10000000/1000000]; //3
delay(1);
P1 = 0xFE;//1111 1110;????????
P2 = table[num%1000000/100000]; //4
delay(1);
P1 = 0xFD;//1111 1101;?????
P2 = table[num%100000/10000]; //?? num???,??1000????????????,????????
delay(1);
P1 = 0xFB;//1111 1011;????????
P2 = table[num%10000/1000];//2, %?????
delay(1);
P1 = 0xF7;//1111 0111;????????
P2 = table[num%1000/100]; //3
delay(1);
P1 = 0xFE;//1111 1110;????????
P2 = table[num%100/10]; //4
delay(1);
P1 = 0xFD;//1111 1101;?????
P2 = table[num%10]; //?? num???,??1000????????????,????????
delay(1);
} |
|