PROGRAM P ;*************************************** ; written by: John Morton * ; date: 14/03/05 * ; version: 1.0 * ; file saved as: tempsense.asm * ; for PIC12F675 * ; clock frequency: Int. 4 MHz * ; *************************************** ; Program Description: Bath temperature measuring device list P=12F675 include "c:\pic\p12f675.inc" ;============== ; Declarations: W_temp equ 20h STATUS_temp equ 21h org 0 ; first instruction to be executed goto Start ; org 4 ; interrupt service routine goto isr ; ;=========== ; Subroutines: Init bsf STATUS, RP0 ; goes to Bank 1 call 3FFh ; calls calibration address movwf OSCCAL ; moves w. reg into OSCCAL movlw b'010000' ; GP0-2 are LEDs, GP4 analogue movwf TRISIO ; input clrf WPU ; weak pull-ups disabled movlw b'10000000' ; weak pull-ups disabled, no timer movwf OPTION_REG ; used movlw b'01000000' ; enables A/D interrupt movwf PIE1 ; clrf IOC ; disables GPIO change int. clrf VRCON ; turns off comparator V. ref. movlw b'00011000' ; A/D clock: Fosc/8 = 2µs; AN3/GP4 movwf ANSEL ; is anal. input, others are digital bcf STATUS, RP0 ; back to Bank 0 clrf GPIO ; resets input/output port movlw b'01000000' ; enables peripheral interrupts movwf INTCON ; movlw b'00000111' ; turns off comparator movwf CMCON ; clrf T1CON ; turns off TMR1 movlw b'00001101' ; Turns on ADC, selects AN3, movwf ADCON0 ; relative to VDD, left-justified retfie ; isr movwf W_temp ; stores w.reg in temp register movfw STATUS ; stores STATUS in temporary movwf STATUS_temp ; register bcf STATUS, RP0 ; goes to Bank 0 bcf PIR1, 6 ; clears A/D interrupt flag bsf STATUS, RP0 ; goes to Bank 1 movlw 0x80 ; subtracts lower byte subwf ADRESL, w ; comf STATUS, w ; inverts carry flag (bit 0 of STATUS) andlw b'00000001' ; masks all other bits bcf STATUS, RP0 ; goes to Bank 0 addlw 0x12 ; add this to the number we are subwf ADRESH, w ; subtracting from the higher byt4 btfss STATUS, C ; goto Cold ; ADRESH:L < 0x1280, so Òcold!Ó bsf STATUS, RP0 ; goes to Bank 1 movlw 0x80 ; subtracts lower byte subwf ADRESL, w ; comf STATUS, w ; inverts carry flag (bit 0 of STATUS) andlw b'00000001' ; masks all other bits bcf STATUS, RP0 ; goes to Bank 0 addlw 0x15 ; add this to the number we are subwf ADRESH, w ; subtracting from the higher byt btfss STATUS, C ; goto OK ; ADRESH:L < 0x1580, so OK goto Hot ; ADRESH:L = 0x1580, so Hot! Cold movlw b'000001' ; turns on ÔcoldÕ LED movwf GPIO ; goto prereturn ; OK movlw b'000010' ; turn on ÔOKÕ LED movwf GPIO ; goto prereturn ; Hot movlw b'000100' ; turn on ÔHotÕ LED movwf GPIO ; goto prereturn ; prereturn movfw STATUS_temp ; restores STATUS register to movwf STATUS ; original value swapf W_temp, f ; restores working register to swapf W_temp, w ; original value retfie ; returns, enabling GIE ;============ ; Program Start Start call Init ; sets everything up Main bsf ADCON0, 1 ; start A/D conversion goto Main ; END