技术热线: 4007-888-234

软件模拟用24c02

更新时间: 2019-03-23
阅读量:1867

十年专注单片机方案开发的方案公司英锐恩,分享软件模拟用24c02。英锐恩现提供服务产品涉及主控芯片:8位单片机、16位单片机、32位单片机及各类运算放大器等。

INCLUDE STATUS EQU 3H PORTB EQU 6H PORTC EQU 7H EEPROM EQU 08H ADDR EQU 09H BUFIN EQU 0AH BUFOUT EQU 0BH SLAVE EQU 0CH TXBUF EQU 0DH BIT EQU 0EH DLY1 EQU 0FH DLY2 EQU 10H DI EQU 7 DO EQU 6 SDA EQU 7 SCL EQU 6 ACKF EQU 0 ;********************** ORG 7FFH GOTO MAIN ORG 000H ;********************** BSTART BSF PORTB,SDA BSF PORTB,SCL MOVLW B'00111111' TRIS PORTB NOP NOP NOP NOP NOP NOP BCF PORTB,SDA NOP NOP NOP NOP NOP BCF PORTB,SCL NOP NOP RETLW 0 ;********************** BSTOP BCF PORTB,SDA MOVLW B'00111111' TRIS PORTB BCF PORTB,SDA NOP NOP NOP BSF PORTB,SCL NOP NOP NOP BSF PORTB,SDA NOP NOP BCF PORTB,SCL NOP NOP RETLW 0 ;********************** TX MOVLW D'8' MOVWF BIT TXLP BCF 

EEPROM,DO BTFSC TXBUF,7 BSF EEPROM,DO CALL BITOUT RLF TXBUF DECFSZ BIT GOTO TXLP CALL BITIN BTFSC EEPROM,DI BSF PORTC,ACKF RETLW 0 ;************************ RX CLRF BUFIN MOVLW D'8' MOVWF BIT BCF STATUS,0 RXLP RLF BUFIN BCF BUFIN,0 CALL BITIN BTFSC EEPROM,DI BSF BUFIN,0 DECFSZ BIT GOTO RXLP BSF EEPROM,DO CALL BITOUT RETLW 0 ;********************** BITOUT MOVLW B'00111111' tris PORTB BTFSS EEPROM,DO GOTO BITLOW BSF PORTB,SDA GOTO CLKOUT BITLOW BCF PORTB,SDA CLKOUT BSF PORTB,SCL NOP NOP NOP NOP BCF PORTB,SCL RETLW 

0 ;********************** BITIN BSF EEPROM,DI MOVLW B'10111111' TRIS PORTB BSF PORTB,SCL NOP NOP NOP NOP NOP BTFSS PORTB,SDA BCF EEPROM,DI BCF PORTB,SCL RETLW 0 ;*********************** MAIN MOVLW B'00000000' TRIS PORTC CLRF PORTC WRITE CLRF PORTC MOVLW B'10100000' MOVWF SLAVE MOVLW B'10101010' MOVWF BUFOUT CLRF ADDR LOOP0 CALL BSTART MOVF SLAVE,0 MOVWF TXBUF CALL TX MOVF ADDR,0 MOVWF TXBUF CALL TX MOVF BUFOUT,0 MOVWF TXBUF CALL TX CALL BSTOP DELAY10MS MOVLW D'13' MOVLW DLY1 MOVLW 0FFH MOVWF DLY2 LP0 DECFSZ DLY2 GOTO $-1 DECFSZ DLY1 GOTO $-5 READ CLRF PORTC MOVLW B'10100000' MOVWF SLAVE CLRF ADDR LOOP1 CALL BSTART MOVF SLAVE,0 MOVWF TXBUF CALL TX MOVF ADDR,0 MOVWF TXBUF CALL TX CALL BSTART MOVLW B'10100001' MOVWF TXBUF CALL TX CALL RX CALL BSTOP NOP NOP NOP NOP NOP NOP MOVF BUFIN,0 MOVWF PORTC LOOP2 NOP GOTO $-1 ;************************ END