Trouble with LCD 2x8 and sequential display of values


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Trouble with LCD 2x8 and sequential display of values

    Sorry, sometimes I get carried away ...

    Code:
    '***************************************************************************
    '*  Name    : DT18x20_Fratello.pbp
    '*  Author  : Darrel Taylor
    '*  Date    : 2/19/2012
    '*  Version : 1.1 (2/24/2012)
    '*  Target  : 16F684 @ 4 mhz
    '***************************************************************************
    
    DEFINE  OSC 4
    CLEAR
    ;----[Main Options]---------------------------------------------------------
    TimeToShow CON 5                ; Seconds to show each temperature
    
    ;----[Battery Options]------------------------------------------------------
    Res1   CON 20000                ; Top Resistor of Voltage Divider
    Res2   CON 10000                ; Bottom Resistor of Divider
    VDD    CON 50                   ; VDD voltage
    MaxBat CON 140   ; 14.0V        ; Batt indicator Max
    MinBat CON 98    ;  9.8V        ; Batt indicator Min
    
    ;----[DS1820 Options]----Value----Default-----------------------------------
    DEFINE  DS1820_DECIMALS    1    ; 1
    DEFINE  DS18B20_ONLY       YES  ; NO
    DEFINE  DS1820_VERIFYCRC   YES  ; NO
    DEFINE  DS1820_USETIMEOUT  NO   ; YES
    MaxRetries  CON 4
    INCLUDE "DT18x20.pbp"           ; Include DT18x20 module
    ; --- To get the include file, Register at http://darreltaylor.com/whatsup/
    
    Inside   VAR PORTC.5            ; Pin assigned to Inside Sensor
    Outside  VAR PORTC.4            ; Pin assigned to Outside Sensor
    
    ;----[Elapsed Timer]--------------------------------------------------------
    INCLUDE "Elapsed.bas"
    ; --- To get the include file ... Go to ...
    ; --- http://www.pbpgroup.com/modules/wfsection/article.php?article
    GOSUB ResetTime
    
    ;----[LCD definitions]------------------------------------------------------
    DEFINE LCD_DREG  PORTC          ; LCD Data port
    DEFINE LCD_DBIT  0              ; starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTA          ; LCD Enable port
    DEFINE LCD_EBIT  2              ;     Enable bit
    DEFINE LCD_RSREG PORTA          ; LCD Register Select port
    DEFINE LCD_RSBIT 1              ;     Register Select bit
    DEFINE LCD_BITS  4              ; LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2              ; number of lines on LCD
    DEFINE LCD_COMMANDUS 2000       ; Command delay time in us 
    DEFINE LCD_DATAUS 50            ; Data delay time in us 
    
    ;----[Analog options]-------------------------------------------------------
    DEFINE ADC_BITS  10
    DEFINE ADC_CLOCK  3
    ADCON0.7=1                    ; Right Justify A/D results
    
    ;----[Program Variables]----------------------------------------------------
    BattLevel  VAR BYTE             ; 0 - 10, 0=Empty  10=Full
    RawBattery VAR WORD
    Volts      VAR WORD
    LastVolts  VAR WORD : LastVolts=0
    Sensor     VAR BIT  : Sensor=1
    Char       VAR BYTE
    y          VAR BYTE
    Retries    VAR BYTE
    TempW      VAR WORD
    GIE        VAR INTCON.7
    
    ;----[Initialization]-------------------------------------------------------
    CMCON0=7                      ; disable Comparators
    ANSEL=0                       ; All Digital
    ADCON1=$30                    ; ADC_CLOCK is FRC
    LCDOUT $FE,1:PAUSE 250:LCDOUT $FE,1 ' Initialize LCD
    
    LCDOUT " TERMO- ",$FE,$C0,"  VOLT  "
    GOSUB StartConversions          ; get the first reading started
    PAUSE 4000
    
    GOSUB StartTimer                ; Start the Elapsed Timer
    Seconds=TimeToShow            ; Force 1st display on start-up
    SecondsChanged=1
    
    ;----[Main Program Loop]----------------------------------------------------
    Main:
        IF SecondsChanged THEN
            SecondsChanged=0
            IF Seconds !=0 AND Seconds != TimeToShow THEN GOSUB StartConversions
            IF Seconds=TimeToShow THEN      ; on each period
                Seconds=0
                Sensor=!Sensor              ; Toggle sensors
                LCDOUT $FE,$80
                IF Sensor=0 THEN
                    LCDOUT "I:      "         ; Indicate Inside sensor
                ELSE
                    LCDOUT "O:      "         ; Indicate Outside sensor
                ENDIF
            ENDIF
        ENDIF
      ;---------------------------------
        IF Sensor=0 THEN    
            @  DS1820_Select  _Inside         ; Select Inside DS18x20 pin
        ELSE
            @  DS1820_Select  _Outside        ; Select Outside DS18x20 pin
        ENDIF
        DS1820_Flags=0                      ; clear flags before Stat
        GIE=0                               ; disable interrupts
            @ DS1820_Stat                     ;   get sensor status
        GIE=1                               ; enable interrupts
        IF DS1820_Done THEN                   ; if conversion finished
            @ DS1820_Read                     ; try to read the temp
            Retries=0
          RetryRead:
            IF DS1820_Error=0 THEN          ; if there were no errors
                GOSUB TempToLCD               ; display TempC
            ELSE                              ;--- Error reading Sensor --------    
                IF Retries < MaxRetries THEN
                    Retries=Retries + 1
                    @ DS1820_Read             ; try to read it again (no Conv)
                    GOTO RetryRead
                ENDIF
                LCDOUT $FE,$82,"Error "       
            ENDIF
        ENDIF
        GOSUB ReadVoltage
        PAUSE 100  
    GOTO Main                                
    
    ;----[Start conversion on both sensors]-------------------------------------
    StartConversions:
        @  DS1820_Select  _Inside             ; Select Inside DS18x20 pin
        @  DS1820_Convert                     ; start conversion
        @  DS1820_Select  _Outside            ; Select Outside DS18x20 pin
        @  DS1820_Convert                     ; start conversion
    RETURN
    
    ;----[Display TempC on LCD]-------------------------------------------------
    TempToLCD:
        TempW=TempC
        LCDOUT $FE,$82
        IF ABS(TempW)/DS1820_DIG < 10 THEN LCDOUT " "
        IF TempW.15 THEN 
            LCDOUT "-"                        ; if negative, display minus sign
        ELSE
            LCDOUT "+"
        ENDIF
        TempW=ABS(TempW)                    ; get the positive value
        LCDOUT DEC TempW/DS1820_DIG           ; Display the Integer portion
        LCDOUT "."                            ;   display decimal point
        TempW=TempW//DS1820_DIG             ;   get decimal portion
        LCDOUT  DEC1 TempW DIG 0 
        IF ABS(TempC) < 1000 THEN 
            LCDOUT $DF 
        ENDIF
    RETURN
    
    ;----[Read battery voltage]-------------------------------------------------
    RT     CON Res1 + Res2                    ; Total Divider Resistance
    
    ReadVoltage:
        ADCIN 3, RawBattery
        Volts=RawBattery * Rt
        Volts=DIV32 Res2
        Volts=Volts * VDD
        Volts=DIV32 1023
        IF Volts != LastVolts THEN
            LastVolts=Volts
            LCDOUT $FE,$C1
            IF Volts/10 < 10 THEN LCDOUT " "
            LCDOUT " ",DEC Volts/10,",",DEC1 Volts Dig 0," V"
            IF Volts >= MaxBat THEN
                BattLevel=12
            ELSE
                IF Volts <= MinBat THEN
                    BattLevel=0
                ELSE
                    BattLevel=(Volts - MinBat +1) * 12 / (MaxBat - MinBat +1)
                ENDIF
            ENDIF
            GOSUB ShowBattery
        ENDIF
    RETURN
    
    ;----[Show Battery Icon  0 - 12, 0=Empty  12=Full]--------------------------
    ShowBattery:
        lcdout $FE,$C0,1,$FE,$48,$0A,$1F
        for y=4 to 1 step -1
            if BattLevel >= (y * 3) then
                Char=$1F
            else
                if BattLevel >= (y * 3 - 1) then
                    Char=$17
                else
                    if BattLevel >= (y * 3 - 2) then
                        Char=$13
                    else
                        Char=$11
                    endif
                endif
            endif
            lcdout Char
        next y
        lcdout $1F
    return
    
    
    Attached Files Attached Files
    Last edited by Darrel Taylor; - 24th February 2012 at 09:16.
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: Trouble with LCD 2x8 and sequential display of values

    A GREAT piece of code ! A VERRY GOOD EXAMPLE !!!
    As usual, I'm speechless...Thank YOU, Mr. Darrel !

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


    Did you find this post helpful? Yes | No

    Default Re: Trouble with LCD 2x8 and sequential display of values

    Bad post, sorry...
    but I can' compile the code : "Cannot open file (Include file "P16F684.inc" not found)" ?!
    Last edited by fratello; - 24th February 2012 at 09:35.

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


    Did you find this post helpful? Yes | No

    Default Re: Trouble with LCD 2x8 and sequential display of values

    I am so sorry ... ....
    What a dumb I am ...
    Of course, Mr. Darrel have the answer : http://www.picbasic.co.uk/forum/show...2195#post52195
    Everything works just fine !

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


    Did you find this post helpful? Yes | No

    Default Re: Trouble with LCD 2x8 and sequential display of values

    Everything works just fine ! Thanks again, Mr.Darrel !
    One last (I hope ) request : Can this "lint" be removed ? I try to find another value for "LCDOUT $nn", but without good results ...
    Thanks !
    Attached Images Attached Images   

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Trouble with LCD 2x8 and sequential display of values

    Two ways ...

    1) Add a 0 to the last LCDOUT ...
    Code:
        lcdout $1F,0
    2) You can make the battery icon 1 pixel taller ...
    Code:
                ELSE
                    BattLevel = (Volts - MinBat +1) * 15 / (MaxBat - MinBat +1)
                ENDIF
            ENDIF
            GOSUB ShowBattery
        ENDIF
    RETURN
    
    ;----[Show Battery Icon  0 - 15, 0=Empty  15=Full]--------------------------
    ShowBattery:
        lcdout $FE,$C0,1,$FE,$48,$0A,$1F
        for y = 5 to 1 step -1
            if BattLevel >= (y * 3) then
                Char = $1F
            else
                if BattLevel >= (y * 3 - 1) then
                    Char = $17
                else
                    if BattLevel >= (y * 3 - 2) then
                        Char = $13
                    else
                        Char = $11
                    endif
                endif
            endif
            lcdout Char
        next y
        lcdout $1F
    return
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: Trouble with LCD 2x8 and sequential display of values

    Just finish to write my own code, based on previous source (see post #1 ), it's good for me ...BUT ...
    Of course, Mr.Darrel solution it's BETTER !
    I owe with some thousands of e-beer ! Thanks again !

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