for(j=0;j<110;j++);
}
voiddelay1(ucharx)
{
uchari;
while(x--)
{
for(i=0;i<13;i++)
{
}
}
}
voiddelay_jiepai()
{
unsignedchari,j;
for(i=0;i<250;i++)
for(j=0;j<250;j++)
;
}
/*lcd.h头文件声明*/
#ifndef__LCD_H__
#define__LCD_H__
#include
#include
#defineucharunsignedchar
#defineuintunsignedint
sbitRS=P2^6;
sbitRW=P2^5;
sbitE=P2^7;
//sbitPSB=P3^2;
sbitBF=P0^7;
externucharcheck_busy();
externvoidwrite_com(ucharcom);
externvoidwrite_dat(uchardat);
externvoidwrite_string(uchar*s,ucharadd);
externvoidclear_screen();
externvoidmove_flag();
externvoidinit_lcd();
#endif
/*lcd.c部分程序*/
#include"lcd.h"
#include"delay.h"
#include"music.h"
ucharcheck_busy()
{
bitresult;
RS=0;
RW=1;
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
result=BF;
E=0;
returnresult;
}
voidwrite_com(ucharcom)
{
while(check_busy()==1);
RS=0;
RW=0;
E=0;
P0=com;
E=1;
E=0;
}
voidwrite_dat(uchardat)
{
while(check_busy()==1);
RS=1;
RW=0;
E=0;
P0=dat;
E=1;
E=0;
}
voidwrite_string(uchar*s,ucharadd)
{
write_com(add);
while(*s)
{
write_dat(*s);
s++;
}
}
voidclear_screen()
{
write_com(0x01);
delay
(1);
}
voidinit_lcd()
{
//PSB=1;
delay(5);
write_com(0x30);
delay(5);
write_com(0x30);
delay(5);
write_com(0x0c);
delay(5);
write_com(0x06);
delay(5);
write_com(0x01);
}
/*ds18b20.h头文件声明*/
#ifndef__DS18B20_H__
#define__DS18B20_H__
#include
#include
#defineucharunsignedchar
#defineuintunsignedint
sbitDQ=P3^7;
externucharTL;
externucharTH;
externucharTN;
externucharTD;
externucharread_ds18b20(void);
externvoidready_ds18b20(void);
#endif
/*ds18b20.c程序部分*/
#include"ds18b20.h"
uchartime;
ucharTL;
ucharTH;
ucharTN;
ucharTD;
bitinit_ds18b20(void)
{
bitflag;
DQ=1;
for(time=0;time<2;time++);
DQ=0;
for(time=0;time<200;time++);
DQ=1;
for(time=0;time<10;time++);
flag=DQ;
for(time=0;time<200;time++);
return(flag);
DQ=1;
}
ucharread_ds18b20(void)
{
uchari=0,dat;
for(i=0;i<8;i++)
{
DQ=1;
_nop_();
DQ=0;
dat>>=1;
_nop_();
DQ=1;
for(time=0;time<2;time++);
if(DQ==1)
dat|=0x80;
else
dat|=0x00;
for(time=0;time<10;time++);
}
return(dat);
}
voidwrite_ds18b20(uchardat)
{
uchari=0;
for(i=0;i<8;i++)
{
DQ=0;
for(time=0;time<5;time++);
DQ=dat&0x01;
for(time=0;time<15;time++);
DQ=1;
for(time=0;time<1;time++);
dat>>=1;
}
for(time=0;time<4;time++);
}
voidready_ds18b20(void)
{
init_ds18b20();
write_ds18b20(0xCC);
write_ds18b20(0x44);
for(time=0;time<100;time++);
init_ds18b20();
write_ds18b20(0xCC);
write_ds18b20(0xBE);
}
/*ds1302.h头文件声明*/
#ifndef__DS1302_H__
#define__DS1302_H__
#include
#include
#defineucharunsignedchar
#defineuintunsignedint
sbitSCL=P3^6;
sbitSDA=P3^4;
sbitRST=P3^5;
externuchartime_data[7];
externvoidwrite_ds1302_byte(ucharbyte);
externvoidwrite_ds1302(ucharadd,ucharbyte);
externucharread_ds1302_byte(ucharadd);
externvoidread_ds1302(void);
externvoidset_ds1302(void);
#endif
/*ds1302.c部分程序*/
#include"ds1302.h"
ucharwrite_add[7]={0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};//写(年周月日时分秒)
ucharread_add[7]={0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};//读(年周月日时分秒)
uchartime_data[7]={11,6,12,30,12,43,50};
voidwrite_ds1302_byte(ucharbyte)//写寄存器地址
{
uchari;
for(i=0;i<8;i++)
{
SCL=0;
SDA=byte&0x01;
byte=byte>>1;
SCL=1;
}
}
voidwrite_ds1302(ucharadd,ucharbyte)//单字节写
{
RST=0;
_nop_();
SCL=0;
_nop_();
RST=1;
_nop_();
write_ds1302_byte(add);
write_ds1302_byte(byte);
RST=0;
SDA=1;
SCL=1;
}
ucharread_ds1302_byte(ucharadd)
{
uchari,value=0x00;
RST=0;
_nop_();
SCL=0;
_nop_();
RST=1;
_nop_();
write_ds1302_byte(add);
for(i=0;i<8;i++)
{
if(SDA)
value|=0x80;
SCL=0;
value=value>>1;
SCL=1;
}
RST=0;
SCL=0;
_nop_();
SCL=1;
SDA=1;
_nop_();
return(value);
}
voidread_ds1302(void)//读所有时间
{
uchari,*p;
p=read_add;
for(i=0;i<7;i++)
{
time_data[i]=read_ds1302_byte(*p);
p++;
}
}
voidset_ds1302(void)
{
uchari,gaowei,diwei,*p;
for(i=0;i<7;i++)
{
gaowei=time_data[i]/10;
diwei=time_data[i]%10;
time_data[i]=diwei+gaowei*16;
}
write_ds1302(0x8e,0x00);//去写保护
p=write_add;
for(i=0;i<7;i++)
{
write_ds1302(*p,time_data[i]);
p++;
}
write_ds1302(0x8e,0x80);//加写保护,防止误动作
}
/*ir.h*头文件声明/
#ifndef_IR_H__
#define_IR_H__
#include
#include
#include"delay.h"
#include"lcd.h"
#include"music.h"
#defineucharunsignedchar
#defineuintunsignedint
sbitIR=P3^2;
externucharIR_com[7];
externvoidSound();
externvoidYaokong();
externvoidJiema();
#endif
/*ir.c部分程序*/
#include"ir.h"
#include"ds1302.h"
voidYaokong()
{
uchargao,di;
gao=IR_com[6]-48;
di=IR_com[5]-48;
switch(gao)
{
case0:
switch(di)//gaoweiwei0
{
case7:
write_string("惜时如金",0x98);break;//0x07:
EQ
case9:
write_string("时间就是金钱",0x98);break;//0x09:
VOL+
case8:
write_string("一寸光阴",0x98);break;//0x08:
4
case19:
write_string("一寸金",0x98);break;//0x0c:
1
case20:
write_string("寸金难买寸光阴",0x98);break;//0x0d:
U/SD
};break;
case1:
switch(di)//gaoweiwei1
{
case5:
write_string("锄禾",0x98);break;//0x15:
VOL-
case6:
write_string("锄禾日当午",0x98);break;//0x16:
0
case8:
write_string("汗滴禾下土",0x98);break;//0x18:
2
case9:
write_string("谁知盘中餐",0x98);break;//0x19:
RPT
case19:
write_string("粒粒皆辛苦",0x98);break;//0x1c:
5
};break;
case4:
switch(di)
{
case0:
write_string("劝君更进一杯酒",0x98);break;//0x40:
zuo
case2:
write_string("西出阳关无故人",0x98);break;//0x42:
7
case3:
write_string("风萧萧兮逆水寒",0x98);break;//0x43:
you
//case4:
;break;//0x44:
zanting
case5:
clear_screen();break;//0x45:
dianyuan//清屏功能键
case6:
clear_screen();
delay
(1);
write_string("请欣赏Music",0x80);
delay
(1);
write_string("<<梦里水乡>>",0x90);
delay
(1);
write_string("是否播放?
",0x88);
delay(5);
yinyue();
break;//0x46:
Mode
case7:
;break;//0x47:
jingyin
case17:
write_string("只有更好",0x98);break;//0x4a:
9
};break;
case5:
switch(di)
{
case2:
write_string("北国风光",0x98);break;//0x52:
8
case17:
write_string("万里雪飘",0x98);break;//0x5a:
6
case21:
write_string("江山内外",0x98);break;//0x5e:
3
};break;
}
}
voidJiema()
{
ucharj,k,N=0;
delay1(15);
if(IR==1)
{
EX0=1;
return;
}
while(!
IR)
{
delay1
(1);
}
for(j=0;j<4;j++)
{
for(k=0;k<8;k++)
{
while(IR)
{
delay1
(1);
}
while(!
IR)
{
delay1
(1);
}
while(IR)
{
delay1
(1);
N++;
if(N>=30)
{
EX0=1;
return;
}
}
IR_com[j]=IR_com[j]>>1;
if(N>=8)
{
IR_com[j]=IR_com[j]|0x80;
}
N=0;
}
}
if(IR_com[2]!
=~IR_com[3])
{
EX0=1;
return;
}
IR_com[5]=IR_com[2]&0x0F;
IR_com[6]=IR_com[2]>>4;
if(IR_com[5]>9)
{
IR_com[5]=IR_com[5]+0x37;
}
else
IR_com[5]=IR_com[5]+0x30;
if(IR_com[6]>9)
{
IR_com[6]=IR_com[6]+0x37;
}
else
IR_com[6]=IR_com[6]+0x30;
Sound();
}
/*music.h头文件声明*/
#ifndef_MUSIC_H__
#define_MUSIC_H__
#include
#include
#include"delay.h"
#include"ir.h"
#defineucharunsignedchar
#defineuintunsignedint
//以下是C调低音的音频宏定义
#defined_dao262
#defined_re286
#defined_mi311
#defined_fa349
#defined_sao392
#defined_la440
#defined_xi494
//以下是C调中音的音频宏定义
#definedao523
#definere587
#definemi659
#definefa698
#definesao784
#definela880
#definexi987
//以下是C调高音的音频宏定义
#defineh_dao1046
#defineh_re1174
#defineh_mi1318
#defineh_fa1396
#defineh_sao1567
#defineh_la1760
#defineh_xi1975
sbitsounder=P1^5;
externuintC;
externucharflag_music;
externvoidSound();
externvoidyinyue(void);
#endif
/*music.c部分程序*/
#include"music.h"
uintC;//储存定时器的定时常数
uintcodef[]={d_sao,dao,re,mi,sao,mi,re,dao,re,mi,//春天的黄昏请你陪我到
dao,dao,dao,d_la,d_sao,//梦中的水乡
d_sao,dao,re,mi,sao,mi,re,dao,re,mi,re,//让挥动的手在薄雾中飘荡
mi,sao,sao,mi,sao,sao,dao,la,sao,//不要惊醒杨柳岸那些
dao,dao,dao,sao,mi,//缠绵的往事
mi,dao,//化作
re,re,mi,re,d_la,dao,dao,re,d_la,d_sao,//一缕轻烟已消失已消失在远方
d_sao,dao,re,mi,sao,mi,re,dao,re,mi,//暖暖的午后闪过一片片
dao,dao,dao,d_la,d_sao,//粉红的衣裳
d_sao,dao,re,mi,sao,mi,re,dao,re,mi,re,//谁也载不走那扇古老的窗
mi,sao,sao,mi,sao,sao,dao,la,sao,//玲珑少年在岸上守候
dao,dao,dao,sao,mi,//一生的时光
mi,dao,//为何
re,re,mi,re,d_la,dao,dao,re,mi,sao,//没能做个你梦中的新娘
d_sao,d_la,sao,sao,mi,re,dao,re,sao,//淡淡相思都写在脸上
re,mi,sao,sao,mi,sao,la,sao,//沉沉离别背在肩上
mi,sao,la,la,sao,la,la,sao,mi,dao,//泪水流过脸庞,所有的话
d_la,d_sao,dao,dao,re,mi,mi,//现在还是没有讲
d_sao,d_la,sao,sao,mi,re,dao,re,sao,//看那青山荡漾在水上
re,mi,sao,sao,mi,sao,la,sao,//看那晚霞吻着夕阳
mi,sao,la,sao,la,la,h_dao,sao,mi,re,dao,re,mi,//我用一生的爱去寻找那一个家
re,d_la,d_sao,dao,sao,mi,//今夜你在何方
d_sao,d_la,dao,//转回头
re,re,dao,re,mi,re,//迎着你的笑颜
sao,mi,re,re,dao,re,mi,re,//心事全都被你发现
d_la,mi,re,re,mi,re,d_la,//梦里遥远的幸福
d_sao,d_sao,d_sao,d_sao,d_la,dao,dao,//他就在我的身旁
0xff};//以0xff作为音符的结束标志
//以下是简谱中每个音符的节拍
//"4"对应4个延时单位,"2"对应2个延时单位,"1"对应1个延时单位
ucharcodeJP[]={1,1,1,1,3,1,1,1,1,2,//春天的黄昏请你陪我到
2,2,2,2,4,//梦中的水乡
1,1,1,1,3,1,1,1,1,2,6,//让挥动的手在薄雾中飘荡
1,1,2,2,2,1,3,1,1,//不要惊醒杨柳岸哪那些
2,2,2,1,5,//缠绵的往