📄 080630.lst
字号:
C51 COMPILER V7.06 080630 07/27/2008 13:47:08 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE 080630
OBJECT MODULE PLACED IN 080630.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 080630.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //*********************************************************************/*
2 /*DS12CR887高精度万年历 C51程序
3
4 编写:wsb
5 日期:2008-7-7
6 QQ:576515317
7
8 功能:电路采用DS12CR887高精度时钟芯片,用74HC595驱动15个码管
9 采用模拟串口的方式进行数据的发送。三个独立按键,一个功能
10 键,一个时间加,一个时间减,组成时间调整功能。
11 一个DS18B20数字温度传感器实现环境温度的读取。
12 能够显示的内容有年、月、日、时、分、秒、星期和温度。
13 */
14 #include <reg52.h>
15
16 #define uchar unsigned char
17
18 #define uint unsigned int
19
20 uchar code table[]={
21 0xc0,0xf9,0xa4,0xb0,
22 0x99,0x92,0x82,0xf8,
23 0x80,0x90,0x88,0x83,
24 0xc6,0xa1,0x86,0x8e,0xbf};
25
26
27 uchar shi,fen,miao,nian,yue,ri,xq,s1num,tt;
28 uint temp;
29 bit flag;
30
31 //DS12CR887的四个位声明
32 sbit dscs=P2^5;
33 sbit dsas=P2^4;
34 sbit dswr=P2^3;
35 sbit dsds=P2^2;
36
37 sbit tempDS=P2^1; //DS18B20 I/0口定义
38
39 sbit s1=P3^0; //功能键
40 sbit s2=P3^1; //时间加
41 sbit s3=P3^2; //时间减
42
43 sbit rd=P3^7;
44
45 sbit SH_CP=P1^4; //移位寄存器时钟脉冲
46
47 sbit ST_CP=P1^5; //存储寄存器时钟脉冲输出锁存器控制
48
49 sbit d1=P1^3;//双二极管闪烁
50
51 sbit DS=P1^7; //串行数据输入
52
53 void delay(uint count) //延时子函数
54
55 {
C51 COMPILER V7.06 080630 07/27/2008 13:47:08 PAGE 2
56 1
57 1 uint i;
58 1
59 1 while(count)
60 1
61 1 {
62 2
63 2 i=200;
64 2
65 2 while(i>0)
66 2
67 2 i--;
68 2
69 2 count--;
70 2
71 2 }
72 1
73 1 }
74 /************************
75 函数名:dsreset()
76 功能 :DS18B20初始化复位
77 *************************/
78 void dsreset(void)
79
80 {
81 1
82 1 uint i;
83 1
84 1 tempDS=0;
85 1
86 1 i=103;
87 1
88 1 while(i>0)i--;
89 1
90 1 tempDS=1;
91 1
92 1 i=4;
93 1
94 1 while(i>0)i--;
95 1
96 1 }
97
98
99 /************************
100 函数名:tmpreadbit()
101 功能:从DS18B20里读一位
102 *************************/
103 bit tmpreadbit(void)
104
105 {
106 1
107 1 uint i;
108 1
109 1 bit dat;
110 1
111 1 tempDS=0;i++; //i++ for delay 小延时一下
112 1
113 1 tempDS=1;i++;i++;
114 1
115 1 dat=tempDS;
116 1
117 1 i=8;while(i>0)i--;
C51 COMPILER V7.06 080630 07/27/2008 13:47:08 PAGE 3
118 1
119 1 return (dat);
120 1
121 1 }
122
123 /************************
124 函数名:tmpread()
125 功能:从DS18B20里读一个字节
126 *************************/
127 uchar tmpread(void)
128
129 {
130 1
131 1 uchar i,j,dat;
132 1
133 1 dat=0;
134 1
135 1 for(i=1;i<=8;i++)
136 1
137 1 {
138 2
139 2 j=tmpreadbit();
140 2
141 2 dat=(j<<7)|(dat>>1); //读出的数据最低位在最前面,这样刚好//一个字节在DAT里
142 2
143 2 }
144 1
145 1 return(dat); //将一个字节数据返回
146 1
147 1 }
148
149
150 /************************
151 函数名:tmpwritebyte()
152 功能:写一个字节到DS18B20里
153 *************************/
154 void tmpwritebyte(uchar dat)
155
156 {
157 1
158 1 uint i;
159 1
160 1 uchar j;
161 1
162 1 bit testb;
163 1
164 1 for(j=1;j<=8;j++)
165 1
166 1 {
167 2
168 2 testb=dat&0x01;
169 2
170 2 dat=dat>>1;
171 2
172 2 if(testb) //write 1 写1部分
173 2
174 2 {
175 3
176 3 tempDS=0;
177 3
178 3 i++;i++;
179 3
C51 COMPILER V7.06 080630 07/27/2008 13:47:08 PAGE 4
180 3 tempDS=1;
181 3
182 3 i=8;while(i>0)i--;
183 3
184 3 }
185 2
186 2 else
187 2
188 2 {
189 3
190 3 tempDS=0; //write 0 写0部分
191 3
192 3 i=8;while(i>0)i--;
193 3
194 3 tempDS=1;
195 3
196 3 i++;i++;
197 3
198 3 }
199 2
200 2 }
201 1
202 1 }
203
204
205 /************************
206 函数名:tmpchange()
207 功能:给18B20发送温度转换命令
208
209 *************************/
210 void tmpchange(void)
211
212 {
213 1
214 1 dsreset(); //初始化DS18B20
215 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -