1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Basic Printing Formatting Question

Discussion in 'Oshonsoft' started by GreyHairOldGuy, Dec 7, 2014.

  1. GreyHairOldGuy

    GreyHairOldGuy New Member

    Joined:
    May 30, 2011
    Messages:
    12
    Likes:
    0
    Location:
    Canada
    I have been doing a fair amount of controller programming with Oshonsoft and it has been fantastic. I now want to add a simple 2x16 line display and am using 9600 baud serial because it is just one I/O line and I can use almost any spare bit in my PIC controller (using DIGOLE.COM Serial or I2C - LCD Controller - under $10 on ebay)

    I am calculating temperature in degrees F. using the following formula and PTT is my 8 bit count from the A/D (from a thermistor) and PTP is a calculated 16 bit word containing my degrees in F to 1 decimal place (IE 789m = 78.9 degrees F.
    ptp = ((255 - ptt) * 100 / 16) - 150 (which all works fine and calculates correctly)

    My present print statement:
    Serout tx, 9600, "Ct=", #ptt, " Tp=", #ptp, "F", 0xd 'Print Temperature in Degrees F

    Which displays for 66.8 degrees F (with an input A/D count of 124)
    Ct=124 Tp=668F

    So my (Obvious?) question: How do I get it to display 66.8 instead of 668

    Second question on the same vein (am I allowed two?)

    I have two operator controllers that generate a code of - 0 through 3 for Off, Low, Med and High
    Presently I just print the 0-3 code from both Pump 1 and Pump 2 with the following print statement:
    Serout tx, 9600, "Pump1=", #pp1, " ", "Pump2=", #pp2, 0xd 'Print Out Pump Codes

    If I wanted to take that 0-2 code and print out for example:
    Pump 1 = High (which would represent a count of 3), or Pump 1 = Low (etc)
    How would I do that?

    (....am I asking how to work with strings????)

    Thank you in advance for what is probably a dumb question, and I really hope someone can give me a simple explanation.
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,168
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE
    Have you bought the Floating point add on???? Vladimir has enabled Floating point printing in the serout, Hserout and LCDprint statements.

    Other than that you can write a small routine that will output the correct format..

    Code (basic):

    Proc Print_Float(  Value as Word)
       Dim ch as byte
       ch =  value / 100 MOD 10
       Lcdout  (ch + 48)
       ch =  value / 10
       Lcdout  (ch + 48)
       Lcdout  "."
       ch =  value  MOD 10
       Lcdout (ch + 48)
    End Proc
     
    This is a basic piece of code... I have one that will print 1,2 or 3 decimal places...
     
  3. GreyHairOldGuy

    GreyHairOldGuy New Member

    Joined:
    May 30, 2011
    Messages:
    12
    Likes:
    0
    Location:
    Canada
    THANK YOU Ian - I didn't know about MOD
    I ended up with:
    Dim ch As Byte 'Working Register for Temperature Parts
    ch = ptp / 10 'Divide by 10 (Get Integer portion)
    Serout sd, 9600, #ch, "." 'Print Integer Temperature & Decimal Point
    ch = ptp Mod 10 'Get Fraction Remainder
    Serout sd, 9600, #ch, " F", 0xd 'Print Fraction Remainder
    Works fine

    My second question - I have no problem looking for 0-3 and having 4 separate print statements to cover the OFF, LOW, MED HIGH states I wanted to print.
    What I was asking was how do I (and maybe it's not the way to go) preload OFF etc in another part of my program and then print out in one statement.
    DIM XXX(4) as byte ' (I have never used arrays (yet))
    XXX="OFF" ' Preload XXX array with text
    Serout tx,9600, #XXX ' Later on print out my desired text

    3rd question:
    I think I purchased everything and floating point is listed on all the modules I purchased
    I can't seem to find any info on how to use it.

    Tks again
    Mike
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,168
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE

    Trouble with MOD

    a = 101

    Print (a / 10) & "." & ( a MOD 10 )

    answer 10.1 Spot on

    Print (a / 100) & "." & ( a MOD 100)

    answer 1.1..... Nope it won't show the leading zero...
     

Share This Page