- 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);//月
您可能关注的文档
- 2016学生家庭情况调查评议表.doc
- 2016小学班主任工作小结.doc
- 2016幼儿园家长会主持词.doc
- 2016志愿填报之戏剧影视导演专业解读.docx
- 2016晋升主管述职报告.doc
- 2016最新315活动方案.doc
- 2016江西农信社考试行测片段阅读标题特征.docx
- 2016浙江农民创富大赛活动方案.doc
- 2016暑期典型事迹调查表.docx
- 2016社区面试自我介绍范文.doc
- 河北盐山中学等校2025-2026学年上学期高三一模化学试卷(含解析).docx
- 河北正定中学2025-2026学年高一上学期期末考试物理试卷(含解析).docx
- 河北张家口市怀安县2025-2026学年第一学期期末教学综合评价八年级地理试卷(含解析).docx
- 河南安阳市殷都区2025-2026学年第一学期期末教学质量检测七年级地理试卷(含解析).docx
- 河南安阳市滑县2025一2026学年第一学期期末学业质量监测八年级地理试题(含解析).docx
- 河南安阳市林州市2025-2026学年上学期期末考试高一政治试题(含解析).docx
- 河南焦作市武陟县第一中学2025-2026学年高一上学期1月月考语文试卷(含解析).docx
- 河南济源市2025-2026学年上学期期末学业质量调研七年级历史试卷(含解析).docx
- PICC导管并发症的紧急处理与护理.pptx
- 河南鹤壁市2025-2026学年高二上学期期末考试生物试题(含解析).docx
最近下载
- DB37_T 4904-2025 链式切割水泥土连续墙技术规程.docx VIP
- DB37_T 4903-2025 沥青路面防裂封水粘结层技术规范.docx VIP
- DB37_T 4909-2025 城市轨道交通隧道结构渗漏水治理技术规程.docx VIP
- 2026年河南工业和信息化职业学院单招职业技能考试题库及参考答案详解.docx VIP
- DB37_T 4914-2025 电梯按需维护保养管理技术规范.docx VIP
- DB37_T 4915-2025 氧气瓶充装自动控制技术要求.docx VIP
- 最全汉语水平的考试HSK6级历年真题经典版.pdf VIP
- 博朗-欧乐B_OralB 5000__O3762_5_CHIN使用说明书.pdf VIP
- DB37_T 4918.5-2025 政务信息化项目管理 第5部分:项目和系统编码.docx VIP
- 价值链视角下的山西汾酒公司资金管理问题与优化路径探究11000字【论文】 .docx VIP
原创力文档

文档评论(0)