当前位置:首页 » 编程语言 » 8段数码管c语言代码
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

8段数码管c语言代码

发布时间: 2022-05-02 06:18:09

Ⅰ 任务:用C语言设计程序,完成8个数码管的显示控制

假设8个数码管公共端均接地,同时显示1-9
#include
#include
#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
#include
#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);
}
}
}

Ⅱ 如何用C语言静态显示让8段数码管每个段同时显示不同的数

按照你的要求,只能使用多个一位的
数码管
,多为的要不同显示只能用动态。(多段数码管内部电路限制)
每一个数码管都接一个八位
锁存器
所有锁存器输入都接P1
然后用单片机P2控制锁存器的
使能

这样代码和动态显示代码差不多。但是不会有动态的闪烁

Ⅲ 51单片机显示八位数码管的C语言程序

1、最开始,我们先打开keil。