我想用51单片机做一个篮球计时器24秒倒计时,用数码管显示,求各位高手帮忙画电路原理图,谢谢
1个回答
展开全部
#include "reg51.h"
#define uchar unsigned char
uchar display_code[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
uchar display_data[8]={0,0,0,0,0,0,0,0};
uchar time[]={0,0,0};
void delay(void)
{
uchar i;
for(i=250;i>0;i--);
}
void display()
{
uchar i,k;
k=0x80;
for(i=0;i<8;i++)
{
P2=0;
P0=display_code[display_data[i]];
P2=k;
k=k>>1;
delay();
}
P2=0;
}
void calc()
{
time[0]++;
if(time[0]>23)
time[0]=0;
}
void convert()
{
display_data[0]=time[0]/10;
display_data[1]=time[0]%10;
}
void main(void)
{
uchar i;
while(1)
{
for(i=0;i<250;i++)
{
display();
}
calc();
convert();
}
}
#define uchar unsigned char
uchar display_code[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
uchar display_data[8]={0,0,0,0,0,0,0,0};
uchar time[]={0,0,0};
void delay(void)
{
uchar i;
for(i=250;i>0;i--);
}
void display()
{
uchar i,k;
k=0x80;
for(i=0;i<8;i++)
{
P2=0;
P0=display_code[display_data[i]];
P2=k;
k=k>>1;
delay();
}
P2=0;
}
void calc()
{
time[0]++;
if(time[0]>23)
time[0]=0;
}
void convert()
{
display_data[0]=time[0]/10;
display_data[1]=time[0]%10;
}
void main(void)
{
uchar i;
while(1)
{
for(i=0;i<250;i++)
{
display();
}
calc();
convert();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询