Shop OBEX P1 Docs P2 Docs Learn Events
Serial out — Parallax Forums

Serial out

KiwiKiwi Posts: 85
edited 2005-04-07 14:03 in General Discussion
hello,

Example: say that you have a 8bits memory space, that contains the value #255. I want to display this number on a LCD or Hyperterminal. That would means that i first have to·send the asci value of ·#2, then #5,and· #5.

But how can i implement a division instruction or routine·to obtain the 2,5,5?

Kurt

Comments

  • BeanBean Posts: 8,129
    edited 2005-04-07 10:59
    I typically use the "subtraction" method.

    Count how many times you can subtract 100 until the value underflows, then add 100 to the value
    Count how many times you can subtract 10 until the value underflows, then add 10 to the value
    The value left is the units (1's) value.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "A problem well defined, is a problem·half solved."
    ·
  • KenMKenM Posts: 657
    edited 2005-04-07 14:03
    I also use the method Bean mentioned.

    The entire program can be found at

    ·http://www.parallax.com/sx/contest/contest_door_velocity.asp
    ;this sub is used to get number of hundreds from the division result
    get_bhunds
     inc  bhunds  ;increment bhunds    
     mov  w,source0 ;move 100 decimal into w
     sub  accum0,w ;subtract 100 from accum0
     mov  w,source1 ;move source1 into w
     sb  c  ;skip next line if carry was set
     movsz  w,++source1 ;move into w source1 +1
     sub  accum1,w ;subtract w from accum1
     snb  c  ;skip next line if carry was not set
     jmp  get_bhunds ;jump to get_bhunds
     dec  bhunds  ;decrement bhunds
     mov  w,#$64  ;move $64 (drec 100) into w
     add  accum0,w ;add $64 to accum0
     mov  w,#$00  ;move 0 into w
     mov  temp0,w  ;move w into temp0
     snb  c  ;skip next line if carry was not set
     movsz  w,++temp0 ;move temp0 +1 into w
     add  accum1,w ;add w to accum1 (restore to correct value)
     ret    ;done adding 100 to accum0 and accum1
    ;now bhunds holds the number of 100's from dividing number of micrseconds into the
    ;constant value of 1,610,128
     
    
    ;now get number of ctens
    get_ctens
     inc  ctens  ;increment ctens
     mov  w,source0 ;move source0 into w
     sub  accum0,w ;subtract w from accum0
     snb  c  ;skip if carry not set
     jmp  get_ctens ;jump to get_ctens
     dec  ctens  ;decrement ctens
    ;ctens now holds the number of 10's after the number of 100's was extracted
     mov  w,#$0a  ;move $0a into w
     add  accum0,w ;add w to accum0
    ;accum0 now holds number of left over ctens which is the same as the number of ones
     mov  w,accum0   ;move accum0 into w
     mov  ones,w  ;move w into ones
     ret
    
    
Sign In or Register to comment.