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
    579


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    OK, I will follow Your advice ...
    This is the last attempt, not-working (just "000" on display). Already feel like I came out of patience with this problem .
    Code:
    ' Pulse counter   - attempt to converted for LED display termometer
    ' =============
    '
    ' File name : Count_Display.bas
    ' Company : Mister E
    ' Programmer : Steve Monfette
    ' Date : 27/12/2004
    ' Device : PIC16F628A
    '
    '
    ' This program display to 3 x 7 segments dislay the result of
    ' pulses count on PORTA.4 pin/sec.
    '
    ' Hardware connection :
    ' ---------------------
    '      1. 3 X 7 segments display on PORTB<7:0>
    '      2. 3 X PNP transistor on PORTA<3:0> to drive common anode
    '         of each 7 segments display
    '
    '
    ' Programming mode and PIC define
    ' -------------------------------
    '
    ;@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF
    CMCON=7       ' ADDED FOR PIC16F628A   
    DEFINE OSC 20 ' use 20 MHZ oscillator
    
    
        ' I/O Definition
        ' --------------
        '
    TRISA = %11111000 ' PORTA  : <2:0> outputs to common Anode of 7 segment
                          '                1. PORTA.0 More significant
                          '                2. PORTA.2 Less significant
                          '        : PORTA.4 input for signal
                          '
    TRISB = 0         ' PORTB connected to 7 segments
                      '       B0 : segment a
                      '       B1 : segment b
                      '       B2 : segment c
                      '       B3 : segment d
                      '       B4 : segment e
                      '       B5 : segment f
                      '       B6 : segment g
                      '       B7 : segment decimal dot
                          
    
    ' Internal EEPROM definition
    ' --------------------------
    '
    data @0,192,249,164,176,153,146,130,248,128,144 ' table to convert
                                                    ' numbers to 7 segments
                                                    ' pattern output when
                                                    ' drive invert
                                                        
    
    
    ' Interrupt and register definition
    ' ---------------------------------
    
    OPTION_REG = %1111000   ' TMR0 clock source : RA4/T0CKI
                            ' increment on low to high transition
                            ' Prescaler assign to WDT
                            ' WDT rate 1:1
                            '
    INTCON = %10100000      ' Enable global interrupt
                            ' Disable EE write interrupt
                            ' Enable TMR0 overflow interrupt
    
            
        ' Variable definition
        ' -------------------
        '
    DisplayPort  var PORTB   ' Port for 7 Segments
    ;ClockInput   var PORTA.4 ' Input pin for signal
    _7Seg1       con 14      ' enable more significant 7 segment display
    _7Seg2       con 13      ' enable mid significant 7 segment display
    _7Seg3       con 11      ' enable less significant 7 segment display
    Digit_1          var byte    ' Hundreds digit
    Digit_2          var byte    ' Tenth digit
    Digit_3          var byte    ' Unit digit
    ToBeDisplay  var word    ' Result of count to be send to 7 segment display
    Display      var byte    ' Temp variable
    DisplayLoop  var byte    '
    Delay        var word    ' Variable for Delay loop
    OverFlowVar  var word        '
    Thousands    var bit         ' Flag for count >= 1000 & < 10 000
    TenThousands var bit         ' Flag for count >= 10 000
    
    ;===========================================
    Temp   	        Var     byte
    Temperature     Var     Word
    TempC           Var     Word
    I               Var     Byte
    Sign            Var     Word
    DQ      VAR PORTA.4
    DQ_DIR  var TRISA.4
    command var byte
    pis     var byte
    ;============================================
        ' Variable and software initialisation
        ' ------------------------------------
        '
    tobedisplay = 0 ' set initial value of count
    TMR0 = 0        ' reset prescaller
    On interrupt GoTo SetVarToBeDisplay
    
    
    Gosub init1820 			' Init the DS1820
    
    command = $cc 			' Issue Skip ROM command
    Gosub write1820
    
    command = $44 			' Start temperature conversion
    Gosub write1820
    
    
    Gosub init1820 			' Do another init
    
    command = $cc 			' Issue Skip ROM command
    Gosub write1820
        
    MainLoop:
    command = $be           ' Read the temperature
    Gosub write1820
    Gosub read1820
    
        ' MainLoop
        ' ---------
        '
        ' 1. display the result of the count on RA4 pin
        ' 2. refresh display
        ' 3. reset Timer0
        ' 4. reload prescaler.
        '
        ' Duration of the procedure : 1 sec
        '           fine tuned by DelayBetweenEachDisplay Sub
        '
        ' Looping 1 sec and get results of the pulse count in
        ' TMR0 + OverFlowVar
        '
    DisplayRefresh:
            '
        ' Testing amount of count
        ' -----------------------
        '
        ' Get the result of count and place decimal point flag
        ' on the according 7 segments
        '
        'If tobedisplay>= 1000 Then
        'tobedisplay = tobedisplay / 10
        'Else
        '    tenthousands = 0
        '       thousands = 1
        'EndIf
         
        '
        ' convert digit to 7 segment output pattern
        ' -----------------------------------------
    display=ToBeDisplay dig 2 ' Read hundreds digit
    read display, digit_1     ' Convert hundreds
         if thousands==1 then digit_1=digit_1 & $7F ' enable decimal dot
                                                       ' by clearing PORTB.7
    
        display=ToBeDisplay dig 1 ' Read tenths digit
        read display, digit_2     ' Convert tens
            if tenthousands==1 then digit_2=digit_2 & $7F ' enable decimal dot                          '
                                                      ' by clearing PORTB.7
                                                      
            display=ToBeDisplay dig 0 ' Read units digit
            read display, digit_3     ' Convert units
        '
        '
        ' Send digit to 7 segments
        ' ------------------------
        For displayloop = 0 To 111 ' loop for about 1 sec
    
            ' display hundreds
            ' ----------------
            PORTA=_7seg1        ' enable hundreds 7 segment
            displayport = digit_1 ' display
            GoSub DelayBetweenEachDigit
            
            ' display tenth
            ' -------------
            PORTA=_7seg2        ' enable tenth 7 segment
            displayport = digit_2 ' display
            GoSub DelayBetweenEachDigit
            
            ' display units
            ' -------------
            PORTA=_7seg3        ' enable unit 7 segment
            displayport = digit_3 ' display
            GoSub DelayBetweenEachDigit
            
        Next
        
        ToBeDisplay = Temperature
        TMR0 = 0        ' reset prescaller
        GoTo DisplayRefresh
    
    
    DelayBetweenEachDigit:
    
        ' DelayBetweenEachDigit
        ' ---------------------
        ' Produce delay of about 3 mSec
        '
        ' Fine tuned with MPLAB StopWatch to get MainLoop = 1 sec
        '
            For delay = 1 To 307
                @ nop
            Next
            @ nop
            @ nop
            @ nop
            @ nop
            @ nop
            @ nop
            @ nop
        Return
    
    
        disable
    SetVarToBeDisplay:
        '
        ' SetVarToBeDisplay
        ' -----------------
        ' interrupt routine of TMR0 overflow
        '
        ' Reset prescaller
        ' Reset overflow flag
        '
        Temperature = ((tempERATURE>> 1)*100)+((TEMPERATURE.0*5)*10)
        INTCON.2 = 0 ' clear overflow flag
        TMR0 = 0     ' reload TMR0
        Resume
        enable
    
    '====================================================================================== 
    ' Initialize DS1820 and check for presence
    init1820:
       Low DQ              ' Set the data pin low to init
       Pauseus 500         ' Wait > 480us
       DQ_DIR = 1          ' Release data pin (set to input for high)
    
       Pauseus 100         ' Wait > 60us
       If DQ = 1 Then
          Pause 500
          Goto mainLOOP     ' Try again
       Endif
       Pauseus 400         ' Wait for end of presence pulse
       Return
    
    ' Write "command" byte to the DS1820
    write1820:
       For pis = 1 To 8      ' 8 bits to a byte
         If command.0 = 0 Then
            Gosub write0   ' Write a 0 bit
         Else
            Gosub write1   ' Write a 1 bit
         Endif
         command = command >> 1  ' Shift to next bit
       Next pis
       Return
    
    ' Write a 0 bit to the DS1820
    write0:
       Low DQ
       Pauseus 60          ' Low for > 60us for 0
       DQ_DIR = 1          ' Release data pin (set to input for high)
       Return
    
    ' Write a 1 bit to the DS1820
    write1:
       Low DQ              ' Low for < 15us for 1
     @ nop                 ' Delay 1us at 4MHz
       DQ_DIR = 1          ' Release data pin (set to input for high)
       Pauseus 60          ' Use up rest of time slot
       Return
    
    ' Read temperature from the DS1820
    read1820:
       For pis = 1 To 16     ' 16 bits to a word
         temperature = temperature >> 1  ' Shift down bits
         Gosub readbit     ' Get the bit to the top of temp
       Next pis
       If Temperature.15 then       
      Temperature= ~Temperature +1
      Sign  = 1
    Endif
       Return
    
    ' Read a bit from the DS1820
    readbit:
       temperature.15 = 1         ' Preset read bit to 1
       Low DQ              ' Start the time slot
     @ nop                 ' Delay 1us at 4MHz
       DQ_DIR = 1          ' Release data pin (set to input for high)
       If DQ = 0 Then
          temperature.15 = 0      ' Set bit to 0
       Endif
       Pauseus 60          ' Wait out rest of time slot
       Return    
    ;=================================================
    END
    Attached Images Attached Images  

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,626


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    What if you comment the DS1820 logic, set temperature and sign to -20 and test only the display logic?

    Robert

  3. #3
    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

    Near the top of the program you set up a config line but it's commented out. I think for that chip to need to set the HS osc since you're using a 20Meg unit.

    Do you also need to set the CONFIG register to set for oscillator speed and type?

    I'm looking over the data sheet but have to catch it in fits and starts. More questions later.

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


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Thanks for advice ....
    Indeed I commented this : ";@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF"
    But in Proteus I set the freq to 20 MHz.
    If I write "temperature=123", the display show "12.3" ; so, it's work ...but the reading of sensor not work / or the temperature is wrong calculated ...

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,626


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    So the LCD logic works, that's a start.

    Are you doing this only in proteus?

    Robert

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


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    No, I have builded the hardware too ...
    Note : the code for temperature sensor is for DS1820 ; I use DS18B20 - maybe this is the problem ?!

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Hello Fratello,
    your code
    Code:
    PORTA=_7seg1        ' enable hundreds 7 segment
            displayport = digit_1 ' display
            GoSub DelayBetweenEachDigit
    Best I remember and for reasons I don't you cannot assign a port value just that way. Something about BLA = bla being a T/F comparason rather than assignment, don't remember just fuzzy . . . I believe PORTA=_7seg1 is a comparason operator and putting ! or ~ ahead of it converts it to a "Bitwise" operation
    Try this
    Code:
    PORTA=~_7seg1        ' enable hundreds 7 segment
            displayport = digit_1 ' display
            GoSub DelayBetweenEachDigit
    and if that inverts your display then use 2 nots
    PORTA=~~_7seg1        ' enable hundreds 7 segment
            displayport = digit_1 ' display
            GoSub DelayBetweenEachDigit
    As I have not really studied your code I may have misread where your port display is, in any event use not or 2 nots before that port assignment.
    Last edited by Archangel; - 6th July 2013 at 00:28.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    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

    A couple of other things I question:Please bear in mind I'm not a real programmer just a poor hacker!

    You say you set a rate in Protues but don't you have to have those configs to set the chip up to work at that speed even in Proteus?

    Once you go through the mainloop you never go back to it. I don't see a line in your code where you have goto mainloop anywhere.

    On the write1820 sub, and some others, you write either a 0 or a1 then shift if right 1 digit. Won't that constantly shift in a zero? And in same sub there are 8 bits to a byte but I think they shouldstart at 0 not 1. I don't really understand how that works so if I'm wrong I'll look up the 1820 and get schooled up.

  9. #9
    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

    A couple of other things I question:Please bear in mind I'm not a real programmer just a poor hacker!

    You say you set a rate in Protues but don't you have to have those configs to set the chip up to work at that speed even in Proteus?

    Once you go through the mainloop you never go back to it. I don't see a line in your code where you have goto mainloop anywhere.

    On the write1820 sub, and some others, you write either a 0 or a1 then shift if right 1 digit. Won't that constantly shift in a zero? And in same sub there are 8 bits to a byte but I think they shouldstart at 0 not 1. I don't really understand how that works so if I'm wrong I'll look up the 1820 and get schooled up.

  10. #10
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Thank you all for support !
    1. The code (last version, from previous page) work fine - at least show a clear, flicker-free suite of "0" , if I comment all references to temperature ...
    The "copyright code" belong to Mr.Monfette (' File name : Count_Display.bas ' Company : Mister E ' Programmer : Steve Monfette) so it's a WORKING code for LED display. Me, I just attempted to adapt to my project - reading DS18B20 sensor !
    2.If I write in code this line "temperature=123" (instead "calculated" value of temperature), the display show "12.3" ; so, it's work ...but the reading of sensor not work / or the temperature is wrong calculated ...
    3.Indeed, the return in loop was to "DisplayRefresh:", not to "Mainloop:". I've changed that, but not results !
    ...

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 : 1

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