51单片机,8个数码管循环显示1-9的C语言程序。
2个回答
展开全部
假设8个数码管公共端均接地,同时显示1-9
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0x82,0xf8,0x80,0x90,0xff
};
void DelayMS(uint x)
{
uchar t;
while(x--)
for(t=120;t>0;t--);
}
void main()
{
uchar i=0;
P0=0x00;
while(1)
{
P0=~DSY_CODE[i];
i=(i+1)%10;/*显示0-9*/
DelayMS(200);
}
}
下面程序从左到右显示
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};
void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=200;i>0;i--);
}
}
void main()
{
uchar i,k=0x80;
while(1)
{
for(i=8;i>0;i--)
{
P2=0xff;
k=_crol_(k,1);
P0=DSY_CODE[8-i];
P2=k;
DelayMS(3);
}
}
}
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0x82,0xf8,0x80,0x90,0xff
};
void DelayMS(uint x)
{
uchar t;
while(x--)
for(t=120;t>0;t--);
}
void main()
{
uchar i=0;
P0=0x00;
while(1)
{
P0=~DSY_CODE[i];
i=(i+1)%10;/*显示0-9*/
DelayMS(200);
}
}
下面程序从左到右显示
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};
void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=200;i>0;i--);
}
}
void main()
{
uchar i,k=0x80;
while(1)
{
for(i=8;i>0;i--)
{
P2=0xff;
k=_crol_(k,1);
P0=DSY_CODE[8-i];
P2=k;
DelayMS(3);
}
}
}
展开全部
假设8个数码管公共端均接地,同时显示1-9
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0x82,0xf8,0x80,0x90,0xff
};
void DelayMS(uint x)
{
uchar t;
while(x--)
for(t=120;t>0;t--);
}
void main()
{
uchar i=0;
P0=0x00;
while(1)
{
P0=~DSY_CODE[i];
i=(i+1)%10;/*显示0-9*/
DelayMS(200);
}
}
下面程序从左到右显示
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};
void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=200;i>0;i--);
}
}
void main()
{
uchar i,k=0x80;
while(1)
{
for(i=8;i>0;i--)
{
P2=0xff;
k=_crol_(k,1);
P0=DSY_CODE[8-i];
P2=k;
DelayMS(3);
}
}
}
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0x82,0xf8,0x80,0x90,0xff
};
void DelayMS(uint x)
{
uchar t;
while(x--)
for(t=120;t>0;t--);
}
void main()
{
uchar i=0;
P0=0x00;
while(1)
{
P0=~DSY_CODE[i];
i=(i+1)%10;/*显示0-9*/
DelayMS(200);
}
}
下面程序从左到右显示
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
};
void DelayMS(uint x)
{
uchar i;
while(x--)
{
for(i=200;i>0;i--);
}
}
void main()
{
uchar i,k=0x80;
while(1)
{
for(i=8;i>0;i--)
{
P2=0xff;
k=_crol_(k,1);
P0=DSY_CODE[8-i];
P2=k;
DelayMS(3);
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询