|
动态数码管程序:
#include "reg51.h"
#include "intrins.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit A2=P2^2;
sbit A3=P2^3;
sbit A4=P2^4;
u8 code Srt[16]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71} ;
void tye(u16 j)
{
while(j--);
}
void Dtys()
{
int i;
i=0;
for (i;i<8;i++)
{
P0=0x00;
switch(i)
{
case 0:
A2=0;A3=0;A4=0;break;
case 1:
A2=1;A3=0;A4=0;break;
case 2:
A2=0;A3=1;A4=0;break;
case 3:
A2=1;A3=1;A4=0;break;
case 4:
A2=0;A3=0;A4=1;break;
case 5:
A2=1;A3=0;A4=1;break;
case 6:
A2=0;A3=1;A4=1;break;
case 7:
A2=1;A3=1;A4=1;break; }
}
P0=Srt[i+1];
tye(100);
}
void main()
{
while (1)
{
Dtys();
}
}
静态数码管程序:
#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit A2=P2^2;
sbit A3=P2^3;
sbit A4=P2^4;
u8 code Srt[16]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71} ;
void tye(u16 i)
{
while(i--);
}
void main()
{
while (1)
{
A2=0;
A3=0;
A4=0;
P0=Srt[0];
tye(100);
A2=1;
A3=0;
A4=0;
P0=Srt[1];
tye(100);
A2=0;
A3=1;
A4=0;
P0=Srt[2];
tye(100);
A2=1;
A3=1;
A4=0;
P0=Srt[3];
tye(100);
A2=0;
A3=0;
A4=1;
P0=Srt[4];
tye(100);
A2=1;
A3=0;
A4=1;
P0=Srt[5];
tye(100);
A2=0;
A3=1;
A4=1;
P0=Srt[6];
tye(100);
A2=1;
A3=1;
A4=1;
P0=Srt[7];
tye(100);
}
} |
|