📄 24c16.lst
字号:
C51 COMPILER V6.23a 24C16 08/23/2005 14:15:32 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE 24C16
OBJECT MODULE PLACED IN 24c16.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe 24c16.c DB OE SMALL ROM(LARGE)
stmt level source
1 //=======================================
2 //功能:对24c16卡读写操作
3 //改写:清风徐徐(改自[永远不开的壶]程序)
4 //时间:2004.5.17
5 //qq: 78779514
6 //更多源代码:http://www.qfmcu.com/
7 //======================================
8 #include <reg52.h>
9 #include<intrins.h>
10
11 #define uchar unsigned char
12 #define uint unsigned int
13 #define ulong unsigned long
14
15 unsigned char a[]="01234567";
16
17 /*---------------------------------------------
18 读写24C16标准程序段
19 完成日期:03/7/9
20 作者:reed
21 -------------------------------------------*/
22 //#include"main.h"
23 sbit SDA=P0^1;
24 sbit SCL=P0^0;
25 sbit rht0=P3^0;
26 sbit rht1=P3^1;
27 sbit rht2=P3^2;
28 sbit rht3=P3^3;
29 sbit rht4=P3^4;
30 sbit rht5=P3^5;
31 sbit rht6=P3^6;
32 sbit rht7=P3^7;
33 /*-----------------------------------------------
34 调用方式:void start_bit(void)
35 函数说明:开始位
36 -----------------------------------------------*/
37 void start_bit(void)
38 {
39 1 SCL=1;_nop_();
40 1 SDA=1;_nop_();
41 1 SDA=0;_nop_();
42 1 SCL=0;_nop_();
43 1 }
44 /*-----------------------------------------------
45 调用方式:void stop_bit(void)
46 函数说明:停止位
47 -----------------------------------------------*/
48 void stop_bit(void)
49 {
50 1 SDA=0;_nop_();
51 1 SCL=1;_nop_();
52 1 SDA=1;_nop_();
53 1 }
54 /*-----------------------------------------------
55 调用方式:void mast_ack(void)
C51 COMPILER V6.23a 24C16 08/23/2005 14:15:32 PAGE 2
56 函数说明:主答函数
57 -----------------------------------------------*/
58 void mast_ack(void)
59 {
60 1 SCL=0;_nop_();
61 1 SDA=0;_nop_();
62 1 SCL=1;_nop_();
63 1 SCL=0;_nop_();
64 1 SDA=1;_nop_();
65 1 }
66 /*-----------------------------------------------
67 调用方式:void ack(void)
68 函数说明:应答函数
69 -----------------------------------------------*/
70 void ack(void)
71 {
72 1 SDA=1;
73 1 //SCL=0;_nop_();
74 1 SCL=1;_nop_();
75 1 while(SDA);
76 1 SCL=0;_nop_();
77 1 }
78 /*-----------------------------------------------
79 调用方式:void no_ack(void)
80 函数说明:无需应答位,在读程序中用到
81 -----------------------------------------------*/
82 void no_ack(void)
83 {
84 1 SDA=1;_nop_();
85 1 SCL=0;_nop_();
86 1 SCL=1;_nop_();
87 1 while(SDA);
88 1 SCL=0;_nop_();
89 1 }
90 /*-----------------------------------------------
91 调用方式:write_8bit(uchar ch)
92 函数说明:写一个字节(8位)数据
93 -----------------------------------------------*/
94 write_8bit(uchar ch)
95 {
96 1 uchar i=8;
97 1 SCL=0;_nop_();
98 1 while(i--)
99 1 {
100 2 // SDA=(bit)(ch&0x80);_nop_();
101 2 // ch<<=1;
102 2 if(ch & 0x80)
103 2 SDA=1;
104 2 else
105 2 SDA=0;
106 2 _nop_();
107 2 ch<<=1;
108 2 SCL=1;_nop_();
109 2 SCL=0;_nop_();
110 2 }
111 1 }
112 /*----------------------------------------------
113 调用方式:uchar read24c16(uint address)
114 函数说明:读24c16指定地址数据(字节读)
115 -----------------------------------------------*/
116 uchar read24c16(uint address)
117 {
C51 COMPILER V6.23a 24C16 08/23/2005 14:15:32 PAGE 3
118 1 uchar data rdata;
119 1 uchar i=8;
120 1 EA=0;//避免与串口通讯等中断冲突
121 1 start_bit();
122 1 write_8bit(0xA0);
123 1 ack();
124 1 write_8bit(address);
125 1 ack();//伪写
126 1 start_bit();
127 1 write_8bit(0xA1);
128 1 ack();
129 1 while(i--)
130 1 {
131 2 rdata<<=1;
132 2 SCL=0;_nop_(); SCL=1;
133 2 if(SDA) rdata|=0x01;
134 2 }
135 1 //no_ack();
136 1 stop_bit();
137 1 EA=1;
138 1 return rdata;
139 1 }
140 /*-----------------------------------------------
141 调用方式:void write24c16(uint address,uchar ddata)
142 函数说明:写数据到24c16的指定地址(字节写)
143 -----------------------------------------------*/
144 void write24c16(uint address,uchar ddata)
145 {
146 1 EA=0; //避免与串口通讯等中断冲突
147 1 start_bit();
148 1 write_8bit(0xA0);
149 1 ack();
150 1 write_8bit(address);
151 1 ack();
152 1 write_8bit(ddata);
153 1 ack();
154 1 stop_bit();
155 1 EA=1;
156 1 }
157 /*-----------------------------------------------
158 调用方式:void page_wr(uint firstw_ad,uint counter,uint data firstr_ad)
159 函数说明:页面写函数,firstw_ad为写入字节单元的首地址,
160 *firstr-ad为被写入数据所在首地址指针
161 counter为写入数据字节数
162 -----------------------------------------------*/
163 void page_wr(uint firstw_ad,uint counter,uint firstr_ad)
164 {
165 1 uchar data *ufirstr_ad;
166 1 ufirstr_ad=firstr_ad;
167 1 start_bit();
168 1 write_8bit(0xA0);
169 1 ack();
170 1 write_8bit(firstw_ad);
171 1 ack();
172 1 while(counter--)
173 1 {
174 2 write_8bit(*ufirstr_ad);
175 2 ufirstr_ad++;
176 2 ack();
177 2 }
178 1 stop_bit();
179 1 }
C51 COMPILER V6.23a 24C16 08/23/2005 14:15:32 PAGE 4
180 /*-----------------------------------------------
181 调用方式:void page_rd(uint firstrd_ad,uint count,uint firstwr_ad)
182 函数说明:页面读函数,firstrd-ad为所读字节首地址,count为读字节数
183 *ufirstwr-ad为读出数据存储首地址指针
184 -----------------------------------------------*/
185 void page_rd(uint firstrd_ad,uint count,uint firstwr_ad)
186 {
187 1 uchar j=8;
188 1 uchar data *ufirstwr_ad;
189 1 ufirstwr_ad=firstwr_ad;
190 1 start_bit();
191 1 write_8bit(0xA0);
192 1 ack();
193 1 write_8bit(firstrd_ad);
194 1 ack();
195 1 start_bit();
196 1 write_8bit(0xA1);
197 1 ack();
198 1 while(count--)
199 1 {
200 2 uchar i=8;
201 2 while(i--)
202 2 {
203 3 (*ufirstwr_ad)<<=1;
204 3 SCL=0;_nop_();_nop_();SCL=1;
205 3 if(SDA) (*ufirstwr_ad)|=0x01;
206 3 }
207 2 ufirstwr_ad++;
208 2 mast_ack();
209 2 }
210 1 while(j--)
211 1 {
212 2 (*ufirstwr_ad)<<=1;
213 2 SCL=0;_nop_();_nop_();SCL=1;
214 2 if(SDA) (*ufirstwr_ad)|=0x01;
215 2 }
216 1 no_ack();
217 1 stop_bit();
218 1 }
219
220 void main(void)
221 {
222 1 uchar b[8];
223 1 P1=0xff;
224 1 page_wr(1,8,a);
*** WARNING C214 IN LINE 224 OF 24C16.C: 'Argument': conversion: pointer to non-pointer
225 1 page_rd(1,8,b);
*** WARNING C214 IN LINE 225 OF 24C16.C: 'Argument': conversion: pointer to non-pointer
226 1 //b[0]=read24c16(0x02);
227 1 if(b[0]=='0') rht0=0;
228 1 if(b[1]=='1') rht1=0;
229 1 if(b[2]=='2') rht2=0;
230 1 if(b[3]=='3') rht3=0;
231 1 if(b[4]=='4') rht4=0;
232 1 if(b[5]=='5') rht5=0;
233 1 if(b[6]=='6') rht6=0;
234 1 if(b[7]=='7') rht7=0;
235 1 while(1);
236 1 }
237
C51 COMPILER V6.23a 24C16 08/23/2005 14:15:32 PAGE 5
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 463 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 9 13
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 2 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -