📄 main.lst
字号:
C51 COMPILER V7.06 MAIN 03/18/2006 11:03:10 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN MAIN.OBJ
COMPILER INVOKED BY: D:\Program Files\keil\C51\BIN\C51.EXE MAIN.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include<reg52.h>
2 code unsigned char seg7code[11]={0x3f,0x06,0x5b,0x4f,0x66,
3 0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //显示段码
4 void Delay(unsigned int tc) //显示延时程序
5 {while( tc != 0 )
6 1 {unsigned int i;
7 2 for(i=0; i<100; i++);
8 2 tc--;}
9 1 }
10 sbit TMDAT =P3^1; //DS18B20的数据输入/输出脚DQ,根据情况设定
11 unsigned int sdata;//测量到的温度的整数部分
12 unsigned char xiaoshu1;//小数第一位
13 unsigned char xiaoshu2;//小数第二位
14 unsigned char xiaoshu;//两位小数
15 bit fg=1; //温度正负标志
16 void dmsec (unsigned int count) //延时部分
17 {
18 1 unsigned char i;
19 1 while(count--)
20 1 {for(i=0;i<115;i++);}
21 1 }
22 void tmreset (void) //发送复位
23 {
24 1 unsigned char i;
25 1 TMDAT=0;
26 1 for(i=0;i<103;i++);
27 1 TMDAT = 1;
28 1 for(i=0;i<4;i++);
29 1 }
30 bit tmrbit (void) //读一位//
31 {
32 1 unsigned int i;
33 1 bit dat;
34 1 TMDAT = 0;
35 1 i++;
36 1 TMDAT = 1;
37 1 i++; i++; //微量延时 //
38 1 dat = TMDAT;
39 1 for(i=0;i<8;i++);
40 1 return (dat);
41 1 }
42 unsigned char tmrbyte (void) //读一个字节
43 {
44 1 unsigned char i,j,dat;
45 1 dat = 0;
46 1 for (i=1;i<=8;i++)
47 1 {
48 2 j = tmrbit();
49 2 dat = (j << 7) | (dat >> 1);
50 2 }
51 1 return (dat);
52 1 }
53 void tmwbyte (unsigned char dat) //写一个字节
54 {
55 1 unsigned char j,i;
C51 COMPILER V7.06 MAIN 03/18/2006 11:03:10 PAGE 2
56 1 bit testb;
57 1 for (j=1;j<=8;j++)
58 1 {
59 2 testb = dat & 0x01;
60 2 dat = dat >> 1;
61 2 if (testb)
62 2 { TMDAT = 0; //写0
63 3 i++; i++;
64 3 TMDAT = 1;
65 3 for(i=0;i<8;i++);
66 3 }
67 2 else
68 2 { TMDAT = 0; //写0
69 3 for(i=0;i<8;i++);
70 3 TMDAT = 1;
71 3 i++; i++;
72 3 }
73 2 }
74 1 }
75 void tmstart (void) //发送ds1820 开始转换
76 {
77 1 tmreset(); //复位
78 1 dmsec(1); //延时
79 1 tmwbyte(0xcc); //跳过序列号命令
80 1 tmwbyte(0x44); //发转换命令 44H,
81 1 }
82 //********温度存在全局变量 sdata中.小数存在xiaoshu中********
83 void tmrtemp (void) //读取温度
84 {
85 1 unsigned char a,b;
86 1 tmreset (); //复位
87 1 dmsec (1); //延时
88 1 tmwbyte (0xcc); //跳过序列号命令
89 1 tmwbyte (0xbe); //发送读取命令
90 1 a = tmrbyte (); //读取低位温度
91 1 b = tmrbyte (); //读取高位温度
92 1 if(b>0x7f) //最高位为1时温度是负
93 1 {
94 2 a=~a; //补码转换,取反加一
95 2 b=~b+1;
96 2 fg=0; //读取温度为负时fg=0
97 2 }
98 1 sdata = a/16+b*16; //整数部分
99 1 xiaoshu1 = (a&0x0f)*10/16; //小数第一位
100 1 xiaoshu2 = (a&0x0f)*100/16%10;//小数第二位
101 1 xiaoshu=xiaoshu1*10+xiaoshu2; //小数两位
102 1 }
103 //*********对外接口函数void DS18B20PRO(void);**************
104 void DS18B20PRO(void)
105 {
106 1 tmstart();
107 1 //dmsec(5); //如果是不断地读取的话可以不延时 //
108 1 tmrtemp(); //读取温度,执行完毕温度将存于TMP中 //
109 1 }
110
111 //////////////////
112 void Led()
113 {
114 1 if(fg==1) //温度为正时显示的数据
115 1 {
116 2 P2=P2&0xef;
117 2 P0=seg7code[sdata/10]; //输出十位数
C51 COMPILER V7.06 MAIN 03/18/2006 11:03:10 PAGE 3
118 2 Delay(8); P2=P2|0xf0; P2=P2&0xdf;
119 2 P0=seg7code[sdata%10]|0x80; //输出个位和小数点
120 2 Delay(8); P2=P2|0xf0; P2=P2&0xbf;
121 2 P0=seg7code[xiaoshu1]; //输出小数点后第一位
122 2 Delay(8); P2=P2|0xf0; P2=P2&0x7f;
123 2 P0=seg7code[xiaoshu2]; //输出小数点后第二位
124 2 Delay(4); P2=P2|0xf0;
125 2 }
126 1 if(fg==0) //温度为负时显示的数据
127 1 {
128 2 P2=P2&0xef;
129 2 P0=seg7code[11]; //负号
130 2 Delay(8); P2=P2|0xf0; P2=P2&0xdf;
131 2 P0=seg7code[sdata/10]|0x80; //输出十位数
132 2 Delay(8); P2=P2|0xf0; P2=P2&0xbf;
133 2 P0=seg7code[sdata%10]; //输出个位和小数点
134 2 Delay(8); P2=P2|0xf0; P2=P2&0x7f;
135 2 P0=seg7code[xiaoshu1]; //输出小数点后第一位
136 2 Delay(4); P2=P2|0xf0;
137 2 }
138 1 }
139 main()
140 {
141 1 fg=1;
142 1 while(1)
143 1 {
144 2 DS18B20PRO();
145 2 Led();
146 2 }
147 1 }
148
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 511 ----
CONSTANT SIZE = 11 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 5 2
IDATA SIZE = ---- ----
BIT SIZE = 1 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -