📄 24c02.lst
字号:
C51 COMPILER V6.21 24C02 03/08/2002 13:07:32 PAGE 1
C51 COMPILER V6.21, COMPILATION OF MODULE 24C02
OBJECT MODULE PLACED IN 24c02.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE 24c02.c LARGE OPTIMIZE(SIZE) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <reg52.h>
2 #include <intrins.h>
3 // 对24C02的读、写
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 /***************for 24c02************************************************************/
8 #define WriteDeviceAddress 0xa0
9 #define ReadDviceAddress 0xa1
10 #define NOP5() _nop_();_nop_();_nop_();_nop_();_nop_()
11 /***************************************************************************/
12 sbit SCL=P1^6;
13 sbit SDA=P1^7;
14 /***************************************************************************/
15 void delay_ms(unsigned char number);
16 /***************************************************************************/
17 void Start() {
18 1 SDA=1;
19 1 NOP5();
20 1 SCL=1;
21 1 NOP5();
22 1 SDA=0;
23 1 NOP5();
24 1 SCL=0;
25 1 NOP5();
26 1 }
27
28 /***************************************************************************/
29 void Stop() {
30 1 SDA=0;
31 1 NOP5();
32 1 SCL=1;
33 1 NOP5();
34 1 SDA=1;
35 1 NOP5();
36 1 SCL=0;
37 1 NOP5();
38 1 }
39
40 /***************************************************************************/
41 void Ack() {
42 1 SDA=0;
43 1 NOP5();
44 1 SCL=1;
45 1 NOP5();
46 1 SCL=0;
47 1 NOP5();
48 1 SDA=1;
49 1 }
50
51 /***************************************************************************/
52 void NoAck()
53 {
54 1 SDA=1;
55 1 NOP5();
C51 COMPILER V6.21 24C02 03/08/2002 13:07:32 PAGE 2
56 1 SCL=1;
57 1 NOP5();
58 1 SCL=0;
59 1 NOP5();
60 1 }
61
62 /***************************************************************************/
63 bit TestAck(void) {
64 1 bit ErrorBit;
65 1 SDA=1;
66 1 NOP5();
67 1 SCL=1;
68 1 NOP5();
69 1 ErrorBit=SDA;
70 1 NOP5();
71 1 SCL=0;
72 1 return(ErrorBit);
73 1 }
74
75 /***************************************************************************/
76 void Write8Bit(unsigned char input) {
77 1 unsigned char temp;
78 1 for(temp=8;temp!=0;temp--) {
79 2 SDA=(bit)(input&0x80);
80 2 NOP5();
81 2 SCL=1;
82 2 NOP5();
83 2 SCL=0;
84 2 NOP5();
85 2 input=input<<1;
86 2 }
87 1 }
88
89 /***************************************************************************/
90
91 void write24c02(unsigned char *Wdata,unsigned char RomAddress,unsigned char number) {
92 1 Start();
93 1 Write8Bit(WriteDeviceAddress);
94 1 TestAck();
95 1 Write8Bit(RomAddress);
96 1 TestAck();
97 1 for(;number!=0;number--) {
98 2 Write8Bit(*Wdata);
99 2 TestAck();
100 2 Wdata++;
101 2 }
102 1 Stop();
103 1 delay_ms(10);
104 1 }
105
106 /***************************************************************************/
107 unsigned char Read8Bit() {
108 1 unsigned char temp,rbyte=0;
109 1 for(temp=8;temp!=0;temp--) {
110 2 SCL=1;
111 2 rbyte=rbyte<<1;
112 2 rbyte=rbyte|((unsigned char)(SDA));
113 2 SCL=0;
114 2 }
115 1 return(rbyte);
116 1 }
117
C51 COMPILER V6.21 24C02 03/08/2002 13:07:32 PAGE 3
118 /***************************************************************************/
119 void read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes) {
120 1 Start();
121 1 Write8Bit(WriteDeviceAddress);
122 1 TestAck();
123 1 Write8Bit(RomAddress);
124 1 TestAck();
125 1 Start();
126 1 Write8Bit(ReadDviceAddress);
127 1 TestAck();
128 1 while(bytes!=1) {
129 2 *RamAddress=Read8Bit();
130 2 Ack();
131 2 RamAddress++;
132 2 bytes--;
133 2 }
134 1 *RamAddress=Read8Bit();
135 1 NoAck();
136 1 Stop();
137 1 }
138
139 /***************************************************************************/
140
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 311 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 10
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
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 + -