• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統 > 設計應用 > 24LCxx系列的EEPROM的讀寫程序實例

    24LCxx系列的EEPROM的讀寫程序實例

    作者: 時間:2012-08-12 來源:網絡 收藏

    本文引用地址:http://www.czjhyjcfj.com/article/171046.htm

    ;********************************************************
    ;* *
    ;* ? PIC16F877A ?I2C Master 家Α????Α ?dㄒ{Α *
    ;* *
    ;* Written by: Richard Yang *
    ;* Sr. Corporate Application Engineer *
    ;* Microchip Technology Inc. *
    ;* Date: Oct. 2nd '2002 *
    ;* Revision: 1.00 *
    ;********************************************************


    ;*************************************************
    ; This source code provides a demonstration of the MSSP peripheral
    ; on the PIC16F87x MCU.
    ;
    ;
    ;*********** The subroutines for *****************
    ;
    ; EE_Random_Read ; EEPROM Random address Read from EEPROM
    ; EE_SEQU_Read ; EEPROM Sequential Read form EEPROM
    ; EE_Ack_Check ; Polling current status of EEPROM
    ; EE_Page_Write ; Page Write function for EEPROM
    ; EE_Byte_Write ; Write a byte to EEPROM with address setting
    ;
    ;*********** The subroutines for I2C *****************
    ;
    ; Init_I2C_Master ; Initial I2C Module for Master Mode , 7-bit address
    ; StartI2C ; Send a START Condition !!
    ; StopI2C ; Send s STOP Condition
    ; RstartI2C ; Send a Repeat Start conditional to I2C
    ; Non_Ack ; Send a Non-acknowledge signal to I2C
    ; An_Ack ; Send a acknowledge signal to I2C
    ; Sebd_Byte ; Send a byte to I2C bus
    ; RecI2C ; Enable Read a byte form slave device
    ; I2C_Done : Wait the I2C completed the currect process
    ;
    ;***************************************************

    list p=16f877a
    #i nclude p16f877a.inc>

    ;
    ;***************************************
    ; wq跑計?RAM???
    ;
    CBLOCK 0x20

    I2C_Ctrl
    I2C_Addr
    I2C_Data
    I2C_Page_Length
    D_Count
    ENDC
    cblock 0x40
    I2C_Page_Buffer:8
    I2C_SEQU_Buffer:8
    endc
    ;
    ;***************************************
    ; wqい_?既?竟??

    w_temp EQU 0x72
    status_temp EQU 0x73
    pclath_temp EQU 0x74
    ;
    ;***************************************
    ; wq 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 startup code @ the reset vector
    ;********************************************
    Reset_Addr
    org 0x00
    nop
    goto Main_Init
    ;
    org 0x04
    goto ISR
    ;
    ;*************************************************************
    ;**** The Start Address of ISR is 0x004
    ;**** PUSH POP ?ㄏノdㄒ : Aノ?鉤 PIC16F877 Τ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
    ;
    ;----------------------------------------------------------------------
    ;
    ;* ???代剛{Α|?N?艙計?(0x40-0x47)g??RMA0x40-0x47??m
    ;* ?ノPage Write?よΑN8??じ艙?戈?g? EEPROM ?
    ;* i?A?盎代EEPROMO??ЧΘg??笆??程?N?g
    ;* ??戈??Sequential Read?よΑqEEPROM弄?ㄓ??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 $
    ;
    ;---------------------------------------------------------
    ;
    ;* ???代剛{Α|?g????じ艙?戈?g? EEPROM い
    ;* ?i?A?盎代O??ЧΘg??笆??程?N?g
    ;* ??戈??qEEPROM弄?ㄓ??I2C_Data既?竟い
    ;
    Test_1byte_RW


    上一頁 1 2 3 下一頁

    評論


    相關推薦

    技術專區

    關閉
    主站蜘蛛池模板: 广东省| 博爱县| 英吉沙县| 光泽县| 新兴县| 永丰县| 元朗区| 卫辉市| 教育| 哈密市| 青铜峡市| 德惠市| 昌图县| 莎车县| 桂林市| 莱阳市| 晋江市| 黄平县| 上饶市| 沙湾县| 永川市| 和平县| 四平市| 广丰县| 连山| 忻城县| 安化县| 从江县| 县级市| 英山县| 大英县| 徐闻县| 阳泉市| 临漳县| 五常市| 曲麻莱县| 大港区| 榆社县| 萍乡市| 丹棱县| 罗源县|