找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 996|回复: 1
打印 上一主题 下一主题
收起左侧

各位大佬,求帮忙看一下为什么仿真不行,数码管不显示

[复制链接]
跳转到指定楼层
楼主


单片机源程序如下:
#include<reg51.h>
#define uChar unsigned char
#define uInt unsigned int
uChar a[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uChar b[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uChar second=50,minute=59,hour=12,year=18,month=07,day=21,count;
sbit Key1 = P3^0; //计时停止
sbit Key2 = P3^1; //调位
sbit Key3 = P3^2; //加一
sbit Key4 = P3^3; //切换  
sbit Buzzer=P1^1;
/*********************延迟函数********************/
void Delay(uInt t)
{
while(t)
{
t--;
}
}
/*********************时分秒显示函数*******************/
void Dispaly1(uChar second,uChar minute,uChar hour)
{
/*********************第一位数码管*********************/
P2=b[0];
P0=a[hour/10];
Delay(10);
/*********************第二位数码管*********************/
P2=b[1];
P0=a[hour%10];
Delay(10);
/*********************第三位数码管*********************/
P2=b[2];
P0=0x40;
Delay(10);
/*********************第四位数码管*********************/
P2=b[3];
P0=a[minute/10];
Delay(10);
/*********************第五位数码管*********************/
P2=b[4];
P0=a[minute%10];
Delay(10);
/*********************第六位数码管*********************/
P2=b[5];
P0=0x40;
Delay(10);
/*********************第七位数码管*********************/
P2=b[6];
P0=a[second/10];
Delay(10);
/*********************第八位数码管*********************/
P2=b[7];;
P0=a[second%10];
Delay(10);
}
/*********************年月日显示函数********************/
void Dispaly2(uChar day,uChar month,uChar year)
{
P2=b[0];
P0=a[day/10];
Delay(10);

P2=b[1];
P0=a[day%10];
Delay(10);

P2=b[2];
P0=0x40;
Delay(10);

P2=b[3];
P0=a[month/10];
Delay(10);

P2=b[4];
P0=a[month%10];
Delay(10);

P2=b[5];
P0=0x40;
Delay(10);

P2=b[6];
P0=a[year/10];
Delay(10);

P2=b[7];
P0=a[year%10];
Delay(10);
}
/*********************时钟按键扫描函数*********************/
void Keyscan1()
{
static uChar i=0,j=0;
if(Key1==0)
{
Delay(10); //消抖
if(Key1==0)
while(!Key1); //等待按键弹
i++;
}
/*时钟暂停功能*/
if(i%2==1)
{
TR0=0;/*如果是奇数次按键自然关闭定时器0*/
}
if(i%2==0)
{
TR0=1;/*如果是偶数次按键则打开定时器0*/
}
/*时钟调位和数值加一功能*/
if(Key2==0)
{
Delay(10);
if(Key2==0)
while(!Key2);
j++;
}
if(j%4==1)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
second++;
if(second==60)
second=0;
}
}
if(j%4==2)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
minute++;
if(minute==60)
minute=0;
}
}
if(j%4==3)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
hour++;
if(hour==24)
hour=0;
}
}
}
/*日期按键扫描函数*/
void Keyscan2()
{
static uChar m=0,n=0;
if(Key1==0)
{
Delay(10);
if(Key1==0)
while(!Key3);
m++;
}
if(m%2==1)
{
TR0=0;/*奇数次按键则关闭定时器0*/
}

if(m%2==0)
{
TR0=1;/*偶数次按键则打开定时器0*/
}
if(Key2==0)
{
Delay(10);
if(Key2==0)
while(!Key2);
n++;
}
/*日期调位和日期加一功能*/
if(n%4==1)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
day++;
if(day==30)
day=0;
}
}
if(n%4==2)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
month++;
if(month==12)
month=0;
}
}
if(n%4==3)
{
if(Key3==0)
{
Delay(10);
if(Key3==0)
while(!Key3);
year++;
if(year==99)
year=0;
}
}
}

/************************************************/
/***************主函数***************************/
/************************************************/
void main()
{                                                
TMOD=0x01;          /*定时器以方式一工作*/
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;/*10ms计时*/
EA=1;
ET0=1;/*允许定时器0中断*/
TR0=1;/*打开定时器0*/
while(1)
{
static uChar h=0;
/*时钟和日期切换功能*/
if(Key4==0)
{
Delay(10);
if(Key4==0)
while(!Key4);
h++;
}
if(h%2==0)/*如果按键偶数次则显示时钟*/
{
Dispaly1(second,minute,hour);
Keyscan1();
}

if(h%2==1)/*如果按键奇数次则显示日期*/
{
Dispaly2(year,month,day);
Keyscan2();
}
}
}
/**********************中断函数**************************/
void time0_int(void) interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
count++;
if(count==100)/*10ms??ê±£???100′??ò??o?1s*/
{
count=0;
second++;
if(second==60)
{
second=0;
minute++;
if(minute==60)
{
minute=0;
hour++;
if(hour==24)
{
hour=0;
day++;
if(day==30)
{
day=0;
month++;
if(month==12)
{
month=0;
year++;
if(year==99)
{
year=0;
}
}
}
}
}
}
}
/*判断整点提醒*/
if(second==00&&minute==00)                                                                  
Buzzer=0;
else
Buzzer=1;
}
这是代码

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:749012 发表于 2020-6-18 12:56 | 只看该作者
仿真没有错误,就是数码管什么都不显示
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表