list p=pic16c74 __config h'3ffa' ;HS crystal, 20Mhz include ; temp equ 0x20 target equ 0x21 ;target temp value to trigger relay targdly equ 0x22 ;used to pause display when setting target flag equ 0x23 cntr equ 0x24 ; org 0 ;reset vector goto start ;go to beginning of program on reset ; org 4 btfsc PIR1,TMR1IF ;timer 1 overflowed? goto timer1 retfie ; start movlw 0xbf ;'-' segment value movwf PORTB ;set output movwf PORTD ;latches to initial value clrf PORTA ;clear port a latches bsf STATUS,RP0 ;select register bank 1 clrf PIE1 ;disable all peripheral interrupts bsf TRISC,0 ;RC0 needs to be input for osc to function bsf PIE1,TMR1IE ;enable TMR1 int movlw b'00000011' ;RA0=A/D input, RA1=A/D input, RA2=Relay output movwf TRISA ;porta all input/analog clrf TRISB ;PORTB/PORTD output to 7-segment LEDs clrf TRISD movlw 0x04 ;RA0 and RA1 Analog, RA2 Digital, Vref=Vdd movwf ADCON1 ;set bcf STATUS,RP0 ;select register bank 0 bcf T1CON,TMR1ON ;timer 1 not on movlw 0x80 ;TIM1H:TIM1L = 0x8000 = 1sec movwf TMR1H clrf TMR1L clrf INTCON ;disable all interrupts clrf PIR1 ;clear all falgs movlw 0x0e ;T1CKPS1 (Prescale) = 1, T1OSCEN (osc shutoff) = enabled movwf T1CON ;T1SYNC (ext clk input) = no sync, TMR1CS = external bsf INTCON,PEIE ;enable peripheral interrupts bsf INTCON,GIE ;enable global ints call getAD1 ;get target temp value movwf target ;save for compare clrf targdly ;clear target display counter clrf flag ;to tell which a/d to perform, RA0 or RA1 bsf T1CON,TMR1ON ;turn timer on sleep goto $-1 ; timer1 bcf PIR1,TMR1IF ;clear flag bcf INTCON,GIE ;disable all ints movlw 0x01 ;halfadd value xorwf flag,1 ;compute operation to perform movf flag,0 addwf PCL,1 ;go to proper routine goto trgsamp goto temsamp trgsamp call getAD1 ;get target value movwf temp subwf target,0 ;check it btfsc STATUS,Z ;zero set if equal, same target goto timerx movf temp,0 ;get new target value movwf target movlw 0x01 movwf flag ;do trigger sample next go around also goto dispit temsamp call getAD0 ;get RA0 thermister value movwf temp subwf target,0 btfss STATUS,C bsf PORTA,2 ;trigger relay, temp has reached goal dispit movlw .186 subwf temp,0 ;end of table values btfsc STATUS,C goto valerr ;error, value out of range movlw .98 ;base of table values subwf temp,0 btfss STATUS,C ;if carry clear then goto valerr ;error, value out of range call temptab ;convert to temp setleds movwf temp andlw 0x0f call ledtab movwf PORTB swapf temp,0 andlw 0x0f call ledtab movwf PORTD timerx bcf PIR1,TMR1IF ;clear flag movlw 0x80 movwf TMR1H clrf TMR1L retfie ;enable ints and return to sleep valerr movlw 0xaa ;0x0a is disp in ledtab to special out of range value goto setleds getAD0 movlw b'10000001' ;fosc/32, chan0 (RA0), ADON adconv movwf ADCON0 clrf cntr decfsz cntr,1 goto $-1 clrf cntr decfsz cntr,1 goto $-1 bsf ADCON0,GO btfsc ADCON0,NOT_DONE ;check if A/D complete goto $-1 movf ADRES,0 clrf ADCON0 ;clear reg and shutdown AD logic return getAD1 movlw b'10001101' ;fosc/32, chan1 (RA1), GO, ADON goto adconv ; ; 7-segment conversion ; ledtab addwf PCL,1 retlw 0xc0 ;0 retlw 0xfc ;1 retlw 0x92 ;2 retlw 0x98 ;3 retlw 0xac ;4 retlw 0x89 ;5 retlw 0x81 ;6 retlw 0xdc ;7 retlw 0x80 ;8 retlw 0x8c ;9 retlw 0xbf ;- ; ;tempature table ; temptab addwf PCL,1 retlw 0x99 ;98 retlw 0x98 ;99 retlw 0x98 ;100 retlw 0x97 ;101 retlw 0x96 ;102 retlw 0x95 ;103 retlw 0x94 ;104 retlw 0x93 ;105 retlw 0x93 ;106 retlw 0x92 ;107 retlw 0x91 ;108 retlw 0x90 ;109 retlw 0x89 ;110 retlw 0x89 ;111 retlw 0x88 ;112 retlw 0x87 ;113 retlw 0x86 ;114 retlw 0x86 ;115 retlw 0x85 ;116 retlw 0x85 ;117 retlw 0x84 ;118 retlw 0x83 ;119 retlw 0x82 ;120 retlw 0x81 ;121 retlw 0x80 ;122 retlw 0x80 ;123 retlw 0x79 ;124 retlw 0x78 ;125 retlw 0x78 ;126 retlw 0x77 ;127 retlw 0x76 ;128 retlw 0x76 ;129 retlw 0x75 ;130 retlw 0x74 ;131 retlw 0x73 ;132 retlw 0x72 ;133 retlw 0x71 ;134 retlw 0x70 ;135 retlw 0x70 ;136 retlw 0x69 ;137 retlw 0x69 ;138 retlw 0x68 ;139 retlw 0x67 ;140 retlw 0x67 ;141 retlw 0x66 ;142 retlw 0x65 ;143 retlw 0x64 ;144 retlw 0x63 ;145 retlw 0x62 ;146 retlw 0x62 ;147 retlw 0x61 ;148 retlw 0x60 ;149 retlw 0x59 ;150 retlw 0x59 ;151 retlw 0x58 ;152 retlw 0x58 ;153 retlw 0x57 ;154 retlw 0x56 ;155 retlw 0x55 ;156 retlw 0x54 ;157 retlw 0x53 ;158 retlw 0x53 ;159 retlw 0x52 ;160 retlw 0x51 ;161 retlw 0x51 ;162 retlw 0x50 ;163 retlw 0x49 ;164 retlw 0x49 ;165 retlw 0x48 ;166 retlw 0x47 ;167 retlw 0x46 ;168 retlw 0x45 ;169 retlw 0x44 ;170 retlw 0x44 ;171 retlw 0x43 ;172 retlw 0x42 ;173 retlw 0x41 ;174 retlw 0x40 ;175 retlw 0x39 ;176 retlw 0x39 ;177 retlw 0x38 ;178 retlw 0x37 ;179 retlw 0x37 ;180 retlw 0x36 ;181 retlw 0x35 ;182 retlw 0x34 ;183 retlw 0x33 ;184 retlw 0x32 ;185 retlw 0x32 ;186 end