PIC microcontroller EEPROM reading and writing examples and instructions

Publisher:老王古玩店Latest update time:2011-02-24 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
; PIC microcontroller EEPROM reading and writing examples and instructions
;************************************************************************
; 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.

Reference address:PIC microcontroller EEPROM reading and writing examples and instructions

Previous article:I2C application program for PIC microcontroller1
Next article:PIC I2C reading and writing program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号