Menu

Real or Integer?

Help
MBB
2011-04-23
2013-05-30
  • MBB

    MBB - 2011-04-23

    I'm using a PIC 16F627.

    Lets say I measure a frequency of 42,325 Hz and read this on my LCD display as 42325.  If I divide the 42,325 by 1000 and send it to the LCD, I read 42 on the display.

    Is there any way I can show the .325 decimal part, i.e have the display read 42.325 kHz? (Display a Real number not an Integer)

     
  • gcha44

    gcha44 - 2011-04-23

    hi,
    Some times ago I create a sub I named "printdec" . So you can display on LCD any number you want to divide by 10,100,1000 or 10000 .

    ' factordiv may be 100,1000,10000

    Sub PrintDec (number as word , facteurdiv as word )
    dim wholenumber , remainder  , temp as word

    select case facteurdiv
    case 10
    nop
    case 100
    nop
    case 1000
    nop
    case 10000
    nop
    case else
    exit sub      'to avoid other divisions , even by zero
    end select
    wholenumber= number / facteurdiv
    remainder=number %facteurdiv
    print wholenumber
    print "."
    ' to avoid false displays you must add following lines
    'ie : if number is 10003  and  you want display 10,003
    '10003/1000=10 remainder=3  if you write 10,3 , your display is false but your result is OK

    select case facteurdiv                     
    case 100
    if remainder < 10 then
    print "0"
    end if
    case 1000
    if remainder <100 then
    print "0"
    end if
    if remainder < 10 then
    print "0"
    end if
    case 10000
    if remainder <1000 then
    print "0"
    end if
    if remainder <100 then
    print "0"
    end if
    if remainder< 10 then
    print "0"
    end if
      end select
    print remainder
    end sub

    Regards .GC

     
  • MBB

    MBB - 2011-04-23

    Thanks GC!

     

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.