Revision: 1454
Author: robhamerling
Date: Mon Nov  2 12:37:57 2009
Log: added math library (with currently only sqrt functions)
new sample for 16f886 with use of math library


http://code.google.com/p/jallib/source/detail?r=1454

Added:
  /trunk/include/jal/math.jal
  /trunk/sample/16f886_math.jal
Modified:
  /trunk/CHANGELOG

=======================================
--- /dev/null
+++ /trunk/include/jal/math.jal Mon Nov  2 12:37:57 2009
@@ -0,0 +1,66 @@
+-- ----------------------------------------------------------------------
+-- Title: math.jal - Collection of mathematical functions.
+-- Author: Rob Hamerling, Copyright (c) 2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: 2.4l
+--
+-- This file is part of jallib  (http://jallib.googlecode.com)
+-- Released under the ZLIB license  
(http://www.opensource.org/licenses/zlib-license.html)
+--
+-- Description:
+-- Collection of mathematical routines.
+--
+-- Sources: Several authors.
+--
+-- Notes:
+--
+
+-- --------------------------------------------------------
+-- Calculate the square root of an unsigned 16-bits integer
+-- Returns an 8-bits integer
+-- Original author: Kyle York
+-- --
+function sqrt16(word in x) return byte is
+   var word m, y
+
+   m = 0x4000
+   y = 0
+   while (m != 0) loop
+      var word b
+
+      b = y | m
+      y = y >> 1
+      if (x >= b) then
+         x = x - b
+         y = y | m
+      end if
+      m = m >> 2
+   end loop
+   return byte(y)
+end function
+
+
+-- --------------------------------------------------------
+-- Calculate the square root of an unsigned 32-bits integer
+-- Returns a 16-bits integer
+-- Original author: Kyle York
+-- --
+function sqrt32(dword in x) return word is
+   var dword m, y
+
+   m = 0x40000000
+   y = 0
+   while (m != 0) loop
+      var dword b
+
+      b = y | m
+      y = y >> 1
+      if (x >= b) then
+         x = x - b
+         y = y | m
+      end if
+      m = m >> 2
+   end loop
+   return word(y)
+end function
+
=======================================
--- /dev/null
+++ /trunk/sample/16f886_math.jal       Mon Nov  2 12:37:57 2009
@@ -0,0 +1,67 @@
+-- ------------------------------------------------------
+-- Title: Sample of use of mathematical routines
+--
+-- Author: Rob Hamerling, Copyright (c) 2009, all rights reserved.
+--
+-- Adapted-by:
+--
+-- Compiler: 2.4l
+--
+-- This file is part of jallib  (http://jallib.googlecode.com)
+-- Released under the BSD license  
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description:
+-- Sample mathematical (tes) program for Microchip PIC16f886.
+--
+-- Sources:
+--
+-- Notes:
+--
+-- ------------------------------------------------------
+--
+include 16f886                     -- target PICmicro
+--
+-- This program assumes a 20 MHz resonator or crystal
+-- is connected to pins OSC1 and OSC2.
+pragma target clock 20_000_000      -- oscillator frequency
+-- configuration memory settings (fuses)
+pragma target OSC  HS               -- HS crystal or resonator
+pragma target WDT  disabled         -- no watchdog
+pragma target LVP  disabled         -- no Low Voltage Programming
+pragma target MCLR external         -- reset externally
+--
+enable_digital_io()                 -- disable analog I/O (if any)
+--
+include print
+include delay
+--
+const serial_hw_serial   = true      -- RS232
+const serial_hw_baudrate = 19200     -- speed
+include serial_hardware             -- serial library
+serial_hw_init()
+--
+include math                        -- ibrary with math functions
+--
+alias   led      is pin_C1          -- LED to show looping
+pin_C1_direction =  output
+--
+var word r16                        -- destination of 32 bits result
+var byte r8                         -- destination of 16 bits result
+--
+forever loop
+
+  LED = !LED                        -- flip
+
+  r16 = sqrt32(256*256 + 513)
+  print_word_dec(serial_hw_data,r16)
+  print_crlf(serial_hw_data)
+  delay_100ms(3)
+
+  r8  = sqrt16(16*16 + 33)
+  print_byte_dec(serial_hw_data,r8)
+  print_crlf(serial_hw_data)
+
+  delay_100ms(3)
+
+end loop
+--
=======================================
--- /trunk/CHANGELOG    Sun Nov  1 02:12:55 2009
+++ /trunk/CHANGELOG    Mon Nov  2 12:37:57 2009
@@ -31,9 +31,9 @@

  jal extension:
   - added delay_1s to delay library
- - provisional fix to make rtc_int_tmr0 library independent of ocsillator  
frequency
+ - fix to make rtc_int_tmr0 library independent of ocsillator frequency
   - profiler library to measure execution time of a procedure
- - sqrt library
+ - math library (currently only square root functions)

  samples:
   - seven_segment samples
@@ -43,6 +43,7 @@
   - added sample files for PIC16f723
   - added auto start USB bootloader
   - 3 samples of use of RTC library with 16F886 (resonator and internal  
oscillator)
+ - 1 samples of use of math functions with 16F886

  compiler:
   -

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to