佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1181|回复: 3

MPlab Soruce Code Help!!

[复制链接]
发表于 26-11-2006 09:03 PM | 显示全部楼层 |阅读模式
要怎样写以下的code?

A=256*B+C

D=A*0.4882125

pic data sheet 里只有ADD,
那乘要用什么?
还有0.488要怎样表达?
hex,dec,bin都不能有0.xxx de
回复

使用道具 举报


ADVERTISEMENT

发表于 28-11-2006 08:15 AM | 显示全部楼层
microchip 有 fix point multiplication & division code。

application note AN617:
http://www.microchip.com/stellen ... mp;appnote=en010962

documentation:
http://ww1.microchip.com/downloads/en/AppNotes/00617.pdf

source code:
http://ww1.microchip.com/downloads/en/AppNotes/00617.zip


>>A=256*B+C
>>D=A*0.4882125

如果 B, C 是 integer 那就容易, 用 fix point multiplication。

然后用 fix point multiplication & division:
D = (A * 4882125)/10000000
回复

使用道具 举报

 楼主| 发表于 29-11-2006 10:24 PM | 显示全部楼层
原帖由 GeMan 于 28-11-2006 08:15 AM 发表
microchip 有 fix point multiplication & division code。

application note AN617:
http://www.microchip.com/stellen ... mp;appnote=en010962

docu ...



不懂它的意识,我用pic16f873,
他给的只有16cXXX

A=256*B+C

For this u hav to write a sub routine for multiplication. This can be done using successive addition. If ur value 256 is fixed then u need not want to multiply it. Simply put two zeros in right side.

For example: if B=0x23, then 256*B will be 0x2300, that is two zeroes in right side. Then add C with ur answer. if C=0x45, U will get A=0x2345.

D=A*0.4882125

Remove Decimal point and take the hex value, Multiply it and convert back to decimal and then put the decimal.

Example: In ur equation 0.4882125 , after removing the point u get 4882125, take hex manually, 4882125=0x4A7ECD
change ur equation as
D=A*0x4A7ECD
Then multiply u get 0xA436A3441
Convert it into decimal, u get 44080706625
Then put the decimal point 7 places from right , then u get 44080.706625 ..

以上的能用ma?
回复

使用道具 举报

发表于 1-12-2006 08:50 AM | 显示全部楼层
--不懂它的意识,我用pic16f873,
--他给的只有16cXXX
##一样的。



--A=256*B+C
--For this u hav to write a sub routine for multiplication. --This can be done using successive addition. If ur value --256 is fixed then u need not want to multiply it. Simply --put two zeros in right side.
--For example: if B=0x23, then 256*B will be 0x2300, that --is two zeroes in right side. Then add C with ur answer. --if C=0x45, U will get A=0x2345.
##如果, 256 是 constant, B & C 是 integer 就可以这么做


--D=A*0.4882125
##这个就有问题, 要用 fix point multiplication & division:
D = (A * 4882125)/10000000
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2024 01:17 PM , Processed in 0.170998 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表