list p=12f675 ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ;***** VARIABLE DEFINITIONS ; Accessible depuis les 2 banques sur 12f675 w_temp EQU 0x20 ; variable used for context saving status_temp EQU 0x21 ; variable used for context saving l_tmp equ 0x22 l_tmp1 equ 0x23 l_tmp2 equ 0x24 l_tmp3 equ 0x25 sub_tmp equ 0x26 sub_tmp2 equ 0x27 sub_tmp3 equ 0x28 data_tmp equ 0x29 data_cnt equ 0x2a tempL equ 0x2b tempH equ 0x2c tmp equ 0x2d sleep_cnt equ 0x2e TX equ 0 ALIM_TX equ 5 DS equ 2 ALIM_DS equ 4 ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt main movlw 0x70 bsf STATUS, RP0 movwf OSCCAL movlw B'11111111' movwf OPTION_REG ; Prescaler WDT 1:128 (~2.8s) bcf STATUS, RP0 ; remaining code goes here clrf STATUS clrf GPIO movlw 0x07 movwf CMCON bsf STATUS, RP0 clrf ANSEL movlw B'001110' movwf TRISIO bcf STATUS, RP0 loop: clrf sleep_cnt bsf GPIO, ALIM_DS call wait_100ms call OneWire_Reset movlw 0xcc ; Commande Skip Rom call OneWire_SendByte movlw 0x44 ; Fonction Convert T call OneWire_SendByte ; call wait_1s sleep call OneWire_Reset movlw 0xcc call OneWire_SendByte movlw 0xbe ; Fonction Read Scratchpad call OneWire_SendByte call OneWire_ReadByte movf data_tmp, W movwf tempL call OneWire_ReadByte movf data_tmp, W movwf tempH call OneWire_Reset bcf GPIO, ALIM_DS bsf GPIO, ALIM_TX call wait_100ms movlw .10 movwf tmp tx_loop: call send_space movlw B'10101010' ; Marqueur call send_byte movlw 0x01 ; Adresse du capteur call send_byte movf tempH, W call send_byte movf tempL, W call send_byte decfsz tmp, F goto tx_loop bcf GPIO, ALIM_TX clrf GPIO sleep_loop ; Boucle d'économie d'énergie sleep incf sleep_cnt movlw .100 ; entre 200 et 300s subwf sleep_cnt, W btfss STATUS, Z goto sleep_loop goto loop ;******************************* SOUS-ROUTINES ********** W1_HiZ: MACRO bsf STATUS, RP0 bsf TRISIO, DS bcf STATUS, RP0 ENDM W1_Low: MACRO bcf STATUS,RP0 bcf GPIO, DS bsf STATUS, RP0 bcf TRISIO, DS bcf STATUS, RP0 ENDM wait: MACRO time movlw (time/5)-1 movwf l_tmp1 call wait_5us ENDM wait_5us: nop nop decfsz l_tmp1, F goto wait_5us retlw 0 OneWire_Reset: ; reset = état bas pour > 480us W1_HiZ clrf data_tmp W1_Low wait .500 W1_HiZ wait .100 btfss GPIO, DS incf data_tmp, F ; Si device présent wait .400 retlw 0 OneWire_SendByte: movwf data_tmp movlw .8 movwf data_cnt owsbl: W1_Low nop nop nop nop nop rrf data_tmp, F btfsc STATUS, C bsf GPIO, DS wait .60 W1_HiZ nop nop decfsz data_cnt, F goto owsbl retlw 0 OneWire_ReadByte clrf data_tmp movlw .8 movwf data_cnt owrbl: W1_Low nop nop nop nop nop nop W1_HiZ nop nop nop nop movf GPIO, W andlw 1<