CT107DDS18B20DS1302数码管大集合.docVIP

  • 4
  • 0
  • 约3.18千字
  • 约 6页
  • 2017-05-05 发布于北京
  • 举报
CT107DDS18B20DS1302数码管大集合

#includereg52.h #define rst573 P2=0x1f #define ledY4C P2|=0x80 #define beeY5C P2|=0xa0 #define smgY6C P2|=0xc0 #define smgY7C P2|=0xe0 sbit P04=P0^4; sbit P06=P0^6; sbit P36=P3^6; sbit ww=P1^4;//DS18B20 1wire总线 sbit c1302=P1^7;//SPI时钟 sbit d1302=P2^3;//SPI数据 sbit s1302=P1^3;//SPI使能 高有效 低复位 unsigned char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; void delay6us(unsigned char us) { while(us--); } void delaynms(unsigned int ms) { unsigned int x,y; for(x=ms;x;x--) for(y=110;y;y--); } void init107() { rst573; P36=0; //led P0=0xff; ledY4C; rst573; //bee P04=0; P06=0; beeY5C; rst573; //smg P0=0x00; smgY6C; rst573; } void rst18B20() { ww=0; delay6us(100);//480 11+6*100=611 ww=1; delay6us(20);//240 至少为20 } void write18B20(unsigned char temp) { unsigned char i; for(i=8;i;i--) { ww=0; temp=1; ww=CY; delay6us(5); ww=1;//关键的神机!! } } unsigned char read18B20() { unsigned char i,temp; for(i=8;i;i--) { ww=0; temp=1; ww=1;//关键的神机!! if(ww) temp|=0x80; delay6us(5); } return temp; } unsigned int temperature() { unsigned char temp1,temp2; unsigned int temp; rst18B20(); write18B20(0xcc); write18B20(0x44); rst18B20(); write18B20(0xcc); write18B20(0xbe); temp1=read18B20();//低8位 temp2=read18B20();//高8位 temp=temp2; temp=8; temp+=temp1; temp=(unsigned int)(temp*0.625); return temp; } void write1302(unsigned char addr,unsigned char dat) { unsigned char i; s1302=0; c1302=0; s1302=1; for(i=8;i;i--) { addr=1; d1302=CY; c1302=0; c1302=1; } for(i=8;i;i--) { dat=1; d1302=CY; c1302=0; c1302=1; } s1302=0; } unsigned char read1302(unsigned char addr) { unsigned char i,temp; s1302=0; c1302=0; s1302=1; for(i=8;i;i--) { addr=1; d1302=CY; c1302=0; c1302=1; } for(i=8;i;i--) { temp=1; c1302=1; c1302=0; if(d1302) temp|=0x80; } s1302=0; return temp; } void init1302() { write1302(0x8e,0x00); write1302(0x8c,0x11);//年 write1302(0x8a,0x00);//周 write1302(0x88,0x10);//月

文档评论(0)

1亿VIP精品文档

相关文档