Thursday, July 24, 2014

LM35 THERMOMETER USING PIC16F88

Dear all,

A simple thermometer using PIC16F88 and LM35.

Here we are  using TWO common anode 7 segment display for the OUTPUT indication.

The two 7 segment displays are multiplexed. Switching of the displays are happening with the help of two BC547 transistor. 
Lm35 sensor is connected to the AN1(18 th pin of IC). 
The connections of the seven segment display is shown in the below fig.




ASM code :
    LIST  P=16F88
    #INCLUDE <P16F88.INC>
  
    CBLOCK  0X30
    COUNT
    COUNT4
        COUNT6
        COUNT3
        D1
        RES1
          RES2
        RES3
        RES4
        A1
        A2
        B1
        B2
        NEG_FLAG
        SHIFTH
        SHIFTM
        SHIFTL
        BCOUNT
        NRATORH 
        NRATORM
        NRATORL
        DENOMH
        DENOMM
        DENOML
        REMAINH
        REMAINM
        REMAINL
        LOWBYTE
        HIGHBYTE
        HUNS
        TENS
        ONES
        ENDC
       
       
        ORG   0X0000
        NOP
        NOP
        NOP
        NOP
       
        CLRF   PORTA
        CLRF   PORTB
        BSF   STATUS,RP0    ; SELECT BANK 1
        BCF   STATUS,RP1
        BSF   OSCCON,6      ; SETUP THE INTERNAL OSCILLATOR  
        BSF   OSCCON,5      ; TO USE 4MHZ 
        MOVLW   H'07'         ; TURN OFF THE COMPARATORS
        MOVWF   CMCON  
        MOVLW   B'00000011'    
        MOVWF   TRISA
        MOVLW   B'00000000'   
        MOVWF   TRISB
        MOVLW   B'00000011'  
        MOVWF   ANSEL
        BCF   STATUS,RP0    ; SELECT BANK 0
        BCF   STATUS,RP1
        GOTO   START
        
         
      
        
ADC_INITIALISE
        BCF   STATUS,RP0    ; SELECT BANK 0
        BCF   STATUS,RP1
        BCF   ADCON0,GO      
        BCF   ADCON0,ADCS1   ; SELECTING THE FOSC FOR THE A/D
        BSF   ADCON0,ADCS0   ; HERE WE HAVE SELECTED FOSC/16
        BCF   ADCON0,CHS2    
        BCF   ADCON0,CHS1    
        BSF   ADCON0,CHS0  
      
        BSF   STATUS,RP0    ; SELECT BANK 1
        BCF   STATUS,RP1
        BCF   ADCON1,ADFM    
        BSF   ADCON1,ADCS2   
        BCF   ADCON1,VCFG1   ; SELECT THE SOURCE OF THE VREF
        BCF   ADCON1,VCFG0   
      
        BCF   STATUS,RP0    ; SELECT BANK 0
        BCF   STATUS,RP1
        BSF   ADCON0,ADON    ; TURN ON THE A/D MODULE
      
      ;  CALL   DELAY         ; WAIT FOR THE AQUISTION TIME
        BSF       ADCON0,GO      
      ;  CALL   DELAY         ; WAIT FOR SOME TIME
    
HERE            BTFSC   ADCON0,GO      
        GOTO   HERE       
        MOVF   ADRESH,0     
        MOVWF   LOWBYTE
        CLRF     HIGHBYTE   
        RETURN
      
MULTIPLY:
        CLRF      RES4
        CLRF   RES3
        CLRF      RES2
        MOVLW   0X80
        MOVWF   RES1  
      
        CLRF   NEG_FLAG
    
        BTFSS     A2,7
        GOTO      A_POS
        COMF      A2,F
        COMF   A1,F
        INCF   A1,F
        BTFSC   STATUS, Z
        INCF      A2,F
        INCF   NEG_FLAG, F
A_POS
        BTFSS     B2,7
        GOTO      NEXTBIT
        COMF      B2,F
        COMF      B1,F 
        INCF      B1,F 
        BTFSC     STATUS, Z
        INCF      B2,F
        INCF   NEG_FLAG, F
