📄 eeprom.lst
字号:
C51 COMPILER V7.50 EEPROM 06/20/2008 15:40:18 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE EEPROM
OBJECT MODULE PLACED IN .\Obj\eeprom.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE App\eeprom.c BROWSE DEBUG OBJECTEXTEND PRINT(.\List\eeprom.lst) OBJECT(.\Ob
-j\eeprom.obj)
line level source
1 #include ".\head\intrins.h"
2 #include ".\head\CPU081.h"
3 #include ".\head\define.h"
4 #include ".\head\global.h"
5
6 /*-----------------------------------------------------------------------------------------
7 *
8 * I2C_eeprom driver for 24c01/02/04/08/16
9 * ------------------------------------
10 *
11 *capbility:
12 * - support write serial bytes from MCU ram to eeprom
13 * - support read serial bytes from eeprom to MCU ram
14 * - support write/read serial bytes in one block
15 *
16 *24C02 1block * 32page rows * 4bytes * 8 bit = 128bytes = 1kbits
17 *24C02 1block * 32page rows * 8bytes * 8 bit = 256bytes = 2kbits
18 *24C04 2block * 16page rows * 16bytes * 8 bit = 512bytes = 4kbits
19 *24C08 4block * 16page rows * 16bytes * 8 bit = 1024bytes = 8kbits
20 *24C16 8block * 16page rows * 16bytes * 8 bit = 2048bytes = 16kbits
21 *
22 *----------------------------------------------------------------------------------------*/
23
24 //communication config
25 #define I2CFAILTIMES 30 //*** communication retry times
26
27 //IO_Port config
28 #define SDA_PINCR P1CR //*** select SDA pin IO port
29 #define SDA_PULL P1PCR //***
30 #define SDA_PIN P1_1 //***
31 #define SDA Bin(00000010); //***
32
33 #define SCL_PINCR P1CR //*** select SCL pin IO port
34 #define SCL_PULL P1PCR //***
35 #define SCL_PIN P1_0 //***
36 #define SCL Bin(00000001); //***
37
38 //EEPROM Type config
39
40 #define EEPROM_24C01 0
41 #define EEPROM_24C02 1
42 #define EEPROM_24C04 2
43 #define EEPROM_24C08 3
44 #define EEPROM_24C16 4
45 #define EEPROM_TYPE EEPROM_24C02 //*** select eeprom type
46 #if (EEPROM_TYPE == EEPROM_24C01)
#define PAGE_OVER_ROLL Bin(00000011) //every page contain 4bytes
#elif (EEPROM_TYPE == EEPROM_24C02)
49 #define PAGE_OVER_ROLL Bin(00000111) //every page contain 8bytes
50 #elif (EEPROM_TYPE == EEPROM_24C04)
#define PAGE_OVER_ROLL Bin(00001111) //every page contain 16bytes
#elif (EEPROM_TYPE == EEPROM_24C08)
#define PAGE_OVER_ROLL Bin(00001111) //every page contain 16bytes
#elif (EEPROM_TYPE == EEPROM_24C16)
C51 COMPILER V7.50 EEPROM 06/20/2008 15:40:18 PAGE 2
#define PAGE_OVER_ROLL Bin(00001111) //every page contain 16bytes
#else
#define PAGE_OVER_ROLL Bin(00000111) //every page contain 8bytes
#endif
59
60 /*------------------------------------------------------------------------------------------
61 ; IICDelay
62 ;*** TBD: delay 4us
63 ;notice: user may need to modify here
64 ;-----------------------------------------------------------------------------------------*/
65 void IICDelay(void)
66 {
67 1 //delay 20*0.125=2us
68 1 //+7 LCALL
69 1 _nop_(); //+1 nop
70 1 _nop_(); //+1 nop
71 1 _nop_(); //+1 nop
72 1 _nop_(); //+1 nop
73 1 _nop_(); //+1 nop
74 1 //+8 RET
75 1 }
76 /*------------------------------------------------------------------------------------------
77 ; IICDelayStop
78 ;*** TBD: delay about 10ms on 8M oscillator
79 ;notice: user may need to modify here
80 ;-----------------------------------------------------------------------------------------*/
81 void IICDelayStop(void)
82 {
83 1 Byte i,j;
84 1 for(j=4;j>0;j--)
85 1 {
86 2 RSTSTAT = 0x00; //feed watchdog
87 2 for(i=250;i>0;i--)
88 2 {
89 3 }
90 2 }
91 1 }
92 /*------------------------------------------------------------------------------------------
93 ; IICInit
94 ;-----------------------------------------------------------------------------------------*/
95 void IICInit(void)
96 {
97 1 SDA_PINCR |= SDA;
98 1 SDA_PULL |= SDA;
99 1 SDA_PIN = 1;
100 1 SCL_PINCR |= SCL;
101 1 SCL_PULL |= SCL;
102 1 SCL_PIN = 1;
103 1 }
104 /*------------------------------------------------------------------------------------------
105 ; IICStart
106 ;-----------------------------------------------------------------------------------------*/
107 void IICStart(void)
108 {
109 1 SDA_PINCR |= SDA;
110 1 SDA_PIN=1;
111 1 SCL_PINCR |= SCL;
112 1 SCL_PIN=1;
113 1 IICDelay();
114 1 SDA_PIN=0; //SDA H->L
115 1 IICDelay();
116 1 SCL_PIN=0; //SCL H->L
C51 COMPILER V7.50 EEPROM 06/20/2008 15:40:18 PAGE 3
117 1 }
118 /*------------------------------------------------------------------------------------------
119 ; IICStop
120 ;-----------------------------------------------------------------------------------------*/
121 void IICStop(void)
122 {
123 1 SDA_PINCR |= SDA;
124 1 SDA_PIN=0;
125 1 SCL_PINCR |= SCL;
126 1 SCL_PIN=0;
127 1 IICDelay();
128 1 SCL_PIN=1; //SCL L->H
129 1 IICDelay();
130 1 SDA_PIN=1; //SDA L->H
131 1 IICDelay();
132 1 SDA_PINCR &= ~SDA; //standby
133 1 SCL_PINCR &= ~SCL;
134 1 SDA_PULL |= SDA;
135 1 SCL_PULL |= SCL;
136 1 }
137 /*------------------------------------------------------------------------------------------
138 ; IICReadByte
139 ;return one byte and tell the slave whether to read the apprend bytes by zI2CCounter
140 ;-----------------------------------------------------------------------------------------*/
141 Byte IICReadByte(Byte zI2CCounter)
142 {
143 1 Byte zI2CByteData;
144 1 Byte zI2CBit;
145 1
146 1 SCL_PINCR |= SCL; //SCL output
147 1 SDA_PIN = 1;
148 1 SDA_PINCR &= ~SDA; //SDA input to read bit 1~8 from slave
149 1 for( zI2CBit = 8;zI2CBit >0;zI2CBit--)
150 1 {
151 2 SCL_PIN = 1;
152 2 zI2CByteData *=2;
153 2 if( SDA_PIN )
154 2 {
155 3 zI2CByteData |= Bin(00000001);
156 3 }
157 2 SCL_PIN = 0;
158 2 }
159 1 SDA_PINCR |= SDA; //SDA output to write apprend bit to slave
160 1 if(zI2CCounter == 0 )
161 1 {
162 2 SDA_PIN = 1;
163 2 }
164 1 else
165 1 {
166 2 SDA_PIN = 0;
167 2 }
168 1 IICDelay();
169 1 SCL_PIN = 1;
170 1 IICDelay();
171 1 SCL_PIN = 0;
172 1 IICDelay();
173 1 return zI2CByteData;
174 1 }
175 /*------------------------------------------------------------------------------------------
176 ; IICWriteByte
177 ;write one byte,return 1 if success,return 0 if failure
178 ;-----------------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -