51单片机led4位数码管动态显示“0123”的程序,急急,,,能帮忙的就快点,谢谢啦
4个回答
展开全部
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
//sbit dula=P2^6;
sbit wela1=P2^0;//位选
sbit wela2=P2^1;
sbit wela3=P2^2;
sbit wela4=P2^3;
void delay(uint);
uint a,b;
uchar num;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//字符0123456789
void main()
{
while(1)
{
P0=0xea;
wela1=0;
wela2=1;
wela3=1;
wela4=1;//显示千位数
delay(1000);
P0=0xea;//数字
wela1=1;
wela2=0;
wela3=1;
wela4=1;//显示百位数
delay(1000);
P0=0xea;//数字
wela1=1;
wela2=1;
wela3=0;
wela4=1;//显示十位数
delay(1000);
P0=0xea;//数字
wela1=1;
wela2=1;
wela3=1;
wela4=0;//显示个位数
delay(1000);
}
}
void delay(uint x)
{
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
#define uchar unsigned char
#define uint unsigned int
//sbit dula=P2^6;
sbit wela1=P2^0;//位选
sbit wela2=P2^1;
sbit wela3=P2^2;
sbit wela4=P2^3;
void delay(uint);
uint a,b;
uchar num;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//字符0123456789
void main()
{
while(1)
{
P0=0xea;
wela1=0;
wela2=1;
wela3=1;
wela4=1;//显示千位数
delay(1000);
P0=0xea;//数字
wela1=1;
wela2=0;
wela3=1;
wela4=1;//显示百位数
delay(1000);
P0=0xea;//数字
wela1=1;
wela2=1;
wela3=0;
wela4=1;//显示十位数
delay(1000);
P0=0xea;//数字
wela1=1;
wela2=1;
wela3=1;
wela4=0;//显示个位数
delay(1000);
}
}
void delay(uint x)
{
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
追问
是9999秒的秒表设计 这个好像不对吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};//0-f
uchar disbuf[4] = {0};
void display(){
static uchar com = 0;
P2 = 0;
P0 = table[disbuf[com]];
P2 = (1 << com);
com = (com+ 1) % 4;
}
void delay(int n){
...
}
void main()
{
disbuf[0] = 0;
disbuf[1] = 1;
disbuf[2] = 2;
disbuf[3] = 3;
while(1){
display();
delay(100);
}
}
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};//0-f
uchar disbuf[4] = {0};
void display(){
static uchar com = 0;
P2 = 0;
P0 = table[disbuf[com]];
P2 = (1 << com);
com = (com+ 1) % 4;
}
void delay(int n){
...
}
void main()
{
disbuf[0] = 0;
disbuf[1] = 1;
disbuf[2] = 2;
disbuf[3] = 3;
while(1){
display();
delay(100);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
补充:
void delay(int n){
...
}
改为:
void delay(int n){
uint tmp=n;
while(tmp--);
}
void delay(int n){
...
}
改为:
void delay(int n){
uint tmp=n;
while(tmp--);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
电路错了,什么程序也不能正常显示。
三极管的,集电极、发射极,交换一下即可。
三极管的,集电极、发射极,交换一下即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询