📄 main_v2.lst
字号:
C51 COMPILER V7.06 MAIN_V2 10/26/2008 02:07:00 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE MAIN_V2
OBJECT MODULE PLACED IN main_v2.OBJ
COMPILER INVOKED BY: J:\Keil\C51\BIN\C51.EXE main_v2.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*
2 * Copyright (C) 2007, 华中科技大学电气与电子科技创新中心
3 * All Rights Reserved.
4 *
5 * 文件名: main.c
6 * 文件描述: 万年历主程序
7 *
8 * 当前版本: 1.0
9 * 作者: Zuowenping(fmku007@163.com)
10 * 完成日期: 2008年10月24日
11 *
12 */
13 #include "reg51.h"
14 #include "intrins.h"
15 #include "lcd1602.h"
16 #include "main.h"
17 #include <string.h>
18
19
20 #define MAIN_COUN 99 //中断计数值
21 #define MAX_NO_OP_TIME 10 //最大无操作时间(从调整状态恢复到正常显示状态)
22
23 #define KEY1 0xfe //四个按键键码
24 #define KEY2 0xfd
25 #define KEY3 0xfb
26 #define KEY4 0xf7
27
28 #define STOP 0x00 //秒表停止命令
29 #define START 0x01 //秒表启动命令
30 #define PAUSE 0x02 //秒表暂停命令(依然计数)
31 #define STPAU 0x03 //秒表暂停、不计数
32
33 #define ADD 0x01 //时间调整命令:加
34 #define SUB 0x02 //时间调整命令:减
35
36
37 u8 int_coun=0,sec=0,sec_pre=0; //秒寄存器
38 u8 wink_mode=0; //闪烁控制模式(时间调整用)
39 u8 key_temp=0; //按键共享寄存器
40 u16 key_coun=0; //按键计数寄存器(判断按键时长)
41 u8 key_speed=0; //根据按键时长得到不同的调节速度
42 u8 max_speed=0; //调节速度时长门限
43 u8 sys_mode=1; //系统模式 0:时间调级 1:正常时间显示 2:计数模式3:农历模式
44 u8 sys_mode_pre=10; //上一模式暂存
45 u8 stop_mode=0; //stopwatch工作模式 0:停止1:启动2:暂停仍计数3:暂停不计数
46 bit key_flag=0; //按键标志
47 bit adj_flag=0; //时间调节标志
48 bit wink_ena=1; //闪烁使能控制
49 bit stop_ena=0; //秒表使能控制
50 bit disp_flag=0; //正在显示标志,避免因为在显示过程中进中断调用显示程序,使LCD混乱
51
52 u8 no_op_time=0; //无操作记时寄存器
53
54
55 u8 hour=2,min=7,month=10,day=26;
C51 COMPILER V7.06 MAIN_V2 10/26/2008 02:07:00 PAGE 2
56 u16 m_day=365,year=2008; //时间相关寄存器
57
58 u8 stop_hour=0,stop_min=0,stop_sec=0,stop_ms=0;
59 u8 stop_ms_pre=0; //秒表时间相关寄存器
60
61
62 static u8 code non_leap_table[]={31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31};
- //0-11:non_leap 12-23 leap year month table
63 //平年、闰年每月天数表
64
65
66 void int_svr() interrupt 3 //定时器1中断服务程序
67 {
68 1 TH1=220;
69 1 TL1=37;
70 1 // P3=P3^0x01;
71 1 if(int_coun<MAIN_COUN)
72 1 int_coun+=1;
73 1 else
74 1 { int_coun=0;
75 2 if(sec<59)
76 2 sec+=1;
77 2 else
78 2 sec=0;
79 2 }
80 1 if(int_coun==MAIN_COUN/2&&wink_ena&&!disp_flag)
81 1 {/*put_char(13,1,32);*/wink_set(wink_mode);}
82 1
83 1 if(stop_mode==1||stop_mode==2)
84 1 {
85 2 calc_stop_watch();
86 2 if(stop_ms<99)
87 2 stop_ms+=1;
88 2 else
89 2 stop_ms=0;
90 2
91 2 }
92 1 else if(stop_mode==0)
93 1 {
94 2 stop_ms=0;
95 2 stop_hour=0;
96 2 stop_min=0;
97 2 stop_sec=0;
98 2 }
99 1
100 1 if(stop_mode!=2&&stop_ena&&sys_mode==2&&!disp_flag)display(); //是暂停则不显示更新数据
101 1 }
102
103
104 void main()
105 {
106 1 Sys_Init();
107 1 while(1)
108 1 {
109 2 if(sec_pre!=sec)
110 2 {
111 3 calc_time();
112 3 if(sys_mode==1||sys_mode==0)
113 3 display();
114 3 sec_pre=sec;
115 3 }
116 2
C51 COMPILER V7.06 MAIN_V2 10/26/2008 02:07:00 PAGE 3
117 2 key_scan();
118 2 key_proc();
119 2 }
120 1 }
121
122 void Sys_Init()
123 {
124 1 lcd_init();
125 1 sys_config();
126 1 TMOD=0x10;
127 1 TH1=220;
128 1 TL1=37;
129 1 EA=1;
130 1 ET1=1;
131 1 TR1=1;
132 1 }
133
134 //时间计算函数
135 void calc_time()
136 {
137 1 if(day>non_leap_table[month-1+(calc_day(year)?12:0)])
138 1 day=non_leap_table[month-1+(calc_day(year)?12:0)];
139 1 if(sec_pre==59)
140 1 {
141 2 if(min<59)
142 2 min+=1;
143 2 else
144 2 {
145 3 min=0;
146 3 if(hour<23)
147 3 hour+=1;
148 3 else
149 3 {
150 4 hour=0;
151 4 if(day<non_leap_table[month-1+(calc_day(year)?12:0)])
152 4 day+=1;
153 4 else
154 4 {
155 5 day=1;
156 5 if(month<12)
157 5 month+=1;
158 5 else
159 5 {
160 6 month=1;
161 6 year+=1;
162 6 }
163 5 }
164 4 }
165 3 }
166 2 }
167 1 }
168
169
170 void calc_stop_watch()
171 {
172 1 if(stop_ms==99)
173 1 {
174 2 if(stop_min<59)
175 2 stop_min+=1;
176 2 else
177 2 {
178 3 stop_min=0;
C51 COMPILER V7.06 MAIN_V2 10/26/2008 02:07:00 PAGE 4
179 3 if(stop_hour<99)
180 3 stop_hour+=1;
181 3 else
182 3 {
183 4 stop_hour=0;
184 4 }
185 3 }
186 2 }
187 1 }
188
189
190 //判断是否为闰年
191 unsigned char calc_day(u16 year)
192 {
193 1 if((year%4==0&&year%100!=0)||year%400==0)
194 1 return 1;
195 1 else
196 1 return 0;
197 1 }
198 //显示子程序
199 void display()
200 {
201 1 disp_flag=1;
202 1 if(sys_mode==0||sys_mode==1)
203 1 {
204 2 put_char(0,0,year/1000+48);
205 2 put_char(1,0,(year%1000)/100+48);
206 2 put_char(2,0,year%1000%100/10+48);
207 2 put_char(3,0,year%1000%100%10+48);
208 2
209 2
210 2 put_char(5,0,month/10+48);
211 2 put_char(6,0,month%10+48);
212 2
213 2
214 2 put_char(8,0,day/10+48);
215 2 put_char(9,0,day%10+48);
216 2
217 2 put_char(8,1,hour/10+48);
218 2 put_char(9,1,hour%10+48);
219 2
220 2 put_char(11,1,min/10+48);
221 2 put_char(12,1,min%10+48);
222 2
223 2 put_char(14,1,sec/10+48);
224 2 put_char(15,1,sec%10+48);
225 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -