📄 iictest.lst
字号:
C51 COMPILER V6.14 IICTEST 08/15/2007 14:49:51 PAGE 1
C51 COMPILER V6.14, COMPILATION OF MODULE IICTEST
OBJECT MODULE PLACED IN E:\11SH\ONEUSER\MCU_C\VIIC\VIICTEST\IICTEST.OBJ
COMPILER INVOKED BY: d:\c51\C51.EXE E:\11SH\ONEUSER\MCU_C\VIIC\VIICTEST\IICTEST.C DB SB OE OT(9)
stmt level source
1 /*#include <AT89X051.H>
2 #include <INTRINS.H>*/
3 #pragma code rom(small) OT(9)
4 #include <VIIC.H>
5
6 #define uchar unsigned char
7 #define uint unsigned int
8 #define ulint unsigned long int
9 /*port defined*/
10
11 #define BUTN P1_4
12 #define DAT P3_0
13 #define CLK P3_1
14 #define STR P3_2
15 #define DIS0 P1_2
16 #define DIS1 P1_3
17 #define DIS2 P1_4
18
19 #define SDA P1_7
20 #define SCL P1_6
21 #define WP P1_5
22
23 #define BUZZER P1_0
24 /*flag bit defined*/
25 bit tim0_int_f = 0x20^0;
26 /*variable defined*/
27 unsigned long int timr_cnt=0; /*10ms per number*/
28 uchar code dis[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6};
29 uchar idata count[4]; /*temp. count unit*/
30 uchar slaw,slar;number;
31
32 /*-------------------*/
33 void delay_us()
34 {/*uchar p;
35 1 for(p=0;p<1;p++); */
36 1
37 1 }
38 /*-------------------*/
39 void delay_xx(uint del)
40 {
41 1 uint i;
42 1 for(i=0;i<del;++i);
43 1 }
44 /**********************/
45 /*send timer data for display to the chip 74HC595*/
46 void disp(uchar distemp)
47
48
49 {
50 1 uchar bit_cnt;
51 1
52 1 CLK=0;
53 1 for(bit_cnt=8;bit_cnt>0;--bit_cnt)
54 1 {
55 2
C51 COMPILER V6.14 IICTEST 08/15/2007 14:49:51 PAGE 2
56 2 DAT=distemp&0x01;
57 2 delay_us();
58 2 CLK=1;
59 2 delay_us();
60 2 CLK=0;
61 2 distemp>>=1;
62 2 }
63 1 }
64
65 /*****************************************************/
66 void dis_send(){
67 1 uchar shi_wan,wan_wei,qian_wei,bai_wei;
68 1 uchar shi_wei,ge_wei;
69 1 uchar discod;
70 1
71 1 tim0_int_f=0;
72 1 shi_wan=(uchar)(timr_cnt/100000);
73 1 wan_wei=(uchar)(timr_cnt%100000/10000);
74 1 qian_wei=(uchar)(timr_cnt%100000%10000/1000);
75 1 bai_wei=(uchar)(timr_cnt%100000%10000%1000/100);
76 1 shi_wei=(uchar)(timr_cnt%100000%10000%1000%100/10);
77 1 ge_wei=(uchar)(timr_cnt%100000%10000%1000%100%10);;
78 1
79 1 STR=0;
80 1 discod=dis[ge_wei];
81 1 disp(0x01); /*send bit data*/
82 1 disp(discod);
83 1 STR=1;
84 1 delay_xx(80);
85 1
86 1 STR=0;
87 1 discod=dis[shi_wei];
88 1 disp(0x02);
89 1 disp(discod);
90 1 STR=1;
91 1 delay_xx(80);
92 1
93 1 STR=0;
94 1 discod=dis[bai_wei];
95 1 disp(0x04);
96 1 disp(discod);
97 1 STR=1;
98 1 delay_xx(80);
99 1
100 1 STR=0;
101 1 discod=dis[qian_wei];
102 1 disp(0x08);
103 1 disp(discod);
104 1 STR=1;
105 1 delay_xx(80);
106 1
107 1 STR=0;
108 1 discod=dis[wan_wei];
109 1 disp(0x10);
110 1 disp(discod);
111 1 STR=1;
112 1 delay_xx(80);
113 1
114 1 STR=0;
115 1 discod=dis[shi_wan];
116 1 disp(0x20);
117 1 disp(discod);
C51 COMPILER V6.14 IICTEST 08/15/2007 14:49:51 PAGE 3
118 1 STR=1;
119 1 delay_xx(80);
120 1
121 1 STR=0; /*clear display*/
122 1 disp(0x00);
123 1 disp(0x00);
124 1 STR=1;
125 1 /* STR=0;
126 1 disp(0x08);
127 1 disp(0x8c); /*display "T" */
128 1 /* STR=1; */
129 1 }
130
131 main()
132 {WP=1;
133 1 timr_cnt=123456;
134 1 mainloop:
135 1 dis_send();
136 1 slaw=0xa0; /*write command*/
137 1 count[0]=0x10; /*eeprom's first address*/
138 1 count[1]=(uchar)(timr_cnt/65536);
139 1 count[2]=(uchar)((timr_cnt%65536)/256);
140 1 count[3]=(uchar)(((timr_cnt%65536)%256));
141 1 number=4; /*write 4 bytes including first address*/
142 1 WP=0;
143 1 mbytwr(slaw,count,number);
144 1 WP=0;
145 1 wait_butn: dis_send();
146 1 if(BUTN==0)
147 1 { dis_send(); /*delay 7ms */
148 2 if(BUTN==0)
149 2 { STR=0; /*clear display*/
150 3 disp(0x00);
151 3 disp(0x00);
152 3 STR=1;
153 3
154 3 number=0; /*write first address*/
155 3 count[0]=0x10;
156 3 slaw=0xa0;
157 3 mbytwra(slaw,count,number);
158 3
159 3 number=3; /*read datas from eeprom*/
160 3 slar=0xa1;
161 3 mbytrd(slar,count,number);
162 3
163 3 timr_cnt=(unsigned long int)(65536*count[0]+256*count[1]+count[2]);
164 3
165 3 while(BUTN==0);
166 3 goto mainloop;
167 3 }
168 2 }
169 1 else
170 1 dis_send();
171 1 goto wait_butn;
172 1
173 1 }
174
175
176
177 /*read datas from eeprom after powering on*/
178
179
C51 COMPILER V6.14 IICTEST 08/15/2007 14:49:51 PAGE 4
180 /***************************************************/
181 /*source routine*/
182 /*qq[] is data group read out,including first address*/
183 /*ff[] is data group writed,including first address*/
184 /*number: data transmitted quantities
185 /*used flag:F0 for ACK signal */
186 /***************************************************/
187 void sta() /*START*/
188 {SDA=1;
189 1 NOP;
190 1 SCL=1;
191 1 NOP;
192 1 SDA=0;
193 1 NOP;
194 1 SCL=0;
195 1 }
196
197 void stop() /*STOP*/
198 {SDA=0;
199 1 NOP;
200 1 SCL=1;
201 1 NOP;
202 1 SDA=1;
203 1 NOP;
204 1 SCL=0;
205 1 }
206 void mack() /*send answer*/
207 {SDA=0;
208 1 NOP;
209 1 SCL=1;
210 1 NOP;
211 1 SCL=0;
212 1 SDA=1;
213 1 }
214 void mnack() /*don't answer signal*/
215 {SDA=1;
216 1 NOP;
217 1 SCL=1;
218 1 NOP;
219 1 SCL=0;
220 1 NOP;
221 1 SDA=0;
222 1 }
223 void cack() /*check answer signal*/
224 {SDA=1;
225 1 SCL=1;
226 1 NOP;
227 1 F0=0;
228 1 if(SDA==1)
229 1 F0=1;
230 1 _nop_();
231 1 SCL=0;
232 1 _nop_();
233 1 }
234 void wrbyt(uchar shu) /*send one byte to slave device*/
235 {uchar i=8;
236 1 do
237 1 /* for(i=8;i=0;i--)*/
238 1 {if((shu&0x80)>0)
239 2 {SDA=1;
240 3 NOP;
241 3 SCL=1;
C51 COMPILER V6.14 IICTEST 08/15/2007 14:49:51 PAGE 5
242 3 NOP;
243 3 SCL=0;
244 3 /* SDA=0; */
245 3 }
246 2 else
247 2 {SDA=0;
248 3 NOP;
249 3 SCL=1;
250 3 NOP;
251 3 SCL=0;
252 3 }
253 2 shu=shu<<1;
254 2 i=i-1;
255 2 }
256 1 while(i);
257 1 }
258
259 uchar rdbyt() /*read one byte from slave device*/
260 {uchar nn=0xff,mm=0x80,uu=0x7f;
261 1 uchar i=8;
262 1 /* for(i=0;i<8;i++) */
263 1 do
264 1 {
265 2 SDA=1;
266 2 NOP;
267 2 SCL=1;
268 2 if(SDA==0)
269 2 nn=(nn&uu);
270 2 else
271 2 nn=(nn|mm);
272 2 nn=_crol_(nn,1);
273 2 SCL=0;
274 2 i=i-1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -