
; CC5X Version 3.3A, Copyright (c) B Knudsen Data
; C compiler for the PICmicro family
; ************   2. Sep 2007   8:39  *************

	processor  16F84A
	radix  DEC

	__config 0x3FF6

TMR0        EQU   0x01
STATUS      EQU   0x03
TRISA       EQU   0x85
TRISB       EQU   0x86
INTCON      EQU   0x0B
Carry       EQU   0
Zero_       EQU   2
RP0         EQU   5
T0IF        EQU   2
OPTION_REG  EQU   0x81
RA3         EQU   3
RA4         EQU   4
RB0         EQU   0
RB1         EQU   1
RB2         EQU   2
RB3         EQU   3
RB4         EQU   4
RB5         EQU   5
RB6         EQU   6
RB7         EQU   7
I2C_LAST_SDA EQU   0
I2C_LAST_SCL EQU   1
I2C_NEW_SDA EQU   2
I2C_NEW_SCL EQU   3
I2C_BIT_ON  EQU   4
I2C_BIT_ADR EQU   5
I2C_BIT_RD  EQU   6
I2C_BIT_WR  EQU   7
I2C_BIT_ACK EQU   0
I2C_CLK     EQU   0x1C
I2C_ADR     EQU   0x1D
I2C_DAT     EQU   0x1E
I2C_NBYTE   EQU   0x1F
I2C_TIME    EQU   0x20
t_on        EQU   0x21
t_off       EQU   0x23
t           EQU   0x25
on          EQU   1
svrWREG     EQU   0x0C
svrSTATUS   EQU   0x0D
k           EQU   0x16
l           EQU   0x18
C1cnt       EQU   0x12
C2tmp       EQU   0x13
tmp1        EQU   0x0E
C3cnt       EQU   0x12
C4tmp       EQU   0x13
C5rem       EQU   0x15
C6cnt       EQU   0x12
C7tmp       EQU   0x13
tmp2        EQU   0x10
C8cnt       EQU   0x12
C9tmp       EQU   0x13
C10rem      EQU   0x15
tmp         EQU   0x0E
tmp2_2      EQU   0x0F
C11cnt      EQU   0x10
tmp_2       EQU   0x0E
tmp2_3      EQU   0x0F
C12cnt      EQU   0x10

	GOTO main

  ; FILE clignottement.c
			;
			;
			;#asm
			;_CP_ON                       EQU     H'000F'
			;_CP_OFF                      EQU     H'3FFF'
			;_PWRTE_ON                    EQU     H'3FF7'
			;_PWRTE_OFF                   EQU     H'3FFF'
			;_WDT_ON                      EQU     H'3FFF'
			;_WDT_OFF                     EQU     H'3FFB'
			;_LP_OSC                      EQU     H'3FFC'
			;_XT_OSC                      EQU     H'3FFD'
			;_HS_OSC                      EQU     H'3FFE'
			;_RC_OSC                      EQU     H'3FFF'
			;#endasm

  ; FILE clignottement.c
			;
			;//#pragma chip PIC16F84
			;#pragma config  = _HS_OSC & _WDT_ON & _PWRTE_ON & _CP_OFF
			;
			;#include "int16CXX.h" //gestion des interuption
			;
			;#define SCL  RA4
			;#define SDA  RA3
			;#define bitSCL 4
			;#define bitSDA 3
			;
			;bit  I2C_LAST_SDA;
			;bit  I2C_LAST_SCL;
			;bit  I2C_NEW_SDA;
			;bit  I2C_NEW_SCL;
			;
			;bit  I2C_BIT_ON;
			;bit  I2C_BIT_ADR;
			;bit  I2C_BIT_RD;
			;bit  I2C_BIT_WR;
			;bit  I2C_BIT_ACK;
			;
			;char I2C_CLK;
			;char I2C_ADR;
			;char I2C_DAT;
			;char I2C_NBYTE;
			;char I2C_TIME;
			;
			;uns16 t_on;
			;uns16 t_off;
			;uns16 t;
			;bit	  on;
			;
			;void I2C_Slave_Check();
			;
			;#pragma origin 0x04
	ORG 0x0004
			;interrupt timer(void)
			;{
timer
			;	int_save_registers
	MOVWF svrWREG
	SWAPF STATUS,W
	MOVWF svrSTATUS
			;	if(T0IF){
	BTFSS 0x0B,T0IF
	GOTO  m005
			;		I2C_Slave_Check();
	CALL  I2C_Slave_Check
			;
			;		t++;
	INCF  t,1
	BTFSC 0x03,Zero_
	INCF  t+1,1
			;		if(on==1 && t >= t_on){
	BTFSS 0x1B,on
	GOTO  m002
	MOVF  t_on+1,W
	SUBWF t+1,W
	BTFSS 0x03,Carry
	GOTO  m002
	BTFSS 0x03,Zero_
	GOTO  m001
	MOVF  t_on,W
	SUBWF t,W
	BTFSS 0x03,Carry
	GOTO  m002
			;			RB0  = 1;			
m001	BCF   0x03,RP0
	BSF   0x06,RB0
			;			RB1  = 0;
	BCF   0x06,RB1
			;			RB2  = 0;			
	BCF   0x06,RB2
			;			RB3  = 0;
	BCF   0x06,RB3
			;			RB4  = 0;			
	BCF   0x06,RB4
			;			RB5  = 0;
	BCF   0x06,RB5
			;			RB6  = 0;
	BCF   0x06,RB6
			;			RB7  = 0;
	BCF   0x06,RB7
			;						
			;			t  = 0;
	CLRF  t
	CLRF  t+1
			;			on = 0;
	BCF   0x1B,on
			;		}
			;		if(on==0 && t >= t_off){
m002	BTFSC 0x1B,on
	GOTO  m004
	MOVF  t_off+1,W
	SUBWF t+1,W
	BTFSS 0x03,Carry
	GOTO  m004
	BTFSS 0x03,Zero_
	GOTO  m003
	MOVF  t_off,W
	SUBWF t,W
	BTFSS 0x03,Carry
	GOTO  m004
			;			RB0  = 0;			
m003	BCF   0x03,RP0
	BCF   0x06,RB0
			;			RB1  = 1;
	BSF   0x06,RB1
			;			RB2  = 1;			
	BSF   0x06,RB2
			;			RB3  = 1;
	BSF   0x06,RB3
			;			RB4  = 1;			
	BSF   0x06,RB4
			;			RB5  = 1;
	BSF   0x06,RB5
			;			RB6  = 1;
	BSF   0x06,RB6
			;			RB7  = 1;
	BSF   0x06,RB7
			;						
			;			t  = 0;
	CLRF  t
	CLRF  t+1
			;			on = 1;
	BSF   0x1B,on
			;		}
			;		T0IF = 0;
m004	BCF   0x0B,T0IF
			;
			;	}
			;	int_restore_registers
m005	SWAPF svrSTATUS,W
	MOVWF STATUS
	SWAPF svrWREG,1
	SWAPF svrWREG,W
			;
			;	clrwdt();
	CLRWDT
			;}
	RETFIE
			;
			;//#include "eeprom.c"
			;//#include "I2C.C"
			;//#include "I2C_Slave.C"
			;//#include "I2C_PCF8574.C"
			;
			;
			;
			;
			;
			;void main(void)
			;{	
main
			;	INTCON = 0b10100000;
	MOVLW .160
	MOVWF INTCON
			;	OPTION = 0b11000000;		//Prediviseur : Warchdog every 2.304s
	MOVLW .192
	BSF   0x03,RP0
	MOVWF OPTION_REG
			;
			;	TRISA = 0b11111111;
	MOVLW .255
	MOVWF TRISA
			;	TRISB = 0b00000000;
	CLRF  TRISB
			;
			;	RB0 = 1;
	BCF   0x03,RP0
	BSF   0x06,RB0
			;	RB1 = 0;
	BCF   0x06,RB1
			;	RB2 = 0;
	BCF   0x06,RB2
			;	RB3 = 0;
	BCF   0x06,RB3
			;	RB4 = 0;
	BCF   0x06,RB4
			;	RB5 = 0;
	BCF   0x06,RB5
			;	RB6 = 0;
	BCF   0x06,RB6
			;	RB7 = 0;
	BCF   0x06,RB7
			;
			;	TMR0  = 0;	
	CLRF  TMR0
			;
			;	t_on  = 1000;
	MOVLW .232
	MOVWF t_on
	MOVLW .3
	MOVWF t_on+1
			;	t_off = 2500;
	MOVLW .196
	MOVWF t_off
	MOVLW .9
	MOVWF t_off+1
			;	on	  = 1;
	BSF   0x1B,on
			;
			;	clrwdt();
	CLRWDT
			;
			;	uns16 k = 0;	
	CLRF  k
	CLRF  k+1
			;	while(k<5){
m006	MOVF  k+1,W
	BTFSS 0x03,Zero_
	GOTO  m013
	MOVLW .5
	SUBWF k,W
	BTFSC 0x03,Carry
	GOTO  m013
			;
			;		uns16 l = 0;
	CLRF  l
	CLRF  l+1
			;		while(l<10000){
m007	MOVLW .39
	SUBWF l+1,W
	BTFSS 0x03,Carry
	GOTO  m008
	BTFSS 0x03,Zero_
	GOTO  m009
	MOVLW .16
	SUBWF l,W
	BTFSC 0x03,Carry
	GOTO  m009
			;			nop();
m008	NOP  
			;			l = l+1;
	INCF  l,1
	BTFSC 0x03,Zero_
	INCF  l+1,1
			;			clrwdt();
	CLRWDT
			;		}
	GOTO  m007
			;
			;		RB4 = 1;
m009	BCF   0x03,RP0
	BSF   0x06,RB4
			;
			;		l = 0;
	CLRF  l
	CLRF  l+1
			;		while(l<10000){
m010	MOVLW .39
	SUBWF l+1,W
	BTFSS 0x03,Carry
	GOTO  m011
	BTFSS 0x03,Zero_
	GOTO  m012
	MOVLW .16
	SUBWF l,W
	BTFSC 0x03,Carry
	GOTO  m012
			;			nop();
m011	NOP  
			;			l = l+1;
	INCF  l,1
	BTFSC 0x03,Zero_
	INCF  l+1,1
			;			clrwdt();
	CLRWDT
			;		}
	GOTO  m010
			;
			;		RB4 = 0;
m012	BCF   0x03,RP0
	BCF   0x06,RB4
			;
			;		k = k+1;
	INCF  k,1
	BTFSC 0x03,Zero_
	INCF  k+1,1
			;	}
	GOTO  m006
			;
			;
			;
			;
			;	while(1){		
			;		clrwdt();		
m013	CLRWDT
			;	}
	GOTO  m013
			;
			;}
			;
			;
			;
			;
			;
			;// clk :   0 | 1 |					--> CLK=9 = CLK=0 of next byte
			;// SCL : --__--__
			;// SDA : --X __X --
			;
			;void I2C_Slave_Init()
			;{
I2C_Slave_Init
			;	TRISA.bitSCL = 1;		// Lecture
	BSF   0x03,RP0
	BSF   TRISA,4
			;	TRISA.bitSDA = 1;		// Lecture
	BSF   TRISA,3
			;
			;	I2C_NEW_SCL  = SCL;
	BCF   0x1A,I2C_NEW_SCL
	BCF   0x03,RP0
	BTFSC 0x05,RA4
	BSF   0x1A,I2C_NEW_SCL
			;	I2C_NEW_SDA  = SDA;	
	BCF   0x1A,I2C_NEW_SDA
	BTFSC 0x05,RA3
	BSF   0x1A,I2C_NEW_SDA
			;
			;	I2C_TIME	 = 0;
	CLRF  I2C_TIME
			;
			;	clrwdt();
	CLRWDT
			;}
	RETURN
			;
			;bit I2C_Slave_PIC_Adress()
			;{	
I2C_Slave_PIC_Adress
			;	if(I2C_ADR == 50 || I2C_ADR == 51 || I2C_ADR == 52 || I2C_ADR == 53)	return 1;	
	MOVF  I2C_ADR,W
	XORLW .50
	BTFSC 0x03,Zero_
	GOTO  m014
	MOVF  I2C_ADR,W
	XORLW .51
	BTFSC 0x03,Zero_
	GOTO  m014
	MOVF  I2C_ADR,W
	XORLW .52
	BTFSC 0x03,Zero_
	GOTO  m014
	MOVF  I2C_ADR,W
	XORLW .53
	BTFSS 0x03,Zero_
	GOTO  m015
m014	BSF   0x03,Carry
	RETURN
			;	return 0;			
m015	BCF   0x03,Carry
	RETURN
			;}
			;
			;
			;void I2C_Slave_Action()
			;{	
I2C_Slave_Action
			;	I2C_NBYTE++;
	INCF  I2C_NBYTE,1
			;
			;	I2C_BIT_RD 	 = 0;
	BCF   0x1A,I2C_BIT_RD
			;	I2C_BIT_WR 	 = 0;	
	BCF   0x1A,I2C_BIT_WR
			;	TRISA.bitSDA = 1;
	BSF   0x03,RP0
	BSF   TRISA,3
			;	
			;	switch(I2C_ADR){
	MOVF  I2C_ADR,W
	XORLW .50
	BTFSC 0x03,Zero_
	GOTO  m016
	XORLW .1
	BTFSC 0x03,Zero_
	GOTO  m019
	XORLW .7
	BTFSC 0x03,Zero_
	GOTO  m023
	XORLW .1
	BTFSC 0x03,Zero_
	GOTO  m026
	GOTO  m030
			;		case 50 :
			;			I2C_BIT_RD 	= 1;							
m016	BSF   0x1A,I2C_BIT_RD
			;			if(I2C_NBYTE>1){				
	MOVLW .2
	SUBWF I2C_NBYTE,W
	BTFSS 0x03,Carry
	GOTO  m030
			;				t_on 		= I2C_DAT;
	MOVF  I2C_DAT,W
	MOVWF t_on
	CLRF  t_on+1
			;				t_on	    = t_on*100;	
	MOVF  t_on,W
	MOVWF C2tmp
	MOVF  t_on+1,W
	MOVWF C2tmp+1
	MOVLW .16
	MOVWF C1cnt
m017	BCF   0x03,Carry
	RLF   t_on,1
	RLF   t_on+1,1
	RLF   C2tmp,1
	RLF   C2tmp+1,1
	BTFSS 0x03,Carry
	GOTO  m018
	MOVLW .100
	ADDWF t_on,1
	BTFSC 0x03,Carry
	INCF  t_on+1,1
m018	DECFSZ C1cnt,1
	GOTO  m017
			;				I2C_ADR     = 0;
	CLRF  I2C_ADR
			;			}
			;			break;
	GOTO  m030
			;		case 51 :
			;			I2C_BIT_WR 	 = 1;	
m019	BSF   0x1A,I2C_BIT_WR
			;			uns16 tmp1	 = t_on/100;
	MOVF  t_on,W
	MOVWF C4tmp
	MOVF  t_on+1,W
	MOVWF C4tmp+1
	CLRF  C5rem
	MOVLW .16
	MOVWF C3cnt
m020	RLF   C4tmp,1
	RLF   C4tmp+1,1
	RLF   C5rem,1
	BTFSC 0x03,Carry
	GOTO  m021
	MOVLW .100
	SUBWF C5rem,W
	BTFSS 0x03,Carry
	GOTO  m022
m021	MOVLW .100
	SUBWF C5rem,1
	BSF   0x03,Carry
m022	RLF   tmp1,1
	RLF   tmp1+1,1
	DECFSZ C3cnt,1
	GOTO  m020
			;			I2C_DAT		 = (char)tmp1;
	MOVF  tmp1,W
	MOVWF I2C_DAT
			;			I2C_ADR 	 = 0;
	CLRF  I2C_ADR
			;			break;
	GOTO  m030
			;		case 52 :
			;			I2C_BIT_RD 	= 1;							
m023	BSF   0x1A,I2C_BIT_RD
			;			if(I2C_NBYTE>1){				
	MOVLW .2
	SUBWF I2C_NBYTE,W
	BTFSS 0x03,Carry
	GOTO  m030
			;				t_off 		= I2C_DAT;
	MOVF  I2C_DAT,W
	MOVWF t_off
	CLRF  t_off+1
			;				t_off	    = t_off*100;	
	MOVF  t_off,W
	MOVWF C7tmp
	MOVF  t_off+1,W
	MOVWF C7tmp+1
	MOVLW .16
	MOVWF C6cnt
m024	BCF   0x03,Carry
	RLF   t_off,1
	RLF   t_off+1,1
	RLF   C7tmp,1
	RLF   C7tmp+1,1
	BTFSS 0x03,Carry
	GOTO  m025
	MOVLW .100
	ADDWF t_off,1
	BTFSC 0x03,Carry
	INCF  t_off+1,1
m025	DECFSZ C6cnt,1
	GOTO  m024
			;				I2C_ADR     = 0;
	CLRF  I2C_ADR
			;			}
			;			break;
	GOTO  m030
			;		case 53 :
			;			I2C_BIT_WR 	 = 1;	
m026	BSF   0x1A,I2C_BIT_WR
			;			uns16 tmp2	 = t_off/100;
	MOVF  t_off,W
	MOVWF C9tmp
	MOVF  t_off+1,W
	MOVWF C9tmp+1
	CLRF  C10rem
	MOVLW .16
	MOVWF C8cnt
m027	RLF   C9tmp,1
	RLF   C9tmp+1,1
	RLF   C10rem,1
	BTFSC 0x03,Carry
	GOTO  m028
	MOVLW .100
	SUBWF C10rem,W
	BTFSS 0x03,Carry
	GOTO  m029
m028	MOVLW .100
	SUBWF C10rem,1
	BSF   0x03,Carry
m029	RLF   tmp2,1
	RLF   tmp2+1,1
	DECFSZ C8cnt,1
	GOTO  m027
			;			I2C_DAT		 = (char)tmp2;
	MOVF  tmp2,W
	MOVWF I2C_DAT
			;			I2C_ADR 	 = 0;
	CLRF  I2C_ADR
			;			break;
			;	}	
			;	
			;	clrwdt();
m030	CLRWDT
			;}
	RETURN
			;
			;
			;void I2C_Slave_Check()
			;{
I2C_Slave_Check
			;	I2C_LAST_SCL = I2C_NEW_SCL;
	BCF   0x1A,I2C_LAST_SCL
	BTFSC 0x1A,I2C_NEW_SCL
	BSF   0x1A,I2C_LAST_SCL
			;	I2C_LAST_SDA = I2C_NEW_SDA;
	BCF   0x1A,I2C_LAST_SDA
	BTFSC 0x1A,I2C_NEW_SDA
	BSF   0x1A,I2C_LAST_SDA
			;	I2C_NEW_SCL  = SCL;
	BCF   0x1A,I2C_NEW_SCL
	BCF   0x03,RP0
	BTFSC 0x05,RA4
	BSF   0x1A,I2C_NEW_SCL
			;	I2C_NEW_SDA  = SDA;	
	BCF   0x1A,I2C_NEW_SDA
	BTFSC 0x05,RA3
	BSF   0x1A,I2C_NEW_SDA
			;
			;	if(I2C_BIT_ON){
	BTFSS 0x1A,I2C_BIT_ON
	GOTO  m034
			;		if(I2C_NEW_SCL!=I2C_LAST_SCL)	I2C_TIME = 0;
	BTFSC 0x1A,I2C_NEW_SCL
	GOTO  m031
	BTFSC 0x1A,I2C_LAST_SCL
	GOTO  m032
	GOTO  m033
m031	BTFSC 0x1A,I2C_LAST_SCL
	GOTO  m033
m032	CLRF  I2C_TIME
			;		else{
	GOTO  m034
			;				I2C_TIME++;
m033	INCF  I2C_TIME,1
			;				if(I2C_TIME==255)I2C_BIT_ON=0;
	INCF  I2C_TIME,W
	BTFSC 0x03,Zero_
	BCF   0x1A,I2C_BIT_ON
			;		}
			;	}	
			;
			;
			;	if(I2C_LAST_SCL == 1 && I2C_NEW_SCL == 1){					//start|stop condition		
m034	BTFSS 0x1A,I2C_LAST_SCL
	GOTO  m036
	BTFSS 0x1A,I2C_NEW_SCL
	GOTO  m036
			; 		if(I2C_LAST_SDA == 1 && I2C_NEW_SDA == 0){				//start condition			
	BTFSS 0x1A,I2C_LAST_SDA
	GOTO  m035
	BTFSC 0x1A,I2C_NEW_SDA
	GOTO  m035
			;			I2C_CLK 	= 0;
	CLRF  I2C_CLK
			;			I2C_DAT		= 0;
	CLRF  I2C_DAT
			;			I2C_NBYTE   = 0;
	CLRF  I2C_NBYTE
			;			I2C_BIT_ON 	= 1;
	BSF   0x1A,I2C_BIT_ON
			;			I2C_BIT_ADR	= 1;
	BSF   0x1A,I2C_BIT_ADR
			;			I2C_BIT_RD	= 1;
	BSF   0x1A,I2C_BIT_RD
			;			I2C_BIT_WR	= 0;			
	BCF   0x1A,I2C_BIT_WR
			;		}
			;		if(I2C_LAST_SDA == 0 && I2C_NEW_SDA == 1){				//stop condition
m035	BTFSC 0x1A,I2C_LAST_SDA
	GOTO  m036
	BTFSC 0x1A,I2C_NEW_SDA
			;			I2C_BIT_ON 		= 0;
	BCF   0x1A,I2C_BIT_ON
			;		}
			;	}
			;
			;	
			;	//Clock up
			;	if(I2C_BIT_ON && I2C_LAST_SCL == 0 && I2C_NEW_SCL == 1){	
m036	BTFSS 0x1A,I2C_BIT_ON
	GOTO  m040
	BTFSC 0x1A,I2C_LAST_SCL
	GOTO  m040
	BTFSS 0x1A,I2C_NEW_SCL
	GOTO  m040
			;		I2C_CLK++;
	INCF  I2C_CLK,1
			;
			;		//Read Data : Getting Data
			;		if(I2C_BIT_RD && I2C_CLK!=9)
	BTFSS 0x1A,I2C_BIT_RD
	GOTO  m039
	MOVF  I2C_CLK,W
	XORLW .9
	BTFSC 0x03,Zero_
	GOTO  m039
			;		{	
			;			if(I2C_CLK==1){I2C_DAT = 0;}
	DECF  I2C_CLK,W
	BTFSC 0x03,Zero_
	CLRF  I2C_DAT
			;
			;			if(SDA==1){
	BCF   0x03,RP0
	BTFSS 0x05,RA3
	GOTO  m039
			;				char tmp   = 8-I2C_CLK;
	MOVF  I2C_CLK,W
	SUBLW .8
	MOVWF tmp
			;				char tmp2  = 1<<tmp;
	MOVLW .1
	MOVWF tmp2_2
	MOVF  tmp,W
	BTFSC 0x03,Zero_
	GOTO  m038
	MOVWF C11cnt
m037	BCF   0x03,Carry
	RLF   tmp2_2,1
	DECFSZ C11cnt,1
	GOTO  m037
			;				I2C_DAT   += tmp2;
m038	MOVF  tmp2_2,W
	ADDWF I2C_DAT,1
			;			}
			;		}
			;		
			;		//Write data : waiting for ACK
			;		if(I2C_BIT_WR && I2C_CLK == 9){
m039	BTFSS 0x1A,I2C_BIT_WR
	GOTO  m040
	MOVF  I2C_CLK,W
	XORLW .9
	BTFSS 0x03,Zero_
	GOTO  m040
			;			I2C_BIT_ACK = !SDA;
	BSF   0x1B,I2C_BIT_ACK
	BCF   0x03,RP0
	BTFSC 0x05,RA3
	BCF   0x1B,I2C_BIT_ACK
			;			I2C_BIT_WR  = 0;
	BCF   0x1A,I2C_BIT_WR
			;		}
			;	}
			;		
			;	//Clock down
			;	if(I2C_BIT_ON && I2C_LAST_SCL == 1 && I2C_NEW_SCL == 0){		
m040	BTFSS 0x1A,I2C_BIT_ON
	GOTO  m046
	BTFSS 0x1A,I2C_LAST_SCL
	GOTO  m046
	BTFSC 0x1A,I2C_NEW_SCL
	GOTO  m046
			;
			;		//End of one Byte : Reset the Timer and Look for what is the next byte
			;		if(I2C_CLK==9){
	MOVF  I2C_CLK,W
	XORLW .9
	BTFSS 0x03,Zero_
	GOTO  m041
			;			I2C_CLK = 0;
	CLRF  I2C_CLK
			;			I2C_Slave_Action();
	CALL  I2C_Slave_Action
			;		}
			;
			;
			;		//Writing : Getting data
			;		if(I2C_BIT_WR){
m041	BTFSS 0x1A,I2C_BIT_WR
	GOTO  m045
			;			// Free the line for ACK
			;			if(I2C_CLK==8){				
	MOVF  I2C_CLK,W
	XORLW .8
	BTFSS 0x03,Zero_
	GOTO  m042
			;				TRISA.bitSDA = 1;			
	BSF   0x03,RP0
	BSF   TRISA,3
			;				return;
	RETURN
			;			}
			;
			;			TRISA.bitSDA = 0;			
m042	BSF   0x03,RP0
	BCF   TRISA,3
			;			char tmp    = 7-I2C_CLK;
	MOVF  I2C_CLK,W
	SUBLW .7
	MOVWF tmp_2
			;			char tmp2   = 1<<tmp;
	MOVLW .1
	MOVWF tmp2_3
	MOVF  tmp_2,W
	BTFSC 0x03,Zero_
	GOTO  m044
	MOVWF C12cnt
m043	BCF   0x03,Carry
	RLF   tmp2_3,1
	DECFSZ C12cnt,1
	GOTO  m043
			;				 tmp    = I2C_DAT & tmp2;
m044	MOVF  tmp2_3,W
	ANDWF I2C_DAT,W
	MOVWF tmp_2
			;			SDA 		= (tmp != 0);
	MOVF  tmp_2,W
	BCF   0x03,RP0
	BTFSS 0x03,Zero_
	BSF   0x05,RA3
	BTFSC 0x03,Zero_
	BCF   0x05,RA3
			;		}
			;
			;		//Reading : Send the ACK
			;		if(I2C_BIT_RD && I2C_CLK==8){
m045	BTFSS 0x1A,I2C_BIT_RD
	GOTO  m046
	MOVF  I2C_CLK,W
	XORLW .8
	BTFSS 0x03,Zero_
	GOTO  m046
			;	
			;			TRISA.bitSDA = 0;
	BSF   0x03,RP0
	BCF   TRISA,3
			;			SDA     	 = 0;						// Send the ACK			
	BCF   0x03,RP0
	BCF   0x05,RA3
			;
			;			if(I2C_BIT_ADR){				
	BTFSS 0x1A,I2C_BIT_ADR
	GOTO  m046
			;				I2C_ADR 	= I2C_DAT;				 
	MOVF  I2C_DAT,W
	MOVWF I2C_ADR
			;				I2C_BIT_ADR = 0;
	BCF   0x1A,I2C_BIT_ADR
			;				SDA     	= !I2C_Slave_PIC_Adress();	// Send the ACK
	CALL  I2C_Slave_PIC_Adress
	BTFSS 0x03,Carry
	BSF   0x05,RA3
	BTFSC 0x03,Carry
	BCF   0x05,RA3
			;			}				
			;		}
			;	}
			;
			;	clrwdt();
m046	CLRWDT
	RETURN

	END


; *** KEY INFO ***

; 0x013E  159 word(s) 15 % : I2C_Slave_Check
; 0x0004   64 word(s)  6 % : timer
; 0x0044   83 word(s)  8 % : main
; 0x0097   13 word(s)  1 % : I2C_Slave_Init
; 0x00A4   20 word(s)  1 % : I2C_Slave_PIC_Adress
; 0x00B8  134 word(s) 13 % : I2C_Slave_Action

; RAM usage: 27 bytes (14 local), 41 bytes free
; Maximum call level: 0 (+3 for interrupt)
; Total of 474 code words (46 %)
