|
|
|
|
 |
DS1820温度测量的C51程序
|
|
|
|
文章编号: |
090106202650 |
文章分类: |
电路 > 测量/传感器技术 |
|
点 击: |
|
关 键 词: |
DS1820,温度测量 |
|
文章来源: |
网络 |
|
摘 要: |
DS1820,单芯片温度测量,C51程序 |
|
-
-
-
-
- typedef unsigned char byte;
- typedef unsigned int word;
-
-
- void delay(word useconds)
- {
- for(;useconds>0;useconds--);
- }
-
-
- byte ow_reset(void)
- {
- byte presence;
- DQ = 0;
- delay(29);
- DQ = 1;
- delay(3);
- presence = DQ;
- delay(25);
- return(presence);
- }
-
-
- byte read_byte(void)
- {
- byte i;
- byte value = 0;
- for (i=8;i>0;i--)
- {
- value>>=1;
- DQ = 0;
- DQ = 1;
- delay(1);
- if(DQ)value|=0x80;
- delay(6);
- }
- return(value);
- }
-
-
- void write_byte(char val)
- {
- byte i;
- for (i=8; i>0; i--)
- {
- DQ = 0;
- DQ = val&0x01;
- delay(5);
- DQ = 1;
- val=val/2;
- }
- delay(5);
- }
-
-
- char Read_Temperature(void)
- {
- union
- {
- byte c[2];
- int x;
- }temp;
-
- ow_reset();
- write_byte(0xCC);
- write_byte(0xBE);
- temp.c[1]=read_byte();
- temp.c[0]=read_byte();
- ow_reset();
- write_byte(0xCC);
- write_byte(0x44);
- return temp.x/2;
- }
-
|
|
|
|
|
|
|
|
|
|
|