?? thermometor_main.lst
字號:
C51 COMPILER V7.00 THERMOMETOR_MAIN 11/13/2007 14:58:20 PAGE 1
C51 COMPILER V7.00, COMPILATION OF MODULE THERMOMETOR_MAIN
OBJECT MODULE PLACED IN .\Thermometor_Main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\Thermometor_Main.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #define uchar unsigned char
2 #define uint unsigned int
3 #define ulong unsigned long
4
5 #include<REG52.h>
6 sbit Sign_Port =P3^0;
7 sfr Dat_Port =0x80;
8 sfr Cs_Port =0xa0;
9 sbit TMDAT = P3^3;
10 uchar code table[11]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
11 0x7F,0x6F,0x00};
12 uchar tmpbuf[5];
13
14 void Delay(int useconds)
15 {
16 1 int s;
17 1 for (s=0; s<useconds;s++);
18 1 }
19
20 uchar Reset_Bus(void)
21 {
22 1 uchar presence;
23 1 TMDAT = 0;
24 1 Delay(29);
25 1 TMDAT = 1;
26 1 Delay(3);
27 1 presence = TMDAT;
28 1 Delay(25);
29 1 return(presence);
30 1 }
31
32 void Write_Bit(char bitval)
33 {
34 1 TMDAT = 0;
35 1 if(bitval==1) TMDAT =1;
36 1 Delay(5);
37 1 TMDAT = 1;
38 1 }
39 void Write_Byte(char val)
40 {
41 1 uchar i;
42 1 uchar temp;
43 1 for (i=0; i<8; i++) {
44 2 temp = val>>i;
45 2 temp &= 0x01;
46 2 Write_Bit(temp);
47 2 }
48 1 Delay(5);
49 1 }
50
51
52 uchar Read_Bit(void)
53 {
54 1 uchar i;
55 1 TMDAT = 0;
C51 COMPILER V7.00 THERMOMETOR_MAIN 11/13/2007 14:58:20 PAGE 2
56 1 TMDAT = 1;
57 1 for (i=0; i<3; i++);
58 1 return(TMDAT);
59 1 }
60
61
62 uchar Read_Byte(void)
63 {
64 1 uchar i;
65 1 uchar value = 0;
66 1 for (i=0;i<8;i++)
67 1 {
68 2 if(Read_Bit()) value|=0x01<<i;
69 2 Delay(6);
70 2 }
71 1 return(value);
72 1 }
73
74
75 uint DS18B20_Tmp_Read(void)
76 {
77 1 uint TEMP;
78 1 uchar TEMP_LSB,TEMP_MSB;
79 1 Reset_Bus();
80 1 Write_Byte(0xCC);
81 1 Write_Byte(0x44);
82 1 Delay(5);
83 1 Reset_Bus();
84 1 Write_Byte(0xCC);
85 1 Write_Byte(0xBE);
86 1 TEMP_LSB = Read_Byte();
87 1 TEMP_MSB = Read_Byte();
88 1 TEMP=TEMP_MSB;
89 1 TEMP=TEMP<<8;
90 1 TEMP=TEMP|TEMP_LSB;
91 1 return TEMP;
92 1 }
93
94 void Display(void)
95 {
96 1 uchar i,j,temp=0xef;
97 1 for(i=0;i<5;i++)
98 1 {
99 2 Cs_Port=0xff;
100 2 j=tmpbuf[i];
101 2 if(temp==0xFB)
102 2 Dat_Port=(table[j]|0x80);
103 2 else
104 2 Dat_Port=table[j];
105 2 Cs_Port=temp;
106 2 Delay(5);
107 2 Cs_Port=0xff;
108 2 temp=temp>>1;
109 2 temp=temp|0x80;
110 2 }
111 1 }
112
113 void main(void)
114 {
115 1 uint tmp;
116 1 uchar i,tmph,tmpl,sign;
117 1 while(1)
C51 COMPILER V7.00 THERMOMETOR_MAIN 11/13/2007 14:58:20 PAGE 3
118 1 {
119 2 tmp=DS18B20_Tmp_Read();
120 2 sign=(uchar)((tmp>>8)&0xf0);
121 2 if(sign==0xf0)
122 2 {
123 3 tmp=(~tmp)+1;
124 3 Sign_Port=0;
125 3 }
126 2 else Sign_Port=1;
127 2 tmpl=(uchar)(tmp&0x0f);
128 2 tmph=(uchar)((tmp>>4)&0xff);
129 2 tmpl=tmpl*6.25;
130 2 tmpbuf[4]=tmpl%10;
131 2 tmpbuf[3]=tmpl/10;
132 2 tmpbuf[2]=tmph%10;
133 2 tmpbuf[1]=(tmph%100)/10;
134 2 tmpbuf[0]=tmph/100;
135 2 if(tmpbuf[0]==0)
136 2 {
137 3 tmpbuf[0]=10;
138 3 if(tmpbuf[1]==0)
139 3 tmpbuf[1]=10;
140 3 }
141 2 for(i=0;i<20;i++)
142 2 {
143 3 Display();
144 3
145 3 }
146 2
147 2 }
148 1 }
149
150
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 401 ----
CONSTANT SIZE = 11 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 5 2
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 + -