📄 at24c02.lst
字号:
C51 COMPILER V8.02 AT24C02 10/17/2006 16:52:42 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE AT24C02
OBJECT MODULE PLACED IN AT24C02.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE AT24C02.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 ###############################################################################
3 Wiznet.
4 5F Simmtech Bldg., 228-3, Nonhyun-dong, Kangnam-gu,
5 Seoul, Korea
6
7 (c) Copyright 2002, Wiznet, Seoul, Korea
8
9 Filename : at24c02.c
10 Created : 2002/01/29
11 Modified :
12 Description : Implement I2C I/F using Port #1's No 3(SDA) and No 4(SCL) of 89C51 MCU and Read/Write Serai
-l EEPROM, AT24C02.
13 AT24C02 Size : 2K Bits, 256 Byte,
14 AT24C02 Address Range : 0x00 ~ 0xFF
15 AT24C02 I/F : I2C using SDA and SCL
16 Note : AT24C02 has Address A2-A0 to address several,but it's not implemented in this source.
17 And AT24C02 has PAGE(8 BYTE) Writing, but it's not implemented in this source and it's possible to impleme
-nt using this functions.
18 ###############################################################################
19 */
20
21 /*
22 ###############################################################################
23 Include Part
24 ###############################################################################
25 */
26 #include "i2c.h" // i2c definition file
27 #include "AT24C02.h" // Header file
28
29 /*
30 ###############################################################################
31 Function Implementation Part
32 ###############################################################################
33 */
34
35 /*
36 Description : Check operatiton of EEP_ROM(AT24C02)
37 Write 0xEE value into 0xFE address and 0xFF value into 0xFF address.Read and Verify these value.
38 Argument :
39 Return Value : success = 1, fail = 0;
40 Note :
41 */
42 char Check_EEPROM()
43 {
44 1 char c=0;
45 1 if(EEP_Write(0xFE,0xEE)==0) return 0; // write 0xEE's value into 0x00 address
46 1 if(EEP_Write(0xFF,0xFF)==0) return 0; // write 0xFF's value into 0xFF address
47 1 if(EEP_Read(0xFE,&c, NACK)==0) return 0; // read 0x00's value
48 1 if(c != (char)0xEE) return 0; // Verify
49 1 if(EEP_Read(0xFF,&c,NACK)==0) return 0; // read 0xFF's value
50 1 if(c != (char)0xFF) return 0; // Verify
51 1 return 1;
52 1 }
53
C51 COMPILER V8.02 AT24C02 10/17/2006 16:52:42 PAGE 2
54 /*
55 Description : Write 1 byte data('d') into appropriate address(addr)
56 Argument :
57 Return Value : success = 1, fail = 0;
58 Note :
59 */
60 char EEP_Write(char addr, char d)
61 {
62 1 GEN_START(); // Generate "START BIT PATTERN" and inform starting of i2C into AT24C02.
63 1 WriteByte(DEVICE_WR); // Write device's address defined by AT24C02
64 1 if( WAIT_ACK()!=ACK ) // if AT24C02 receive DEVICE_WR or not correctly, wait for ACK
65 1 return 0;
66 1
67 1 WriteByte(addr); // Inform address to write to AT24C02
68 1 if( WAIT_ACK()!= ACK ) // wait for ACK
69 1 return 0;
70 1
71 1 WriteByte(d); // write Data
72 1
73 1 if( WAIT_ACK()!= ACK ) // wait for ACK
74 1 return 0;
75 1 GEN_STOP(); // Send "STOP BIT Pattern" to AT24C02, Informa the end of I2C.
76 1 Delay(10);
77 1 return 1;
78 1 }
79
80 /*
81 Description : Write len-sized data string into appropriate address(addr)
82 Argument : addr - address to write into AT24C02(INPUT)
83 d - starting address of data string's to write(INPUT)
84 len - length of data string's to write(INPUT)
85 Return Value : success = 1, fail = 0;
86 Note :
87 */
88 char EEP_WriteBytes(char addr, char* d,int len)
89 {
90 1 int i;
91 1 for(i = 0; i < len ; i++) // Log per 1 Byte
92 1 if(EEP_Write(addr+i,d[i])==0) return 0;
93 1 return 1;
94 1 }
95
96 /*
97 Description :Read from AT24C02 of appropriate address(addr) and Return into 'd' value.
98 Argument : addr - address to be read from AT24C02(INPUT)
99 d - variable to store value to be read (OUTPUT)
100 IsContinue - to read sequentially, send ACK instead of NACK. Flag's value:ACK-->ACK, NACK-->NACK (INPUT)
101 Return Value : success = 1, fail = 0;
102 Note :
103 */
104 char EEP_Read(char addr, char* d,char IsContinue)
105 {
106 1 GEN_START();
107 1 WriteByte(DEVICE_WR); // Write device's address defined by AT24C02 to write
108 1 if( WAIT_ACK()!= ACK )
109 1 return 0;
110 1 WriteByte(addr); // Inform address to write to AT24C02 actually
111 1 if( WAIT_ACK()!= ACK )
112 1 return 0;
113 1 GEN_START(); // Inform starting of Read
114 1 WriteByte(DEVICE_RD); // Write device's address defined by AT24C02 to read
115 1 if( WAIT_ACK()!= ACK )
C51 COMPILER V8.02 AT24C02 10/17/2006 16:52:42 PAGE 3
116 1 return 0;
117 1 *d = ReadByte();
118 1 if(IsContinue == NACK )
119 1 {
120 2 if(WAIT_ACK()!=NACK) return 0;
121 2 GEN_STOP(); // If it's read just 1Byte,inform all operations are finished.
122 2 }
123 1 else // If it's read continuously, do without STOP
124 1 SEND_ACK(IsContinue); // If it's read continuously, then ACK.Else if just 1Byte, then NACK.
125 1 return 1;
126 1 }
127
128 /*
129 Description : Read each 'len' length from AT24C02 of appropriate address(addr) and Write into 'd' and R
-eturn
130 Argument : addr - Address to be read from AT24C02(INPUT)
131 d - starting address variable to be stored data string's value to be Read(INPUT)
132 len - data string's length to Read(INPUT)
133 Return Value : success = 1, fail = 0;
134 Note : It's implemented according to Datasheet,but can't be read in sequential.So read each 1 Byt
-e repeatedly.
135 */
136 char EEP_ReadBytes(char addr, char* d, int len)
137 {
138 1 char c;
139 1 int i ;
140 1
141 1 for(i = 0 ; i < len ; i++) // Read each 1 byte and store into 'd' sequentially.
142 1 {
143 2 if(EEP_Read(addr+i,&c,NACK)==0)
144 2 return 0;
145 2 d[i] = c;
146 2 }
147 1 /*
148 1 if(!EEP_Read(addr,&c,ACK)) return 0; // 1Byte绰 Read 1Byte according to I2C Spec(ACK instead of NACK,
-Read 1 Byte without STOP)
149 1 d[0] = c;
150 1 for(i = 1 ; i < len ; i++) // Read 1 Byte through I2C continuously and wait for ACK
151 1 {
152 1 d[i] = ReadByte();
153 1 PutHTOA(d[i]);PutStringLn("");
154 1 if(i == len -1 ) // If read last Byte, don't wait for ACK and send NACK
155 1 {
156 1 if(WAIT_ACK()!=NACK) return 0;
157 1 }
158 1 else SEND_ACK(ACK);
159 1 }
160 1 GEN_STOP(); // All operations are finished.
161 1 */
162 1 return 1;
163 1 }
164
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 399 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 25
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
C51 COMPILER V8.02 AT24C02 10/17/2006 16:52:42 PAGE 4
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -