Program N : ;************************************ ; written by : John Morton * ; date : 25/08/97 * ; version : 1.0 * ; file saved as : TempSense * ; for PIC71 * ; clock frequency : 2.47 MHz * ;************************************ ; PROGRAM FUNCTION : To detect whether bath water temperature is too cold, o.k., or ; too hot. list P=16C71 include "c:\pic\p16c71.inc" ;============ ; Declarations : porta equ 05 portb equ 06 org 0 goto Start ;=========== ; Subroutines : Init clrf porta ; resets input/output ports clrf portb goto InitContinue ; skips address 0004 goto isr ; at address 0004, goes to isr InitContinue bsf STATUS, 5 ; selects bank 1 movlw b'00001' ; RA0 : temperature sensor, movwf TRISA ; RA1- 4 : not connected clrf TRISB ; RB0 - 2 : LEDs, RB3 - 7 : not connected movlw b'00000010' ; sets up ADCON1 : RA0 and RA1 as analogue movwf ADCON1 ; inputs, Vref is the supply voltage movlw b'00000111' ; sets up timing register movwf OPTION_REG ; TMR0 prescaled at 256 bcf STATUS, 5 ; goes back to bank 0 movlw b'01000001' ; sets up A/D register : movwf ADCON0 ; clock : Fosc/8, channel : AN0, converter is on movlw b'11000000' ; sets up interrupts register : movwf INTCON ; global and A/D interrupts enabled return ; returns from the subroutine isr bcf ADCON0, 1 ; resets A/D interrupt flag movlw d'18' ; compares result with the decimal number 18 subwf ADRES, w ; without affecting ADRES btfss STATUS, C ; goto Cold ; less than 18, so too cold movlw d'23' ; compares result with the decimal number 23 subwf ADRES, w ; without affecting ADRES btfss STATUS, C ; goto Ok ; less than 23, so o.k. goto Hot ; more than 23, so hot Cold movlw b'00000001' ; turns on cold LED (others off) movwf portb ; retfie ; returns, enabling global interrupt Ok movlw b'00000010' ; turns o.k. LED (others off) movwf portb ; retfie ; returns, enabling global interrupt Hot movlw b'00000100' ; turns on hot LED (others off) movwf portb ; retfie ; returns, enabling global interrupt ;============= ; Program Start : Start call Init ; sets everything up Main bsf ADCON0, 2 ; starts A/D conversion goto Main ; keeps looping until interrupted END