LIST p=12F629 #include ; _CP_ON _CP_OFF Code protection ; _PWRTE_ON _PWRTE_OFF Timer reset sur power on ; _WDT_ON _WDT_OFF Watch-dog ; _LP_OSC _XT_OSC _HS_OSC _RC_OSC Oscillateur __CONFIG _MCLRE_OFF & _CP_OFF & _CPD_OFF & _WDT_ON &_BODEN_OFF & _INTRC_OSC_NOCLKOUT &_PWRTE_ON ;v1 Detection signal telecommande (RB0) ;v2 compression temps reel ;v3 : test majoration minoration avnt test bit precedent ;v4 Avec Watchdog ;Front montant descendant separer ;v5 Connection directe au pc (sans transistor adapteur de niveau) #DEFINE VERSION "5" movlf macro _L,_F movlw _L movwf _F endm movff macro _F1,_F2 movf _F1,W movwf _F2 endm #DEFINE TAILLE_MAX 38 ;(64-8) CBLOCK 0x20 ; 25 byte StartByte:TAILLE_MAX ;Local fonctions local1:1 local2:1 local3:1 local4:1 local6:1 local7:1 booleen:1 TailleCode:1 ENDC #DEFINE LED_STATUS GPIO,0 ;sortie #DEFINE TELEC GPIO,4 ;entre #DEFINE TELEC_GND GPIO,5 ;sortie #DEFINE TX_RS232 GPIO,2 ;sortie #DEFINE RX_RS232 GPIO,1 ;entre #DEFINE BitPrec booleen,1 #DEFINE BitPrecD booleen,2 #DEFINE TAILLEMINOCT 2 ;19 en hexa (dec:25) ;LOCAL FONCTION #DEFINE Tempo local1 #DEFINE Taille local1 #DEFINE TailleOctet local1 #DEFINE Tempo2 local2 #DEFINE DureeEnCours local2 #DEFINE NbrBit local3 #DEFINE Caractere local4 #DEFINE DureePrec local4 #DEFINE Minoration local6 #DEFINE FSR1 local6 #DEFINE DureePrecD local7 ;MACRO __c2c_rs232_delay macro LOCAL label_0010 movlw D'30' movwf Tempo2 label_0010 decfsz Tempo2, F goto label_0010 endm ;Compacter(in StartByte,in StartByte,in Taille,in static TempsMoyen,out TailleCmp) ;Compacter_8(in FSR,in static TempsMoyen,out CodeRed) ;Attente () ;Attend25us () ;Acquerir(in FSR,out Taille) ;TempsMoyen Recherchepetgr (in FSR,in Taille) ;CopieEeprom (in FSR,in Taille,in EEDATA) ; Bool CodeIdentique (in FSR1, in FSR2, in Taille) ;CopierCode (in FSR1,in FSR2,in Taille) ;EnvoiChaine (in FSR,in Taille) enoi en rs232 ;EnvoiChar (in W) ;ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ; ; DEBUT DU PROGRAMME ; ;_______________________________; org H'3FF' retlw H'94' org H'0' ;Vecteur de reset On_Reset BANKSEL OSCCAL call H'3FF' movwf OSCCAL BANKSEL GPIO clrf GPIO movlf H'07',CMCON BANKSEL TRISIO movlf B'11011010',TRISIO ; TX_RS232 sortie movlf B'11000100',OPTION_REG ;Prescaler 1:32 BANKSEL GPIO bcf INTCON,GIE bcf LED_STATUS bcf TELEC_GND bsf TX_RS232 movlw B'00011111' ;BANK 0 andwf FSR,F ;BANK 0 clrwdt movlw H'33' call EnvoiChar movlw D'16' call EnvoiChar movlw "T" call EnvoiChar movlw "e" call EnvoiChar movlw "l" call EnvoiChar movlw "e" call EnvoiChar movlw "c" call EnvoiChar movlw "o" call EnvoiChar movlw "m" call EnvoiChar movlw "m" call EnvoiChar movlw "a" call EnvoiChar movlw "n" call EnvoiChar movlw "d" call EnvoiChar movlw "e" call EnvoiChar movlw " " call EnvoiChar movlw "v" call EnvoiChar movlw VERSION call EnvoiChar movlw "x" call EnvoiChar Acquisition ;AQUISITION 1 bcf LED_STATUS movlf StartByte,FSR AttenFron clrwdt btfsc TELEC ; attent front montant 1 goto AttenFron bsf LED_STATUS call AcquerirCmp movff TailleOctet,TailleCode bcf LED_STATUS ; ;------ Test si code enier movlw TAILLEMINOCT subwf TailleCode,W ;TailleCode-TAILLEMIN_RC btfss STATUS,C ;C=1 positif continue prog goto Acquisition movlw H'33' ;StartChar call EnvoiChar movf TailleCode,W ;WidthChar call EnvoiChar movlf StartByte,FSR ;DataChars movff TailleCode,Taille call EnvoiChaine goto Acquisition ;Programme Terminé ;--------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------- Attend25us ;Attend25us () { incfsz Tempo,F goto Attend25us retlw 0 ; } Attente ;Attente () { incfsz Tempo,F goto Attente incf Tempo2,F clrwdt btfss Tempo2,7 goto Attente clrf Tempo2 retlw 0 ; } ;EnvoiChar (in W) EnvoiChar movwf FSR1 movlf 1,Taille movlf FSR1,FSR ;EnvoiChaine (in FSR,in Taille) EnvoiChaine movff INDF,Caractere movlw D'9' movwf NbrBit bsf TX_RS232 clrwdt nop BitSuiv clrwdt __c2c_rs232_delay nop nop decfsz NbrBit, F goto EnvoiBit bcf TX_RS232 __c2c_rs232_delay incf FSR,F decfsz Taille,F goto EnvoiChaine retlw 0 EnvoiBit nop nop rrf Caractere, F btfss STATUS, C goto Envoi0 bcf TX_RS232 goto BitSuiv Envoi0 nop nop bsf TX_RS232 goto BitSuiv ;RecoiChar () RecoiChar btfsc RX_RS232 goto RecoiChar goto RecoiCharIm RecoiCharIm movlw D'8' movwf NbrBit clrf Caractere movlw D'15' movwf Tempo2 RS_DELAY2 decfsz Tempo2, F goto RS_DELAY2 btfsc RX_RS232 return ;Erreur BitSuiva __c2c_rs232_delay rrf Caractere, F bcf Caractere, 7 btfsc RX_RS232 bsf Caractere, 7 decfsz NbrBit, F goto BitSuiva __c2c_rs232_delay movf Caractere, W return __c2c_getchar__end AcquerirCmp ;Acquerir(in FSR,out TailleOctet) { clrf TMR0 ;init timer clrf DureePrec clrf DureePrecD movlf 1,TailleOctet movlf 8,NbrBit bcf BitPrec ; bcf BitPrecD goto AttendFrontDescendant AttendFrontMontant clrwdt ;attent front montant n incf TMR0,W btfsc STATUS,Z ;test fin de code par Time out goto retourner_AcquerirCmp btfsc TELEC goto AttendFrontMontant movff TMR0,DureeEnCours clrf TMR0 call SauverCmpM movlw TAILLE_MAX-1 ;test fin de code par saturation memoire subwf TailleOctet, W btfsc STATUS, C ;if (FSR>63) goto fin goto retourner_AcquerirCmp AttendFrontDescendant clrwdt btfss TELEC ; attent front decendant n goto AttendFrontDescendant movff TMR0,DureeEnCours clrf TMR0 call SauverCmpD goto AttendFrontMontant retourner_AcquerirCmp movlw 8 subwf NbrBit,W btfss STATUS,Z retlw 0 FinirOctet bcf STATUS,C ;Finir l'octet avec des zeros rlf INDF,F decfsz NbrBit,F goto FinirOctet decf TailleOctet,F retlw 0 SauverCmpM ;SauverCmp(in FSR, ;goto Sauver2 ;Debug TestMajoration ;Bit Precedent = 0 bcf STATUS,C rrf DureePrec,W ;/2 movwf Minoration bcf STATUS,C rrf Minoration,F ;/4 movf Minoration,W btfsc STATUS,Z movlw 1 ; si DureePrec/4 = 0 alors on dit =1 addwf DureePrec,W ; W=DureePrec + 12.5% subwf DureeEnCours,W ; DureeEncours - W btfsc STATUS,C ;C=1 -> Resultat positif goto SetBit TestMinoration ;BitPrecedent = 1 bcf STATUS,C rrf DureePrec,W ;/2 movwf Minoration bcf STATUS,C rrf Minoration,F ;/4 bcf STATUS,C rrf Minoration,F ;/8 movf Minoration,W btfsc STATUS,Z movlw 1 ; si DureePrec/8 = 0 alors on dit =1 subwf DureePrec,W ; W=DureePrec - 12.5% subwf DureeEnCours,W ; DureeEncours - W btfsc STATUS,C ;C=1 -> Resultat positif goto GarderPrecedent btfss BitPrec goto SetBitsPrecs ClearBit bcf STATUS,C rlf INDF,F bcf BitPrec goto Retourner_SauverCmp GarderPrecedent btfss BitPrec goto ClearBit SetBit bsf STATUS,C rlf INDF,F bsf BitPrec Retourner_SauverCmp movff DureeEnCours,DureePrec decfsz NbrBit,F retlw 0 incf FSR,F clrf INDF movlf 8,NbrBit incf TailleOctet,F retlw 0 SetBitsPrecs movlw B'01010101' iorwf INDF,F goto ClearBit SauverCmpD ;SauverCmp(in FSR, ;goto Sauver2 ;Debug ;goto SauverCmpM TestMajorationD ;Bit Precedent = 0 bcf STATUS,C rrf DureePrecD,W ;/2 movwf Minoration bcf STATUS,C rrf Minoration,F ;/4 movf Minoration,W btfsc STATUS,Z movlw 1 ; si DureePrec/4 = 0 alors on dit =1 addwf DureePrecD,W ; W=DureePrec + 12.5% subwf DureeEnCours,W ; DureeEncours - W btfsc STATUS,C ;C=1 -> Resultat positif goto SetBitD TestMinorationdD ;BitPrecedent = 1 bcf STATUS,C rrf DureePrecD,W ;/2 movwf Minoration bcf STATUS,C rrf Minoration,F ;/4 bcf STATUS,C rrf Minoration,F ;/8 movf Minoration,W btfsc STATUS,Z movlw 1 ; si DureePrec/8 = 0 alors on dit =1 subwf DureePrecD,W ; W=DureePrec - 12.5% subwf DureeEnCours,W ; DureeEncours - W btfsc STATUS,C ;C=1 -> Resultat positif goto GarderPrecedentD btfss BitPrecD goto SetBitsPrecsD ClearBitD bcf STATUS,C rlf INDF,F bcf BitPrecD goto Retourner_SauverCmpD GarderPrecedentD btfss BitPrecD goto ClearBitD SetBitD bsf STATUS,C rlf INDF,F bsf BitPrecD Retourner_SauverCmpD movff DureeEnCours,DureePrecD decfsz NbrBit,F retlw 0 incf FSR,F clrf INDF movlf 8,NbrBit incf TailleOctet,F retlw 0 SetBitsPrecsD movlw B'10101010' iorwf INDF,F goto ClearBitD ; } END ; fin du programme