;******************************************************** ; FICHIER........: Clignotant ; AUTEUR ........: S. Lichtenberger ; DESCRIPTION ...: Clignotant progammable ; NOTES .........: ; COPYRIGHT .....: S. Lichtenberger ; Version .......: 10/04/2008 ;******************************************************** PROCESSOR PIC12F675 INCLUDE __config _MCLRE_OFF & _CP_OFF & _INTRC_OSC_NOCLKOUT & _WDT_OFF & _BODEN_ON ; Définition GPIO et TRIS InPulse EQU 4 ; Entrée Pulse Option1 EQU 0 ; Led allumée en permanence (test) OutLed EQU 2 TrisBits EQU B'011011' OptionBits EQU B'00000000' ; Pull up ON #DEFINE Page0 Bcf STATUS,5 #DEFINE Page1 Bsf STATUS,5 #DEFINE LedON bsf GPIO,OutLed #DEFINE LedOFF bcf GPIO,OutLed org 0x20 AdresseTempsON EQU 0 AdresseTempsOFF EQU 1 ValeurPulse RES 1 ; Résultat de LecturePulse (Pules N) TempsON RES 1 TempsOFF RES 1 DelaiON RES 1 DelaiOFF RES 1 Delay RES 1 X_Delay RES 1 NbDel1 RES 1 WriteDataEE RES 1 ; Valeur à écrire en EEPROM Compteur ; ========================================================================= ; Départ Coldstart: ORG 0 page1 call 0x3FF movwf OSCCAL ; Init Oscal pour 4 MHz movlw OptionBits movwf OPTION_REG movlw Trisbits movwf TRISIO movlw b'00000000' movwf ANSEL ; AN3 selecté en analogique page0 movlw b'00000111' movwf CMCON movlw b'00110000' ; Validation timer 1 movwf T1CON clrf GPIO ; Prog Sortie à 0 call Tempo500ms ; Fin des initialisations Main: btfsc GPIO,Option1 ; Mode test, led allumée goto ModeClignotant LedON goto Main ModeClignotant: movlw b'00110001' ; Validation timer 1 movwf T1CON clrf TMR1L clrf TMR1H TestPulse: btfss GPIO,InPulse goto Programmer btfss PIR1,TMR1IF goto TestPulse ; attente entrée basse ou IRQ nop bcf PIR1,TMR1IF goto Clignoter Programmer: ; On a un signal, durée dans ValeurPulse call LecturePulse movfw ValeurPulse movwf TempsON movlw 0x30 subwf TempsON,F movfw TempsON movwf WriteDataEE movlw 0 call EE_Write ; Pour le OFF movlw 5 call ClignoterWfois call LecturePulse movfw ValeurPulse movwf TempsOFF movlw 0x30 subwf TempsOFF,W movwf TempsOFF movwf WriteDataEE movlw 1 call EE_Write goto TemposSet Clignoter: ; lire les données et aller en clignotement continu movlw 0 ; adresse ON call EE_READ movwf TempsON movlw 1 ; adresse OFF call EE_READ movwf TempsOFF TemposSet: ; Lecture des données, initialisation des tempos BclClignotement: movfw TempsON movwf DelaiON movfw TempsOFF movwf DelaiOFF LedON BclON: call Tempo100ms decfsz DelaiON goto BclON LedOFF BclOff: call Tempo100ms decfsz DelaiOFF goto BclOFF goto BclClignotement LecturePulse: AtFinDuPulse: btfss GPIO,InPulse goto AtFinDuPulse ; attente entrée basse AtPulseH: btfss GPIO,InPulse goto AtPulseH ; attente entrée haute movlw 0xC0 movwf TMR1L movlw 0xFF movwf TMR1H AtFinPulse: btfsc GPIO,InPulse goto AtFinPulse ; attente entrée basse movfw TMR1L movwf ValeurPulse return ; le pulse vaut ValeurPulse *8 µs ClignoterWfois: movwf Compteur BclClignoterWfois: LedON call Tempo500ms LedOFF call Tempo500ms decfsz Compteur goto BclClignoterWfois return ;================================== ; Delais divers ; 500µs DELAY500: MOVLW D'100' MOVWF DELAY DELAY500_LOOP: DECFSZ DELAY, F GOTO DELAY500_LOOP RETURN ; Tempo W fois 500µs X_DELAY500: MOVWF X_DELAY X_DELAY500_LOOP: CALL DELAY500 DECFSZ X_DELAY, F GOTO X_DELAY500_LOOP RETURN Tempo50ms: movlw 100 goto X_DELAY500 Tempo100ms: movlw 20 goto X_DELAY500 Tempo250ms: movlw 2 movwf NbDel1 goto T500Loop Tempo500ms: movlw 4 movwf NbDel1 T500Loop: call Tempo50ms decfsz NbDel1 goto T500Loop return ;================================== ; Lecture d'une donnée en EEPROM ; En entrée, W=adress ; En sortie, W=donnée lue EE_Read: Page1 movwf EEADR bsf EECON1,RD movfw EEDATA goto ExitEE ;================================== ; Ecriture d'une donnée en EEPROM ; En entrée, W contient l'adresse ; La donnée est dans WriteDataEE EE_Write: ; bcf INTCON,GIE ; Interdit les IRQ Page1 ; Bank = 1 Movwf EEADR ; Ecriture de l'adresse Page0 Movfw WriteDataEE ; Lecture de la donnée Page1 MOVWF EEDATA ; Ecriture de la donnée BSF EECON1,WREN MOVLW 0x55 ;55h MOVWF EECON2 MOVLW 0xAA ;AAh MOVWF EECON2 BSF EECON1,WR AttenteFinEcriture: BTFSC EECON1,WR GOTO AttenteFinEcriture BCF EECON1,WREN ExitEE: Page0 ; bsf INTCON,GIE ; Autorise les IRQ nop RETURN DE "Clignotant - S. Lichtenberger - Version 10/04/08" ;================================================ ORG 0x3FF SetOSCAL: retlw 0x2C ;db 0x34,0x2C ; Valeur OSCAL - A lire pour chaque Proc avant son effacement. END