#include
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit rs=P3^5;
sbit lcden=P3^4;
sbit s1=P3^0;//功能键挑选
sbit s2=P3^1;//数值加1
sbit s3=P3^2;//数值减1
sbit s4=P3^6;//闹钟检查设置键
sbit rd=P3^7;//
sbit beep=P2^3;//蜂鸣器
sbit dscs=P1^4;
sbit dsas=P1^5;
sbit dsrw=P1^6;
sbit dsds=P1^7;
sbit dsirq=P3^3;
sbit DQ=P2^2; //温度数据通信线
uint temp,tplsb,tpmsb; //温度
uchar s1num,s4num,flag,flag1;
uchar miao,shi,fen,week,ri,yue,nian,amiao,afen,ashi;
uchar code table1[]=” – – “;
uchar code table2[]=” : : “;
// 周一周二 周三 周四周五 周六周日
uchar code table3[]={0xff,0x4d,0x54,0x57,0x54,0x46,0x53,0x53};
// M T W T F S S
uchar code table4[]={0xff,0x4f,0x55,0x45,0x48,0x52,0x41,0x55};
// O U E H R A U
uchar code table5[]={0xff,0x4e,0x45,0x44,0x55,0x49,0x54,0x4e};
// N E D U I T N
void write_ds(uchar,uchar);
void set_alarm(uchar,uchar,uchar);
uchar read_ds(uchar);
//void set_time();
void read_alarm();
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x–)
for(y=110;y>0;y–);
}
void Delay_DS18B20(uint num)
{
while(num–) ;
}
void write_com(uchar com)
{
rs=0;
lcden=0;
P0=com;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void write_date(uchar date)
{
rs=1;
lcden=0;
P0=date;
delay(3);
lcden=1;
delay(3);
lcden=0;
}
void init()
{
uchar num;
EA=1; //翻开总中止
EX1=1;//开定时器0中止
IT1=1;//
flag1=0;//闹钟设置,0为不响
s1num=0;
dula=0;//封闭数码管
wela=0;//封闭数码管
lcden=0;
rd=0;
//set_time();
read_alarm();
write_ds(0x0a,0x20);//时钟芯片寄存器A
write_ds(0x0b,0x26);//时钟芯片寄存器B
//read_ds(0x0c); //时钟芯片寄存器C
write_com(0x38); //液晶显示形式
write_com(0x0c); //液晶显示、开关、光标翻开
write_com(0x06); //液晶地址指针及光标移动状况
write_com(0x01); //清屏
write_com(0x80); //屏幕榜首行
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(1);
}
write_com(0x80+0x40);//屏幕第二行
for(num=0;num<16;num++)
{
write_date(table2[num]);
delay(1);
}
}
void Init_DS18B20()
{
uchar x=0;
DQ = 1; //DQ复位
Delay_DS18B20(8);//稍做延时
DQ = 0; //单片机将DQ拉低
Delay_DS18B20(80);//准确延时,大于480us
DQ = 1; //拉高总线
Delay_DS18B20(14);
x = DQ; //稍做延时后,假如x=0则初始化成功,x=1则初始化失利
Delay_DS18B20(20);
}
uchar ReadOneChar()
{
uchar i=0;
uchar dat = 0;
for (i=8;i>0;i–)
{
DQ = 0; // 给脉冲信号
dat>>=1;
DQ = 1; // 给脉冲信号
if(DQ)
dat|=0x80;
Delay_DS18B20(4);
}
return(dat);
}
void WriteOneChar(uchar dat)
{
uchar i=0;
for (i=8; i>0; i–)
{
DQ = 0;
DQ = dat&0x01;
Delay_DS18B20(5);
DQ = 1;
dat>>=1;
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/260697.html