单片机里有个6位连一体的共阴极数码管,能否让他从000000动态显示
#include<reg52.h>#defineucharunsignedchar#defineuintunsignedintunsignedcharSM[10]={0x...
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char SM[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//数码0~9
unsigned char wei[6]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
unsigned char i,k,j,m;
void delayms(uchar i)
{uint k;
for(;i!=0;i--)
{for(k=0;k<250;k++);}
}
void display(uint i)
{
P2=wei[5];
P0=SM[i/1];
i=i%1;
delayms(1);
P2=wei[4];
P0=SM[i/10];
i=i%10;
delayms(1);
P2=wei[3];
P0=SM[i/100];
i=i%100;
delayms(1);
P2=wei[2];
P0=SM[i/1000];
i=i%1000;
delayms(2);
P2=wei[1];
P0=SM[i/10000];
i=i%10000;
delayms(1);
P2=wei[0];
P0=SM[i/100000];
i=i%100000;
delayms(1);
}
void main(void)
{
uint j=123456,m;
P0=0xff;
P2=0x00;
delayms(1000);
while(1)
{
j++;
for(m=0;m<25;m++)
display(j);
}
} 展开
#define uchar unsigned char
#define uint unsigned int
unsigned char SM[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//数码0~9
unsigned char wei[6]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
unsigned char i,k,j,m;
void delayms(uchar i)
{uint k;
for(;i!=0;i--)
{for(k=0;k<250;k++);}
}
void display(uint i)
{
P2=wei[5];
P0=SM[i/1];
i=i%1;
delayms(1);
P2=wei[4];
P0=SM[i/10];
i=i%10;
delayms(1);
P2=wei[3];
P0=SM[i/100];
i=i%100;
delayms(1);
P2=wei[2];
P0=SM[i/1000];
i=i%1000;
delayms(2);
P2=wei[1];
P0=SM[i/10000];
i=i%10000;
delayms(1);
P2=wei[0];
P0=SM[i/100000];
i=i%100000;
delayms(1);
}
void main(void)
{
uint j=123456,m;
P0=0xff;
P2=0x00;
delayms(1000);
while(1)
{
j++;
for(m=0;m<25;m++)
display(j);
}
} 展开
1个回答
展开全部
void display(unsigned long i)
{
P2=wei[0];
P0=SM[i % 1000000 / 100000];
delayms(5);
P0 = 0x00;
P2=0xFF;
P2=wei[1];
P0=SM[i % 100000 / 10000];
delayms(5);
P0 = 0x00;
P2=0xFF;
P2=wei[2];
P0=SM[i % 10000 / 1000];
delayms(5);
P0 = 0x00;
P2=0xFF;
P2=wei[3];
P0=SM[i % 1000 / 100];
delayms(5);
P0 = 0x00;
P2=0xFF;
P2=wei[4];
P0=SM[i % 100 / 10];
delayms(1);
P0 = 0x00;
P2=0xFF;
P2=wei[5];
P0=SM[i % 10];
delayms(1);
P0 = 0x00;
P2=0xFF;
}
void main(void)
{
uint j=123456,m;
P0=0xff;
P2=0x00;
delayms(1000);
while(1)
{
j++;
if(++m >= 20000)
m = 0;
if(m == 0)
display(j);
}
j 变量溢出了,给你改一下
{
P2=wei[0];
P0=SM[i % 1000000 / 100000];
delayms(5);
P0 = 0x00;
P2=0xFF;
P2=wei[1];
P0=SM[i % 100000 / 10000];
delayms(5);
P0 = 0x00;
P2=0xFF;
P2=wei[2];
P0=SM[i % 10000 / 1000];
delayms(5);
P0 = 0x00;
P2=0xFF;
P2=wei[3];
P0=SM[i % 1000 / 100];
delayms(5);
P0 = 0x00;
P2=0xFF;
P2=wei[4];
P0=SM[i % 100 / 10];
delayms(1);
P0 = 0x00;
P2=0xFF;
P2=wei[5];
P0=SM[i % 10];
delayms(1);
P0 = 0x00;
P2=0xFF;
}
void main(void)
{
uint j=123456,m;
P0=0xff;
P2=0x00;
delayms(1000);
while(1)
{
j++;
if(++m >= 20000)
m = 0;
if(m == 0)
display(j);
}
j 变量溢出了,给你改一下
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询