?? wendu1-1.lst
字號:
C51 COMPILER V7.02b WENDU1_1 06/22/2008 20:04:22 PAGE 1
C51 COMPILER V7.02b, COMPILATION OF MODULE WENDU1_1
OBJECT MODULE PLACED IN wendu1-1.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE wendu1-1.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <reg52.h>
2 #define uchar unsigned char
3 #define uint unsigned int
4 sbit DS=P3^5; //define interface 定義接口
5 uint temp; // variable of temperature 定義一個(gè)變量用來表示溫度
6 uchar flag1; // sign of the result positive or negative 定義一個(gè)標(biāo)志,標(biāo)志溫度是否還是正
7 sbit P2_0=P2^7; //數(shù)碼管位選
8 sbit P2_1=P2^6;
9 sbit P2_2=P2^5;
10 sbit P2_3=P2^4;
11 uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82, //數(shù)字編碼
12 0xf8,0x80,0x90,0xc6};
13 uchar code table1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02, //帶小數(shù)點(diǎn)的編碼
14 0x78,0x00,0x10};
15 /**************************************************
16 作者:森 時(shí)間:2008--6--22 20:01
17 *************************************************/
18 void delay(uint z) //delay 延時(shí)子程序
19 {
20 1 uint x,y;
21 1 for(x=z; x>0; x--)
22 1 for(y=110; y>0; y--);
23 1 }
24
25 void dsreset(void) //send reset and initialization command 發(fā)送初始化命令子程序
26 {
27 1 //uint i;
28 1 DS=0;
29 1 delay(5);
30 1 //i=103;
31 1 //while(i>0)i--;
32 1 DS=1;
33 1 delay(1);
34 1 //i=4;
35 1 //while(i>0)i--;
36 1 }
37
38 bit tmpreadbit(void) //read a bit 讀一位
39 {
40 1 uint i;
41 1 bit dat;
42 1 DS=0;i++; //i++ for delay
43 1 DS=1;i++;i++;
44 1 dat=DS;
45 1 i=8;
46 1 while(i>0)i--;
47 1 return (dat);
48 1 }
49
50 uchar tmpread(void) //read a byte date 讀一個(gè)字節(jié)
51 {
52 1 uchar i,j,dat;
53 1 dat=0;
54 1 for(i=1;i<=8;i++)
55 1 {
C51 COMPILER V7.02b WENDU1_1 06/22/2008 20:04:22 PAGE 2
56 2 j=tmpreadbit();
57 2 dat=(j<<7)|(dat>>1); //讀出的數(shù)據(jù)最低位在最前面,這樣剛好一個(gè)字節(jié)在DAT里
58 2 }
59 1 return(dat);
60 1 }
61
62 void tmpwritebyte(uchar dat) //write a byte to ds18b20 給溫度傳感器寫一個(gè)字節(jié)
63 {
64 1 uint i;
65 1 uchar j;
66 1 bit testb;
67 1 for(j=1; j<=8; j++)
68 1 {
69 2 testb=dat&0x01;
70 2 dat=dat>>1;
71 2 if(testb) //write 1
72 2 {
73 3 DS=0;
74 3 i++;i++;
75 3 DS=1;
76 3 i=8;
77 3 while(i>0)i--;
78 3 }
79 2 else
80 2 {
81 3 DS=0; //write 0
82 3 i=8;
83 3 while(i>0)i--;
84 3 DS=1;
85 3 i++;i++;
86 3 }
87 2
88 2 }
89 1 }
90
91 void tmpchange(void) //DS18B20 begin change 發(fā)送溫度轉(zhuǎn)換命令
92 {
93 1 dsreset();
94 1 delay(5);
95 1 tmpwritebyte(0xcc); // address all drivers on bus
96 1 tmpwritebyte(0x44); // initiates a single temperature conversion
97 1 }
98
99 uint tmp() //get the temperature 得到溫度值
100 {
101 1 float tt;
102 1 uchar a,b;
103 1 dsreset();
104 1 delay(1);
105 1 tmpwritebyte(0xcc);
106 1 tmpwritebyte(0xbe);
107 1 a=tmpread();
108 1 b=tmpread();
109 1 temp=b;
110 1 temp<<=8; //two byte compose a int variable
111 1 temp=temp|a;
112 1 tt=temp*0.0625;
113 1 temp=tt*10+0.5;
114 1 return temp;
115 1 }
116
117 void delay10ms() //delay 延時(shí)10MS子函數(shù)
C51 COMPILER V7.02b WENDU1_1 06/22/2008 20:04:22 PAGE 3
118 {
119 1 uchar a,b;
120 1 for(a=10;a>0;a--)
121 1 for(b=60;b>0;b--);
122 1 }
123
124 void display(uint tem) //display 顯示子函數(shù)
125 {
126 1 uchar A1,A2,A3,A4;
127 1 A1=table[tem/100];
128 1 A2=table1[tem%100/10];
129 1 A3=table[tem%10];
130 1 A4=0xc6;
131 1
132 1 P0=A1;
133 1 P2_0=0;
134 1 P2_1=1;
135 1 P2_2=1;
136 1 P2_3=1;
137 1 delay10ms();
138 1 P0=A2;
139 1 P2_1=0;
140 1 P2_0=1;
141 1 P2_2=1;
142 1 P2_3=1;
143 1 delay10ms();
144 1 P0=A3;
145 1 P2_2=0;
146 1 P2_0=1;
147 1 P2_1=1;
148 1 P2_3=1;
149 1 delay10ms();
150 1 //P2=0xff;
151 1 //delay(10);
152 1 P0=A4;
153 1 P2_3=0;
154 1 P2_0=1;
155 1 P2_1=1;
156 1 P2_2=1;
157 1
158 1 }
159
160
161 void main() //主函數(shù)
162 {
163 1 do
164 1 {
165 2 tmpchange(); //溫度轉(zhuǎn)換,
166 2 display(tmp()); //顯示溫度值
167 2 }
168 1 while(1);
169 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 465 ----
CONSTANT SIZE = 21 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 6
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
C51 COMPILER V7.02b WENDU1_1 06/22/2008 20:04:22 PAGE 4
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -