Menu

need help with getting pic to do some math

Help
2008-12-20
2013-05-30
  • Nobody/Anonymous

    here is the relavent parts:

    #chip 16F685, 4 'mhz
    #config OSC=INTOSC, MCLRE=off, WDT=off

    dim test as word
    dim lcdvalue as word
    dim lcdvaluetemp as word

    test = ReadAD10(AN0)
    Bin2ascii1 (test_H)
    Bin2ascii (test)

    sub Bin2ascii1 (LCDValue)#NR
    SERm = lcdvalue
    end sub

    sub Bin2ascii (LCDValue)#NR

    if serm = 1 then
    lcdvaluetemp = lcdvalue + 256
    end if
    if serm = 2 then
    lcdvaluetemp = lcdvalue + 513
    end if
    if serm = 3 then
    lcdvaluetemp = lcdvalue + 768
    end if
    if serm = 0 then
    lcdvaluetemp = lcdvalue
    end if

    lcdvalue = lcdvaluetemp

    lcdvaluetemp = lcdvalue / 1000
    sertho = lcdvaluetemp 
    lcdvalue = lcdvalue - lcdvaluetemp * 1000

    lcdvaluetemp = lcdvalue / 100
    SERCEN = LCDValueTemp 
    LCDValue = LCDValue - LCDValueTemp * 100

    LCDValueTemp = LCDValue /10
    SERDEC = LCDValueTemp
    LCDValue = LCDValue - LCDValueTemp *10

    serone = LCDValue

    I need to have the pic multiply the lcdvaluetemp by 0.4745 to make the output what I want
    but all the ways I have tried to do this I get wierd outputs?

     
    • Nobody/Anonymous

      Complex math does work in fact, in my experience.

      Shouldn't that be 512 instead of 513?

      Also, in your digit code, you will need seperate variables.  In the second / 100 part, you use LCDValue that has the 1000 remainder already.  I don't understand why you are trying to decode a value that is the same, I suspect there is a simpler way to do it in your case.

      Also, you can force word math on a byte by using a [WORD] in the operation.  Not to say it's needed here.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.