📄 iic.lst
字号:
C51 COMPILER V7.06 IIC 12/01/2006 20:12:25 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE IIC
OBJECT MODULE PLACED IN IIC.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE IIC.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1
2 #include <reg51.h>
3
4 //unsigned char code tab[22]={0x0bf,0x86,0x0db,0x0cf,0x0e6,0x0ed,0x0fd,0x087,0x0ff,0x0e7,0x0f7,0x0fc,0x0b9
-,0x0de,0x0f9,0x0f1};
5 //unsigned char code tab[22]={0x0bf,0x86,0x0db,0x0cf,0x0e6,0x0ed,0x0fd,0x087,0x0ff,0x0e7,0x0f7,0x0fc,0x0b9
-,0x0de,0x0f9,0x0f1};
6 unsigned char code tab[10]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6};
7
8 // 对24C04的读、写
9 // extern void DelayMs(unsigned int);
10 // extern void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes);
11 // extern void Write24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes);
12
13 /***************************************************************************/
14 #define WriteDeviceAddress 0xa0
15 #define ReadDviceAddress 0xa1
16
17 /***************************************************************************/
18 //sbit SCL=P1^6;
19 //sbit SDA=P1^7;
20 sbit SCL=P1^3;
21 sbit SDA=P1^4;
22 //sbit DOG=P3^7;
23
24 /***************************************************************************/
25 void DelayMs(unsigned int number) {
26 1 unsigned char temp;
27 1 for(;number!=0;number--/*,DOG=!DOG*/)
28 1 {
29 2 for(temp=112;temp!=0;temp--)
30 2 {
31 3 }
32 2 }
33 1 }
34
35 /***************************************************************************/
36 void Start() {
37 1 SDA=1;
38 1 SCL=1;
39 1 SDA=0;
40 1 SCL=0;
41 1 }
42
43 /***************************************************************************/
44 void Stop() {
45 1 SCL=0;
46 1 SDA=0;
47 1 SCL=1;
48 1 SDA=1;
49 1 }
50
51 /***************************************************************************/
52 void Ack() {
53 1 SDA=0;
C51 COMPILER V7.06 IIC 12/01/2006 20:12:25 PAGE 2
54 1 SCL=1;
55 1 SCL=0;
56 1 SDA=1;
57 1 }
58
59 /***************************************************************************/
60 void NoAck() {
61 1 SDA=1;
62 1 SCL=1;
63 1 SCL=0;
64 1 }
65
66 /***************************************************************************/
67 bit TestAck() {
68 1 bit ErrorBit;
69 1 SDA=1;
70 1 SCL=1;
71 1 ErrorBit=SDA;
72 1 SCL=0;
73 1 return(ErrorBit);
74 1 }
75
76 /***************************************************************************/
77 void Write8Bit(unsigned char input) {
78 1 unsigned char temp;
79 1 for(temp=8;temp!=0;temp--) {
80 2 SDA=(bit)(input&0x80);
81 2 SCL=1;
82 2 SCL=0;
83 2 input=input<<1;
84 2 }
85 1 }
86
87 /***************************************************************************/
88 void Write24c02(unsigned char *Wdata,unsigned char RomAddress,unsigned char number) {
89 1 Start();
90 1 Write8Bit(WriteDeviceAddress);
91 1 TestAck();
92 1 Write8Bit(RomAddress);
93 1 TestAck();
94 1 for(;number!=0;number--) {
95 2 Write8Bit(*Wdata);
96 2 TestAck();
97 2 Wdata++;
98 2 }
99 1 Stop();
100 1 DelayMs(10);
101 1 }
102
103 /***************************************************************************/
104 unsigned char Read8Bit() {
105 1 unsigned char temp,rbyte=0;
106 1 for(temp=8;temp!=0;temp--) {
107 2 SCL=1;
108 2 rbyte=rbyte<<1;
109 2 rbyte=rbyte|((unsigned char)(SDA));
110 2 SCL=0;
111 2 }
112 1 return(rbyte);
113 1 }
114
115 /***************************************************************************/
C51 COMPILER V7.06 IIC 12/01/2006 20:12:25 PAGE 3
116 void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes)
117 {
118 1 //unsigned char temp,rbyte;
119 1 Start();
120 1 Write8Bit(WriteDeviceAddress);
121 1 TestAck();
122 1 Write8Bit(RomAddress);
123 1 TestAck();
124 1 Start();
125 1 Write8Bit(ReadDviceAddress);
126 1 TestAck();
127 1 while(bytes!=1) {
128 2 *RamAddress=Read8Bit();
129 2 Ack();
130 2 RamAddress++;
131 2 bytes--;
132 2 }
133 1 *RamAddress=Read8Bit();
134 1 NoAck();
135 1 Stop();
136 1 }
137
138 /***************************************************************************/
139 //李澄20061118添加
140 void main()
141 {
142 1 unsigned char WrBuff[10];//写十个数据进去
143 1 unsigned char RdBuff[10];
144 1 int i,j;
145 1 for(i=0;i<10;i++)WrBuff[i]=i;
146 1 Write24c02(WrBuff,0x10,10);
147 1 P1=0x01;
148 1 P0=tab[WrBuff[0]];
149 1 for(i=0;i<6000;i++)
150 1 for(j=0;j<100;j++);
151 1 Read24c02(RdBuff,0x10,10);
152 1 P1=0x02;
153 1 P0=tab[RdBuff[1]];
154 1 while(1);
155 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 319 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 30
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 + -