基于51单片机电子闹钟的设计,用C语言,跪求高手
电路什么的都弄好了,程序也有,就是运行不起来,跪求高手,解决了提高悬赏!!!!!!#include<reg51.h>#include<intrins.h>#defineu...
电路什么的都弄好了,程序也有,就是运行不起来,跪求高手,解决了提高悬赏!!!!!!
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
/*位声明*/
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^3;
sbit key4=P1^4;
/*数码管显示数值*/
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0x0ff};
/*函数声明*/
void jia();
void jian();
/*数组定义,数组内含8哥数值*/
uchar table[8],table2[8],table3[8],table4[8];
/*时间显示初始值*/
uchar shil,fenl,miaol,shi2,fen2,miao2,shi3,fen3,miao3;
uchar shi4,fen4,miao4;
uchar flag,flag1,wss,cnt,cnt1,alm1,aml2,aml3;
/* 1秒 等时 位闪 次数 校时 闹1 闹2 闹3*/
uchar flag2;
/* 蜂鸣*/
/*延时函数,用于动态扫描数码管*/
void delay(uchar i)
{ uchar x,y;
for(x=i;x>0;x--)
for(y=120;y>0;Y--);
}
/*初始化函数*/
void init()
{ TMOD=0x01; /*工作方式1*/
TH0=0x3c; /*定时时间为:50ms (65536-50000)/250*/
TL0=0x0b0; /*65536-50000%250*/
ET0=1; /*打开定时器*/
EA=1; /*开总中断*/
TR0=1; /*启动定时器*/ 展开
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
/*位声明*/
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^3;
sbit key4=P1^4;
/*数码管显示数值*/
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0x0ff};
/*函数声明*/
void jia();
void jian();
/*数组定义,数组内含8哥数值*/
uchar table[8],table2[8],table3[8],table4[8];
/*时间显示初始值*/
uchar shil,fenl,miaol,shi2,fen2,miao2,shi3,fen3,miao3;
uchar shi4,fen4,miao4;
uchar flag,flag1,wss,cnt,cnt1,alm1,aml2,aml3;
/* 1秒 等时 位闪 次数 校时 闹1 闹2 闹3*/
uchar flag2;
/* 蜂鸣*/
/*延时函数,用于动态扫描数码管*/
void delay(uchar i)
{ uchar x,y;
for(x=i;x>0;x--)
for(y=120;y>0;Y--);
}
/*初始化函数*/
void init()
{ TMOD=0x01; /*工作方式1*/
TH0=0x3c; /*定时时间为:50ms (65536-50000)/250*/
TL0=0x0b0; /*65536-50000%250*/
ET0=1; /*打开定时器*/
EA=1; /*开总中断*/
TR0=1; /*启动定时器*/ 展开
3个回答
展开全部
#include<reg52.h>
#include<intrins.h>
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
#define rst573 P2&=0X1F
#define y4 P2|=0X80
#define y5 P2|=0XA0
#define y6 P2|=0XC0
#define y7 P2|=0XE0
sbit s5=P3^2;
sbit s4=P3^3;
sbit s6=P3^1;
sbit s7=P3^0;
sbit scl=P1^7;
sbit IO=P2^3;
sbit rst1302=P1^3;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code chu[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar time[8]={0xa4,0xb0,0xbf,0x90,0x90,0xbf,0xc0,0xc0};
uchar miao1,miao2,fen1,fen2,shi1,shi2,shi,fen;
void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=120;j>0;j--);
}
void writebyte(uchar add,uchar date)
{
uchar i;
scl=0;
IO=0;
rst1302=1;
for(i=0;i<8;i++)
{
scl=0;
IO=add&0x01;
scl=1;
add>>=1;
}
for(i=0;i<8;i++)
{
scl=0;
IO=date&0x01;
scl=1;
date>>=1;
}
rst1302=0;
}
uchar readbyte(uchar add)
{
uchar i,temp;
scl=0;
IO=0;
rst1302=1;
for(i=0;i<8;i++)
{
scl=0;
IO=add&0x01;
scl=1;
add>>=1;
}
for(i=0;i<8;i++)
{
scl=1;
temp>>=1;
scl=0;
if(IO)
temp|=0x80;
}
return temp;
}
void set1302()
{
writebyte(0x8e,0x00);
writebyte(0x84,0x00);
writebyte(0x82,0x00);
writebyte(0x80,0x00);
writebyte(0x8e,0x80);
}
void read1302(uchar *p)
{
p[0]=readbyte(0x85);
writebyte(0x84,0x00);
p[1]=readbyte(0x83);
writebyte(0x82,0x00);
p[2]=readbyte(0x81);
writebyte(0x00,0x00);
}
void zhuanghuan()
{
shi=time[0];
fen=time[1];
miao1=(time[2]/16)%10;
miao2=(time[2]%16)%10;
}
void display()
{
rst573;
P0=chu[0];
y6;
rst573;
P0=tab[shi>>4];
y7;
delay(2);
rst573;
P0=chu[1];
y6;
rst573;
P0=tab[shi&0x0f];
y7;
delay(2);
rst573;
P0=chu[3];
y6;
rst573;
P0=tab[fen>>4];
y7;
delay(2);
rst573;
rst573;
P0=chu[4];
y6;
rst573;
P0=tab[fen&0x0f];
y7;
delay(2);
rst573;
P0=chu[6];
y6;
rst573;
P0=tab[miao1];
y7;
delay(2);
rst573;
P0=chu[7];
y6;
rst573;
P0=tab[miao2];
y7;
delay(2);
rst573;
P0=chu[2];
y6;
rst573;
P0=0xbf;
y7;
delay(2);
rst573;
P0=chu[5];
y6;
rst573;
P0=0xbf;
y7;
rst573;
delay(1);
read1302(time);
zhuanghuan();
}
void jian()
{
if(s4==0)
{
delay(5);
if(s4==0)
{
while(!s4)
display();
writebyte(0x8e,0x00);
shi++;
if(shi==10) //对应BCD的0~9
shi=16;
if(shi==26) //对应BCD的10~19
shi=32;
if(shi==36) //对应BCD的19~23
shi=0;
writebyte(0x84,shi);
}
}
if(s5==0)
{
delay(5);
if(s5==0)
{
while(!s5)
display();
writebyte(0x8e,0x00);
shi--;
if(shi==-1) //对应BCD的23~20
shi=35;
if(shi==31) //对应BCD的19~10
shi=25;
if(shi==15) //对应BCD的9~0
shi=9;
writebyte(0x84,shi);
}
}
if(s6==0)
{
delay(5);
if(s6==0)
{
while(!s6)
display();
writebyte(0x8e,0x00);
fen++;
if(fen==10) //对应BCD的0~9
fen=16;
if(fen==26) //对应BCD的10~19
fen=32;
if(fen==42) //对应BCD的20~29
fen=48;
if(fen==58) //对应BCD的30~39
fen=64;
if(fen==74) //对应BCD的40~49
fen=80;
if(fen==90) //对应BCD的50~59
fen=0;
writebyte(0x82,fen);
}
}
if(s7==0)
{
delay(5);
if(s7==0)
{
while(!s7)
display();
writebyte(0x8e,0x00);
fen--;
if(fen==-1) //对应BCD的59~50
fen=89;
if(fen==79) //对应BCD的49~40
fen=73;
if(fen==63) //对应BCD的39~30
fen=57;
if(fen==47) //对应BCD的29~20
fen=41;
if(fen==31) //对应BCD的19~10
fen=25;
if(fen==15) //对应BCD的9~0
fen=9;
writebyte(0x82,fen);
}
}
}
void main()
{
set1302();
while(1)
{
jian();
display();
}
}
#include<intrins.h>
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
#define rst573 P2&=0X1F
#define y4 P2|=0X80
#define y5 P2|=0XA0
#define y6 P2|=0XC0
#define y7 P2|=0XE0
sbit s5=P3^2;
sbit s4=P3^3;
sbit s6=P3^1;
sbit s7=P3^0;
sbit scl=P1^7;
sbit IO=P2^3;
sbit rst1302=P1^3;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code chu[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar time[8]={0xa4,0xb0,0xbf,0x90,0x90,0xbf,0xc0,0xc0};
uchar miao1,miao2,fen1,fen2,shi1,shi2,shi,fen;
void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=120;j>0;j--);
}
void writebyte(uchar add,uchar date)
{
uchar i;
scl=0;
IO=0;
rst1302=1;
for(i=0;i<8;i++)
{
scl=0;
IO=add&0x01;
scl=1;
add>>=1;
}
for(i=0;i<8;i++)
{
scl=0;
IO=date&0x01;
scl=1;
date>>=1;
}
rst1302=0;
}
uchar readbyte(uchar add)
{
uchar i,temp;
scl=0;
IO=0;
rst1302=1;
for(i=0;i<8;i++)
{
scl=0;
IO=add&0x01;
scl=1;
add>>=1;
}
for(i=0;i<8;i++)
{
scl=1;
temp>>=1;
scl=0;
if(IO)
temp|=0x80;
}
return temp;
}
void set1302()
{
writebyte(0x8e,0x00);
writebyte(0x84,0x00);
writebyte(0x82,0x00);
writebyte(0x80,0x00);
writebyte(0x8e,0x80);
}
void read1302(uchar *p)
{
p[0]=readbyte(0x85);
writebyte(0x84,0x00);
p[1]=readbyte(0x83);
writebyte(0x82,0x00);
p[2]=readbyte(0x81);
writebyte(0x00,0x00);
}
void zhuanghuan()
{
shi=time[0];
fen=time[1];
miao1=(time[2]/16)%10;
miao2=(time[2]%16)%10;
}
void display()
{
rst573;
P0=chu[0];
y6;
rst573;
P0=tab[shi>>4];
y7;
delay(2);
rst573;
P0=chu[1];
y6;
rst573;
P0=tab[shi&0x0f];
y7;
delay(2);
rst573;
P0=chu[3];
y6;
rst573;
P0=tab[fen>>4];
y7;
delay(2);
rst573;
rst573;
P0=chu[4];
y6;
rst573;
P0=tab[fen&0x0f];
y7;
delay(2);
rst573;
P0=chu[6];
y6;
rst573;
P0=tab[miao1];
y7;
delay(2);
rst573;
P0=chu[7];
y6;
rst573;
P0=tab[miao2];
y7;
delay(2);
rst573;
P0=chu[2];
y6;
rst573;
P0=0xbf;
y7;
delay(2);
rst573;
P0=chu[5];
y6;
rst573;
P0=0xbf;
y7;
rst573;
delay(1);
read1302(time);
zhuanghuan();
}
void jian()
{
if(s4==0)
{
delay(5);
if(s4==0)
{
while(!s4)
display();
writebyte(0x8e,0x00);
shi++;
if(shi==10) //对应BCD的0~9
shi=16;
if(shi==26) //对应BCD的10~19
shi=32;
if(shi==36) //对应BCD的19~23
shi=0;
writebyte(0x84,shi);
}
}
if(s5==0)
{
delay(5);
if(s5==0)
{
while(!s5)
display();
writebyte(0x8e,0x00);
shi--;
if(shi==-1) //对应BCD的23~20
shi=35;
if(shi==31) //对应BCD的19~10
shi=25;
if(shi==15) //对应BCD的9~0
shi=9;
writebyte(0x84,shi);
}
}
if(s6==0)
{
delay(5);
if(s6==0)
{
while(!s6)
display();
writebyte(0x8e,0x00);
fen++;
if(fen==10) //对应BCD的0~9
fen=16;
if(fen==26) //对应BCD的10~19
fen=32;
if(fen==42) //对应BCD的20~29
fen=48;
if(fen==58) //对应BCD的30~39
fen=64;
if(fen==74) //对应BCD的40~49
fen=80;
if(fen==90) //对应BCD的50~59
fen=0;
writebyte(0x82,fen);
}
}
if(s7==0)
{
delay(5);
if(s7==0)
{
while(!s7)
display();
writebyte(0x8e,0x00);
fen--;
if(fen==-1) //对应BCD的59~50
fen=89;
if(fen==79) //对应BCD的49~40
fen=73;
if(fen==63) //对应BCD的39~30
fen=57;
if(fen==47) //对应BCD的29~20
fen=41;
if(fen==31) //对应BCD的19~10
fen=25;
if(fen==15) //对应BCD的9~0
fen=9;
writebyte(0x82,fen);
}
}
}
void main()
{
set1302();
while(1)
{
jian();
display();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这样说我们是帮不上忙的,请把你的详细情况说下,首先你的硬件电路是没有问题的,先用测试程序将所有的数码管点亮。然后再进行你的程序更改可能会好些·!还是数码管共阴和共阳接线是不同的你没有搞错吧。是一个尺寸的数码管不,还是有其它尺寸的?尺寸不一样引脚功能是不同的。
追问
能给个qq帮我看下吗?
追答
121097954
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询