📄 24c02.lst
字号:
C51 COMPILER V7.01 24C02 10/19/2002 17:21:43 PAGE 1
C51 COMPILER V7.01, COMPILATION OF MODULE 24C02
OBJECT MODULE PLACED IN 24c02.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE 24c02.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <AT89X52.H>
2 // 对24C02的读、写
3 // extern void DelayMs(unsigned int);
4 // extern void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes);
5 // extern void Write24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes);
6
7 /***************************************************************************/
8 #define WriteDeviceAddress 0xa0
9 #define ReadDviceAddress 0xa1
10 //unsigned char WriteDeviceAddress=0xa0;
11 //unsigned char ReadDviceAddress=0xa1;
12 /***************************************************************************/
13 sbit SCL=P1^1;
14 sbit SDA=P1^0;
15 /***************************************************************************/
16 void DelayMs(unsigned int number) {
17 1 unsigned char temp;
18 1 for(;number!=0;number--)
19 1 {
20 2 for(temp=224;temp!=0;temp--) {
21 3 }
22 2 }
23 1 }
24
25 /***************************************************************************/
26 void Start() {
27 1 SDA=1;
28 1 SCL=1;
29 1 SDA=0;
30 1 SCL=0;
31 1 }
32
33 /***************************************************************************/
34 void Stop() {
35 1 SCL=0;
36 1 SDA=0;
37 1 SCL=1;
38 1 SDA=1;
39 1 }
40
41 /***************************************************************************/
42 void Ack() {
43 1 SDA=0;
44 1 SCL=1;
45 1 SCL=0;
46 1 SDA=1;
47 1 }
48
49 /***************************************************************************/
50 void NoAck() {
51 1 SDA=1;
52 1 SCL=1;
53 1 SCL=0;
54 1 }
55
C51 COMPILER V7.01 24C02 10/19/2002 17:21:43 PAGE 2
56 /***************************************************************************/
57 bit TestAck() {
58 1 bit ErrorBit;
59 1 SDA=1;
60 1 SCL=1;
61 1 ErrorBit=SDA;
62 1 SCL=0;
63 1 return(ErrorBit);
64 1 }
65
66 /***************************************************************************/
67 void Write8Bit(unsigned char input) {
68 1 unsigned char temp;
69 1 for(temp=8;temp!=0;temp--) {
70 2 SDA=(bit)(input&0x80);
71 2 SCL=1;
72 2 SCL=0;
73 2 input=input<<1;
74 2 }
75 1 }
76
77 /***************************************************************************/
78 void Write24c02(unsigned char *Wdata,unsigned char RomAddress,unsigned char number) {
79 1 Start();
80 1 Write8Bit(WriteDeviceAddress);
81 1 TestAck();
82 1 Write8Bit(RomAddress);
83 1 TestAck();
84 1 for(;number!=0;number--) {
85 2 Write8Bit(*Wdata);
86 2 TestAck();
87 2 Wdata++;
88 2 }
89 1 Stop();
90 1 DelayMs(10);
91 1 }
92
93 /***************************************************************************/
94 unsigned char Read8Bit() {
95 1 unsigned char temp,rbyte=0;
96 1 for(temp=8;temp!=0;temp--) {
97 2 SCL=1;
98 2 rbyte=rbyte<<1;
99 2 rbyte=rbyte|((unsigned char)(SDA));
100 2 SCL=0;
101 2 }
102 1 return(rbyte);
103 1 }
104
105 /***************************************************************************/
106 void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes)
107 {
108 1 //unsigned char temp,rbyte;
109 1 Start();
110 1 Write8Bit(WriteDeviceAddress);
111 1 TestAck();
112 1 Write8Bit(RomAddress);
113 1 TestAck();
114 1 Start();
115 1 Write8Bit(ReadDviceAddress);
116 1 TestAck();
117 1 while(bytes!=1) {
C51 COMPILER V7.01 24C02 10/19/2002 17:21:43 PAGE 3
118 2 *RamAddress=Read8Bit();
119 2 Ack();
120 2 RamAddress++;
121 2 bytes--;
122 2 }
123 1 *RamAddress=Read8Bit();
124 1 NoAck();
125 1 Stop();
126 1 }
127
128 /***************************************************************************/
129 void main(void)
130 {
131 1 unsigned int ee_data=0xAA55;
132 1 unsigned char i=0;
133 1 DelayMs(1000);
134 1 Write24c02((unsigned char *)&ee_data,0x10,2);
135 1 DelayMs(1000);
136 1 Read24c02((unsigned char *)&ee_data,0x10,2);
137 1 if(ee_data==0xaa55)
138 1 {
139 2 P0=(unsigned char)ee_data;
140 2 DelayMs(1000);
141 2 P0=(unsigned char)(ee_data>>8);
142 2 DelayMs(1000);
143 2 while(1)
144 2 {
145 3 P0=~(1<<i);
146 3 DelayMs(1000);
147 3 if(i<7)
148 3 i++;
149 3 else
150 3 i=0;
151 3 }
152 2 }
153 1 else
154 1 {
155 2 P0=0x3c;
156 2 while(1)
157 2 ;
158 2 }
159 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 319 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 12
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -