📄 +
字号:
C51 COMPILER V8.02 时钟 11/19/2012 19:28:08 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE 时钟
OBJECT MODULE PLACED IN 时钟.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 时钟.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include<reg51.h>
2 #define uint unsigned int
3 #define uchar unsigned char
4 uchar code table[]={"0000-00-00"};
5 uchar code table1[]={"00:00:00"};
6 uchar code table2[]={"MONTUSWEDTHUFRISATSUN"};
7 sbit rs=P2^0;
8 sbit rw=P2^1;
9 sbit e=P2^2;
10 sbit key1=P2^3;
11 sbit key2=P2^4;
12 sbit key3=P2^5;
13 char shi,ge,num1;
14 char num,shi1=0,fen=0,miao=0,ri=0,yue=0; uchar xingqi=1;
15 int nianqian=0,nianhou=0;
16 void delay(unsigned int z)
17 {
18 1 uchar x,y;
19 1 for(x=z;x>0;x--)
20 1 for(y=110;y>0;y--);
21 1 }
22 void write_com(uchar com)
23 {
24 1
25 1 rs=0;
26 1 rw=0;
27 1 P0=com;
28 1 delay(5);
29 1 e=1;
30 1 delay(5);
31 1 e=0;
32 1 }
33 void write_data(uchar date)
34 {
35 1 rs=1;
36 1 rw=0;
37 1 P0=date;
38 1 delay(5);
39 1 e=1;
40 1 delay(5);
41 1 e=0;
42 1 }
43 void init()
44 {
45 1 rs=0;
46 1 write_com(0x38);
47 1 write_com(0x0c);
48 1 write_com(0x06);
49 1 write_com(0x01);
50 1 delay(5);
51 1 }
52 void write_wang(uchar add,uchar date)
53 {
54 1 shi=date/10;
55 1 ge=date%10;
C51 COMPILER V8.02 时钟 11/19/2012 19:28:08 PAGE 2
56 1 write_com(0x80+0X40+add);
57 1 write_data(0x30+shi);
58 1 write_data(0x30+ge);
59 1
60 1 }
61 void write_wang1(uchar add,uchar date)
62 {
63 1 shi=date/10;
64 1 ge=date%10;
65 1 write_com(0x80+add);
66 1 write_data(0x30+shi);
67 1 write_data(0x30+ge);
68 1
69 1 }
70 void write_wang2(uchar add,int date)
71 {
72 1 shi=date/10;
73 1 ge=date%10;
74 1 write_com(0x80+add);
75 1 write_data(0x30+shi);
76 1 write_data(0x30+ge);
77 1 }
78 void keycan()
79 {
80 1 uchar i;
81 1 if(key1==0)
82 1 {
83 2 delay(5);
84 2 if(key1==0)
85 2 {
86 3 num1++;
87 3 while(!key1);
88 3 if(num1==1)
89 3 {
90 4 TR0=0;
91 4 write_com(0x80+0x40+7);
92 4 write_com(0x0f);
93 4 }
94 3 }
95 2 if(num1==2)
96 2 {
97 3 write_com(0x80+0x40+4);
98 3 }
99 2 if(num1==3)
100 2 {
101 3 write_com(0x80+0x40+1);
102 3
103 3 }
104 2 if(num1==4)
105 2 {
106 3 write_com(0x80+9);
107 3 }
108 2 if(num1==5)
109 2 write_com(0x80+6);
110 2 if(num1==6)
111 2 write_com(0x80+3);
112 2 if(num1==7)
113 2 write_com(0x80+1);
114 2 if(num1==8)
115 2 write_com(0x80+13);
116 2 if(num1>=9)
117 2 {
C51 COMPILER V8.02 时钟 11/19/2012 19:28:08 PAGE 3
118 3 num1=0;
119 3 TR0=1;
120 3 write_com(0x0c);
121 3 }
122 2 }
123 1 if(num1!=0)
124 1 {
125 2 if(key2==0)
126 2 {
127 3 delay(5);
128 3 if(key2==0)
129 3 {
130 4 while(key2!=1);
131 4 if(num1==1)
132 4 {
133 5 miao++;
134 5 if(miao==60)
135 5 {
136 6 miao=0;
137 6 }
138 5 write_wang(6,miao);
139 5 write_com(0x80+0x40+6);
140 5 }
141 4 if(num1==2)
142 4 {
143 5 fen++;
144 5 if(fen==60)
145 5 {
146 6 fen=0;
147 6 }
148 5 write_wang(3,fen);
149 5 write_com(0x80+0x40+3);
150 5 }
151 4 if(num1==3)
152 4 {
153 5 shi1++;
154 5 if(shi1==24)
155 5 {
156 6 shi1=0;
157 6 }
158 5 write_wang(0,shi1);
159 5 write_com(0x80+0x40);
160 5 }
161 4 if(num1==4)
162 4 {
163 5 ri++;
164 5 if(ri==32)
165 5 {
166 6 ri=0;
167 6 }
168 5 write_wang1(8,ri);
169 5 write_com(0x80+8);
170 5 }
171 4 if(num1==5)
172 4 {
173 5 yue++;
174 5 if(yue==13)
175 5 {
176 6 yue=0;
177 6 }
178 5 write_wang1(5,yue);
179 5 write_com(0x80+5);
C51 COMPILER V8.02 时钟 11/19/2012 19:28:08 PAGE 4
180 5 }
181 4 if(num1==6)
182 4 {
183 5 nianhou++;
184 5 if(nianhou==99)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -