新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 24LCxx系列的EEPROM讀寫的程序?qū)嵗?/p>

        24LCxx系列的EEPROM讀寫的程序?qū)嵗?/h1>
        作者: 時間:2012-07-18 來源:網(wǎng)絡(luò) 收藏

        ;*
        ;*******************************************************
        ;
        ; Send Command for BYTE WRITE :
        ; Start+ 0xA0 + EE_Address + Write_Data + Stop
        ;
        EE_Byte_Write
        call StartI2C ; Set SSPCON2.SEN
        ;
        bcf I2C_Ctrl,0 ; Clear for Write Command
        movf I2C_Ctrl,W ; Send Slave Address to I2C Bus
        call Send_Byte
        ;
        movf I2C_Addr,W ; Send out the Command
        call Send_Byte
        ;
        movf I2C_Data,W ; Send out the Data
        call Send_Byte
        ;
        call StopI2C ; Initial STOP Condition
        return
        ;
        ;**********************************************************************
        ;
        ; As following subroutines perform commonly used I2C functions.
        ; You can use these subroutines for your I2C access
        ;
        ;**********************************************************************
        ;
        ;*** Initial I2Cmodule fot 7-bit I2C Master Mode with 100Kcps @4MHz
        ;
        Init_I2C_Master
        BANKSEL TRISC ; Initial PortC,bit 3 4 as Input
        bsf SCL ; RC3 = SCL , RC4 = SDA
        bsf SDA
        ;
        BANKSEL PORTC
        bsf SCL ; SCL = Hi
        bsf SDA ; SDA = Hi
        ;
        movlw b'00101000' ; I2C Master Mode, Clock Rate: FOSC/(4*SSPADD+1)
        movwf SSPCON ;
        ;
        banksel SSPADD
        movlw .9 ; This gives 100KHz I2C clock @ 4MHz
        movwf SSPADD ; (4MHz/4) / (9+1)= 100KHz
        ;
        movlw b'10000000' ; Disable slew rate control,
        movwf SSPSTAT ; and clear status bits
        ;
        movlw b'00000000' ; Set SCL,SDA into Ready status
        movwf SSPCON2
        ;
        return
        ;
        ;****** Send START condition to bus *******
        ;
        StartI2C ; Initiate the I2C START condition.
        banksel SSPCON2
        bsf SSPCON2,SEN
        goto I2C_Done
        ;
        ;****** Send STOP condition to bus *******
        ;
        StopI2C
        banksel SSPCON2
        bsf SSPCON2,PEN
        goto I2C_Done
        ;
        ;****** Send RESTART condition to bus *******
        ;
        RstartI2C
        banksel SSPCON2
        bsf SSPCON2,RSEN
        goto I2C_Done
        ;
        ;****** Send a Non-Acknowledge status to bus (ACK=1) *******
        ;
        Non_Ack
        banksel SSPCON2
        bsf SSPCON2,ACKDT ; Set the ACK bit
        bsf SSPCON2,ACKEN ; Initiate the NACK sequence.
        goto I2C_Done
        ;
        ;****** Send an Acknowledge status to bus (ACK=0) *******
        ;
        An_Ack
        banksel SSPCON2
        bcf SSPCON2,ACKDT ; Clear the ACK bit
        bsf SSPCON2,ACKEN ; Initiate the NACK sequence.
        goto I2C_Done
        ;
        ;****** Send data to I2C bus from Wreg. *******
        ;
        Send_Byte
        banksel SSPBUF
        movwf SSPBUF
        goto I2C_Done
        ;
        ;****** Enable I2C Receive for Master Mode *******
        ;
        RecI2C
        banksel SSPCON2
        bsf SSPCON2,RCEN ; Set the receive enable bit.
        goto I2C_Done
        ;
        ;****** Check the I2C stage is completed ********
        ;
        I2C_Done
        banksel PIR1
        btfss PIR1,SSPIF ; Poll for SSPIF
        goto $-1
        bcf PIR1,SSPIF
        return
        ;
        Delay_mS
        banksel D_Count
        movlw .124 ; Load .5mS Dealy Value
        movwf D_Count
        _D_mS nop
        decfsz D_Count,F
        goto _D_mS
        return
        ;
        ; *********** End Of Program !!!!!
        ;
        end

        本文引用地址:http://www.104case.com/article/171137.htm

        上一頁 1 2 3 下一頁


        關(guān)鍵詞: 程序 實例 讀寫 EEPROM 系列 24LCxx

        評論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 霍邱县| 剑河县| 阳高县| 利津县| 陈巴尔虎旗| 同心县| 江永县| 聂拉木县| 正定县| 东台市| 浏阳市| 济源市| 昂仁县| 城固县| 府谷县| 南宁市| 昭通市| 马尔康县| 龙川县| 太湖县| 古田县| 灯塔市| 泾川县| 巫溪县| 巴林左旗| 福贡县| 太谷县| 盈江县| 虎林市| 博湖县| 寻乌县| 南和县| 上高县| 沅江市| 临西县| 菏泽市| 衡山县| 思南县| 陇西县| 萨迦县| 石棉县|