阅读:1650回复:4
PIC16F73读写24C01的程序(I/O口模拟I2C总线)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;*****E2PROM code ;*****Start code E2PROM_START BSF PORTC,SDAT BSF PORTC,SCLK BSF STATUS,5 MOVLW DATA_OUT MOVWF TRISC BCF STATUS,5 NOP NOP NOP NOP NOP BCF PORTC,SDAT NOP NOP NOP NOP NOP NOP BCF PORTC,SCLK NOP NOP NOP NOP RETURN ;*****Stop code E2PROM_STOP BCF PORTC,SCLK BCF PORTC,SDAT BSF STATUS,5 MOVLW DATA_OUT MOVWF TRISC BCF STATUS,5 NOP NOP NOP NOP BSF PORTC,SCLK NOP NOP NOP NOP BSF PORTC,SDAT NOP NOP NOP NOP BCF PORTC,SCLK NOP NOP RETURN ;*****Byte out code E2PROM_BYTE_OUT MOVLW 08H MOVWF E2PROM_cnt BSF STATUS,5 MOVLW DATA_OUT MOVWF TRISC BCF STATUS,5 OUT_LOOP BCF PORTC,SCLK NOP NOP NOP BTFSS E2PROM_data,7 GOTO PULL_DOWN_SDAT BSF PORTC,SDAT GOTO OUT_NEXT_BIT PULL_DOWN_SDAT BCF PORTC,SDAT OUT_NEXT_BIT RLF E2PROM_data,1 NOP NOP BSF PORTC,SCLK NOP NOP NOP NOP NOP NOP DECFSZ E2PROM_cnt,1 GOTO OUT_LOOP BCF PORTC,SCLK BSF STATUS,5 MOVLW DATA_IN MOVWF TRISC BCF STATUS,5 NOP NOP BSF PORTC,SCLK NOP NOP NOP NOP NOP NOP WAIT_ACK_LOOP BTFSC PORTC,SDAT GOTO WAIT_ACK_LOOP BCF PORTC,SCLK NOP NOP NOP NOP NOP NOP RETURN ;*****Byte in code E2PROM_BYTE_IN MOVLW 08H MOVWF E2PROM_cnt CLRF E2PROM_data BSF STATUS,5 MOVLW DATA_IN MOVWF TRISC BCF STATUS,5 BCF STATUS,0 IN_LOOP RLF E2PROM_data,1 BCF PORTC,SCLK NOP NOP NOP NOP NOP BSF PORTC,SCLK NOP NOP NOP BTFSS PORTC,SDAT GOTO REC_DOWN_SDAT BSF E2PROM_data,0 GOTO IN_NEXT_BIT REC_DOWN_SDAT BCF E2PROM_data,0 IN_NEXT_BIT NOP NOP NOP BCF PORTC,SCLK NOP NOP NOP DECFSZ E2PROM_cnt,1 GOTO IN_LOOP NOP NOP NOP RETURN ;*****Read code READ_E2PROM MOVLW 0A0H MOVWF E2PROM_data CALL E2PROM_START CALL E2PROM_BYTE_OUT MOVF E2PROM_addr,0 MOVWF E2PROM_data CALL E2PROM_BYTE_OUT MOVLW 0A1H MOVWF E2PROM_data CALL E2PROM_START CALL E2PROM_BYTE_OUT CALL E2PROM_BYTE_IN CALL E2PROM_STOP RETURN ;*****Write code WRITE_E2PROM MOVLW 0A0H MOVWF E2PROM_data CALL E2PROM_START CALL E2PROM_BYTE_OUT MOVF E2PROM_addr,0 MOVWF E2PROM_data CALL E2PROM_BYTE_OUT MOVF Need_write_data,0 MOVWF E2PROM_data CALL E2PROM_BYTE_OUT CALL E2PROM_STOP RETURN [此贴子已经被作者于2002-12-27 14:10:15编辑过]
|
|
|
1楼#
发布于:2002-12-27 22:12
PIC16F73读写24C01的程序(I/O口模拟I2C总线)
怎么每行都左对齐了?把我的排版格式都变了! |
|
|
2楼#
发布于:2006-01-20 01:11
如下: WAIT_ACK_LOOP BTFSC PORTC,SDAT GOTO WAIT_ACK_LOOP BCF PORTC,SCLK [此贴子已经被作者于2006-1-19 17:16:10编辑过]
|
|
4楼#
发布于:2006-08-14 07:54
|
|
|