📄 1820.lst
字号:
C51 COMPILER V7.01 1820 10/29/2004 10:34:39 PAGE 1
C51 COMPILER V7.01, COMPILATION OF MODULE 1820
OBJECT MODULE PLACED IN 1820.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE 1820.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //DS1820 C51 子程序
2 //这里以11.0592M晶体为例,不同的晶体速度可能需要调整延时的时间
3 sbit DQ =P2^1;//根据实际情况定义端口
*** ERROR C202 IN LINE 3 OF 1820.C: 'P2': undefined identifier
4
5 typedef unsigned char byte;
6 typedef unsigned int word;
7
8 //延时
9 void delay(word useconds)
10 {
11 1 for(;useconds>0;useconds--);
12 1 }
13
14 //复位
15 byte ow_reset(void)
16 {
17 1 byte presence;
18 1 DQ = 0; //pull DQ line low
*** ERROR C202 IN LINE 18 OF 1820.C: 'DQ': undefined identifier
19 1 delay(29); // leave it low for 480us
20 1 DQ = 1; // allow line to return high
*** ERROR C202 IN LINE 20 OF 1820.C: 'DQ': undefined identifier
21 1 delay(3); // wait for presence
22 1 presence = DQ; // get presence signal
*** ERROR C202 IN LINE 22 OF 1820.C: 'DQ': undefined identifier
23 1 delay(25); // wait for end of timeslot
24 1 return(presence); // presence signal returned
25 1 } // 0=presence, 1 = no part
26
27 //从 1-wire 总线上读取一个字节
28 byte read_byte(void)
29 {
30 1 byte i;
31 1 byte value = 0;
32 1 for (i=8;i>0;i--)
33 1 {
34 2 value>>=1;
35 2 DQ = 0; // pull DQ low to start timeslot
*** ERROR C202 IN LINE 35 OF 1820.C: 'DQ': undefined identifier
36 2 DQ = 1; // then return high
*** ERROR C202 IN LINE 36 OF 1820.C: 'DQ': undefined identifier
37 2 delay(1); //for (i=0; i<3; i++);
38 2 if(DQ)value|=0x80;
*** ERROR C202 IN LINE 38 OF 1820.C: 'DQ': undefined identifier
39 2 delay(6); // wait for rest of timeslot
40 2 }
41 1 return(value);
42 1 }
43
44 //向 1-WIRE 总线上写一个字节
45 void write_byte(char val)
46 {
47 1 byte i;
48 1 for (i=8; i>0; i--) // writes byte, one bit at a time
C51 COMPILER V7.01 1820 10/29/2004 10:34:39 PAGE 2
49 1 {
50 2 DQ = 0; // pull DQ low to start timeslot
*** ERROR C202 IN LINE 50 OF 1820.C: 'DQ': undefined identifier
51 2 DQ = val&0x01;
*** ERROR C202 IN LINE 51 OF 1820.C: 'DQ': undefined identifier
52 2 delay(5); // hold value for remainder of timeslot
53 2 DQ = 1;
*** ERROR C202 IN LINE 53 OF 1820.C: 'DQ': undefined identifier
54 2 val=val/2;
55 2 }
56 1 delay(5);
57 1 }
58
59 //读取温度
60 char Read_Temperature(void)
61 {
62 1 union{
63 1 byte c[2];
64 1 int x;
65 1 }temp;
66 1
67 1 ow_reset();
68 1 write_byte(0xCC); // Skip ROM
69 1 write_byte(0xBE); // Read Scratch Pad
70 1 temp.c[1]=read_byte();
71 1 temp.c[0]=read_byte();
72 1 ow_reset();
73 1 write_byte(0xCC); //Skip ROM
74 1 write_byte(0x44); // Start Conversion
75 1 return temp.x/2;
76 1 }
C51 COMPILATION COMPLETE. 0 WARNING(S), 10 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -