;Program description: Write the contents of 55h~58h inside the MPU to 24c02 via the I2C bus from external interrupt 0, and then read the written contents to
STOP:CLR SCL
CLR SDA
ACALL DELAY
SETB SCL
ACALL DELAY
SETB SDA
ACALL DELAY
RIGHT
REV: MOV R0,#08H
REV0: SETB SCL
LCALL DELAY
MOV C,SDA
RLC A
CLR SCL
LCALL DELAY
DJNZ R0,REV0
RIGHT
ACKO:
CLR SDA
ACALL DELAY
SETB SCL
ACALL DELAY
CLR SCL
ACALL DELAY
SETB SDA
ACALL DELAY
RIGHT
;Send a non-receive receive acknowledge bit
ACKN:
SETB SDA
ACALL DELAY
SETB SCL
ACALL DELAY
CLR SCL
ACALL DELAY
Reference address:51 MCU drives I2C (24C02) assembly language program
;MPU internal data memory 60H~~63H
SCL EQU P1.1
SDA EQU P1.0
org 0000h
jmp begin
org 0003H
ljmp write
org 0013H
ljmp read
;Main program
begin:
mov 55H,#41H
mov 56h,#42h
MOV 57h,#43H
MOV 58H, #44H
mov tcon,#0
setb ex0
setb ex1
setb of
main:
nop
jmp main
;**********************************************************
;Program to read 24C02 data
read:
ACALL START ; start signal
MOV A,#0A0H ; send the slave address
ACALL SEND ;Send control word
ACALL ACKI; receive response
JC OUTEND ; No response, transfer to end
MOV A,#00H; Set the internal address of the slave device to be read
ACALL SEND
ACALL ACKI
JC OUTEND
ACALL START ; start signal
ORL A,#0A1H; Set the control word and prepare to receive
ACALL SEND ;Send control word
ACALL ACKI
JC OUTEND
MOV R2,#4 ; Prepare to receive the number of bytes of data
MOV R1,#60H ; The received byte is stored at address 60H in the master device
IN0:
ACALL REV ; receive a byte
ACALL ACKO; the host sends a response signal to 24C02
MOV @R1,A ; store the received data in the storage unit
INC R1
DEC R2
CJNE R2,#1,IN0 ; Determine whether it is the last received byte
ACALL REV ;Receive the last byte
ACALL ACKN;
MOV @R1,A ; store the received data in the storage unit
OUTEND:
ACALL STOP ;Stop signal
jnb p3.3,$
rarely
;**********************************************************
;Program to write 24C02 data
write:
LCALL START ; start signal
MOV A,#0A0H; set control word, ready to send
ACALL SEND ;Send control word
ACALL ACKI ;Receive acknowledgment
JC WRITEEND ; The slave device does not respond, and the transfer ends
MOV A,#00H ; Set the internal address of the slave device
ACALL SEND ;Send the internal address
ACALL ACKI
JC WRITEEND
MOV R2,#4; Set the number of bytes to send
MOV R1,#55H ;Header address of data to be sent in the master device
OUT1:
MOV A,@R1
ACALL SEND; send data
ACALL ACKI;
JC WRITEEND
INC R1
DJNZ R2,OUT1 ;Sending is not finished, continue sending
WRITEEND:
ACALL STOP ;Stop signal
jnb p3.2,$; prevent further interruption
rarely
;********************************************************
;********************
;I2C simulation program
; Start signal
START:
CLR SCL
SETB SDA
ACALL DELAY
SETB SCL
ACALL DELAY
CLR SDA
ACALL DELAY
CLR SCL
RIGHT
; Stop signal:
; Receive a byte
; Send a byte
SEND:
MOV R0, #08H
CLR SCL
SEND0:
RLC A
MOV SDA,C
SETB SCL
ACALL DELAY
CLR SCL
DJNZ R0,SEND0
SETB SDA
RIGHT
; Receive an acknowledge bit:
AKI:
SETB SCL
ACALL DELAY
MOV C,SDA
CLR SCL
RIGHT
; Send a receive acknowledge bit
DELAY:
NOP
NOP
NOP
RIGHT
END
Previous article:LCD1602 LCD screen password lock assembly program for 51 single chip microcomputer
Next article:51 MCU serial port test C language program
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Guess you like
- Why is there no CUBEMX project in the STM32L0 official HAL library routine?
- Measurement of radar power, spectrum and related parameters
- [ESP32-Audio-Kit Audio Development Board Review]——(2): Questions about play_mp3_control
- Is it popular to reduce the size of laptop keyboards now?
- (Bonus 5) GD32L233 Review - CRC (with the clearest article explaining CRC in history)
- Recruiting MCU development engineers (workplace: Beijing, Wuhan)
- ST FOC electrical angle problem
- Altium Designer software is abnormal, please solve it! ! !
- Unboxing
- 5G frequency band division among the three major operators