1. Overview
24LC65 is a serial E2PROM chip with a large capacity at present, with a storage capacity of 8kB, small size, low power consumption, and power-off protection. The AT89C52 microcontroller also has an 8kB internal ROM, and also has the characteristics of low power consumption and strong control function. The microcontroller system composed of the two has low hardware overhead, data can be transmitted serially, and has low power consumption, which is very practical. However, it is more troublesome to write and read programs for 24LC65. This article will introduce the programming method and introduce the application programming of writing and reading 24LC65 that has been passed using the subroutine structure.
2. Connection between 24LC65 and microcontroller
2.1 Pin functions of 24LC65
24LC65 uses an 8-pin DIP package, and the pin functions are as follows:
Pins 1 to 3 (A0, A1, A2) are three-bit address input terminals;
Pin 4 GND is the ground terminal;
Pin 5 SDA is the binary data input and output terminal;
Pin 6 SCL is the clock input terminal;
Pin 7 NC is floating;
Pin 8 VCC is the 5V positive power supply.
2.2 Connection between 24LC65 and microcontroller
The connection circuit is shown in Figure 1. There are 8 24LC65 chips in total. The three-bit address A2, A1, and A0 of the chip are connected into 8 configurations. A2, A1, and A0 are arranged to form 8 chip select addresses. Therefore, up to 8 chips can be selected on two lines, and 64kB storage space can be addressed. Each chip addresses 8kB. Among them, the address range of chip 1 is 0000H~1FFFH, and the address range of chip 8 is E000H~FFFFH. SDA is the serial data input and output line, and SCL is the clock input terminal. Before each access to 24LC65, the I2C data bus operation must be started, and each time the access ends, the I2C data bus operation must also be stopped. The operation timing is determined by the relationship between SCL and SDA. As shown in Figure 2, it can be seen that when SCL is high, the I2C bus is started when SDA changes from high to low, and the bus operation is stopped when SDA changes from low to high. If the bus is started for a read operation, 1 bit of data is read out on the falling edge of the SCL pulse. If a write operation is started, 1 bit of data is written on the rising edge of the SCL pulse.
3. Data Format
The data format for each write operation of E2PROM 24LC65 is composed of 4 bytes. The first byte is:
1 |
0 |
1 |
0 |
A2 |
A1 |
A0 |
R/W |
Among them, A2, A1, and A0 are address bits, R/W is the read-write bit, R/W=1, read E2PROM operation; R/W=0, write E2PROM operation.
The second byte is:
X |
X |
X |
A12 |
A11 |
A10 |
A9 |
A8 |
Among them, × is arbitrary, A12, A11, A10, A9, A8 are the high 5 bits of the address of E2PROM 24LC65.
The third byte is the lower 8-bit address A7~A0 of E2PROM 24LC65. The fourth byte is the 8-bit data. Note that each byte is followed by an ACK signal.
4. Write 24LC65 program
The key is to use the instructions of MCS-51 microcontroller to write a subroutine to 24LC65. The main program can be called four times in a row to achieve the purpose of writing a byte of data to 24LC65. Assume that the byte addresses of the bytes to be written in the microcontroller are 6FH, 6EH, ..., 68H, and are stored in the D7, D6, ..., D0 bits of the bytes to be written, respectively, as the entry parameters for calling the subroutine to write a byte. Start by the main program and stop the bus. The programs are as follows:
; The main program starts and stops the bus
SETB P3.1 ; SCL=1
SETB P3.0 ; SDA=1
CLR P3.0 ; SDA=0, start the bus
┊
┊
CLR P3.0
SETB P3.1
SETB P3.0 ; Stop bus operation
; Subroutine to write one byte
MOV C, 6FH ; D7 bit is sent to carry C
CLR P3.1
MOV P3.0, C
SETB P3.1 ; Write D7 bit
CLR P3.1
MOV C, 6EH ; D6 bit is sent to carry C
MOV P3.0, C
SETB P3.1 ; Write D6 bit
CLR P3.1
MOV C, 6DH ; D5 bit is sent to carry C
MOV P3.0, C
SETB P3.1 ; Write D5 bit
CLR P3.1
MOV C, 6CH
MOV P3.0, C
SETB P3.1 ; Write D4 bit
CLR P3.1
MOV C, 6BH
MOV P3.0, C
SETB P3.1
; Write D3
bit
CLR
P3.1
MOV C, 6AH
MOV
P3.0, C
SETB
P3.1 ; Write D2 bit
CLR P3.1 MOV C, 69H MOV P3.0, C
SETB P3.1 ; Write D1 bit
CLR P3.1
MOV C, 68H
MOV P3.0, C
SETB P3.1 ; Write D0 bit
CLR P3.1
NOP
SETB P3.1 ; Write one byte end
CLR P3.1 ; ACK
RET
5. Read 24LC65 program
The program for reading 24LC65 includes both write control word and write address operations, as well as read data operations. The write control word and write address operations are the same as the program for writing 24LC65, that is, the first three bytes are the same, except that the bus operation must be stopped after the third byte. The fourth byte restarts the bus and sends the read command. Only the fifth byte is the operation for reading 24LC65. The program for reading 24LC65 is as follows:
MOV R7, #08H
READ: SETB P3.1; read a byte in A
CLR P3.1; shift out a bit
MOV C, P3.0; shift out a bit and pass it to carry C
RLC A
DJNZ R7, READ
SETB P3.1
CLR P3.1; ACK
CLR P3.0
SETB P3.1
SETB P3.0; stop the bus
RET
. The program runs reliably and is highly practical in actual use. If you want to increase the storage capacity, you can select two more I/O lines of the microcontroller and connect eight 24LC65 chips to form another 64kB serial E2PROM.
Previous article:Design and implementation of electronic price-computing scale based on AT89C51 single-chip microcomputer
Next article:Using AT89C2051 to remotely control household appliances
Recommended ReadingLatest update time:2024-11-16 19:42
- Popular Resources
- Popular amplifiers
- Teach you to learn 51 single chip microcomputer-C language version (Second Edition) (Song Xuefeng)
- EDA Technology Practical Tutorial--Verilog HDL Edition (Sixth Edition) (Pan Song, Huang Jiye)
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
- An easy introduction to electronic technology learning methods and analytical thinking (Hu Bin)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- MSP430 FRAM Technology – How-tos and Best Practices
- ESP32-CAM Video Surveillance Robot
- Ask the Experts | Confused about DC-DC selection? MPS can help you solve it!
- A comprehensive analysis of dipole antennas
- MicroPython Hands-on (29) - SIoT of the Internet of Things
- Here the role of the voltage regulator + diode combination
- Bluetooth bracelet master control selection
- A small bug in mpy on ESP32/ESP8266
- 【XMC4800 Relax EtherCAT Kit Review】+ Getting Started with DAVE, PWM Module Application
- Explain the circuit diagram, thanks