📄 p163.lst
字号:
C51 COMPILER V7.06 P163 12/23/2008 16:41:52 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE P163
OBJECT MODULE PLACED IN p163.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE p163.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include"lcd.c"
2 #include"keypad.c"
3 #define putchar write_lcd_data
4 typedef struct{
5 char hour;
6 char minute;
7 char second;
8 }time;
9 typedef struct{
10 char year;
11 char month;
12 char day;
13 }date;
14 time now={23,59,0},display;
15 date today={04,05,29},tmpday;
16 static unsigned timer0_tick=100,mode=0,operation;
17 char code dayofmonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
18 char code weekday[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
19 char code command[1][6]={"Watch"};
20 //char code int2char[]="0123456789";
21 char gotkey();
22 void display_time(void)
23 {
24 1 gotoxy(1,0);
25 1 display_lcd_number(display.hour);
26 1 display_lcd_string(":");
27 1 display_lcd_number(display.minute);
28 1 display_lcd_string(":");
29 1 display_lcd_number(display.second);
30 1 }
31 void display_date()
32 {
33 1 char i,days=4;
34 1 gotoxy(2,2);
35 1 display_lcd_number(today.year);
36 1 display_lcd_string("/");
37 1 display_lcd_number(today.month);
38 1 display_lcd_string("/");
39 1 display_lcd_number(today.day);
40 1 display_lcd_string(" ");
41 1 if(today.month > 1)
42 1 for(i=0;i<=today.month-2;i++)
43 1 days+=(dayofmonth[i]%7);
44 1 if( today.year !=0 ) days+=((today.year-1)/4)+today.year+1;
45 1 if (today.year%4==0 && today.month >2) days++;
46 1 days=(days+today.day) % 7;
47 1 display_lcd_string(&weekday[days][0]);
48 1 }
49 int getdigit(unsigned char x,unsigned char y)
50 {
51 1 char keys;
52 1 do {
53 2 gotoxy(x,y);
54 2 putchar('_');
55 2 keys=gotkey();
C51 COMPILER V7.06 P163 12/23/2008 16:41:52 PAGE 2
56 2 gotoxy(x,y);
57 2 putchar(num[keys]);
58 2 } while(keys>9);
59 1 return(keys);
60 1 }
61 int gettime()
62 {
63 1 char temp;
64 1 do {
65 2 while((temp=getdigit(1,0))>2); //时的十位数不能大于2
66 2 temp=temp*10+getdigit(1,1);
67 2 if (temp > 23) display_time();
68 2 } while (temp > 23);
69 1 display.hour=temp;
70 1 while((temp=getdigit(1,3))>5);
71 1 display.minute=temp*10+getdigit(1,4);
72 1 return(1);
73 1 }
74 char monthday(char year,char month)
75 {
76 1 if(month==2 && year%4==0) //润年的2月有29天
77 1 return(29);
78 1 else
79 1 return(dayofmonth[month-1]); //非闰年时的该月份天数
80 1 }
81 int getdate()
82 {
83 1 char temp,days;
84 1 temp=getdigit(2,2);
85 1 tmpday.year=temp*10+getdigit(2,3);
86 1 do {
87 2 while((temp=getdigit(2,5))>1); //月的十位数不能大于1
88 2 temp=temp*10+getdigit(2,6);
89 2 if (temp > 12) display_date(); //月份的数字不能大于12
90 2 } while (temp > 12);
91 1 tmpday.month=temp;
92 1 do {
93 2 while((temp=getdigit(2,8))>3); //日的十位数不能大于3
94 2 temp=temp*10+getdigit(2,9);
95 2 days=monthday(tmpday.year,tmpday.month);
96 2 if(temp > days || temp==0) display_date();
97 2 } while (temp > days || temp==0);
98 1 //输入的日期大于该月日期就重新输入
99 1 tmpday.day=temp;
100 1 return(1);
101 1 }
102 static void timer0_isr(void) interrupt TF0_VECTOR using 1
103 {
104 1 TR0=0;
105 1 TH0=(65536-10000)/256;
106 1 TH0=(65536-10000)%256;
107 1 TR0=1;
108 1 if(--timer0_tick) return;
109 1 timer0_tick=100;
110 1 now.second++; //秒加1
111 1 if (now.second==60) { //如果秒等于60
112 2 now.second=0; //秒恢复为0
113 2 now.minute++; //分加1
114 2 if (now.minute==60) { //如果分等于60
115 3 now.minute=0; //分恢复为0
116 3 now.hour++; //时加1
117 3 if (now.hour==24) { //如果时等于24
C51 COMPILER V7.06 P163 12/23/2008 16:41:52 PAGE 3
118 4 now.hour=0; //时恢复为0
119 4 today.day++; //日加1
120 4 if (today.day>monthday(today.year,
121 4 today.month)) {
122 5 today.day=1;
123 5 //如果日超过当月最大日数,就变成1
124 5 today.month++;
125 5 //月加1
126 5 if(today.month==13) {
127 6 //如果月等于13
128 6 today.month=1;
129 6 //月恢复为1
130 6 today.year++;
131 6 //年加1
132 6 }
133 5 }
134 4 display_date();
135 4 }
136 3 }
137 2 }
138 1 if (operation==11 ) return;
139 1 display=now;
140 1 display_time();
141 1 }
142 static void timer0_initialize(void)
143 {
144 1 EA=0;
145 1 TR0=0;
146 1 TMOD &= 0XF0;
147 1 TMOD |=0x01;
148 1 TH0=(65536-10000)/256;
149 1 TH0=(65536-10000)%256;
150 1 PT0=0;
151 1 ET0=1;
152 1 TR0=1;
153 1 EA=1;
154 1 }
155 void main (void) {
156 1 char keys;
157 1 init_lcd();
158 1 gotoxy(2,0);
159 1 display_lcd_string("20");
160 1 display=now;
161 1 display_time();
162 1 display_date();
163 1 gotoxy(1,9);
164 1 display_lcd_string(&command[mode][0]);
165 1 timer0_initialize();
166 1 do {
167 2 keys=gotkey();
168 2 if(keys==1) {
169 3 operation=1;
170 3 if ( gettime()) now=display;
171 3 if ( getdate()) {
172 4 today=tmpday;
173 4 display_date();
174 4 }
175 3 }
176 2 operation=0;
177 2 } while(1);
178 1 }
179
C51 COMPILER V7.06 P163 12/23/2008 16:41:52 PAGE 4
180
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1212 ----
CONSTANT SIZE = 90 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 18 4
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -