📄 24c02.lst
字号:
C51 COMPILER V7.20 24C02 11/01/2005 23:35:39 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE 24C02
OBJECT MODULE PLACED IN 24c02.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 24c02.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <reg51.h>
2 #include <absacc.h>
3 #include "INTRINS.H"
4 #define uchar unsigned char
5 /***************************************************************************/
6 #define WriteDeviceAddress 0xa0 /*24c02的写地址*/
7 #define ReadDviceAddress 0xa1 /*24c02的读地址*/
8 /***************************************************************************/
9 sbit P1_5=P1^5;
10 sbit P1_4=P1^4;
11 sbit SDA =P2^5;
12 sbit SCL =P2^6;
13 sbit P2_7=P2^7;
14 sbit P3_5=P3^5;
15 sbit P3_4=P3^4;
16 unsigned char code table[1]={0x01};
17 unsigned char code table2[1]={0x02};
18 unsigned char table1[1];
19 /*********************延时程序*******************************************/
20 void DelayMs(unsigned int number)
21 { unsigned char temp;
22 1 for(;number!=0;number--)
23 1 {
24 2 for(temp=112;temp!=0;temp--);
25 2 }
26 1 }
27
28 /***************************************************************************
29 ***************************24c02开始程序************************************
30 ***************************************************************************/
31 void Start()
32 {
33 1 SDA=1;
34 1 SCL=1;
35 1 SDA=0;
36 1 SCL=0;
37 1 }
38 /***************************************************************************
39 ***************************24c02停止程序************************************
40 ***************************************************************************/
41 void Stop()
42 {
43 1 SCL=0;
44 1 SDA=0;
45 1 SCL=1;
46 1 SDA=1;
47 1 }
48
49 /***************************************************************************/
50 void Ack()
51 {
52 1 SDA=0;
53 1 SCL=1;
54 1 SCL=0;
55 1 SDA=1;
C51 COMPILER V7.20 24C02 11/01/2005 23:35:39 PAGE 2
56 1 }
57
58 /***************************************************************************/
59 void NoAck()
60 {
61 1 SDA=1;
62 1 SCL=1;
63 1 SCL=0;
64 1 }
65 /***************************************************************************
66 *返回错误标志,ErrorBit=SDA,为1错误,0正确*********************************
67 ***************************************************************************/
68 bit TestAck()
69 {
70 1 bit ErrorBit;
71 1 SDA=1;
72 1 SCL=1;
73 1 ErrorBit=SDA;
74 1 SCL=0;
75 1 return(ErrorBit);
76 1 }
77 /***************************************************************************
78 ***************************24c02写一个字节程序******************************
79 ***************************************************************************/
80 void Write8Bit(unsigned char input)
81 {
82 1 unsigned char temp;
83 1 for(temp=8;temp!=0;temp--)
84 1 {
85 2 SDA=(bit)(input&0x80);/*从高位依次取input的各位*/
86 2 SCL=1;
87 2 SCL=0;
88 2 input=input<<1; /*相等与RLC,取了CY位*/
89 2 }
90 1 }
91 /***************************************************************************
92 ***************************24c02写程序**************************************
93 ***************************************************************************/
94 void Write24c02(unsigned char *Wdata,unsigned char RomAddress,unsigned char number)
95 {
96 1 Start();/*IIC开始*/
97 1 Write8Bit(WriteDeviceAddress);/*写入器件地址0xa0*/
98 1 TestAck();/*测试ACK位*/
99 1 Write8Bit(RomAddress);/*写入器件控制单元地址*/
100 1 TestAck();/*测试ACK位*/
101 1 for(;number!=0;number--)
102 1 {
103 2 Write8Bit(*Wdata);
104 2 TestAck();
105 2 Wdata++;
106 2 }
107 1 Stop();/*IIC停止*/
108 1 DelayMs(10);/*延长10MS,保证数据写入*/
109 1 }
110 /***************************************************************************
111 ***************************24c02读一个字节程序******************************
112 ***************************************************************************/
113 unsigned char Read8Bit()
114 {
115 1 unsigned char temp,rbyte=0;
116 1 for(temp=8;temp!=0;temp--)
117 1 {
C51 COMPILER V7.20 24C02 11/01/2005 23:35:39 PAGE 3
118 2 SCL=1;
119 2 rbyte=rbyte<<1;
120 2 rbyte=rbyte|((unsigned char)(SDA));
121 2 SCL=0;
122 2 }
123 1 return(rbyte); /*把数据返回*/
124 1 }
125 /***************************************************************************
126 ***************************24c02读程序**************************************
127 ***************************************************************************/
128 void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes)
129 {
130 1 Start(); /*IIC开始*/
131 1 Write8Bit(WriteDeviceAddress);/*写入器件地址0xa0*/
132 1 TestAck();/*测试ACK位*/
133 1 Write8Bit(RomAddress);/*写入器件控制单元地址*/
134 1 TestAck();/*测试ACK位*/
135 1 Start();/*IIC再次发送开始*/
136 1 Write8Bit(ReadDviceAddress);
137 1 TestAck();/*测试ACK位*/
138 1 while(bytes!=1)
139 1 {
140 2 *RamAddress=Read8Bit();/*存一个读到的数据到RamAddress+I*/
141 2 Ack();/*发送IIC再读*/
142 2 RamAddress++;/*存取地址加一*/
143 2 bytes--;
144 2 }
145 1 *RamAddress=Read8Bit();
146 1 NoAck();/*发送IIC停止读*/
147 1 Stop();/*IIC停止*/
148 1 }
149 /***************************************************************************/
150 chushihua()
151 {
152 1 P0=0xff;
153 1 P1=0xff;
154 1 P2=0xff;
155 1 P3=0xff;
156 1 P2_7=0;
157 1 }
158 /*申明:你自己看懂以后自己写,我给你的是最简单的程序,就是上电根据最后的状态,在运行中根据你的按键来说明问
-题*/
159 main()
160 {
161 1 chushihua();/*初始化程序*/
162 1 Read24c02(table1,0x10,0x01);
163 1 if(table1[0]==0x01) {P1_4=0;P1_5=1;}
164 1 else {P1_4=1;P1_5=0;}
165 1 /*以上第一次上电的时候检查,对应的 LED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -