;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; NOM: KLX1 (d'après "YouBiTonMatic en PIC" : ; http://www.ptitrain.com/electronique/microp/index.htm) ; Version: 1.0 ; Circuit: Veroboard ; Auteur: PSi, adaptation Patrice Ruffel ; ATTENTION : version pour 12F629 LIST p=PIC12F629 ; Définition de processeur #include ; Définitions des constantes errorlevel -302 __CONFIG _CPD_OFF & _BODEN_OFF & _CP_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _INTRC_OSC_NOCLKOUT ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; DECLARATIONS DE VARIABLES SPECIFIQUES CBLOCK 0x020 ; début de la zone des variables CPT_256 : 1 ; compteurs pour la durée de chaque son SAV_TMR1H : 1 ; sauvegarde valeur TMR1 poids fort SAV_TMR1L : 1 ; sauvegarde valeur TMR1 poids faible Delai_H : 1 ; Poids forts du delai Delai_L : 1 ; Poids faibles du delai ENDC ; Fin de la zone des variables #include <629.inc> ; paramétrage standard ; ensemble des paramètres (registres) ; pour une utilisation standard du PIC ; (pas de convertisseur, ni comparateur...) ; contient également des morceaux de ; programme standard ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; PARAMETRES SPECIFIQUES BANK1 clrf TRISIO ; port en sortie bsf TRISIO,5 ; sauf 5 pour déclenchement bsf TRISIO,4 ; et 4 pour déclenchement clrf WPU ; pas de résistances de rappel sauf bsf WPU,5 ; résistance de rappel sur le port 5 bsf WPU,4 ; résistance de rappel sur le port 4 ; registre controle interruptions INTCON BANK0 et 1 clrf INTCON bsf INTCON,GIE ; interruptions activées en permanence bsf INTCON,PEIE ; autorise interruption périphériques (notamment timer 1) ; registre interruptions périphériques clrf PIE1 bsf PIE1,TMR1IE ; autorise les interruptions Timer1 BANK0 bcf GPIO,1 ; sortie à 0 ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; Boucle principale Etat54a00 btfsc GPIO,5 ; attente déclenchement goto Test4a1 call SON_Tii ; appel des sons call SON_Tii call SON_Taa call SON_Taa call SON_Taa call SON_Taa call SON_Tii goto Etat54a10 Test4a1 btfsc GPIO,4 ; attente déclenchement goto Etat54a00 call SON_Tii ; appel des sons call SON_Taa goto Etat54a01 Etat54a10 btfss GPIO,5 ; attente déclenchement goto Test4a1bis call Delai_Confirmation btfss GPIO,5 ; attente déclenchement goto Test4a1bis call SON_Tii ; appel des sons call SON_Taa call SON_Tii call SON_Taa call SON_Taa call SON_Taa call SON_Taa goto Etat54a00 Test4a1bis btfsc GPIO,4 ; attente déclenchement goto Etat54a10 call SON_Taa ; appel des sons call SON_Tii goto Etat54a11 Etat54a01 btfsc GPIO,5 ; attente déclenchement goto Test4a0 call SON_Taa ; appel des sons call SON_Taa call SON_Tii call SON_Taa call SON_Taa call SON_Taa call SON_Taa call SON_Taa call SON_Tii goto Etat54a11 Test4a0 btfss GPIO,4 ; attente déclenchement goto Etat54a01 call Delai_Confirmation btfss GPIO,4 ; attente déclenchement goto Etat54a01 call SON_Taa ; appel des sons goto Etat54a00 Etat54a11 btfss GPIO,5 ; attente déclenchement goto Test4a0bis call Delai_Confirmation btfss GPIO,5 ; attente déclenchement goto Test4a0bis call SON_Taa ; appel des sons call SON_Taa call SON_Tii call SON_Tii call SON_Tii call SON_Tii call SON_Tii call SON_Tii call SON_Taa goto Etat54a01 Test4a0bis btfss GPIO,4 ; attente déclenchement goto Etat54a11 call Delai_Confirmation btfss GPIO,4 ; attente déclenchement goto Etat54a11 call SON_Tii ; appel des sons goto Etat54a10 ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; Sous programmes ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; ; Délai de confirmation état 1 Delai_Confirmation ; 100 ms movlw d'39' ; valeur poids forts du delai movwf Delai_H ; sauvegarde movlw d'16' ; valeur poids faibles du delai movwf Delai_L ; sauvegarde Boucle_delai nop ; boucle de 10 µs nop ; soit 9 NOP nop nop nop nop nop nop nop decfsz Delai_L,f ; décrément poids faibles, test à 0 goto Boucle_delai ; cas non 0 ; cas à 0 ; movlw d'255' ; poids faibles du delai remis à 255 ; movwf Delai_L ; sauvegarde decfsz Delai_H,f ; décrément poids forts, test à 0 goto Boucle_delai ; cas non 0 Boucle_pf nop ; boucle de 10 µs nop ; soit 9 NOP nop nop nop nop nop nop nop decfsz Delai_L,f ; décrément poids faibles, test à 0 goto Boucle_pf ; cas non 0 return ; cas 0 ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; ; son Tii, 660 Hz SON_Tii movlw d'253' ; valeur poids fort du timer movwf SAV_TMR1H ; sauvegarde movwf TMR1H ; chargement timer poids fort movlw d'27' ; valeur poids faibledu timer movwf SAV_TMR1L ; sauvegarde movwf TMR1L ; chargement timer poids faible bsf T1CON, TMR1ON ; lancement du timer movlw d'255' ; chargement compteur durée movwf CPT_256 boucle_Tii btfsc T1CON, TMR1ON ; test fin durée (=timer arreté) goto boucle_Tii ; attente fin durée return ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; ; son Taa, 370 Hz SON_Taa movlw d'250' movwf SAV_TMR1H movwf TMR1H movlw d'201' movwf SAV_TMR1L movwf TMR1L bsf T1CON, TMR1ON movlw d'255' movwf CPT_256 boucle_Taa btfsc T1CON, TMR1ON goto boucle_Taa return ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; interruption TMR1 ; appelée à chaque interruption TMR1 inttimer1 bcf T1CON, TMR1ON ; arret timer movfw SAV_TMR1H ; chargement timer poids fort movwf TMR1H movfw SAV_TMR1L ; chargement timer poids faible movwf TMR1L movlw b'00000010' ; inversion sortie xorwf GPIO,f decfsz CPT_256,f ; décrément compteur durée bsf T1CON, TMR1ON ; relancer timer return ;÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ ; interruption TMR0 ; appelée à chaque interruption TMR0 inttimer0 return END