INTERRUPT:

asm {
			; switch vers diffrentes interrupts
			;-----------------------------------
	
			; Interruption rception TIMER 0
			; ----------------------------

INTTMR1
	bnk1
	BTFSS PIE1,TMR1IE
	goto Intrb0
	bnk0
	BTFSS PIR1,TMR1IF
	goto Intrb0
	BcF PIR1,TMR1IF
	movlw 255
	movwf tmr1l
	movlw 0x39
	movwf	tmr1h

	decf diz,f
	btfss status,z
	goto Nodiz
		movlw 100
		MOVWF DIZ
		incf sec,f
		bsf bits2,5
NoDiz
	movf timer1,w
	BTFSc	status,z
	goto  TMR1_SET

	decf timer1,f
	BTFSS	status,z
	goto  TMR1_SET
			; stop motor
	Bcf PORTC,0
	Bcf PORTC,1
	Bcf PORTC,2
	Bcf PORTC,3
	bcf portc,4 ; fin tir ,end fire
	bsf bits2,2 ; Next statement
	clrf moteur
TMR1_SET

Intrb0
	bnk0
	btfss	INTCON,INTF
	GOTO 	INTtmr0
	bcf	INTCON,INTF
	; mesure verouill
	btfsc bits2,4
	GOTO 	INTtmr0
	bnk1
	btfsc	OPTION_REG,INTEDG
	goto SetValue
	bsf	OPTION_REG,INTEDG
	bnk0
	bsf INTCON,T0IF
	bsf INTCON,T0IE
	clrf	TMR0
	clrf	balise
	bcf bits2,4
	goto  INTtmr0
SetValue
	bcf	OPTION_REG,INTEDG
	bnk0
	movf	TMR0,w
	movwf	balise
	bcf INTCON,T0IE
	bsf bits2,4

INTtmr0
	bnk0
	btfss	INTCON,T0IE
	GOTO 	intRB
	btfss	INTCON,T0IF
	GOTO 	intRB
;		============ TIMER 0 ============
	bcf	INTCON,T0IF

	movlw	128
	movwf	TMR0

;	BTFSS	bits,5
;	goto SetBit1
;	bcf bits,5
;	bcf portA,0
;	goto bitOk1
;SetBit1:
;	bsf bits,5
;	bsf portA,0
;bitOk1
	
			; Interruption rception USART
			; ----------------------------
intRB
	btfss	INTCON,RBIF
	GOTO 	intTmr2
	BCF	INTCON,RBIF
	bcf	PORTC,0
	bcf	PORTC,1
	bcf	PORTC,2
	bcf	PORTC,3
	clrf  Moteur
	movf PORTB,w
	movwf FSR
	sublw 255
	btfsc status,z
	goto NoMem
	movf FSR,w
	movwf StopIm
NoMem
	BCF INTCON,RBIE

intTmr2
	bnk1 
	btfss PIE1,TMR2IE
	GOTO 	intsw0
	bnk0

	btfss	PIR1,TMR2IF
	GOTO 	intsw0
	BCF	PIR1,TMR2IF

; test de 255 
	Movf	Vitesse,w
	addlw 1
	Btfsc	STATUS,Z
	goto PWMoff

	movf	MOTEUR,w
	Btfsc	STATUS,Z
	goto  PWMoff
	
PWMon
	BTFSS	BITS,4
	goto  PWML

; PWM partie haute
	bsf portA,0
	Movf	Vitesse,w
	bnk1
	Movwf	PR2
	bnk0

	movf	moteur,w
;	sublw	1
	movwf	35
	andlw	7
	MOVLW	#HIGH#SetMoteur    ; SEGMENT ADRESS 
	MOVWF	PCLATH  		;
	MOVLW	#LOW#SetMoteur     ; OFFSET ADRESS 
;	ADDLW	1       		;
	ADDWF	35,W    		; COMPUTE TARGET ADRESSE 
	BTFSC	STATUS,CY       ; SEE IF OVERFLOW 
	INCF	PCLATH,F        ;IF SO, INCREMENT PCLATH
	call	SetMoteur
	clrf	PCLATH

	BCF	BITS,4
	goto EndPWM	
PWMoff
	BCF	PIR1,TMR2IF
	bnk1 
	BCF PIE1,TMR2IE
	bnk0
PWML
	bcf portA,0
	BSF	BITS,4
	Movf	Vitesse2,w
	bnk1
	Movwf	PR2
	bnk0
	BCF	PORTC,0
	BCF	PORTC,1
	BCF	PORTC,2
	BCF	PORTC,3
EndPWM



intsw0
	bnk0
	btfss	PIR1,RCIF	; oui, tester si interrupt en cours
	GOTO 	intsw1		; non sauter
	bcf PIR1,RCIF	; acquit  reception 
	call	RX_INT_HANDLER  ; oui, traiter interrupt
	bnk0
	bcf PIR1,TXIF
			; Interruption transmission USART
			; -------------------------------
intsw1
	btfsc	PIR1,TXIF	; oui, tester si interrupt en cours
	call	TX_INT_HANDLER		; oui, traiter interrupt
			;restaurer registres
			;-------------------
restorereg
	movf	PCLATH_temp, w	; charger PCLATH sauv
	movwf	PCLATH		; restaurer PCLATH 
	movf	FSR_temp , w	; charger FSR sauv
	movwf	FSR		; restaurer FSR
	swapf	status_temp,w	; swap ancien status, rsultat dans w
	movwf   STATUS		; restaurer status
	swapf   w_temp,f	; Inversion L et H de l'ancien W
                       		; sans modifier Z
	swapf   w_temp,w  	; Rinversion de L et H dans W
				; W restaur sans modifier status
	retfie  		; return from interrupt
}
'

