用KEIL编辑说目标没有产生,高人们帮看看那里出问题了?
其中.H文件怎么添加啊
?
/************************************************************
显示年、月、日、时、分、秒、温度
按键调时、闹铃、
/***********************************************************/
#include<REG52.H>
#include<intrins.H>
#include"ds1302.h"
#include"ds18b20.h"
/*****************************************************************/
#define uchar unsigned char
#define uint unsigned int //宏定义
sbit SH_CP1=P2^0;
sbit DS1 =P2^1;
sbit ST_CP1=P2^2;
sbit SH_CP2=P2^3;
sbit DS2 =P2^4;
sbit ST_CP2=P2^5;
sbit SH_CP3=P3^0;
sbit DS3 =P3^1;
sbit ST_CP3=P3^2;
sbit k1 =P1^3;
sbit k2 =P1^4;
sbit k3 =P1^5;
sbit k4 =P1^6;
sbit fen =P3^3;
uchar code du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d, //数码管段
0x7d,0x07,0x7f,0x6f,0x40,0x00};
uchar code we[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf, //数码管位
0xbf,0x7f};
uchar tt1[8]; //日历暂存
uchar tt2[7]; //时间、星期暂存
uchar tt3[4];//温度暂存
uchar
time[7];//读时间暂存
uchar code inittime[]={11,7,10,30,23,43,20};
uchar code write_add[]={0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};
// 年 星期 月 日 时 分 秒
uchar code read_add[]={0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};
uint temp;
uchar tflag;
/***************************74HC595函数********************************************/
void in1(uchar Data)
{
uint i;
for(i=0;i<8;i++)
{
SH_CP1=0;
DS1=Data&0x80;
Data<<=1;
SH_CP1=1;
}
}
void out1()
{
ST_CP1=0;
_nop_();
_nop_();
ST_CP1=1;
}
void in2(uchar Data)
{
uint i;
for(i=0;i<8;i++)
{
SH_CP2=0;
DS2=Data&0x80;
Data<<=1;
SH_CP2=1;
}
}
void out2()
{
ST_CP2=0;
_nop_();
_nop_();
ST_CP2=1;
}
void in3(uchar Data)
{
uint i;
for(i=0;i<8;i++)
{
SH_CP3=0;
DS3=Data&0x80;
Data<<=1;
SH_CP3=1;
}
}
void out3()
{
ST_CP3=0;
_nop_();
_nop_();
ST_CP3=1;
}
/*************************读温度函数***************************************/
uchar readvalue_ds18b20()
{
uchar g,d;
init_ds18b20();
write_byte_ds18b20(0xcc);
write_byte_ds18b20(0x44);
delay1(300);
init_ds18b20();
write_byte_ds18b20(0xcc);
write_byte_ds18b20(0xbe);
g=read_byte_ds18b20();
d=read_byte_ds18b20();
temp=d<<8;
temp|=g;
if(temp<0xfff)
{
tflag=1;
}
else
{
temp=~temp+1;
tflag=0;
}
temp=temp*(0.625);
return temp;
}
/*********************显示函数**************************************/
void set_time()//初始时间函数
{
uchar i;
write_dat_ds1302(0x8e,0x00);
for(i=0;i<7;i++)
{
write_dat_ds1302(write_add
,inittime/10*16+inittime%10);
}
write_dat_ds1302(0x8e,0x80);
}
void read_time()//读时间
{
uchar i;
for(i=0;i<7;i++)
{
time=read_dat_ds1302(read_add);
}
}
void display()//显示
{
uchar i;
read_time();
readvalue_ds18b20();
tt1[0]=time[1]%16; //星期
tt1[1]=time[4]/16;
tt1[2]=time[4]%16;//时
tt1[3]=time[5]/16;
tt1[4]=time[5]%16;// 分
tt1[5]=time[6]/16; //秒
tt1[6]=time[6]%16;
tt2[0]=2;
tt2[1]=0;
tt2[2]=time[0]/16; //年
tt2[3]=time[0]%16;
tt2[4]=time[2]/16; //月
tt2[5]=time[2]%16;
tt2[6]=time[3]/16; //日
tt2[7]=time[3]%16;
for(i=0;i<7;i++)
{
in1(we);
in1(du[tt1]);
out1();
delay1(200);
}
for(i=0;i<8;i++)
{
in2(we);
in2(du[tt2]);
out2();
delay1(200);
}
tt3[0]=temp/1000;
tt3[1]=temp%1000/100;
tt3[2]=temp%100/10;
tt3[3]=temp%10;
if(tflag==1)
{
if(tt3[0]==0)
{
tt3[0]=11;
if(tt3[1]==0)
{
tt3[1]=11;
}
}
}
else
{
if(tt3[0]==0)
{
tt3[0]=10;
if(tt3[1]==0)
{
tt3[1]=10;
tt3[0]=11;
}
}
}
for(i=0;i<3;i++)
{
in3(we);
in3(du[tt3]);
out3();
delay1(200);
}
}
/**********************键盘*****************************************/
void BB(uint i)
{
uint a,b;
for(a=i;a>0;a--)
{
for(b=50;b>0;b--);
fen=~fen;
}
}
void key()
{
uchar j,shi,fen,miao,xq,nian,yue,ri;
display();
nian=time[0]/16*10+time[0]%16;
xq =time[1]/16*10+time[1]%16;
yue =time[2]/16*10+time[2]%16;
ri =time[3]/16*10+time[3]%16;
shi =time[4]/16*10+time[4]%16;
fen =time[5]/16*10+time[5]%16;
miao=time[6]/16*10+time[6]%16;
if(!k1)
{
delay(5);
if(!k1)
{
BB(100);
while(!k1);
j++;
if(j==8)
{
j=0;
}
}
}
if(j!=0)
{
if(!k2)
{
delay(5);
if(!k2)
{
BB(100);
while(!k2);
if(j==1)
{
miao++;
if(miao>59)
{
miao=0;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[6],miao/10*16+miao%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==2)
{
fen++;
if(fen>59)
{
fen=0;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[5],fen/10*16+fen%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==3)
{
shi++;
if(shi>23)
{
shi=0;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[4],shi/10*16+shi%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==4)
{
xq++;
if(xq>7)
{
xq=1;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[1],xq/10*16+xq%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==5)
{
ri++;
if(((yue==1)||(yue==3)||(yue==5)||(yue==7)||(yue==8)||
(yue==10)||(yue==12))&&(ri>31))
{
ri=1;
}
if(((yue==4)||(yue==6)||(yue==9)||(yue==11))&&(ri>30))
{
ri=1;
}
if(yue==2)
{
if(((nian%4==0)&&(nian%100!=0))||(nian%400==0))
{
if(ri>29)
{
ri=1;
}
}
else
{
if(ri>28)
{
ri=1;
}
}
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[3],ri/10*16+ri%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==6)
{
yue++;
if(yue>12)
{
yue=1;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[2],yue/10*16+yue%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==7)
{
nian++;
if(nian>99)
{
nian=0;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[0],nian/10*16+nian%10);
write_dat_ds1302(0x8e,0x80);
}
}
}
if(!k3)
{
delay(5);
if(!k3)
{
BB(100);
while(!k3);
if(j==1)
{
miao--;
if(miao==-1)
{
miao=59;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[6],miao/10*16+miao%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==2)
{
fen--;
if(fen==-1)
{
fen=59;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[5],fen/10*16+fen%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==3)
{
shi--;
if(shi==-1)
{
shi=23;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[4],shi/10*16+shi%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==4)
{
xq--;
if(xq<1)
{
xq=7;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[1],xq/10*16+xq%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==5)
{
ri--;
if(((yue==1)||(yue==3)||(yue==5)||(yue==7)||(yue==8)||
(yue==10)||(yue==12))&&(ri<1))
{
ri=31;
}
if(((yue==4)||(yue==6)||(yue==9)||(yue==11))&&(ri<1))
{
ri=30;
}
if((yue==2))
{
if((nian%4==0)&&(nian%100!=0)||(nian%400==0))
{
if(ri<1)
{
ri=29;
}
}
else
{
if(ri<1)
{
ri=28;
}
}
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[3],ri/10*16+ri%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==6)
{
yue--;
if(yue<1)
{
yue=12;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[2],yue/10*16+yue%10);
write_dat_ds1302(0x8e,0x80);
}
if(j==7)
{
nian--;
if(nian<0)
{
nian=99;
}
write_dat_ds1302(0x8e,0x00);
write_dat_ds1302(write_add[0],nian/10*16+nian%10);
write_dat_ds1302(0x8e,0x80);
}
}
}
}
if(!k4)
{
delay(5);
if(!k4)
{
BB(100);
while(!k4);
j=0;
}
}
}
/*****************主函数************************************************/
void main()
{
set_time();
while(1)
{
key();
}
}
这个是DS1302的程序#include"ds1302.h"
void write_byte_ds1302(uchar dat)
{
uchar i;
ACC=dat;
for(i=8;i>0;i--)
{
io=ACC0;
sclk=1;
sclk=0;
ACC>>=1;
}
}
uchar read_byte_ds1302()
{
uchar i;
for(i=0;i<8;i++)
{
ACC>>=1;
ACC7=io;
sclk=1;
sclk=0;
}
return (ACC);
}
void write_dat_ds1302(uchar add,uchar dat)
{
rst=0;
sclk=0;
rst=1;
write_byte_ds1302(add);
write_byte_ds1302(dat);
sclk=1;
sclk=0;
rst=0;
sclk=1;
}
uchar read_dat_ds1302(uchar add)
{
uchar value;
rst=0;
sclk=0;
rst=1;
write_byte_ds1302(add);
value=read_byte_ds1302();
sclk=1;
sclk=0;
rst=0;
sclk=1;
return value;
}
这个是ds18b20的
#include"ds18B20.h"
void delay(uint ms)
{
uint a,b;
for(a=ms;a>0;a--)
for(b=110;b>0;b--);
}
void delay1(uint t)
{
while(t--);
}
void init_ds18b20()
{
uchar n;
dq=1;
delay1(8);
dq=0;
delay1(80);
dq=1;
delay1(4);
n=dq;
delay1(8);
}
void write_byte_ds18b20(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
dq=0;
dq=dat&0x01;
delay1(4);
dq=1;
dat>>=1;
}
delay1(4);
}
uchar read_byte_ds18b20()
{
uchar i,value;
for(i=0;i<8;i++)
{
dq=0;
value>>=1;
delay1(4);
dq=1;
if(dq)
value|=0x80;
delay1(4);
}
return value;
}
请高人们费心看一下,菜鸟求助啊,老是出目标没有产生怎么解决啊?
一周热门 更多>