51单片机显示八位数码管的C语言程序
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32是一种32位的微控制器,由意法半导体(STMicroelectronics)公司设计和生产。STM32是一种非常常见的嵌入式系统芯片,广泛应用于物联网、汽车、工业控制、医疗设备等领域。STM32具有以下特点:1. 体积小巧:STM...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
展开全部
这是按照郭天祥的实验板的电路画的仿真图吧,数码管的段码和位码用两片74HC573锁存这种电路,在实物电路板上是可以显示出来的,但是用proteus仿真,就不行了,不论程序怎么写,显示出来都是缺位的。在电路板上完全通过的程序,到proteus仿真就不对了。如果有实验板还是在实验板上做吧。如果非要用proteus仿真,那就不能用573锁存了,直接用P2口输出段码,用P0输出位,0有效,正好驱动8位共阴数码管。
下面是针对这个仿真图的程序,你试一下就知道显示缺位。但这个程序在实验板上是完全通过的。
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar num[]={1,2,3,4,5,6,7,8};
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delayms();
void display();
void main()
{
while(1)
{
display();
}
}
void delayms()
{
uchar i,j;
for(i=150;i>0;i--)
for(j=150;j>0;j--);
}
void display()
{
uchar i,wei=0xfe;
for(i=0;i<8;i++)
{
wela=1;
P0=wei;
wela=0;
dula=1;
P0=table[num[i]];
dula=0;
wei=_crol_(wei,1);
delayms();
}
}
下面是针对这个仿真图的程序,你试一下就知道显示缺位。但这个程序在实验板上是完全通过的。
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar num[]={1,2,3,4,5,6,7,8};
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delayms();
void display();
void main()
{
while(1)
{
display();
}
}
void delayms()
{
uchar i,j;
for(i=150;i>0;i--)
for(j=150;j>0;j--);
}
void display()
{
uchar i,wei=0xfe;
for(i=0;i<8;i++)
{
wela=1;
P0=wei;
wela=0;
dula=1;
P0=table[num[i]];
dula=0;
wei=_crol_(wei,1);
delayms();
}
}
更多追问追答
追问
需要静态的,大神可以给个静态的吗。这个一直闪跳
追答
对,是这样的,如果延时长了,可以显示出8位,但是闪跳。延时短了,就缺位,把延时子程序中的第一行for(i=150;i>0;i--)删掉,就不跳了,但是缺位。可以在延时子程序上多试试,改变两个变量i,j的初始值,要显示全了,就得跳,不跳就缺位。这就是proteus仿真的缺陷。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^7;
sbit wela=P2^6;
uchar num[] = {1, 2, 3, 4, 5, 6, 7, 8};
uchar code table[] = {
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delayms()
{
uchar i, j;
for(i = 150; i > 0; i--) for(j = 150; j > 0; j--);
}
void display()
{
uchar i, wei = 1;
for(i = 0; i < 8; i++) {
P0 = ~table[num[i]]; dula = 1; dula = 0;
P0 = wei; wela = 1; wela = 0;
wei *= 2; delayms();
P0 = 0; wela = 1; wela = 0;
}
}
void main()
{
while(1) {
display();
}
}
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^7;
sbit wela=P2^6;
uchar num[] = {1, 2, 3, 4, 5, 6, 7, 8};
uchar code table[] = {
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delayms()
{
uchar i, j;
for(i = 150; i > 0; i--) for(j = 150; j > 0; j--);
}
void display()
{
uchar i, wei = 1;
for(i = 0; i < 8; i++) {
P0 = ~table[num[i]]; dula = 1; dula = 0;
P0 = wei; wela = 1; wela = 0;
wei *= 2; delayms();
P0 = 0; wela = 1; wela = 0;
}
}
void main()
{
while(1) {
display();
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<reg51.h>
unsigned char ledtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
unsigned char sec,min,hour,dat,scanled;
unsigned char key,time;
unsigned char disdat[8];
void dischg()
{
disdat[0]=sec/10;
disdat[1]=sec%10;
disdat[2]=min/10;
disdat[3]=min%10;
disdat[4]=hour/10;
disdat[5]=hour%10;
disdat[6]=dat/10;
disdat[7]=dat%10;
}
void t0isr() interrupt 1 //秒计时
{
TR0=0;
TH0=0x3c;
TL0=0xb0;
TR0=1;
time++;
if(time==20)
{
time=0;
sec++;
if(sec>59)
{
sec=0;
min++;
if(min>59)
{
hour++;
if(hour>23)
{
hour=0;
dat++;
if(dat>30)dat=0;
}
}
}
}
dischg();
}
void t1isr() interrupt 3 //显示
{
TR1=0;
TH1=0xec;
TL1=0x78;
TR1=1;
switch(scanled)
{
case 0:
P2=0x01;
P0=ledtab[disdat[0]];
break;
case 1:
P2=0x02;
P0=ledtab[disdat[1]];
break;
case 2:
P2=0x04;
P0=ledtab[disdat[2]];
break;
case 3:
P2=0x08;
P0=ledtab[disdat[3]];
break;
case 4:
P2=0x10;
P0=ledtab[disdat[4]];
break;
case 5:
P2=0x20;
P0=ledtab[disdat[5]];
break;
case 6:
P2=0x40;
P0=ledtab[disdat[6]];
break;
case 7:
P2=0x80;
P0=ledtab[disdat[7]];
break;
default:break;
}
scanled++;
scanled%=8;
}
main()
{
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0xec;
TL1=0x78;
EA=1;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
sec=0;
min=0;
hour=0;
dat=0;
scanled=0;
time=0;
while(1);
}
unsigned char ledtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
unsigned char sec,min,hour,dat,scanled;
unsigned char key,time;
unsigned char disdat[8];
void dischg()
{
disdat[0]=sec/10;
disdat[1]=sec%10;
disdat[2]=min/10;
disdat[3]=min%10;
disdat[4]=hour/10;
disdat[5]=hour%10;
disdat[6]=dat/10;
disdat[7]=dat%10;
}
void t0isr() interrupt 1 //秒计时
{
TR0=0;
TH0=0x3c;
TL0=0xb0;
TR0=1;
time++;
if(time==20)
{
time=0;
sec++;
if(sec>59)
{
sec=0;
min++;
if(min>59)
{
hour++;
if(hour>23)
{
hour=0;
dat++;
if(dat>30)dat=0;
}
}
}
}
dischg();
}
void t1isr() interrupt 3 //显示
{
TR1=0;
TH1=0xec;
TL1=0x78;
TR1=1;
switch(scanled)
{
case 0:
P2=0x01;
P0=ledtab[disdat[0]];
break;
case 1:
P2=0x02;
P0=ledtab[disdat[1]];
break;
case 2:
P2=0x04;
P0=ledtab[disdat[2]];
break;
case 3:
P2=0x08;
P0=ledtab[disdat[3]];
break;
case 4:
P2=0x10;
P0=ledtab[disdat[4]];
break;
case 5:
P2=0x20;
P0=ledtab[disdat[5]];
break;
case 6:
P2=0x40;
P0=ledtab[disdat[6]];
break;
case 7:
P2=0x80;
P0=ledtab[disdat[7]];
break;
default:break;
}
scanled++;
scanled%=8;
}
main()
{
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0xec;
TL1=0x78;
EA=1;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
sec=0;
min=0;
hour=0;
dat=0;
scanled=0;
time=0;
while(1);
}
更多追问追答
追答
#include
unsigned char ledtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
void t1isr() interrupt 3 //显示
{
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
switch(scanled)
{
case 0:
P2=0x01;
P0=~ledtab[1];
break;
case 1:
P2=0x02;
P0=~ledtab[2];
break;
case 2:
P2=0x04;
P0=~ledtab[3];
break;
case 3:
P2=0x08;
P0=~ledtab[4];
break;
case 4:
P2=0x10;
P0=~ledtab[5];
break;
case 5:
P2=0x20;
P0=~ledtab[6];
break;
case 6:
P2=0x40;
P0=~ledtab[7];
break;
case 7:
P2=0x80;
P0=~ledtab[8];
break;
default:break;
}
scanled++;
scanled%=8;
}
main()
{
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
EA=1;
TR0=1;
ET0=1;
while(1);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询