📄 main.lst
字号:
C51 COMPILER V6.12 MAIN 06/27/2007 16:47:25 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\main.OBJ
COMPILER INVOKED BY: D:\学习\专业工具\Keil51\C51\BIN\C51.EXE .\main.c DEBUG OBJECTEXTEND
stmt level source
1 #include "include.h"
2 #include "ds12887.h"
3 #include "p8255.h"
4
5 #define open 0x00//打开所有显示位
6 #define close 0xff//关闭所有显示位
7 #define first_open 0xdf//显示秒个位
8 #define secon_open 0xef//显示秒十位
9 #define three_open 0xf7//显示分个位
10 #define four_open 0xfb//显示分十位
11 #define five_open 0xfd//显示时个位
12 #define six_open 0xfe//显示时十位才
13
14
15 uchar code d2q[]={0x7b,0X30,0Xea,0Xf8,0Xb1,0Xd9,0XDB,0X70,0Xfb,0Xf9};//十进制转换为七段码
16
17 uchar data time[7];//时间缓冲
18 uint data tem;//温度缓冲
19 uchar data thl1;//定时器1初值
20
21 uchar data timch_bitchoose=0;//调时位选
22 uchar data t1_intrup_time=0;//T1中断次数,用于闪动1分自动退出调时状态
23 uchar data flash_T=0;//记录一个闪动周期动态显示的次数,用于闪动周期的占空比
24
25
26 /////////////////数码管的闪动亮灭的开关控制变量//////////////////
27 uchar data six_flash=open;//控制第六位数码管的闪动灭
28 uchar data five_flash=open;//控制第五位数码管的闪动灭
29 uchar data four_flash=open;//
30 uchar data three_flash=open;
31 uchar data secon_flash=open;//控制第二位数码管的闪动灭
32 uchar data first_flash=open;//控制第一位数码管的闪动灭
33
34
35
36 uchar data flash_time=0;//在调时状态下无操作时由调时状态自动退出前闪动的时间
37 uchar data showtime=0;//控制是显示时间(0)还是显示日期(4)
38 bit bdata leapyear=0;//记录是否闰年 闰年=1
39 uchar data showpoint=0x00;//控制在显示日期时显示数点
40
41 //中断函数
42 void Int0_timeset_bit(void);//调时位选
43 void T1_sec_end(void);//定时50ms,中断响应从12887读取时间送入缓冲区
44 void T0_time_set(void);//调时值设置,加1
45
46
47 void display(); //显示
48 void delay(uchar data x);//延迟 x ms
*** WARNING C258 IN LINE 48 OF .\MAIN.C: 'x': mspace on parameter ignored
49 uchar BCD2BIN(uchar data BCD);
*** WARNING C258 IN LINE 49 OF .\MAIN.C: 'BCD': mspace on parameter ignored
50 uchar BIN2BCD(uchar data BIN);
*** WARNING C258 IN LINE 50 OF .\MAIN.C: 'BIN': mspace on parameter ignored
51 void keyscan();//扫描8255 C口 键盘,进而判断是显示时间(showtime=0)还是显示日期(showtime=4)
52 void if_leapyear();//判断是否闰年
C51 COMPILER V6.12 MAIN 06/27/2007 16:47:25 PAGE 2
53 //void Init();
54
55
56
57 main()
58 {
59 1
60 1
61 1 P8255Con=0x88;//A口方式0输出,B口方式0输出,C口高四位输入,低四位输出
62 1 P8255Con=0x88;
63 1
64 1 TMOD=0X16;//0001 0110,定时器0采用外部计数方式2,定时器1采用定时方式1
65 1 TH0=0xfe;
66 1 TL0=0XFE;//定时初值,定时器0计1满
67 1 thl1=15536;//定时器1定时50ms
68 1
69 1 IT0=1;//INT0中断采用下降沿
70 1 IT1=1;//INT1中断采用下降沿
71 1
72 1 EX0=1;//外部中断0允许
73 1 EX1=1;//外部中断1允许
74 1 ET0=1;//定时中断0允许
75 1 ET1=1;//定时中断1允许
76 1 EA=1;//总中断允许
77 1
78 1 PT0=0;
79 1 PT1=1;//读取时间函数为最高优先级
80 1 PX0=0;
81 1 PX1=0;
82 1
83 1 TR0=1;//开启定时器0
84 1 TR1=1;
85 1
86 1
87 1 P8255Con=0x88;//A口方式0输出,B口方式0输出,C口高四位输入,低四位输出
88 1 P8255Con=0x88;
89 1 //P1=0X00;
90 1
91 1
92 1 //SetTime(BIN2BCD(00),BIN2BCD(38),BIN2BCD(17));
93 1 //SetDate(0x26,0x06,0x07);
94 1
95 1
96 1 while(1)
97 1 {
98 2 keyscan();//确定显示时间还是日期
99 2 display();//显示
100 2 }
101 1
102 1 }
103
104
105
106 //////////////////调时位选////////////////////////
107
108 void Int0_timeset_bit(void) interrupt 0 using 1//调时位选
109 {
110 1 timch_bitchoose++;//调时位的移位
111 1
112 1 if(timch_bitchoose==4)//退出调时状态
113 1 timch_bitchoose=0;
114 1
C51 COMPILER V6.12 MAIN 06/27/2007 16:47:25 PAGE 3
115 1 //根据要调时的位确定各个闪动开关变量的开与闭
116 1 switch(timch_bitchoose)
117 1 {
118 2 case 0:six_flash=0x00;five_flash=0x00;three_flash=0x00;four_flash=0x00;secon_flash=0x00;first_flash=0x0
-0;break;//不是调时状态
119 2 case 1:six_flash=0x00;five_flash=0x00;three_flash=0x00;four_flash=0x00;secon_flash=0xff;first_flash=0xf
-f;break;//调秒,闪
120 2 case 2:six_flash=0x00;five_flash=0x00;three_flash=0xff;four_flash=0xff;secon_flash=0x00;first_flash=0x0
-0;break;//调分,闪
121 2 case 3:six_flash=0xff;five_flash=0xff;three_flash=0x00;four_flash=0x00;secon_flash=0x00;first_flash=0x0
-0;break;//调时,闪
122 2 }
123 1
124 1 }
125
126
127 /////////////////////每50ms从128887读取时间,从ds1820读取温度写入缓冲区//////////////////
128
129 void T1_sec_end(void) interrupt 3 using 3//
130 { uchar data i;
131 1
132 1 thl1=15536;//重新赋初值
133 1 t1_intrup_time++;
134 1 if(t1_intrup_time==20)//满1秒钟
135 1 {
136 2 t1_intrup_time=0;
137 2 flash_time++;
138 2
139 2 if(flash_time==30)//在调时状态时,如果不操作,则30秒后自动退出调时状态
140 2 {
141 3 flash_time=0;
142 3 timch_bitchoose=0;
143 3 }
144 2 }
145 1 //从12887读取时间送缓冲区
146 1 time[0]=GetSeconds();
147 1 time[1]=GetMinutes();
148 1 time[2]=GetHours();
149 1 time[3]=GetDay();
*** WARNING C206 IN LINE 149 OF .\MAIN.C: 'GetDay': missing function-prototype
150 1 time[4]=GetDate();
151 1 time[5]=GetMonth();
152 1 time[6]=GetYear();
153 1 //从ds1820读取温度
154 1 tem=ReadTemperature();
*** WARNING C206 IN LINE 154 OF .\MAIN.C: 'ReadTemperature': missing function-prototype
155 1 //将BCD码转换为二进制
156 1 for(i=0;i<7;i++)
157 1 time[i]=BCD2BIN(time[i]);
158 1
159 1 }
160
161 /****************调时状态时,时间修改**************************/
162
163 void T0_time_set(void) interrupt 1 using 2//调时值设置
164 {
165 1 flash_time=0;//保证从调时状态自动返回的前提是无调时操作
166 1
167 1 switch(timch_bitchoose)
168 1 {
169 2 case 0:break;
170 2 case 1:if(showtime==4)
C51 COMPILER V6.12 MAIN 06/27/2007 16:47:25 PAGE 4
171 2 time[0+showtime]++;//调日,
172 2 else
173 2 time[0+showtime]=0;//调秒清零
174 2 break;
175 2 case 2:time[1+showtime]++;break;//调分或月
176 2 case 3:if(showtime!=4||time[6]!=99)//
177 2 time[2+showtime]++;
178 2 else
179 2 time[2+showtime]=0;
180 2 break;//调时或年
181 2 }
182 1 if(time[0]>=60)//调秒防溢出
183 1 time[0]=0;
184 1 if(time[1]>=60)//调分防溢出
185 1 time[1]=0;
186 1 if(time[2]>=24)//调时防止溢出
187 1 time[2]=0;
188 1 if(time[3]>=8)//调星期防止溢出
189 1 time[3]=1;
190 1 if(time[5]>=13)//调月防止溢出
191 1 time[5]=1;
192 1
193 1 //调日期防止溢出
194 1 if(time[5]==1||time[5]==3||time[5]==5||time[5]==7||time[5]==8||time[5]==10||time[5]==12)//含31天的月份
195 1 {
196 2 if(time[4]>=32)
197 2 time[4]=0;
198 2 }
199 1 else
200 1 {
201 2 if(time[5]==4||time[5]==6||time[5]==9||time[5]==11)//30天的月份
202 2 {
203 3 if(time[4]>=31)
204 3 time[4]=0;
205 3 }
206 2 else //二月是28天还是29天
207 2 {
208 3 if_leapyear();//判断是否闰年,闰年时leapyear=1
209 3 if(leapyear==1)//是闰年
210 3 {
211 4 if(time[4]>=30)
212 4 time[4]=0;
213 4 }
214 3 else//不是闰年
215 3 {
216 4 if(time[4]>=29)
217 4 time[4]=0;
218 4 }
219 3
220 3 }
221 2
222 2 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -