微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 硬件工程师文库 > 读写24LCxx系列的EEPROM的实例程序

读写24LCxx系列的EEPROM的实例程序

时间:02-16 来源:匠人的百宝箱 点击:

w_temp  EQU 0x72
status_temp EQU 0x73
pclath_temp EQU 0x74
;
;***************************************
;       ﹚竡 I2C ???の竲?
;
EEPROM_CMD equ 0xA0  ; Device adress of Slave Point
EE_Read  equ .1
EE_Write equ .0

;
#define  SCL PORTC,3  ; I2C SCL pin
#define  SDA PORTC,4  ; I2C SDA pin

;

;********************************************
; Locates START($0.5760)up code @ the reset vector
;********************************************
Reset_Addr
   org  0x00
   nop
   goto Main_Init
;
   org  0x04
   goto ISR
;
;*************************************************************
;**** The START($0.5760) Address of ISR is 0x004
;**** "PUSH" & "POP" ?ㄏノ絛ㄒ : 続ノ?钩 PIC16F877($4.6800) ΤSHARE BANK ?PIC
;**************************************************************
ISR 
Push  movwf   w_temp             ; save off current W register contents
   movf STATUS,w           ; move status register into W register
   movwf status_temp        ; save off contents of STATUS register
   movf PCLATH,W
   movwf pclath_temp

;        Put your interrupt code here
;
Pop   movf pclath_temp,W
   movwf PCLATH
   movf    status_temp,w    ; retrieve copy of STATUS register
   movwf STATUS            ; restore pre-isr STATUS register contents
   swapf   w_temp,f
   swapf   w_temp,w          ; restore pre-isr W register contents
;
   retfie                    ; return from interrupt
  
 
;----------------------------------------------------------------------

Main_Init  
   pagesel Init_I2C_Master  ; Set PAGE to PCLATH Register
      call    Init_I2C_Master  ; Init the MSSP for I2C Master
;
      banksel I2C_Ctrl
   movlw EEPROM_CMD   ; Load EEPROM command address @ 0xA0
   movwf I2C_Ctrl
;
;
Main
;
;----------------------------------------------------------------------
;
;* ???代刚祘&Alpha($5.2300);穦?盢?舱计?(0x40-0x47)糶??RMA0x40-0x47??竚     
;* ?ノPage Write?よ&Alpha($5.2300);盢8??じ舱?戈?糶? EEPROM ?                 
;* 秈︽?篈?盎代EEPROM琌??ЧΘ糶??笆??程?盢?糶                  
;* ??戈??Sequential Read?よ&Alpha($5.2300);眖EEPROM弄?ㄓ??I2C_SEQU_Bufferい    
;

Test_Page_RW
   movlw 0x08
   movwf I2C_Page_Length
   movlw I2C_Page_Buffer
_Fill_RAM movwf FSR
   movwf INDF
   incf FSR,W
   decfsz I2C_Page_Length,F
   goto _Fill_RAM
;   
Test_Page_Write
;   banksel I2C_Ctrl
   movlw EEPROM_CMD   ; Load EEPROM command address @ 0xA0
   movwf I2C_Ctrl
   movlw 0x10     ; Select EEPROM location at 0x00
   movwf I2C_Addr
   movlw .8
   movwf I2C_Page_Length
   call EE_Page_Write
;
   call EE_Ack_Check
;
   banksel I2C_Ctrl
   movlw EEPROM_CMD   ; Load EEPROM command address @ 0xA0
   movwf I2C_Ctrl
   movlw 0x10
   movwf I2C_Addr
   movlw .8
   movwf I2C_Page_Length
   call EE_SEQU_Read
;
   goto $
;
;---------------------------------------------------------
;
;* ???代刚祘&Alpha($5.2300);穦?糶????じ舱?戈?糶? EEPROM い               
;* ?秈︽?篈?盎代琌??ЧΘ糶??笆??程?盢?糶                           
;* ??戈??眖EEPROM弄?ㄓ??I2C_Data既?竟い                      
;       
Test_1byte_RW

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top