📄 ds.lst
字号:
C51 COMPILER V8.01 DS 11/02/2008 21:28:38 PAGE 1
C51 COMPILER V8.01, COMPILATION OF MODULE DS
OBJECT MODULE PLACED IN ds.OBJ
COMPILER INVOKED BY: D:\stup\keil\C51\BIN\C51.EXE ds.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include<reg51.h>
2 #define uchar unsigned char
3 #define uint unsigened int
4 uchar now;
5 uchar temp,temp1,temp2;
6 sbit DQ=P1^7;
7 sbit P0_4=P0^4;
8 sbit P0_5=P0^5;
9 sbit P0_6=P0^6;
10
11 uchar seg7code[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x00};
12
13 void delay_18B20(unsigned int i)
14 {
15 1 while(i--);
16 1 }
17 void delay(uchar x)
18 {
19 1 uchar a,b;
20 1 for(a=80;a>0;a--)
21 1 for(b=x;b>0;b--);
22 1 }
23
24 uchar Init_DS18B20()
25 {
26 1 unsigned char x=0;
27 1 DQ = 1; //DQ复位
28 1 delay_18B20(8); //稍做延时
29 1 DQ = 0; //单片机将DQ拉低
30 1 delay_18B20(80); //精确延时 大于 480us
31 1 DQ = 1; //拉高总线
32 1 delay_18B20(14);
33 1 now=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
34 1 delay_18B20(20);
35 1 return now;
36 1 }
37
38 /***********ds18b20读一个字节**************/
39
40 unsigned char ReadOneChar(void)
41 {
42 1 uchar i=0;
43 1 uchar dat = 0;
44 1 for (i=8;i>0;i--)
45 1 {
46 2 DQ = 0; // 给脉冲信号
47 2 dat>>=1;
48 2 DQ = 1; // 给脉冲信号
49 2 if(DQ)
50 2 dat|=0x80;
51 2 delay_18B20(4);
52 2 }
53 1 return(dat);
54 1 }
55
C51 COMPILER V8.01 DS 11/02/2008 21:28:38 PAGE 2
56 /*************ds18b20写一个字节****************/
57
58 void WriteOneChar(uchar dat)
59 {
60 1 unsigned char i=0;
61 1 for (i=8; i>0; i--)
62 1 {
63 2 DQ = 0;
64 2 DQ = dat&0x01;
65 2 delay_18B20(5);
66 2 DQ = 1;
67 2 dat>>=1;
68 2 }
69 1 }
70
71 /**************读取ds18b20当前温度************/
72
73 void ReadTemperature()
74 {
75 1
76 1 unsigned char a=0;
77 1 unsigned char b=0;
78 1
79 1 Init_DS18B20();
80 1 WriteOneChar(0xCC); // 跳过读序号列号的操作
81 1 WriteOneChar(0x44); // 启动温度转换
82 1
83 1 delay_18B20(100); // this message is wery important
84 1
85 1 Init_DS18B20();
86 1 WriteOneChar(0xCC); //跳过读序号列号的操作
87 1 WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
88 1
89 1 delay_18B20(100);
90 1
91 1 a=ReadOneChar(); //读取温度值低位
92 1 b=ReadOneChar(); //读取温度值高位
93 1
94 1 temp1=b<<4;
95 1 temp1+=(a&0xf0)>>4;//整数位
96 1 temp2=a&0x0f; //小数位
97 1 // temp=((b*256+a)>>4); //当前采集温度值除16得实际温度值
98 1 temp=b&0xf0; //正负数的确定
99 1 }
100 void display(uchar bai,uchar shi,uchar ge,uchar xiao)
101 {
102 1 ReadTemperature();
103 1 P0=seg7code[bai];
104 1 P0_4=0;
105 1 P0_5=0;
106 1 P0_6=1;
107 1 delay(3);
108 1
109 1 P0=seg7code[shi];
110 1 P0_4=1;
111 1 P0_5=0;
112 1 P0_6=1;
113 1 delay(3);
114 1
115 1 P0=seg7code[ge];
116 1 P0_4=0;
117 1 P0_5=1;
C51 COMPILER V8.01 DS 11/02/2008 21:28:38 PAGE 3
118 1 P0_6=1;
119 1 delay(3);
120 1
121 1 P0=seg7code[xiao];
122 1 P0_4=1;
123 1 P0_5=1;
124 1 P0_6=1;
125 1 delay(3);
126 1 }
127
128 main()
129 {
130 1 //Init_DS18B20();
131 1 while(1)
132 1 {
133 2 display(temp1/100,temp1/10%10,temp1%10,temp2/10);;
134 2 }
135 1 }
136
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 317 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 15 5
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -