Suitable for PIC series, assembly, memory tight friends
SDA EQU 5 ;'OC'
SCL EQU 4
ACKF EQU 0
EE_VCC EQU 2
EE_WP EQU 1 ;'H' DISABLE 'L'ENABLE
DO EQU 7
TX_BUF EQU 0X30
BUF_IN EQU 0X31
EEPROM EQU 0X32
BIT_COUNT EQU 0X33
byte_count equ 0x34
ACK EQU 0X35
rom_buf1 equ 0x36
rom_buf2 equ 0x37
rom_buf3 equ 0x38
rom_buf4 equ 0x39
rom_buf5 equ 0x3a
;**********************Start signal****************************************
BSTART:
BSF PORTA,SDA
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,SDA
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,SCL
NOP
NOP
RETLW 0
;***********************Stop signal********************************
BSTOP:
BCF PORTA,SDA
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTA,SDA
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RETLW 0
;**********************Send N_ACK**************************
SEND_ACK:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,SDA
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
RETLW 0
;**********************Send N_ACK**************************
READ_ACK:
BSF TRISA,SDA ;SET SDA IN
CLRF ACK
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BTFSS PORTA,SDA
INCF ACK,F
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,SCL
BCF TRISA,SDA ;SET SDA OUT
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RETLW ACK;0
;**********************Send a byte**************************
BYTEOUT:
MOVLW D'8'
MOVWF BIT_COUNT
TXLP
nop
nop
CALL BITOUT
RLF TX_BUF,F
DECFSZ BIT_COUNT,F
GOTO TXLP
CALL READ_ACK
;CALL BITIN ;ACK
;BTFSC EEPROM,OF
; BSF PORTC,ACKF
RETLW 0
;************************Receive a byte********************************
BYTEIN:
BSF TRISA,SDA ;SET SDA IN
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
CLRF BUF_IN
MOVLW D'8'
MOVWF BIT_COUNT
BCF C ;BCF STATUS,0
RXLP RLF BUF_IN,F
;BCF BUFIN,0
CALL BITIN
;BTFSC EEPROM,OF
;BSF BUFIN,0
DECFSZ BIT_COUNT,F
GOTO RXLP
;BSF EEPROM,DO
;CALL BITOUT
BCF TRISA,SDA ;SET SDA OUT
NOP
NOP
NOP
NOP
NOP
NOP
RETLW 0
;**********************send********************************
BITOUT
;MOVLW B'00111111'
;MOVWF TRISA
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BTFSS TX_BUF,7
GOTO BITLOW
BSF PORTA,SDA
GOTO CLKOUT
BITLOW BCF PORTA,SDA
CLKOUT
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RETLW 0
;**********************take over****************************
SNAKE
BCF BUF_IN,0 ;EEPROM,DI
;BSF TRISA,SDA ;SET SDA IN
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF PORTA,SCL
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BTFSC PORTA,SDA
BSF BUF_IN,0
BCF PORTA,SCL
;BCF TRISA,SDA ;SET SDA OUT
RETLW 0
;-------------------------
;temp0:addr
;temp1:data
;-------------------------
writebyte
nop
nop
call BSTART
nop
movlw 0xa0
movwf TX_BUF
call BYTEOUT
movf temp0,W
movwf TX_BUF
call BYTEOUT
movf temp1,W
movwf TX_BUF
call BYTEOUT
nop
call BSTOP
nop
call BSTOP
return
;-------------------------
;INPUT:temp0 addr
;out:BUFIN
;-------------------------
readbyte
nop
nop
call BSTART
nop
movlw 0xa0
movwf TX_BUF
call BYTEOUT
nop
nop
movf temp0,W ;addr
movwf TX_BUF
call BYTEOUT
nop
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
nop
call BSTART
nop
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
movlw 0xa1
movwf TX_BUF
call BYTEOUT
nop
nop
nop
nop
call BYTEIN
call BSTOP
return
;-------------------------
;temp0:addr '0x10'add '0x20'data
;temp1:data
;-------------------------
writenbyte
nop
nop
call BSTART
nop
movlw 0xa0
movwf TX_BUF
call BYTEOUT
movf temp0,W
movwf TX_BUF
call BYTEOUT
movlw 0x5
movwf byte_count
movlw rom_buf1 ; get the address of rom_buf1
movwf FSR
wx_lp:
movf INDF,W
movwf TX_BUF
call BYTEOUT
INCF FSR,F
DECFSZ byte_count,F
goto wx_lp
nop
nop
call BSTOP
return
;-------------------------
;temp0:addr '0x10'add '0x20'data
;temp1:data num
;-------------------------
readnbyte
nop
nop
call BSTART
nop
movlw 0xa0
movwf TX_BUF
call BYTEOUT
movf temp0,W
movwf TX_BUF
call BYTEOUT
NOP
call BSTART
nop
movlw 0xa1
movwf TX_BUF
call BYTEOUT
movlw 0x5
movwf byte_count
movlw rom_buf1 ; get the address of rom_buf1
movwf FSR
rx_lp:
call BYTEIN
call SEND_ACK
movf BUF_IN,W
movwf INDF
INCF FSR,F
DECFSZ byte_count,F
goto rx_lp
nop
nop
call BSTOP
return
;--------------------------------
test_eeprom:
movlw 0x44
movwf add1
movlw 0x55
movwf add2
movlw 0x66
movwf add3
;movlw 0x20
;movwf temp0
;movlw add1 ;0x23 ;data *pt add1=0x23 flag 2d /2e
;movwf temp1
;call writenbyte
call save_add
call Delay100ms
call Delay100ms
;call Delay100ms
;call Delay100ms
clrf rom_buf1
clrf rom_buf5
movlw 0x20
movwf temp0
call readnbyte
return
;------------------------------------------
save_add:
movlw 0xaa
movwf rom_buf1
movf add1,W
movwf rom_buf2
movf add2,W
movwf rom_buf3
movf add3,W
movwf rom_buf4
movlw 0x55
movwf rom_buf5
movlw 0x20
movwf temp0
call writenbyte
return
;------------------------------------------
save_data:
movlw 0xaa
movwf rom_buf1
movf flag,W
andlw 0x03
movwf rom_buf2
movf LED_speed,W
movwf rom_buf3
movlw 0x08; add3,W
movwf rom_buf4
movlw 0x55
movwf rom_buf5
movlw 0x30
movwf temp0
call writenbyte
return
;-----------------------------------------
;0x20
;
read_add:
movlw 0x20
movwf temp0
call readnbyte
movlw 0xaa
subwf rom_buf1,W
btfss Z
goto rd_err
movlw 0x55
subwf rom_buf5,W
btfss Z
goto rd_err
;---add is ok----------------
movf rom_buf2,W
movwf add1
movf rom_buf3,W
movwf add2
movf rom_buf4,W
movwf add3
bsf match_fin_fb
rd_err
nop
movlw 0xb0
movwf add1
movlw 0x16
movwf add2
movlw 0x47
movwf add3
bsf match_fin_fb
nop
return
;------------------------------------------
;0x30
;-----------------------------------------
read_data:
movlw 0x30
movwf temp0
call readnbyte
movlw 0xaa
subwf rom_buf1,W
btfss Z
goto rdd_err
movlw 0x55
subwf rom_buf5,W
Previous article:PIC microcontroller USB MSC application: use MMC/SD card as storage device for reading and writing
Next article:A simple applet for PIC microcontroller to read/write MMC/SD card
Recommended ReadingLatest update time:2024-11-16 20:49
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Plant growth monitoring system source code based on Raspberry Pi 5
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
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
- Guwei LCR819 bridge cannot be tested maintenance record
- MP2459 related circuit solution
- TI Industrial Robots Online Seminar Resource Sharing
- Power Optimized 77GHz Liquid Level Transmitter Reference Design
- [Gifts to give away] STMicroelectronics Power and Discrete Devices (PDSA) Quiz with Prizes!
- Enjoy the Avnet Artificial Intelligence Cloud Exhibition and challenge the 60-day check-in learning and development record!
- How is the domestic isolated power supply module doing? There are many manufacturers now.
- Detailed explanation of dBm, dB, and dBc
- AutoCAD Eagle is in my game
- Weekly review information~