;************************************************************************
; This is a program to test the function of reading&writting for EEPROM.
; You can observe the value of register(30H--?) buy changing "VALU" and "WRC_".
; Notice that:it must be { ADDR+WRC_<=0ffh } !
;****************************************************************************
include "p16f877.inc"
ADDR EQU 20H ;Write address register
VALU EQU 21H ;Write value
REC_ EQU 22H ;Read count
WRC_ EQU 24H ;Write
countorg 0
goto main
main
bcf STATUS,RP1
bcf STATUS,RP0 ;bank0
movlw 10h
movwf ADDR ;Write EEPROM initial value
movlw 90h
movwf VALU ;Initial write value
movlw 30h
movwf FSR ;Indirect address, read value initial storage address
movlw 0Fh
movwf WRC_ ;Write times
movwf REC_
;incf REC_ ;Read times
wri_ ;Write subroutine
bsf STATUS,RP1
bsf STATUS,RP0 ;bank3
btfsc EECON1,WR
goto $-1
bcf STATUS,RP0
bcf STATUS,RP1 ;bank0
movf ADDR,W
bsf STATUS,RP1 ;bank2
movwf EEADR
bcf STATUS,RP1 ;bank0
movf VALU,W
bsf STATUS,RP1 ;bank2
movwf EEDATA
bsf STATUS,RP0 ;bank3
bcf EECON1,EEPGD ;to data memory
bsf EECON1,WREN
bcf INTCON,GIE
movlw 55h
movwf EECON2
movlw 0aah
movwf EECON2
bsf EECON1,WR
bcf STATUS,RP0
bcf STATUS,RP1 ;bank0
incf ADDR,1
decf VALU,1
decfsz WRC_ ;all write,to read_
goto wri_
read_ ;read subroutine
bcf STATUS,RP1
bcf STATUS,RP0 ;bank0
decf ADDR ;next value
bsf STATUS,RP1 ;bank2
movwf EEADR
bsf STATUS,RP0 ;bank3
EEw&r.asm program description:
1. This program is a demonstration program for reading and writing the EEPROM data area of the PIC16F877 microcontroller;
2. wri_ is a data writing subroutine. This subroutine starts writing to the EEPROM data area from the address determined by the ADDR register (the example starts from 10H). Each write operation will increase the ADDR value by one. The initial value of the written data is given by the VALU register (the example value is 90H). Each write operation will decrease the VALU value by one. After writing the specified number of values (given by the WRC_ register, the example value is 0FH), the writing is terminated and the program goes to read_.
3. read_ is a subroutine for reading data. This subroutine starts reading the EEPROM data area from the address determined by the current value of the ADDR register (current value = ADDR + WRC_ <= 0FFH). Each read operation will reduce the ADDR value by one. After reading the data, the program will store the data in a general register. The starting address is specified by the value of FSR (30H in the example). Each read operation will increase the value of FSR by one. After reading the specified number of values (given by the register REC_, the example value is 0FH), the reading is completed and the program returns to main.
Previous article:I2C application program for PIC microcontroller1
Next article:PIC I2C reading and writing program
- Popular Resources
- Popular amplifiers
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
- Exploring the RF Front End of Massive MIMO Systems (Semiconductor Technology Perspective and Manufacturer Perspective)
- [CC1352P Evaluation] Continue to tinker with SDK examples
- GD32E231 analog IIC driver LIS2DW12
- [TI millimeter wave radar review] + unboxing photos + environment
- Hey guys, why is the ROOM so big in this PCB?
- [NXP Rapid IoT Review] + First login to NXP online programming
- How to read the ceramic capacitor
- What chip can achieve the three-in-one dimming function? 0-10V, PWM, 100K resistor.
- Introduction to bq24780S, commonly used for laptop battery management
- Which is more flexible, a human or a robot? Shadow’s dexterous hands stack cups