51单片机数码管显示程序

我想让数码管扫描显示,第一个显示1第二个是2,依次类推,但是程序仿真就是不对
#include<reg52.h> #define uchar unsigned char #define uint unsigned int //uchar duan,wei;sbit duan=P1^6;sbit wei=P1^7; uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; uchar code table1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; void delay(uint z) { uint x,y; for(x<z;x>0;x--) for(y<100;y>0;y--);
} void main() { uint i,j; while(1) { wei=1; for(j=0;j<8;j++) { P2=table1[j]; wei=0; } duan=1; for(i=0;i<16;i++) { P2=table[i]; delay(20); duan=0; } } }

第1个回答  2014-01-17
你要数码管依次显示的话,我推荐有求余的方式即“%”。追问

怎么写呢,写完我追分

追答

#include //52系列单片机头文件
#define uchar unsigned char //宏定义
#define uint unsigned int
sbit dula=P2^6; //申明u1锁存器的锁存端
sbit wela=P2^7; // u2
uchar num1,num2;
uchar code table[]={ //数组定义
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code aable[]={ //位选数组定义
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void delays(uint); //子函数申明

void main()
{
while(1)
{
for(num1=0;num10;i--)
for(j=1000;j>0;j--)
for(k=110;k>0;k--);
}
/*----------------延时程序-----------------------------------------------*/

本回答被提问者采纳
第2个回答  推荐于2018-03-08
#include<reg52.h> //52系列单片机头文件
#define uchar unsigned char //宏定义
#define uint unsigned int
sbit dula=P2^6; //申明u1锁存器的锁存端
sbit wela=P2^7; // u2
uchar num1,num2;
uchar code table[]={ //数组定义
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code aable[]={ //位选数组定义
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void delays(uint); //子函数申明

void main()
{
while(1)
{
for(num1=0;num1<48;num1++) //6个数循环显示
{
wela=1; //打开u2锁存端
P0=aable[num1%6]; //送入位选信号
wela=0; //关闭u2锁存端
// delays(1);
dula=1; //打开u1锁存端
P0=table[num1%16]; //送入段选信号
dula=0; //关闭u1锁存端
delays(1);
}
}
}
/*---------主函数-----------------------------------------------*/

void delays(uint xs)
{
uint i,j,k;
for(i=xs;i>0;i--)
for(j=1000;j>0;j--)
for(k=110;k>0;k--);
}
/*----------------延时程序-----------------------------------------------*/本回答被网友采纳
第3个回答  2014-01-18
uchar code table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void delay(uchar z)
{ uchar x,y;
for(x=z;x>0;x--)
for(y=0;y<1250;y++);
}
void main()
{
uchar i,j;
while(1)
{
for(j=0;j<8;j++)
{
P2=table1[j];
wei=1;
wei=1;
wei=0;
P2=table[j]; duan=1; delay(10);
P2=0;
duan=0; } } }
第4个回答  2014-01-18
复位电路,当按键按下后,将会怎样?
相似回答