;********************************************************************** ;by Nikolai Golovchenko ;12 bit SQARE ROOT ;Input: ;ACCB0 - high byte ;ACCB1 - low byte ;Result: ;ACCB0 - 6bit ;Used: ;TEMPB0 - temporary for result ;TEMPB1 - temporary for input ;LOOPCNT - counter ;Memory used ;32 instructions ;5 RAM bytes ;11+17*5 + 16 + 6 = 118 cycles all cases ;********************************************************************** Sqrt12 clrf TEMPB0 ;clear all used clrf TEMPB1 ;temporary registers movlw 6 ;and setup counter movwf LOOPCNT ; swapf ACCB0, f ;Left justify swapf ACCB1, w ;12bit value andlw 0x0f ;in two byte iorwf ACCB0, f ;accumulator swapf ACCB1, w ; andlw 0xf0 ; movwf ACCB1 ; Sqrt12a rlf ACCB1, f ;shift next rlf ACCB0, f ;two higher bits rlf TEMPB1, f ;of input rlf ACCB1, f ;to rlf ACCB0, f ;TEMPB1 rlf TEMPB1, f ; movf TEMPB0, w ;take current result (shifted 2 bits left) addlw 0x01 ;and OR with 01 (test bit) - addlw clears C rlf TEMPB0, f ;and reserve place for the next bit subwf TEMPB1, w ;test substraction for borrow btfsc _C bsf TEMPB0, 2 ;set next result bit if no borrow btfsc _C movwf TEMPB1 ;store substraction result if no borrow decfsz LOOPCNT ;repeat untill all 6 bits will be found goto Sqrt12a bcf _C rrf TEMPB0, f ;right rrf TEMPB0, w ;justify the result movwf ACCB0 ;and copy to result register return ;********************************************************************** ;Last updated 16Nov99
| file: /techref/microchip/math/sqrt/sqrt12.htm, 1KB, , updated: 2001/11/7 06:27, local time: 2009/11/21 00:42,
38.107.191.102:LOG IN
|
| ©2009 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/microchip/math/sqrt/sqrt12.htm"> PIC Microcontoller Math Method 12 Bit Square Root</A> |
| Did you find what you needed? |
Watch, recieve and send I2C via serial port. 100Kb/s. Also 5 TTL out & 8 in. $15 chip $30 w/ PCB $40 kit $50 A&T |
Robotics nuts!Check out http://www.verinet.com/~dlc/ email: dlc@verinet.com... This guy ROCKS! He has made (and sells but also releases code, docs, etc...) for a number of cool little robotic modules including whiskers, IR proximity detect and remote control, Sonar proximity detect, PWM, Servo, compass. Most of these use the little PIC 12C508 controller which costs basically nothing and is soooo tiny.The 4 servos, 2400 baud serial servo controller is a wonder of magic and he sells the programmed chip for $8. Wow! |
.