NEXTBIT
        RRF   A2,F
        RRF   A1,F
       
        BTFSS   STATUS, C
        GOTO   NOBIT_L
        MOVF   B1,W
        ADDWF   RES2,F
       
        MOVF   B2, W
        BTFSC   STATUS, C
        INCFSZ   B2, W 
        ADDWF   RES3, F 
        BTFSC   STATUS, C
        INCF   RES4, F
        BCF   STATUS, C
NOBIT_L 
        BTFSS   A1, 7
        GOTO   NOBIT_H
        MOVF   B1,W
        ADDWF   RES3,F
        BTFSC   STATUS, C
        INCF   RES4,F
        MOVF   B2,W  
        ADDWF   RES4,F
NOBIT_H
        RRF   RES4,F
        RRF   RES3,F
        RRF   RES2,F
        RRF   RES1,F
       
        BTFSS     STATUS, C
        GOTO   NEXTBIT
        BTFSS     NEG_FLAG, 0
        GOTO    NO_INVERT  
       
        COMF      RES4,F
        COMF      RES3,F
        COMF      RES2,F
        COMF   RES1,F
       
        INCF      RES1,F
        BTFSC     STATUS,Z
        INCF   RES2,F
        BTFSC     STATUS,Z
        INCF      RES3,F
        BTFSC     STATUS,Z
        INCF      RES4,F
NO_INVERT
        RETURN
 
DIVIDE:  MOVLW    .24
         MOVWF    BCOUNT
         MOVF    NRATORH,W
         MOVWF    SHIFTH
         MOVF    NRATORM,W
         MOVWF    SHIFTM
         MOVF    NRATORL,W
         MOVWF    SHIFTL
         CLRF    NRATORH
         CLRF    NRATORM
         CLRF    NRATORL
 
         CLRF    REMAINH
         CLRF    REMAINM
         CLRF    REMAINL
DLOOP     BCF    STATUS,C
         RLF    SHIFTL,F
         RLF    SHIFTM,F
         RLF      SHIFTH,F
         RLF    REMAINL,F
         RLF    REMAINM,F
         RLF      REMAINH,F
         MOVF     DENOMH,W
         SUBWF    REMAINH,W
         BTFSS    STATUS,Z
         GOTO    NOCHK
 
         MOVF    DENOMM,W
         SUBWF  REMAINM,W
         BTFSS  STATUS,Z
         GOTO    NOCHK
 
         MOVF    DENOML,W
         SUBWF    REMAINL,W
NOCHK           BTFSS    STATUS,C
         GOTO    NOGO
 
         MOVF    DENOML,W
         SUBWF    REMAINL,F
         BTFSS    STATUS,C
         DECF    REMAINM,F
         MOVF    REMAINM,W
         XORLW    0XFF
         BTFSC    STATUS,Z
         DECF    REMAINH,F
         MOVF    DENOMM,W
         SUBWF    REMAINM,F
         BTFSS    STATUS,C
         DECF    REMAINH,F
         MOVF    DENOMH,W
         SUBWF    REMAINH,F
         BSF    STATUS,C
NOGO:
         RLF    NRATORL,F
         RLF    NRATORM,F
         RLF    NRATORH,F
         DECFSZ    BCOUNT,F
         GOTO    DLOOP
      RETURN
 
HEX2DEC  INCF      LOWBYTE                 ; PRE-LOAD TEMPHI + 1
         CLRF      HUNS                    ; HUNS = 0000 0000
         MOVLW     D'246'                  ; MOVE DECIMAL'246' TO W
         MOVWF     TENS                    ; TENS GPR = 1111 0101
         MOVWF     ONES                    ; ONES GPR = 1111 0101
         DECFSZ    LOWBYTE, F              ; DECREMENT TEMPHI REGISTER
         GOTO      $+D'2'                  ; NOT 0, SKIP NEXT INSTRUCTION
         GOTO      $+D'7'                  
         INCFSZ    ONES, F                 
         GOTO      $-D'4'                 
         INCFSZ    TENS, F                
         GOTO      $-D'7'                  
         INCF      HUNS, F                
         GOTO      $-D'10'                
    
         SUBWF     TENS, F                 
         SUBWF     ONES, F 
 
         RETURN



DELAY
        MOVLW   0XFF
        MOVWF   COUNT3
        MOVLW   0X0A
        MOVWF   COUNT4
WAIT            DECFSZ   COUNT3,F
        GOTO   WAIT
        DECFSZ   COUNT4,F
        GOTO   WAIT
        RETURN



DISPLAY 
        MOVLW   0X30
        MOVWF   COUNT6
HERE1          BSF    PORTA,3
        BCF   PORTA,2
        MOVF   TENS,0
        CALL   TABLE1
        MOVWF   PORTB
        CALL   DELAY
        BCF   PORTA,3
        BSF   PORTA,2
        MOVF   ONES,0
        CALL   TABLE1
        MOVWF   PORTB
        CALL   DELAY
        DECFSZ   COUNT6,F
        GOTO   HERE1
        RETURN
        
      
      
       

TABLE1  ADDWF   PCL,F
         RETLW   B'00010001'       ; 0
         RETLW   B'11010111'       ; 1
         RETLW   B'00110010'       ; 2
         RETLW   B'10010010'       ; 3
         RETLW   B'11010100'       ; 4
         RETLW   B'10011000'       ; 5
         RETLW   B'00011000'       ; 6
         RETLW   B'11010011'       ; 7
         RETLW   B'00010000'       ; 8
         RETLW   B'10010000'       ; 9

  
START         NOP
        CALL   ADC_INITIALISE
                 ; 2000 = H'7D0'
        CLRF   A2
        MOVLW   0X3C
        MOVWF   A1
        MOVF   HIGHBYTE,W
        MOVWF   B2
        MOVF   LOWBYTE,W
        MOVWF   B1
        CALL   MULTIPLY      ; 125*ANALOG READ
      
        MOVF   RES3,W
        MOVWF   NRATORH
        MOVF   RES2,0
        MOVWF  NRATORM
        MOVF   RES1,0
        MOVWF   NRATORL
      
        CLRF   DENOMH
        MOVLW   H'00'                     ; 256 = H'FF'
        MOVWF   DENOMM
        CLRF   DENOML
        MOVLW   0XFF
        MOVWF   DENOML
        CALL   DIVIDE
      
        MOVF   NRATORM,0
        MOVWF   HIGHBYTE                  ; TENTHS DEGREES 
        MOVF   NRATORL,0
        MOVWF   LOWBYTE                   ; TENTHS 
        CALL   HEX2DEC
        CALL   DISPLAY
        GOTO   START
        END

 
HEX file:
 
:020000040000FA
:100000000000000000000000850186018316031334
:100010000F178F1607309C000330850000308600D4
:1000200003309B0083120313D828831203131F117C
:100030009F131F179F121F129F15831603139F13E1
:100040001F179F121F12831203131F141F151F194E
:1000500027281E08CB00CC010800B801B701B60163
:100060008030B500BD01BA1F3B28BA09B909B90AE9
:100070000319BA0ABD0ABC1F4328BC09BB09BB0A45
:100080000319BC0ABD0ABA0CB90C031C50283B0862
:10009000B6073C0803183C0FB7070318B80A03104B
:1000A000B91F58283B08B7070318B80A3C08B80717
:1000B000B80CB70CB60CB50C031C43283D1C6B28C0
:1000C000B809B709B609B509B50A0319B60A03197B
:1000D000B70A0319B80A08001830C1004208BE0068
:1000E0004308BF004408C000C201C301C401C801E5
:1000F000C901CA010310C00DBF0DBE0DCA0DC90D47
:10010000C80D45084802031D8B2846084902031DF7
:100110008B2847084A02031C9C284708CA02031C74
:10012000C9034908FF3A0319C8034608C902031C5A
:10013000C8034508C8020314C40DC30DC20DC10B8A
:100140007A280800CB0ACD01F630CE00CF00CB0BC9
:10015000AA28B028CF0FA728CE0FA628CD0AA528F9
:10016000CE02CF020800FF30B3000A30B100B30B5B
:10017000B728B10BB72808003030B200851505113B
:100180004E08CD208600B320851105154F08CD20DF
:100190008600B320B20BBE28080082071134D73482
:1001A00032349234D43498341834D33410349034F4
:1001B00000001520BA013C30B9004C08BC004B08C7
:1001C000BB002D203708C2003608C3003508C40024
:1001D000C5010030C600C701FF30C7006C204308CE
:0C01E000CC004408CB00A220BC20D82892
:00000001FF
 

No comments:

Post a Comment