?? src.lst
字號(hào):
C51 COMPILER V8.02 SRC 09/20/2006 19:53:37 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE SRC
OBJECT MODULE PLACED IN src.OBJ
COMPILER INVOKED BY: E:\Keil8\C51\BIN\C51.EXE src.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #define uchar unsigned char
2 #define uint unsigned int
3 #define DQ P3_7
4 #include<AT89X51.H>
5
6 uint sec;
7 uint min=41;
8 uint hour=18;
9 uint day=14;
10 uint month=9;
11 uint yearl=6;
12 uint yearh=20;
13 uint tcnt;
14 uint cursor=0;
15 uchar a=0xff;
16 uchar code Seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
17
18 void delay(uint t)
19 {
20 1 uint i;
21 1 while(t--)
22 1 {for (i=0;i<125;i++);}
23 1 }
24 void Tdelay(unsigned int i)
25 {
26 1 while(i--);
27 1 }
28 void Kdelay()
29 {
30 1 uchar i,j;
31 1 for(i=100;i>0;i--)
32 1 for(j=248;j>0;j--);
33 1 }
34 Init_DS18B20(void)
35 {
36 1 unsigned char x=0;
37 1 DQ = 1;
38 1 Tdelay(8);
39 1 DQ = 0;
40 1 Tdelay(80);
41 1 DQ = 1;
42 1 Tdelay(14);
43 1 Tdelay(20);
44 1 }
45 //讀一個(gè)字節(jié)
46 ReadOneChar(void)
47 {
48 1 unsigned char i=0;
49 1 unsigned char dat = 0;
50 1 for (i=8;i>0;i--)
51 1 {
52 2 DQ = 0;
53 2 dat>>=1;
54 2 DQ = 1;
55 2 if(DQ)
C51 COMPILER V8.02 SRC 09/20/2006 19:53:37 PAGE 2
56 2 dat|=0x80;
57 2 Tdelay(4);
58 2 }
59 1 return(dat);
60 1 }
61
62 //寫一個(gè)字節(jié)
63 WriteOneChar(unsigned char dat)
64 {
65 1 unsigned char i=0;
66 1 for (i=8; i>0; i--)
67 1 {
68 2 DQ = 0;
69 2 DQ = dat&0x01;
70 2 Tdelay(5);
71 2 DQ = 1;
72 2 dat>>=1;
73 2 }
74 1 }
75
76 //讀取溫度
77 ReadTemperature(void)
78 {
79 1 unsigned char a=0;
80 1 unsigned char b=0;
81 1 unsigned int t=0;
82 1 float tt=0;
83 1 Init_DS18B20();
84 1 WriteOneChar(0xCC);
85 1 WriteOneChar(0x44);
86 1 Init_DS18B20();
87 1 WriteOneChar(0xCC);
88 1 WriteOneChar(0xBE);
89 1 a=ReadOneChar();
90 1 b=ReadOneChar();
91 1 t=b;
92 1 t<<=8;
93 1 t=t|a;
94 1 tt=t*0.0625;
95 1 t= tt*10+0.5;
96 1 return(t);
97 1 }
98
99 void display(uchar L1,uchar L2,uchar L3,uchar L4,uchar L5,uchar L6,uchar L7,uchar L8,uchar L9,uchar L10,uc
-har L11,uchar L12,uchar L13,uchar L14,uchar L15,uchar L16)
100 {
101 1 P2=0x7F;P0=L1;delay(1); //yearh
102 1 P2=0xBF;P0=L2;delay(1); //yearh
103 1 if(cursor==6){P2=0xDF|a;P0=L3;delay(1);}else{P2=0xDF;P0=L3;delay(1);} //yearl
104 1 if(cursor==6){P2=0xEF|a;P0=L4;delay(1);}else{P2=0xEF;P0=L4;delay(1);} //yearl
105 1 if(cursor==5){P2=0xF7|a;P0=L5;delay(1);}else{P2=0xF7;P0=L5;delay(1);} //month
106 1 if(cursor==5){P2=0xFB|a;P0=L6;delay(1);}else{P2=0xFB;P0=L6;delay(1);} //month
107 1 if(cursor==4){P2=0xFD|a;P0=L7;delay(1);}else{P2=0xFD;P0=L7;delay(1);} //day
108 1 if(cursor==4){P2=0xFE|a;P0=L8;delay(1);}else{P2=0xFE;P0=L8;delay(1);} //day
109 1 P2=0xFF;
110 1 if(cursor==3){P1=0x7F|a;P0=L9;delay(1);}else{P1=0x7F;P0=L9;delay(1);} //hour
111 1 if(cursor==3){P1=0xBF|a;P0=L10;delay(1);}else{P1=0xBF;P0=L10;delay(1);} //hour
112 1 if(cursor==2){P1=0xDF|a;P0=L11;delay(1);}else{P1=0xDF;P0=L11;delay(1);} //min
113 1 if(cursor==2){P1=0xEF|a;P0=L12;delay(1);}else{P1=0xEF;P0=L12;delay(1);} //min
114 1 if(cursor==1){P1=0xF7|a;P0=L13;delay(1);}else{P1=0xF7;P0=L13;delay(1);} //sec
115 1 if(cursor==1){P1=0xFB|a;P0=L14;delay(1);}else{P1=0xFB;P0=L14;delay(1);} //sec
116 1 P1=0xFD;P0=L15;delay(1); //temp
C51 COMPILER V8.02 SRC 09/20/2006 19:53:37 PAGE 3
117 1 P1=0xFE;P0=L16;delay(1); //temp
118 1 P1=0xFF;
119 1 }
120
121 main()
122 {
123 1 uint i;
124 1 TMOD=0x02; //設(shè)置模式為定時(shí)器T0的模式2 (8位自動(dòng)重裝計(jì)數(shù)初值的計(jì)數(shù)值)
125 1 TH0=0x06; //設(shè)置計(jì)數(shù)器初值,靠TH0存儲(chǔ)重裝的計(jì)數(shù)值X0=256-250=6
126 1 TL0=0x06;
127 1 TR0=1; //啟動(dòng)T0
128 1 ET0=1; //開(kāi)啟定時(shí)器T0中斷允許
129 1 EA=1; //開(kāi)啟中斷總控制
130 1 while(1)
131 1 {
132 2 if(P3_0==0)
133 2 {
134 3 Kdelay();
135 3 if(P3_0==0)
136 3 {
137 4 cursor++;
138 4 if(cursor>=7){cursor=0;}
139 4 }
140 3 }
141 2 if(P3_1==0)
142 2 {
143 3 Kdelay();
144 3 if(P3_1==0)
145 3 {
146 4 if(cursor==1){sec++;if(sec==60)sec=0;}
147 4 if(cursor==2){min++;if(min==60)min=0;}
148 4 if(cursor==3){hour++;if(hour==24)hour=0;}
149 4 if(cursor==4){day++;if(day==31)day=0;}
150 4 if(cursor==5){month++;if(month==12)month=0;}
151 4 if(cursor==6){yearl++;if(yearl==100)yearl=0;}
152 4 if(cursor==7){yearh++;if(yearh==30)yearh=20;}
153 4 }
154 3 }
155 2 if(P3_2==0)
156 2 {
157 3 Kdelay();
158 3 if(P3_2==0)
159 3 {
160 4 if(cursor==1){sec--;}
161 4 if(cursor==2){min--;}
162 4 if(cursor==3){hour--;}
163 4 if(cursor==4){day--;}
164 4 if(cursor==5){month--;}
165 4 if(cursor==6){yearl--;}
166 4 if(cursor==7){yearh--;}
167 4 }
168 3 }
169 2 i=ReadTemperature();
170 2 display(Seg[yearh/10],Seg[yearh%10],Seg[yearl/10],Seg[yearl%10],Seg[month/10],Seg[month%10],Seg[da
-y/10],Seg[day%10],Seg[hour/10],Seg[hour%10],Seg[min/10],Seg[min%10],Seg[sec/10],Seg[sec%10],Seg[i/100],Seg[i/10%10]);
-
171 2 }
172 1 }
173
174 void t0(void)interrupt 1 using 0 //t0的中斷程序
175 {
176 1 tcnt++;
C51 COMPILER V8.02 SRC 09/20/2006 19:53:37 PAGE 4
177 1 if(tcnt==4000)//定時(shí)器的定時(shí)計(jì)數(shù),4000次250us為1秒
178 1 {
179 2 tcnt=0;
180 2 P3_3=~P3_3;
181 2 a=~a;
182 2 sec++;
183 2 if(sec==60)
184 2 {
185 3 sec=0;
186 3 min++;
187 3 if(min==60)
188 3 {
189 4 min=0;
190 4 hour++;
191 4 if(hour==24)
192 4 {
193 5 hour=0;
194 5 day++;
195 5 if(month==2&&((yearl==0&&yearh%4==0)||(yearl!=0&&yearl%4==0))&&day==30)day=1;
196 5 else if(month==2&&day==29)day=1;
197 5 else if((month==4||month==6||month==9||month==11)&&day==31)day=1;
198 5 else if(day==32)day=1;
199 5 if(day==1)
200 5 {
201 6 month++;
202 6 if(month==13)
203 6 {
204 7 month=1;
205 7 yearl++;
206 7 if(yearl==100)
207 7 {
208 8 yearl=0;
209 8 yearh++;
210 8 if(yearh==100)
211 8 {
212 9 yearh=20;
213 9 }
214 8 }
215 7 }
216 6 }
217 5 }
218 4 }
219 3 }
220 2 }
221 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1689 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 19 23
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -