LONG to WORD

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

LONG to WORD

Post by febo26 »

imam kod za mjerenje pritiska zraka s senzorom BMP0085 s prikazom na 4x20 LCDu i to radi super.
sada pokusavam ispisati vrijednost pritiska na GLCDu ali mi ne ispise tocne vrijednosti.Mislim da je to zbog toga jer su mi varijable LONG velicine a za prikaz na GLCDu mi treba WORD velicina.

dio koda kako se prikazuje na 4x20 LCDu

Code: Select all


'*****************DEFINICIJE ZA BMP SeNZOR***************
 ' Software Defines (variables and pins)
    Cal_table   var word[11]         '11 word array to store calibration data
    lUpres      var long             'Long variable for Uncompensated Pressure
    lPres       var Long             'Long variable for Compensated Pressure
    lTemp_Var1  Var long             'Long temporary variable
    X1          var Long
    X2          var Long
    X3          var Long
    B3          var long
    B4          var long
    B5          var long
    B6          var Long
    B7          var long
    
    lAC1        var Long            'Long variables for cal values actually negative in my sensor
    lAC2        var long            'These are 'cast' from the Word vars into Long vars in code below
    lAC3        var Long 
    lAC4        var Long 
    lMB         var Long
    lMC         var Long
 
    bTemp_Var1  var byte             'Byte temp variable 
    wTemp_Var1  var Word	         'Word temp variable
    wTemp_Var2  var word             'Word temp variable
    lUTemp      var long             'Uncompensated temperature reading from sensor
    lCTemp      var Long             'Compensated (real) temperature x10 (1/10th of C) from sensor
    i2c_Reg     var Byte             'variable for target i2c register address
    OSS         con     $3          'This value is the Over Sampling Setting for the BMP085
                                    '0 = minimum, 3 = maximum. Also change value in Read_pres if you alter OSS 



'Calculate pressure in Pascals from uncompensated pressure lUpres (1/100th's of hPa's)        
        B6 = b5 - 4000

        x1 = (b2 * (B6 * B6 / $1000)) / $800 
        x2 = (lac2 * B6) / $800
        x3 = x1 + x2
        B3 = ((lac1 * 4 + x3) << OSS + 2) / 4     'OSS = Over Sampling constant set above  
 
        x1 = (lac3 * b6) / $2000
        x2 = (b1 * (b6 * b6 / $1000)) / $10000
        x3 = ((x1 + x2) + 2) / 4
        B4 = (lac4 * (x3 + 32768)) / $8000        'Find B4, note lAC4 is an unsigned Long

        B7 = (lUPres - B3) * (50000 >> OSS)       'OSS = Over Sampling constant set above
 
        If B7 < $80000000 then                    'branch if value is above or below range
            lPres = (B7 * 2) / B4
            Else
            lPres = (B7 / B4) * 2
        Endif

        X1 = (lPres / 256) * (lPres / 256)
        X1 = (X1 * 3038) / $10000                 '$10000 = 2^16
        X2 = (-7357 * lPres) / $10000
        lPres = lPres + (X1 + X2 + 3791) / 16     'lPres is the true pressure in Pa

'[b]DISPLAY true pressure in hPa
        X1 = lPres / 100                          'find value above decimal point
                                                  'Shift cursor to line_3   
       LCDOUT $FE,$D4, "P= ",DEC X1,"."          'Send Word size number to LCD        
        X1 = lPres // 100                         'find value below decimal point
        LCDOUT $FE,$D4+8, DEC X1,"hPa"              'Send Word size number to LCD 

'DISPLAY true pressure in hPa
X1 = lPres / 100 'find value above decimal point

LCDOUT $FE,$D4, "P= ",DEC X1,"." 'Send Word size number to LCD
X1 = lPres // 100 'find value below decimal point
LCDOUT $FE,$D4+8, DEC X1,"hPa" 'Send Word size number to LCD



kako ovaj podebljani dio preraditi da dobijem word velicinu i prikazem ju na GLCDu
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7882
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: LONG to WORD

Post by pedja089 »

Napravi makro da prikaze i long :wink:
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: LONG to WORD

Post by febo26 »

e kad bi ja to znao napravit bilo bi super
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7882
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: LONG to WORD

Post by pedja089 »

Moras ispraviti sledece u include fajlu
GLCD_VarData var LONG ' variable to print to lcd
Dodati:

Code: Select all

ASM
    PrintVarL macro x, y, Variable   ; input values from: @PrintVar 0,1, _any_variable  
    local OverVarL                
    goto OverVarL              
OverVarL
    MOVE?CB  x, _GLCD_X
    MOVE?CB  x, _GLCD_SX
    MOVE?CB  y, _PosY          ; move y from above statement to PosY
    MOVE?NN  Variable, _GLCD_VarData ; move variable in statement to VarData
    L?CALL   _GLCD_VariableOut       ; call VariableOut function
    endm
ENDASM
I ispod labele
GLCD_VariableOut:
dodaj koliko hoces cifara da prikazes.
Primer za 5 cifara:

Code: Select all

       Gosub Lcd_SetX
        Gosub Lcd_SetY         ' place character at position PosX and PosY
        GLCD_Char = (GLCD_VarData dig 4) + 48 ' digit number n to character str format
        gosub Lcd_SendChar        ' print char to screen
        PosX = PosX + 6           ' next x position for character

        Gosub Lcd_SetX
        Gosub Lcd_SetY         ' place character at position PosX and PosY
        GLCD_Char = (GLCD_VarData dig 3) + 48 ' digit number n to character str format
        gosub Lcd_SendChar        ' print char to screen
        PosX = PosX + 6           ' next x position for character

        Gosub Lcd_SetX
        Gosub Lcd_SetY         ' place character at position PosX and PosY
        GLCD_Char = (GLCD_VarData dig 2) + 48 ' digit number n to character str format
        gosub Lcd_SendChar        ' print char to screen
        PosX = PosX + 6           ' next x position for character
        Gosub Lcd_SetX
        Gosub Lcd_SetY         ' place character at position PosX and PosY
        GLCD_Char = (GLCD_VarData dig 1) + 48 ' digit number n to character str format
        gosub Lcd_SendChar        ' print char to screen
        PosX = PosX + 6           ' next x position for character
        Gosub Lcd_SetX
        Gosub Lcd_SetY         ' place character at position PosX and PosY
        GLCD_Char = (GLCD_VarData dig 0) + 48 ' digit number n to character str format
        gosub Lcd_SendChar        ' print char to screen
        PosX = PosX + 6           ' next x position for character
Koristis isto kao i za word...
Samo se ovaj makro zove PrintVarL
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7882
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: LONG to WORD

Post by pedja089 »

Javi jel radi...
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: LONG to WORD

Post by febo26 »

RADI
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7882
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: LONG to WORD

Post by pedja089 »

Super...
Znaci i to bi mogao ubaciti :)
Nikako da nadjem vremena da to zavrsim...
febo26
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 207
Joined: 12-08-2008, 19:58

Re: LONG to WORD

Post by febo26 »

Pedja,
da li je moguce s tvojim include fajlom prikazati neku sliku na GLCD-u
ovaj ispis stringova,varijabli i long varijabli radi odlicno jedino mu jos fali ispis slike.
Trenutno imam na GLCDu ispis vremenski prilika u ovom obliku

TIME: 12:34:00
DATE: 23.4.2013
TEMP: 23.4 C
RH = 46 %
PRESSURE= 1024.43.hPa

sad bih htio jos ubacit neku sliku da se povremeno ispise na ekranu ali ne kuzim kako.
User avatar
pedja089
Administrator sajta
Administrator sajta
Posts: 7882
Joined: 20-02-2007, 14:50
Location: Beočin -Srbija

Re: LONG to WORD

Post by pedja089 »

Uf... Jeste i nije...
Moguce je na ovaj nacin

Code: Select all

 x=1
 call setx
 y=0
 call sety
 for i=0 to 63 
    Lookup i, [$01,...................,$FC,$F8], LCDDATA
    GOSUB Lcd_Pod
 next i
A sad mi nista na brzinu ne pada, sta bi mogao napraviti, da ispisuje ceo prvi red, pa onda drugi itd...
Post Reply