|
单片机静态显示数字程序
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit wela=P2^0;
sbit dula=P2^1;
uchar code table[]={
0x3f,0x06,0x5b,0x4f, //不带小数点的编码
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0xbf,0x86, //带小数点的编码
0xdb,0xcf,0xe6,0xed,
0xfd,0x87,0xff,0xef};
void display();
void delay(uint z) //延时子函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
while(1)
{
display();
}
}
void display() //显示子函数
{
dula=1;
P1=table[0];
dula=0;
P1=0xff;
wela=1;
P1=0xfe;
wela=0;
delay(2);
dula=1;
P1=table[1];
dula=0;
P1=0xff;
wela=1;
P1=0xfd;
wela=0;
delay(2);
dula=1;
P1=table[2];
dula=0;
P1=0xff;
wela=1;
P1=0xfb;
wela=0;
delay(2);
dula=1;
P1=table[3];
dula=0;
P1=0xff;
wela=1;
P1=0xf7;
wela=0;
delay(2);
dula=1;
P1=table[4];
dula=0;
P1=0xff;
wela=1;
P1=0xef;
wela=0;
delay(2);
dula=1;
P1=table[5];
dula=0;
P1=0xff;
wela=1;
P1=0xdf;
wela=0;
delay(2);
dula=1;
P1=table[6];
dula=0;
P1=0xff;
wela=1;
P1=0xbf;
wela=0;
delay(2);
dula=1;
P1=table[7];
dula=0;
P1=0xff;
wela=1;
P1=0x7f;
wela=0;
delay(2);
}
|
|