用AT89C51单片机实现四位数码管显示数据!!用c语言程序实现!!例如显示出1234 这四个数。请各位朋友帮忙

争取有仿真图!!谢谢!

第1个回答  2012-06-06
#include<reg52.h>
#include<intrins.h>
typedef unsigned char uchar;
typedef unsigned int uint;

uchar code table[] = {0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8};//- 0xbf

void delay(uchar t)
{
uchar i;
while(t--)
{
for(i = 0;i<100;i++);
}
}

void Opertion ()
{
uchar i,j,k,m,n,a,b,c,d;

//显示---1
for(a = 0;a<20;a++)
{
P2 = 0x08;
for(i = 0;i<3;i++)
{

P0 = 0xbf;
delay(10);
P2 = _cror_(P2,1);
}
//P2 = 0x01
P0 = table[0];
delay(10);
}

//显示--12
for(b = 0;b<20;b++)
{
P2 = 0x08;
for(j = 0;j<2;j++)
{

P0 = 0xbf;
delay(10);
P2 = _cror_(P2,1);
}
P2 = 0x02;
for(k = 0;k<2;k++)
{

P0 = table[k];
delay(10);
P2 = _cror_(P2,1);
}
}

//显示-123
for(c = 0;c<20;c++)
{
P2 = 0x08;
P0 = 0xbf;
delay(10);
for(j = 0;j<3;j++)
{
P2 = _cror_(P2,1);
P0 = table[j];
delay(10);
}
}

//显示1234 2345 3456 4567

for(k = 0;k<4;k++)
{
for(d = 0;d<20;d++)
{
P2 = 0x08;
for(m = 0;m<4;m++)
{
P0 = table[k+m];
//P2 = sel;
delay(10);
P2 = _cror_(P2,1);
}
}
}

d = 0;
//显示567-
for(d = 0;d<20;d++)
{
P2 = 0x08;
for(j = 0;j<3;j++)
{
P0 = table[j+4];
//P2 = sel;
delay(10);
P2 = _cror_(P2,1);
}
P0 = 0xbf;
delay(10);
}
d = 0;
//显示67--
for(d = 0;d<20;d++)
{
P2 = 0x08;
for(j = 0;j<2;j++)
{
P0 = table[j+5];
//P2 = sel;
delay(10);
P2 = _cror_(P2,1);
}
for(k = 0;k<2;k++)
{
P0 = 0xbf;
delay(10);
P2 = _cror_(P2,1);
}
}
d = 0;

//显示7---
for(d = 0;d<20;d++)
{
P2 = 0x08;
//P2 = sel;
P0 = table[6];
delay(10);
for(n = 0;n<3;n++)
{
P2 = _cror_(P2,1);
P0 = 0xbf;
delay(10);
}
}
}

void main()
{
while(1)
{
Opertion();
}
}本回答被提问者采纳
第2个回答  2012-06-05
加扣扣 504111933,我来帮你
相似回答