?? main.lst
字號:
C51 COMPILER V7.50 MAIN 03/04/2001 18:19:09 PAGE 1
C51 COMPILER V7.50, 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
line level source
1 #include<reg52.h>
2 #include<LCD12864.H>
3
4 /****定義按鍵接口**************/
5 sbit Mode=P2^6;
6 sbit Add=P2^7;
7 sbit Dec=P1^5;
8 sbit Ent=P1^6;
9 sbit led1=P1^1;
10 sbit led2=P1^0;
11 sbit led3=P1^4;
12 sbit SPK=P1^3;
13
14 unsigned char code para_month[13]={0,0,3,3,6,1,4,6,2,5,0,3,5}; //星期月參變數(shù)
15
16 unsigned char cnt,counter,counter1;
17
18 unsigned char id,id1,word;
19
20 void Add_key1();
21 void Set_time(unsigned char sel,bit sel_1);
22 void Add_key2();
23 void Set_bell(unsigned char sel,bit sel_1);
24 bit leap_year();
25 unsigned char week_proc();
26
27 extern void Write_24c04( unsigned char add,unsigned char dat);
28 extern unsigned char Read_24C04(unsigned char add);
29
30 /*******************按鍵加一減一程序*******************/
31 void Add_key1()
32 {
33 1 if(Add==0)
34 1 {
35 2 Delay12864(20);
36 2 if(Add==0)
37 2 {
38 3 Set_time(id,0);
39 3 while(Add==0);
40 3 }
41 2 }
42 1 if(Dec==0)
43 1 {
44 2 Delay12864(20);
45 2 if(Dec==0)
46 2 {
47 3 Set_time(id,1);
48 3 while(Dec==0);
49 3 }
50 2 }
51 1 }
52
53 /***************設(shè)定時間**********/
54 void Set_time(unsigned char sel, bit sel_1) //根據(jù)選擇調(diào)整相應(yīng)項目并寫入DS1302
55 {
C51 COMPILER V7.50 MAIN 03/04/2001 18:19:09 PAGE 2
56 1 if(sel==1){
57 2 if(sel_1==0){year++;if(year>99)year=0;}
58 2 else { year--;if(year==0)year=99;}}
59 1 if(sel==2){
60 2 if(sel_1==0){month++; if(month>12)month=1;}
61 2 else {month--;if(month==0)month=12;}}
62 1 if(sel==3){
63 2 if(sel_1==0){date++;if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
64 3 if (date>31) date=1; //大月31天
65 3 if (month==4||month==6||month==9||month==11)
66 3 if (date>30) date=1; //小月30天
67 3 if (month==2)
68 3 {if(leap_year()) //閏年的條件
69 4 {if (date>29) date=1;} //閏年2月為29天
70 4 else
71 4 {if (date>28) date=1;}}
72 3 } //平年2月為28天
73 2 else {date--;if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
74 3 if (date==0) date=31; //大月31天
75 3 if (month==4||month==6||month==9||month==11)
76 3 if (date==1) date=30; //小月30天
77 3 if (month==2)
78 3 {if(leap_year()) //閏年的條件
79 4 {if (date==0) date=29;} //閏年2月為29天
80 4 else
81 4 {if (date==0) date=28;}} //平年2月為28天
82 3 }
83 2 }
84 1 if(sel==4){
85 2 if(sel_1==0){week++;if(week>7)week=1;}
86 2 else{week--;if(week==0)week=7;}}
87 1 if(sel==5){
88 2 if(sel_1==0){hour++;if(hour>23)hour=0;}
89 2 else{hour--;if(hour==0)hour=23;}}
90 1 if(sel==6){
91 2 if(sel_1==0){min++;if(min>59)min=0;}
92 2 else{min--;if(min==0)min=59;}}
93 1 if(sel==7){
94 2 if(sel_1==0){sec++;if(hour>59)sec=0;}
95 2 else{sec--;if(sec==0)sec=59;}}
96 1 // write_clock(0x8e,0x00);//允許寫操作
97 1 // write_clock(address,(item/10)*16+item%10);//轉(zhuǎn)換成16進(jìn)制寫入1302
98 1 // write_clock(0x8e,0x80);//寫保護(hù),禁止寫操作
99 1 }
100 /**************設(shè)定腦鈴*******************/
101 /*******************按鍵加一減一程序*******************/
102 void Add_key2()
103 {
104 1 if(Add==0)
105 1 {
106 2 Delay12864(20);
107 2 if(Add==0)
108 2 {
109 3 Set_bell(id1,0);
110 3 while(Add==0);
111 3 }
112 2 }
113 1 if(Dec==0)
114 1 {
115 2 Delay12864(20);
116 2 if(Dec==0)
117 2 {
C51 COMPILER V7.50 MAIN 03/04/2001 18:19:09 PAGE 3
118 3 Set_bell(id1,1);
119 3 while(Dec==0);
120 3 }
121 2 }
122 1 }
123
124 /***************設(shè)定時間**********/
125 void Set_Bell(unsigned char sel, bit sel_1)//根據(jù)選擇調(diào)整相應(yīng)項目并寫入24
126 {
127 1 signed char address,item;
128 1 signed char max,mini;
129 1 if(sel==7) {address=0x0e; max=59;mini=0;} //秒
130 1 if(sel==6) {address=0x0d; max=59;mini=0;} //分
131 1 if(sel==5) {address=0x0c; max=23; mini=0;} //時
132 1 if(sel==4) {address=0x0b; max=59;mini=0;} //秒
133 1 if(sel==3) {address=0x0a; max=59;mini=0;} //分
134 1 if(sel==2) {address=0x09; max=23; mini=0;} //時
135 1 if(sel==1)
136 1 {
137 2 // address=0x08;
138 2 if(Add ==0 || Dec ==0)
139 2 Bell_Swh=~Bell_Swh;
140 2 Write_24c04(0x08,Bell_Swh);
141 2 } //開關(guān)
142 1
143 1 item = Read_24C04(address);
144 1 if(sel_1==0)
145 1 item++;
146 1 else
147 1 item--;
148 1 if(item>max) item=mini;
149 1 if(item<mini) item=max;
150 1
151 1 Write_24c04(address,item);//寫入24
152 1 }
153
154 //閏年的計算
155 bit leap_year()
156 {
157 1 bit leap;
158 1 if((year%4==0&&year%100!=0)||year%400==0)//閏年的條件
159 1 leap=1;
160 1 else
161 1 leap=0;
162 1 return leap;
163 1 }
164
165 //星期的自動運算和處理
166 unsigned char week_proc()
167 { unsigned char num_leap;
168 1 unsigned char c;
169 1 num_leap=year/4-year/100+year/400;//自00年起到y(tǒng)ear所經(jīng)歷的閏年數(shù)
170 1 if( leap_year()&& month<=2 ) //既是閏年且是1月和2月
171 1 c=5;
172 1 else
173 1 c=6;
174 1 week=(year+para_month[month]+date+num_leap+c)%7;//計算對應(yīng)的星期
175 1 return week;
176 1 }
177 /******************做日期運算*****************/
178 //時間和日期處理程序
179 void pro_timedate()
C51 COMPILER V7.50 MAIN 03/04/2001 18:19:09 PAGE 4
180 {
181 1 sec++;
182 1 if(sec > 59)
183 1 {sec = 0;
184 2 min++;
185 2 if(min>59)
186 2 {min=0;
187 3 hour++;
188 3 if(hour>23)
189 3 {hour=0;
190 4 date++;
191 4 if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
192 4 if (date>31) {date=1;month++;} //大月31天
193 4 if (month==4||month==6||month==9||month==11)
194 4 if (date>30) {date=1;month++;} //小月30天
195 4 if (month==2)
196 4 {if( leap_year()) //閏年的條件
197 5 {if (date>29) {date=1;month++;}} //閏年2月為29天
198 5 else
199 5 {if (date>28) {date=1;month++;}} //平年2月為28天
200 5 }
201 4 if (month>12) {month=1;year++;}
202 4 if (year>99) year=0;
203 4 }
204 3 }
205 2 }
206 1 week_proc();
207 1 Write_24c04( 0x01,0);
208 1 Write_24c04( 0x02,year);
209 1 Write_24c04( 0x03,month);
210 1 Write_24c04( 0x04,date);
211 1 Write_24c04( 0x05,hour);
212 1 Write_24c04( 0x06,min);
213 1 Write_24c04( 0x07,sec);
214 1 //鬧鐘啟用時,報警時間到,啟動Timer1
215 1 }
216 /********定時器0。做時鐘用*****************/
217 void timer0() interrupt 1 using 0
218 {
219 1 TH0=0x3c;
220 1 TL0=0xb2;
221 1 cnt++;
222 1 // if((word==1)&&(Bell_Swh == 1))
223 1 // {
224 1 // TR1=0;
225 1 // }
226 1 if(cnt==20)
227 1 {
228 2 led1^=1;
229 2 cnt=0;
230 2 pro_timedate();
231 2 }
232 1 }
233 /********定時器0。做時鐘用*****************/
234 void timer1() interrupt 3 using 0
235 {
236 1 TH1=0x3c;
237 1 TL1=0xb0;
238 1 counter1++;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -