Thermo 7 segments - little problem


Closed Thread
Results 1 to 40 of 50

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    My final code, using for thermometer with two DS18B20. Works fine !
    Code:
    ;                          CATOD / ANOD COMUN 
    ;                         merge foarte bine !!!
    ;                        VARIANTA 2 SENZORI !!!
    ;                     by Niculescu Dan, APRIL 2011
    ;
    ;
    '======================================================================================
    ;                                                              
    ;                        .oooO                                 
    ;                        (   )   Oooo.                         
    ;                         \ (    (   )
    ;                          \_)    ) /
    ;                                (_/
    ;
    
    @ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_ON
    
    DEFINE OSC 4
    CMCON		= 7
    VRCON 	= 0
    INTCON	= 0
                                    
        COMMON_0   	VAR PORTA.0
        COMMON_1   	VAR PORTA.1
        COMMON_2   	VAR PORTA.2
        COMMON_3   	VAR PORTA.3   
        DQ          VAR PORTA.4
        DQ2		      VAR PORTA.6
        DP          VAR PORTB.7
    
    Temp   	        Var     Byte 		: Temp2   	      Var     Byte
    Temperature     Var     Word 		: Temperature2    Var     Word
    TempC           Var     Word 		: TempC2          Var     Word
    I               Var     Byte 		: I2              Var     Byte
    Sign            Var     Word 		: Sign2           Var     Word
    Float           Var     Word 		: Float2          Var     Word
    V		            Var     Word 		: V2		          Var     Word		   
    Dummy           Var     Byte 		: Dummy2          Var     Byte
    Busy		        Var     Bit  		: Busy2	          Var     Bit
    Delay           Var     Word
    Valoare         VAR     Word
    Semn		        Var     Word
    
        DIGIT_0     VAR 	BYTE
        DIGIT_1     VAR 	BYTE
        DIGIT_2     VAR 	BYTE
        DIGIT_3     VAR 	BYTE
    
    DS18B20_12bit    CON %01111111        ' 750ms,   0.0625°C 
    DS18B20_12bit2   CON %01111111       ' 750ms,   0.0625°C 
    
    TrisB=%00000000				 ' Make PortB outputs
    TrisA=%11110000
    PortA=0:PortB=0			     	 ' Clear PortB and PortA
    
    '======================================================================================
    ' Init Sensor 1
     OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit]
     OWOut DQ, 1, [$CC, $48]       		    ' Start temperature conversion
     OWOut DQ, 1, [$CC, $B8] 
     OWOut DQ, 1, [$CC, $BE] 
     Pause 50
     OWIn DQ, 2, [temperature.byte0, temperature.byte1]
    
    ' Init Sensor 2
     OWOUT DQ2, 1, [$CC, $4E, 0, 0, DS18B20_12bit2]
     OWOut DQ2, 1, [$CC, $48]       		    ' Start temperature conversion
     OWOut DQ2, 1, [$CC, $B8] 
     OWOut DQ2, 1, [$CC, $BE] 
     Pause 50
     OWIn DQ2, 2, [temperature2.byte0, temperature2.byte1]
    
     Pause 100
    '======================================================================================    
    Main :
    If portA.7= 1 then
    valoare=temperature
    semn=sign
    Endif
    If portA.7= 0 then
    valoare=temperature2
    semn=sign2
    Endif
    
    Part1:
    ' Start temp.conv.Sensor1
     OWOut DQ, 1, [$CC, $44] 
     OWOut DQ, 1, [$CC, $BE]
     OWIn DQ, 2, [temperature.byte0, temperature.byte1]  
    
    If Temperature.15 then       
      Temperature= ~Temperature +1
      Sign  = 1
    Endif
     
    Dummy = 625 * Temperature
    TempC = DIV32 10 
    TempC = (Temperature & $7FF) >> 4
    Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
    Temperature = TempC*100 + Float
    
    If Sign=1 then
      V= 10000 - Temperature            
    else
      V= 10000 + Temperature
    EndIf
    
    If V >= 10000 then                  
      Temperature=V-10000
      sign = " "                   
    else                                   
      Temperature=10000-V             	
      sign = "-"
    EndIf
    
    Temperature=Temperature/10
    '===================================== end part one
    Part2 :	
    ' Start temp.conv.Sensor1
     OWOut DQ2, 1, [$CC, $44] 
     OWOut DQ2, 1, [$CC, $BE]
     OWIn DQ2, 2, [temperature2.byte0, temperature2.byte1]  
        
    If Temperature2.15 then       
      Temperature2= ~Temperature2 +1
      Sign2  = 1
    Endif
     
    Dummy2 = 625 * Temperature2
    TempC2 = DIV32 10 
    TempC2 = (Temperature2 & $7FF) >> 4
    Float2 = ((Temperature2.Lowbyte & $0F ) * 25 )>>2
    Temperature2 = TempC2*100 + Float2
    
    If Sign2=1 then
      V2= 10000 - Temperature2           
    else
      V2= 10000 + Temperature2
    EndIf
    
    If V2 >= 10000 then                
      Temperature2=V2-10000
      sign2 = " "                   
    else                                   
      Temperature2=10000-V2             	
      sign2 = "-"
    EndIf
    
    Temperature2=Temperature2/10
    
    '===================================== end part two
    Gosub Selectie
    Gosub Display				' B for Common CATOD;without B for Common ANOD
    
    Goto Main
    
    '======================================================================================       
    Selectie :
    
    IF semn ="-" then					
        DIGIT_3="-"
        else
        DIGIT_3=" "
    ENDIF
     
    IF valoare DIG 2 = 0 THEN
        DIGIT_2 = " "
        ELSE
        DIGIT_2 = valoare dig 2
    ENDIF
    
        DIGIT_1 = valoare dig 1
        DIGIT_0 = valoare dig 0
    
    RETURN
    '======================================================================================       
    Display:					' For Common ANOD
    for i=0 to 3
    
        TEMP = DIGIT_3 : gosub segments
        COMMON_3 = 1 :gosub DelayBetweenEachDigit : COMMON_3 = 0
         
        TEMP = DIGIT_2 : GOSUB segments
        COMMON_2 = 1 :gosub DelayBetweenEachDigit : COMMON_2 = 0
           
        TEMP = DIGIT_1 : GOSUB segments
        COMMON_1 = 1 :DP = 0 : gosub DelayBetweenEachDigit : COMMON_1 = 0 : DP = 1
      
        TEMP = DIGIT_0 : GOSUB segments
        COMMON_0 = 1 :gosub DelayBetweenEachDigit : COMMON_0 = 0
    next i
    RETURN
    '======================================================================================       
    Displayb:					' For Common CATOD
    for i=0 to 3 
        TEMP = DIGIT_3 : gosub segmentsB
        COMMON_3 = 0 :gosub DelayBetweenEachDigit : COMMON_3 = 1
         
        TEMP = DIGIT_2 : GOSUB segmentsB
        COMMON_2 = 0 : gosub DelayBetweenEachDigit : COMMON_2 = 1
       
        TEMP = DIGIT_1 : GOSUB segmentsB
        COMMON_1 = 0 : DP = 1 : gosub DelayBetweenEachDigit : COMMON_1 = 1 : DP = 0
      
        TEMP = DIGIT_0 : GOSUB segmentsB
        COMMON_0 = 0 : gosub DelayBetweenEachDigit : COMMON_0 = 1
    next i
    RETURN
    '======================================================================================       
    segments:  ; CONVERTS DATES TO 7 SEGMENT CODE for Common ANOD
        
        SELECT CASE TEMP       
    CASE 0 	 : PortB=%11000000 ; 0=ON ; 1=OFF
    CASE 1 	 : PortB=%11111001
    CASE 2 	 : PortB=%10100100      
    CASE 3 	 : PortB=%10110000        
    CASE 4 	 : PortB=%10011001
    CASE 5 	 : PortB=%10010010        
    CASE 6 	 : PortB=%10000010
    CASE 7 	 : PortB=%11111000        
    CASE 8 	 : PortB=%10000000       
    CASE 9 	 : PortB=%10010000        
    CASE "-"     : PortB=%10111111               
    CASE " "     : PortB=%11111111        
        END SELECT   
    RETURN
    
    '======================================================================================       
    segmentsB:  ; CONVERTS DATES TO 7 SEGMENT CODE for Common CATOD
        
        SELECT CASE TEMP       
    CASE 0 	 : PortB=%00111111 ; 1=ON ; 0=OFF 
    CASE 1 	 : PortB=%00000110
    CASE 2 	 : PortB=%01011011      
    CASE 3 	 : PortB=%01001111        
    CASE 4 	 : PortB=%01100110
    CASE 5 	 : PortB=%01101101        
    CASE 6 	 : PortB=%01111101
    CASE 7 	 : PortB=%00000111        
    CASE 8 	 : PortB=%01111111       
    CASE 9 	 : PortB=%01101111        
    CASE "-"     : PortB=%01000000               
    CASE " "     : PortB=%00000000        
        END SELECT   
    RETURN
    '====================================================================================== 
    DelayBetweenEachDigit:
    
        ' DelayBetweenEachDigit
        ' ---------------------
        ' Produce delay of about 3 mSec 
        ' Fine tuned with MPLAB StopWatch to get MainLoop = 1 sec
        For delay=1 to 5 
    	@ nop
    	next DELAY
    	@ nop
    	@ nop
    	@ nop                                   
          @ nop
    	@ nop
    	@ nop
    	@ nop
        return      
    '======================================================================================
    END						' of story !!!
    Attached Images Attached Images  
    Last edited by fratello; - 22nd April 2011 at 07:50.

  2. #2
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    I try to use Mr.Darrel "DT_INTS-14.bas" to make another variant of my termometer using 4x7 segments LED, like this :
    Code:
    @ __config _INTOSC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON
    
    DEFINE OSC 4
    CMCON        = 7
    VRCON     = 0
    INTCON    = 0
    DQ        VAR PORTA.4
    CLEAR
    
    SEGDEF    VAR BYTE[3]
    Value     VAR WORD
    Idx       VAR BYTE
    Temp      VAR BYTE
    digitloop VAR BYTE
    Blanking  VAR BIT
    
    Temperature     Var     Word
    TempC           Var     Word
    I               Var     Byte
    Sign            Var     Word
    Float           Var     Word
    V                Var     Word           
    Dummy           Var     Byte
    Busy            Var     Bit
    
    
    DS18B20_12bit   CON %01111111       ' 750ms,   0.0625°C 
    
    TrisB=0                    ' Make PortB outputs
    TrisA.0=0:TrisA.1=0:TrisA.2=0        ' Make only the specific bits of PortA outputs                    
    TrisA.3=0:TrisA.4=1
    PortA=0:PortB=0                     ' Clear PortB and PortA
    
    
    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
        INT_Handler TMR1_INT, _DISP, PBP, yes
      endm
      INT_CREATE ; Creates the interrupt processor
    ENDASM
    
    TRISA = 0
    TRISB = 0
    
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
    T1CON = $1 
    
    ' Init Sensor 1
     OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit]
     OWOut DQ, 1, [$CC, $48]                   ' Start temperature conversion
     OWOut DQ, 1, [$CC, $B8] 
     OWOut DQ, 1, [$CC, $BE] 
     Pause 50
     OWIn DQ, 2, [temperature.byte0, temperature.byte1]
    
    Main:
    ' Start temp.conv.Sensor1
     OWOut DQ, 1, [$CC, $44] 
     OWOut DQ, 1, [$CC, $BE]
     OWIn DQ, 2, [temperature.byte0, temperature.byte1]  
    
    If Temperature.15 then       
      Temperature= ~Temperature +1
      Sign  = 1
    Endif
     
    Dummy = 625 * Temperature
    TempC = DIV32 10 
    TempC = (Temperature & $7FF) >> 4
    Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
    Temperature = TempC*100 + Float
    
    If Sign=1 then
      V= 10000 - Temperature            
    else
      V= 10000 + Temperature
    EndIf
    
    If V >= 10000 then                  
      Temperature=V-10000
      sign = " "                   
    else                                   
      Temperature=10000-V                 
      sign = "-"
    EndIf
    
     FOR Value = 0 TO 9999
        GOSUB SetDisp
       PAUSE 500
     NEXT Value
    GOTO Main
    
    '---[Set 7-seg patterns to WORD value]------------------------------------------
    SetDisp:
      Blanking = 1
      FOR Idx = 3 to 0 STEP -1
        Temp = Value DIG Idx
        IF (Blanking AND Temp != 0) OR Idx = 0 THEN Blanking = 0
        IF Blanking THEN
          Temp = 0
        ELSE
          LookUp Temp,[132,175,193,137,170,152,144,143,128,136,210,251],Temp
        ENDIF
        SEGDEF(Idx) = Temp
      NEXT Idx
    RETURN
    
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    DISP:
      T1CON.0 = 0                ; stop timer
      TMR1H = %11111100
      TMR1L = %00011111
      T1CON.0 = 1                ; restart timer
    
      PORTA = %1111              ; turn off all digits to prevent ghosting
      PORTB = SEGDEF(digitloop)  ; put segment pattern to pin
      PORTA = ~(DCD digitloop)   ; turn on the digit
    
      digitloop = digitloop + 1
      IF digitloop = 4 then digitloop = 0
    @ INT_RETURN
    ...but where I must put the value of temperature ?! Any advice, please ? Thanks !

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    I try something like this
    Code:
     FOR x = 0 TO 9999
     value=temperature
        GOSUB SetDisp
       PAUSE 500
     NEXT x
    GOTO Main
    but without results ... Any thought ?

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    I try to revive this topic ...
    I found here (http://vnnik71.narod.ru/termo_ds18b20.html) schematic and hex file (even source code...) for an thermometer... It works absolutely great ! NO FLICKERING despite the absence of external quartz/HS oscillator !
    How is made ?! I have no ideea ...
    BUT ... in PBP this can be done ?!? I gave up to many LED display projects, because of this issue - annoying flickering ...
    Know somebody a GOOD method to get a stable, sharp display ? Thanks in advance !

  5. #5
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Although I can't open the sight I have a few questions. What is it you're trying to do? Improve upon project posted here or start from scratch?

    What is the range of temperature you want to display?

    What displays do you want to use? If flickering is a problem you could use a faster update rate but the display will only be as good as the quality of the display. I agree 7 segment LEDs are a dime a dozen but some are better than others. Although if you want large displays you may not be able to update them but will need to turn them on the whole time using FETs or transistors.

    What is it ultimately you'd like to see from this project?

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Thanks for reply !
    So ... using as hardware - 16F628A @ 4 MHz and LED display KW4-311AVA, I built one termometer, using DS18B20, with different variants of software (presented in this topic). All my variants have this issue - display flickering, more or less, but present.
    The hardware from the link posted above use same hardware, 16F628 @ 4 Mhz and same display. BUT ... no flickering ! The display look sharp and bright.
    So ... I intend to build an termometer, using same hardware, but flicker-free ! And, despite searching this forum, I could not find any convenient version to apply.
    This is why I asked for help ! Thanks in advance !

  7. #7
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Tried a "variation" of code from post #20 :
    Code:
    ;                        Termo LED 7 seg 
    '======================================================================================
    
    @ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_ON, MCLR_OFF, LVP_OFF, CPD_OFF
    
    
    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    
    DEFINE OSC 4
    CMCON	= 7
    VRCON 	= 0
    INTCON 	= 0
    
                                    
        Common_4   	VAR PORTA.1
        Common_3   	VAR PORTA.0
        Common_2   	VAR PORTA.7
        Common_1   	VAR PORTA.6   
        DQ            VAR PORTA.4
        DP            VAR PORTB.2
    
    Temp   	    Var     Byte
    Temperature     Var     Word
    TempC           Var     Word
    I               Var     Byte
    Sign            Var     Word
    Float           Var     Word
    V		    Var     Word		   
    Dummy           Var     Byte
    Busy		    Var     Bit
        DIGIT_0     VAR 	BYTE
        DIGIT_1     VAR 	BYTE
        DIGIT_2     VAR 	BYTE
        DIGIT_3     VAR 	BYTE
    digit		    Var 	BYTE
    
    DS18B20_12bit 	CON %01111111        	' 750ms,   0.0625°C 
    
    
    
    Data @0,20,215,76,69,135,37,36,87,4,5,255
    
    
    PortA=%00000100
    TrisA=%00111000
    PortB=%11111111
    TrisB=%00000000
    
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
        INT_Handler TMR1_INT, _DISP, PBP, yes
      endm
      INT_CREATE ; Creates the interrupt processor
    ENDASM
    
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
    T1CON = $1 
    
    ' Init Sensor 1
     OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit]
     OWOut DQ, 1, [$CC, $48]                   ' Start temperature conversion
     OWOut DQ, 1, [$CC, $B8] 
     OWOut DQ, 1, [$CC, $BE] 
     Pause 50
     OWIn DQ, 2, [temperature.byte0, temperature.byte1]
    
    Main:
    ' Start temp.conv.Sensor1
     OWOut DQ, 1, [$CC, $44] 
     OWOut DQ, 1, [$CC, $BE]
     OWIn DQ, 2, [temperature.byte0, temperature.byte1]  
    
    If Temperature.15 then       
      Temperature= ~Temperature +1
      Sign  = 1
    Endif
     
    Dummy = 625 * Temperature
    TempC = DIV32 10 
    TempC = (Temperature & $7FF) >> 4
    Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
    Temperature = TempC*100 + Float
    
    If Sign=1 then
      V= 10000 - Temperature            
    else
      V= 10000 + Temperature
    EndIf
    
    If V >= 10000 then                  
      Temperature=V-10000
      sign = " "                   
    else                                   
      Temperature=10000-V                 
      sign = "-"
    EndIf
    
    Temperature=Temperature/10
    
    Gosub Selectie
    
    Goto Main
    
    '======================================================================================
    Selectie :
    
    If sign = "-" then
    PortB = %11101111					
    else 
    PortB = %11111111					
    endif
    
    IF Temperature DIG 2 = 0 THEN
    digit = " "
        else
    digit = Temperature dig 2
    ENDIF
        read digit, DIGIT_2
    
    digit = Temperature dig 1
        read digit, DIGIT_1
        
    digit = Temperature dig 0
        read digit, DIGIT_0
    Return    
    '====================================================================================== 
    Disp:
      T1CON.0 = 0                ; stop timer
      TMR1H = %11111100
      TMR1L = %00011111
      T1CON.0 = 1                ; restart timer
    
    Common_1 = 1 : PAUSE 1 : Common_1 = 0	
          
    PortB = DIGIT_2
    Common_2 = 1 : PAUSE 1 : Common_2 = 0
    
    PortB = DIGIT_1
    Common_3 = 1 : DP = 0 : PAUSE 1 : Common_3 = 0 : DP = 1
    
    PortB = DIGIT_0
    Common_4 = 1 : PAUSE 1 : Common_4 = 0
    
    @ INT_RETURN
    ...but I have some errors :

    ERROR Line 95: Syntax error. (ReEnterPBP.bas)
    ERROR Line 128: Redefiniton of LABEL Vars_Saved. (ReEnterPBP.bas)
    ERROR Line 128: Syntax error. (ReEnterPBP.bas)
    Advices ?! Thanks !

Similar Threads

  1. Windows 7 64 bit problem..can anyone help???
    By ljc4141 in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 18th July 2011, 15:29
  2. LED Machine Tach For Tired Eyes
    By Archangel in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 27th January 2010, 14:55
  3. adding with 7 segments
    By ruijc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th November 2007, 22:51
  4. 7 segments clock
    By the_apprentice in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th April 2006, 18:45
  5. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 20:25

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts