|
|||||||||||
| 技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測(cè)控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng) 驅(qū)動(dòng)編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機(jī) | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計(jì) | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
PIC單片機(jī)的計(jì)算功能 |
| 作者:zmoonp 欄目:單片機(jī) |
各位大嚇,本人最近準(zhǔn)備搞一個(gè)課題。里面接口較多,需要一些外部功能。一般在這種情況下,使用PIC單片機(jī)比較理想,本人一切也這樣用了。但是這次控制里面涉及到很多計(jì)算。而PIC中檔產(chǎn)品的計(jì)算功能又很糟糕,請(qǐng)問(wèn)各位有沒(méi)有搞過(guò)用PIC中檔芯片進(jìn)行大量計(jì)算的項(xiàng)目。在這種情況下,那么通常是怎么解決的。 |
| 2樓: | >>參與討論 |
| 作者: dandongren 于 2003/9/3 16:21:00 發(fā)布:
回! 你都需要什么計(jì)算功能?乘除,開(kāi)方?多少位? |
|
| 3樓: | >>參與討論 |
| 作者: zmoonp 于 2003/9/3 17:09:00 發(fā)布:
乘除,16位 應(yīng)該是16位的乘除運(yùn)算。請(qǐng)問(wèn)有這樣的程序庫(kù)嗎?如果用PIC的中檔芯片運(yùn)算時(shí)間長(zhǎng)嗎? |
|
| 4樓: | >>參與討論 |
| 作者: 張明峰 于 2003/9/3 17:35:00 發(fā)布:
如果是PIC16系列,用C 就不用管太多了。更好的是用PIC18系列,有硬件乘法指令。 |
|
| 5樓: | >>參與討論 |
| 作者: HUXIANHUI 于 2003/9/3 18:23:00 發(fā)布:
知了 不過(guò)低級(jí)的沒(méi)有這兩種指令! |
|
| 6樓: | >>參與討論 |
| 作者: hotpower 于 2003/9/4 1:12:00 發(fā)布:
16位乘除法的匯編程序難嗎???離了C就不行了嗎??? |
|
| 7樓: | >>參與討論 |
| 作者: 張明峰 于 2003/9/4 10:46:00 發(fā)布:
會(huì)者不難,難者不會(huì) 不想打擊一大片。但總讓我感覺(jué)到,上此論壇中有很多人是不知道怎樣用子程序?qū)崿F(xiàn)乘除運(yùn)算的。 |
|
| 8樓: | >>參與討論 |
| 作者: xmljx 于 2003/9/4 21:14:00 發(fā)布:
16位乘除在一般的書中很容易就可找到 運(yùn)行時(shí)間不會(huì)長(zhǎng),我用PIC的32位開(kāi)方的運(yùn)行時(shí)間在2mS左右. |
|
| 9樓: | >>參與討論 |
| 作者: jyhmai 于 2003/9/5 13:55:00 發(fā)布:
可以用一些算法來(lái)實(shí)現(xiàn) 雖然PIC沒(méi)有乘.除指令,但可以用一些算法來(lái)現(xiàn)實(shí),運(yùn)行的時(shí)間也不多,你是幾位運(yùn)算,我可以給你子程序。 |
|
| 10樓: | >>參與討論 |
| 作者: hotpower 于 2003/9/7 19:48:00 發(fā)布:
我覺(jué)得高奇論壇辦得不錯(cuò)--比較專業(yè) |
|
| 11樓: | >>參與討論 |
| 作者: sad_shylion 于 2003/9/7 20:00:00 發(fā)布:
16位BIN數(shù)除法 ;******************************************************************* ; Double PRECISION Division ; 16位BIN數(shù)除法 ; ( Optimized for Speed : straight LINE Code ) ; ;*******************************************************************; ; Division : ACCb(16 bits) / ACCa(16 bits) -> ACCb(16 bits) with ; Remainder in ACCc (16 bits) ; (a) Load the Denominator in location ACCaHI & ACCaLO ( 16 bits ) ; (b) Load the Numerator in location ACCbHI & ACCbLO ( 16 bits ) ; (c) CALL D_div ; (d) The 16 bit result is in location ACCbHI & ACCbLO ; (e) The 16 bit Remainder is in locations ACCcHI & ACCcLO ; ; Performance : ; Program MEMORY : 370 ; Clock Cycles : 263 ; ; NOTE : ; The performance specs are for Unsigned arithmetic ( i.e, ; with "SIGNED equ FALSE "). ; ;*******************************************************************; ; ACCaLO equ 10 ACCaHI equ 11 ACCbLO equ 12 ACCbHI equ 13 ACCcLO equ 14 ACCcHI equ 15 ACCDLO equ 16 ACCDHI equ 17 TEMP equ 18 sign equ 19 ; org 0 ;******************************************************************* SIGNED equ FALSE ; Set This To 'TRUE' if the routines ; ; for Multiplication & Division needs ; ; to be assembled as Signed Integer ; ; Routines. If 'FALSE' the above two ; ; routines ( D_mpy & D_div ) use ; ; unsigned arithmetic. ;*******************************************************************; ; division macro ; divMac MACRO LOCAL NOCHK LOCAL NOGO ; bcf STATUS,CARRY rlf ACCDLO rlf ACCDHI rlf ACCcLO rlf ACCcHI movf ACCaHI,w subwf ACCcHI,w ;check if a>c btfss STATUS,Z_bit goto NOCHK movf ACCaLO,w subwf ACCcLO,w ;if msb equal then check lsb NOCHK btfss STATUS,CARRY ;carry set if c>a goto NOGO movf ACCaLO,w ;c-a into c subwf ACCcLO btfss STATUS,CARRY decf ACCcHI movf ACCaHI,w subwf ACCcHI bsf STATUS,CARRY ;shift a 1 into b (result) NOGO rlf ACCbLO rlf ACCbHI ; ENDM ; ;******************************************************************* ; Double PRECISION Divide ( 16/16 -> 16 ) ; ; ( ACCb/ACCa -> ACCb with remainder in ACCc ) : 16 bit OUTPUT ; with Quotiont in ACCb (ACCbHI,ACCbLO) and Remainder in ACCc (ACCcHI,ACCcLO). ; ; NOTE : Before calling this routine, the user should make sure that ; the Numerator(ACCb) is greater than Denominator(ACCa). If ; the case is not true, the user should scale either Numerator ; or Denominator or both such that Numerator is greater than ; the Denominator. ; ; setup movlw D'16' ; for 16 shifts movwf TEMP movf ACCbHI,w ;move ACCb to ACCD movwf ACCDHI movf ACCbLO,w movwf ACCDLO clrf ACCbHI clr |
|
| 12樓: | >>參與討論 |
| 作者: hotpower 于 2003/9/7 21:07:00 發(fā)布:
好!。〉灿行┎蛔。。。 |
|
| 13樓: | >>參與討論 |
| 作者: zmoonp 于 2003/9/10 15:42:00 發(fā)布:
運(yùn)算子程序 我曾經(jīng)在什么地方看到過(guò)的。但是搞忘了,如果哪位打下能夠提供的話,非常感謝 |
|
| 14樓: | >>參與討論 |
| 作者: mcu_51 于 2003/9/10 15:59:00 發(fā)布:
你們到底在說(shuō)什么?有用嗎? LIST P = 16C54, n = 66 ; ;******************************************************************* ; Binary Floating Point Addition, Subtraction, Multiplication ; and Divide routines. ; ; ; Program: FLOAT.ASM ; Revision Date: ; 1-13-97 Compatibility with MPASMWIN 1.40 ; ;*******************************************************************; ; ; Addition : ACCb(16 bits) + ACCa(16 bits) -> ACCb(16 bits) ; (a) Load the 1st operand in location ACCaLO & ACCaHI ( 16 bits ) with ; the 8 bit exponent in EXPa. ; (b) Load the 2nd operand in location ACCbLO & ACCbHI ( 16 bits ) with ; the 8 bit exponent in EXPb. ; (c) CALL F_add ; (d) The result is in location ACCbLO & ACCbHI ( 16 bits ) with ; the 8 bit exponent in EXPb ; ; Program MEMORY : 55 locations ; ;*******************************************************************; ; ; Subtraction : ACCb(16 bits) - ACCa(16 bits) -> ACCb(16 bits) ; (a) Load the 1st operand in location ACCaLO & ACCaHI ( 16 bits ) with ; the 8 bit exponent in EXPa . ; (b) Load the 2nd operand in location ACCbLO & ACCbHI ( 16 bits ) with ; the 8 bit exponent in EXPb . ; (c) CALL F_sub ; (d) The result is in location ACCbLO & ACCbHI ( 16 bits ) with ; the 8 bit exponent in EXPb. ; ; Program MEMORY : 61 locations ; ;*******************************************************************; ; ; Multiplication : ; ACCb(16 bits)EXP(b) * ACCa(16 bits)EXPa -> ACCb(16 bits)EXPb ; where, EXP(x) represents an 8 bit exponent. ; (a) Load the 1st operand in location ACCaLO & ACCaHI ( 16 bits ) with ; an 8 bit exponent in location EXPa ; (b) Load the 2nd operand in location ACCbLO & ACCbHI ( 16 bits ) with ; an 8 bit exponent in location EXPb ; (c) CALL F_mpy ; (d) The 16 bit result overwrites ACCb(ACCbLO & ACCbHI). The exponent ; is stored in EXPb and the results are normalized. ; ; NOTE : If one needs to get a 32 bit PRODUCT( & an 8 bit exponent ), ; re assemble the program after changing the LINE " Mode16 equ TRUE" ; to " Mode16 equ FALSE ". ; If this option is chosen, then the 32 bit result is returned in ; ( ACCbHI, ACCbLO, ACCcHI, ACCcLO ) and the 8 bit exponent in EXPb. ; This method ( with " Mode16 equ FALSE " ) is NOT Recommended. ; ; Program MEMORY : 102 locations ; ;*******************************************************************; ; ; Division : ; ACCb(16 bits)EXP(b) / ACCa(16 bits)EXP(a) -> ACCb(16 bits)EXP(b) ; with Remainder in ACCc (16 bits) ; (a) Load the Denominator in location ACCaHI & ACCaLO ( 16 bits ) ; with exponent in EXPa ; (b) Load the Numerator in location ACCbHI & ACCbLO ( 16 bits ) ; with exponent in EXPa ; (c) CALL F_div ; (d) The 16 bit result is in location ACCbHI & ACCbLO ; with exponent in EXPb ; (e) The 16 bit Remainder is in locations ACCcHI & ACCcLO ; ; Program MEMORY : 86 locations ; ;*******************************************************************; ; ACCaLO equ 10 ACCaHI equ 11 EXPa equ 12 ACCbLO equ 13 ACCbHI equ 14 EXPb equ 15 ACCcLO equ 16 ACCcHI equ 17 ACCdLO equ 18 ACCdHI equ 19 TEMP equ 1A sign equ 1B ; include "p16c5x.inc" PIC54 equ 1FFH ; Define Reset Vector TRUE equ 1 FALSE equ 0 MSB & |
|
|
|
| 免費(fèi)注冊(cè)為維庫(kù)電子開(kāi)發(fā)網(wǎng)會(huì)員,參與電子工程師社區(qū)討論,點(diǎn)此進(jìn)入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號(hào) |