Revision: 1509
Author: eur.van.andel
Date: Sat Nov 28 01:47:57 2009
Log: added dependencies in libs, mostly delay
added a new format routine to display some digits in decimal format of  
sword, no decimal point

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

Modified:
  /trunk/include/external/humidity/humidity_sht.jal
  /trunk/include/external/lcd/lcd_sterm_master.jal
  /trunk/include/external/temperature/temperature_tc77.jal
  /trunk/include/jal/format.jal

=======================================
--- /trunk/include/external/humidity/humidity_sht.jal   Fri Dec 19 12:28:21  
2008
+++ /trunk/include/external/humidity/humidity_sht.jal   Sat Nov 28 01:47:57  
2009
@@ -11,11 +11,11 @@
  -- temperature multi sensor module comprising a calibrated digital output.
  -- It comes in 5 flavors, with different accuracy and package style:
  -- sensor   hum acc  temp acc    package
--- SHT10    4.5      0.5         SMD (LCC)
--- SHT11    3.0      0.4         SMD (LCC)
--- SHT15    2.0      0.3         SMD (LCC)
--- SHT71    3.0      0.4         4-pin single-in-line
--- SHT75    1.8      0.3         4-pin single-in-line
+-- SHT10    4.5%     0.5C        SMD (LCC)
+-- SHT11    3.0%     0.4C        SMD (LCC)
+-- SHT15    2.0%     0.3C        SMD (LCC)
+-- SHT71    3.0%     0.4C        4-pin single-in-line
+-- SHT75    1.8%     0.3C        4-pin single-in-line
  -- all consist of the same silicon: the less accurate models are sold  
cheaper.
  -- My experience is mixed: I've seen some consistent +2C offset in  
temperature,
  -- but good humidty measurements. The 4-pin package breaks when you touch  
it.
@@ -26,17 +26,26 @@
  -- 0b0000_0011  starts temperature measurement
  -- 0b0000_0101  starts humidity measurement
  -- device returns three bytes: MSB, LSB and CRC
--- higher functions don't do a CRC check
+-- this library doesn't perform any CRC check
  --
  -- Declarations:
  -- var bit SHT_SCK         -- output pin, clock signal to sensor
  -- var bit SHT_DATA        -- data pin, data flows in both directions
  -- var bit SHT_DATA_DIR    -- direction of data pin
  --
--- Still to do: Temperature calculations in different precisions
--- switching heating on/off
+-- Still to do: switching heating on/off
+
+include delay
+
+
+-- ---------------------- COMMUNICATION ROUTINES ----------------------

  -- send start
+--       _____         ________
+-- DATA:      |_______|
+--           ___     ___
+-- SCK : ___|   |___|   |______
+--
  procedure sht_start() is
     SHT_DATA_DIR = output
     SHT_DATA = high
@@ -126,20 +135,22 @@
  end procedure


--- read raw 14-bit temperature from SHT
--- default value of resolution bit is 14 bit temperature
--- SHT takes 210 ms for measurement @ 14 bits
--- we will wait 300 ms
+-- ------------------- HUMIDITY ROUTINES -------------------------------
+
+-- read raw 12-bit humidity from SHT
+-- default value of resolution bit is 12 bit RH
+-- SHT takes 55 ms for measurement @ 12 bits
+-- we will wait 70 ms
  -- SHT may only be switched on for 10% of the time because of self-heating
--- so this measurement can only happen every two seconds!
-procedure read_raw_temp_sht(byte out MSB, byte out LSB, byte out CRC) is
-   var byte counter = 32
+-- so this measurement can only happen every 500ms
+procedure read_raw_hum_sht(byte out MSB, byte out LSB, byte out CRC) is
+   var byte counter = 8
     sht_start()
-   sht_put_data(0b000_00011)   -- start temperature measurement
+   sht_put_data(0b000_00101)   -- start humidity measurement
     sht_wait_ack
     SHT_DATA_DIR = input

-   while (SHT_DATA == high)  & (counter > 1) loop
+   while ((SHT_DATA == high)  & (counter > 1)) loop
        delay_1ms(10)
        counter = counter - 1
     end loop
@@ -158,13 +169,12 @@
  end procedure


--- read raw 12-bit humidity from SHT
--- default value of resolution bit is 12 bit RH
--- SHT takes 55 ms for measurement @ 12 bits
--- we will wait 70 ms
+-- read humidity from SHT, result in byte precision 1%RH
  -- SHT may only be switched on for 10% of the time because of self-heating
  -- so this measurement can only happen every 500ms
-procedure read_raw_hum_sht(byte out MSB, byte out LSB, byte out CRC) is
+procedure read_hum_sht(byte out hum) is
+   var byte MSB, LSB, CRC
+   var dword tmp
     var byte counter = 8
     sht_start()
     sht_put_data(0b000_00101)   -- start humidity measurement
@@ -187,13 +197,18 @@
     SHT_SCK = high
     delay_1us()
     SHT_SCK = low
+
+   tmp = MSB
+   tmp = tmp *  256 + LSB
+   tmp = -4 + ((tmp * 10) / 247) - (tmp * tmp / 357143)     -- 3 digit  
precision
+   hum = byte (tmp)
+
  end procedure

-
--- read humidity from SHT, result in byte precision 1%RH
+-- read humidity from SHT, result in word precision 0.01%RH
  -- SHT may only be switched on for 10% of the time because of self-heating
  -- so this measurement can only happen every 500ms
-procedure read_hum_sht(byte out hum) is
+procedure read_hum_word_sht(word out hum) is
     var byte MSB, LSB, CRC
     var dword tmp
     var byte counter = 8
@@ -221,24 +236,63 @@

     tmp = MSB
     tmp = tmp *  256 + LSB
-   tmp = -4 + ((tmp * 10) / 247) - (tmp * tmp / 357143)     -- 3 digit  
precision
-   hum = byte (tmp)
+   tmp = -400 + ((tmp * 10000) / 2469) - (tmp * tmp /3571)  -- 4-digit  
precision
+   hum = word (tmp)

  end procedure

--- read humidity from SHT, result in word precision 0.01%RH
+
+-- --------------------------- TEMPERATURE ROUTINES  
----------------------------
+
+-- read raw 14-bit temperature from SHT
+-- default value of resolution bit is 14 bit temperature
+-- SHT takes 320 ms for measurement @ 14 bits
+-- we will wait 400 ms
  -- SHT may only be switched on for 10% of the time because of self-heating
--- so this measurement can only happen every 500ms
-procedure read_hum_word_sht(word out hum) is
+-- so this measurement can only happen every two seconds!
+procedure read_raw_temp_sht(byte out MSB, byte out LSB, byte out CRC) is
+   var byte counter = 41
+   sht_start()
+   sht_put_data(0b000_00011)   -- start temperature measurement
+   sht_wait_ack
+   SHT_DATA_DIR = input
+
+   while (SHT_DATA == high)  & (counter > 1) loop
+      delay_1ms(10)
+      counter = counter - 1
+   end loop
+
+   sht_get_data( MSB )      -- read SHT_DATA
+   sht_put_ack()
+   sht_get_data( LSB )      -- read SHT_DATA
+   sht_put_ack()
+   sht_get_data( CRC )      -- read SHT_DATA
+   SHT_DATA_DIR = output
+   SHT_DATA = high         -- no ack, end transmission
+   delay_1us()
+   SHT_SCK = high
+   delay_1us()
+   SHT_SCK = low
+end procedure
+
+
+-- read Celcius temperature from SHT
+-- with 1 C resolution, result is sbyte type, so -126...+127C
+-- SHT takes 320 ms for measurement @ 14 bits
+-- we will wait 400 ms
+-- SHT may only be switched on for 10% of the time because of self-heating
+-- so this measurement can only happen every four seconds!
+procedure read_celsius_temp_sht(sbyte out celsius) is
     var byte MSB, LSB, CRC
-   var dword tmp
-   var byte counter = 8
+   var sdword tmp
+
+   var byte counter = 32
     sht_start()
-   sht_put_data(0b000_00101)   -- start humidity measurement
+   sht_put_data(0b000_00011)   -- start temperature measurement
     sht_wait_ack
     SHT_DATA_DIR = input

-   while ((SHT_DATA == high)  & (counter > 1)) loop
+   while (SHT_DATA == high)  & (counter > 1) loop
        delay_1ms(10)
        counter = counter - 1
     end loop
@@ -254,10 +308,57 @@
     SHT_SCK = high
     delay_1us()
     SHT_SCK = low
-
-   tmp = MSB
+
+-- equation is T = -40.1 + 14_bits/100
+--  we'll do -401 + 14 bits/10 and divide by ten after that
+
+   tmp = sword(MSB)
     tmp = tmp *  256 + LSB
-   tmp = -400 + ((tmp * 10000) / 2469) - (tmp * tmp /3571)  -- 4-digit  
precision
-   hum = word (tmp)
+   tmp = -401 + (tmp/10)
+   tmp = tmp /10
+   celsius = sbyte(tmp)
+
+end procedure
+
+
+-- read Celcius temperature from SHT
+-- with 0.01 C resolution, result is sword type, so -327.68 .. +327.68 C
+-- SHT takes 320 ms for measurement @ 14 bits
+-- we will wait 400 ms
+-- SHT may only be switched on for 10% of the time because of self-heating
+-- so this measurement can only happen every four seconds!
+procedure read_centicelsius_temp_sht(sword out centicelsius) is
+   var byte MSB, LSB, CRC
+   var sdword tmp
+
+   var byte counter = 32
+   sht_start()
+   sht_put_data(0b000_00011)   -- start temperature measurement
+   sht_wait_ack
+   SHT_DATA_DIR = input
+
+   while (SHT_DATA == high)  & (counter > 1) loop
+      delay_1ms(10)
+      counter = counter - 1
+   end loop
+
+   sht_get_data( MSB )      -- read SHT_DATA
+   sht_put_ack()
+   sht_get_data( LSB )      -- read SHT_DATA
+   sht_put_ack()
+   sht_get_data( CRC )      -- read SHT_DATA
+   SHT_DATA_DIR = output
+   SHT_DATA = high         -- no ack, end transmission
+   delay_1us()
+   SHT_SCK = high
+   delay_1us()
+   SHT_SCK = low
+
+-- equation is T = -40.1 + 0.01 * 14_bits
+--  we'll do -4010 + 14 bits and place the decimal point while printing
+
+   centicelsius = sword(MSB)
+   centicelsius = centicelsius *  256 + LSB
+   centicelsius = -4010 + centicelsius

  end procedure
=======================================
--- /trunk/include/external/lcd/lcd_sterm_master.jal    Thu Aug 27 10:25:02  
2009
+++ /trunk/include/external/lcd/lcd_sterm_master.jal    Sat Nov 28 01:47:57  
2009
@@ -6,9 +6,40 @@
  --
  -- This file is part of jallib (http://jallib.googlecode.com)
  --
--- Description: Master Serial Terminal routines
---           : ** For Eur's Contest **
+-- Description: Sterm (Serial Terminal) is a protocol to write to an  
standard HD44780 LCD
+-- and read from a 4x4 matrix keyboard. It was developed for easy  
debugging of JAL programs.
+-- With Sterm and a single PIC pin you can do a  lot of human interfacing,  
often to the point that
+-- nothing else is needed. Especially usefull for projects "beyond the  
PC", that have to work in the field.
  --
+-- Note: as of oct 4, 2009 the slave code has to be upgraded to JALV2 as  
well, and posted with the schematics.
+--
+-- Expects: a single pin, with sterm_pin as variable and sterm_dir as  
direction, like this:
+--
+-- var bit sterm_pin    is    pin_A4
+-- var bit sterm_dir    is    pin_A4_direction
+--
+-- since the traffic on this pin is bidirectional, the pin needs to be  
protected on both sides:
+--
+--       -+---------+ +5V
+--        |         |
+--       .-.        |
+--       | |10k     |
+--       | |        |
+--       '-'        +--o  Sterm connector
+--        |  ___
+-- o------+-|___|------o  Sterm connector
+-- PIC pin   330
+--                  +--o  Sterm connector
+--                  |
+--                  |
+--                 GND
+--
+-- Obviously, Sterm needs +5V and GND as well. The 10k pull-up resistor  
defines the pin state
+-- when nothing is connected and the 330 Ohm resistor protects against too  
much current, for instance when
+-- master and slave talk at the same time.
+--
+-- Master Serial Terminal routines
+--

  -- Frame structure
  --
@@ -49,6 +80,8 @@
  --   R  =  Reset STerm (Active High).
  --

+include delay
+
  function __term_byte( byte in command1 , byte in data1 ) return byte is
     var byte commandtemp
     var bit available = low
=======================================
--- /trunk/include/external/temperature/temperature_tc77.jal    Sat Nov 15  
09:24:23 2008
+++ /trunk/include/external/temperature/temperature_tc77.jal    Sat Nov 28  
01:47:57 2009
@@ -30,6 +30,8 @@
  -- Writing the status_word is not supported here.
  --

+include delay
+
  -- get raw temperature of TC77
  -- output in word, right justified
  procedure tc77_read_raw(word out raw) is
=======================================
--- /trunk/include/jal/format.jal       Mon Sep  7 12:26:40 2009
+++ /trunk/include/jal/format.jal       Sat Nov 28 01:47:57 2009
@@ -1,6 +1,6 @@
  -- Title: Writes formatted values to output device
  -- Author: Stef Mientki, Copyright (c) 2002 .. 2006, all rights reserved.
--- Adapted-by: Joep Suijs, Albert Faber
+-- Adapted-by: Joep Suijs, Albert Faber, Eur van Andel
  -- Compiler: >=2.2
  --
  -- This file is part of jallib (http://jallib.googlecode.com)
@@ -290,6 +290,67 @@
  end procedure
  --  
-----------------------------------------------------------------------------

+--  
-----------------------------------------------------------------------------
+-- writes decimal formatted signed word to output device
+-- output can be specified in length of string and position
+-- values -32767 to +32768, so lenght = 5 max
+-- last digit is position 0, first is 4 = max
+-- 32768, len=3, pos=2 gives 327
+-- 32768, len=1, pos=0 gives 6
+-- 32768, len=2, pos=4 gives 32
+-- added by Eur van Andel, [email protected], 23 NOV 2009
+--  
-----------------------------------------------------------------------------
+procedure format_sword_dec_length(volatile byte out device, sword in data,
+                                  bit in sign, byte in len, byte in pos) is
+
+   var bit data_sign at data:15
+   var byte char[5]
+   var byte i
+
+   if sign then
+      if data_sign then
+         device = "-"
+         data = - data
+      else
+         device = "+"
+      end if
+   else
+      if data_sign then
+         data = - data
+      end if
+   end if
+
+   if len == 0 then            -- nothing more will be printed
+      return
+   end if
+
+   char[0]= byte("0" + data/10_000)
+   data = data % 10_000
+   char[1] = byte("0" + data/1_000)
+   data = data % 1_000
+   char[2] = byte("0" + data/100)
+   data = data % 100
+   char[3] = byte("0" + data/10)
+   data = data % 10
+   char[4] = byte("0" + data)
+
+   i = 0
+   while i + pos < 5 loop        -- no more than 5 digits
+      device = char[i + pos]
+      i = i + 1
+      len = len - 1
+      if len == 0 then
+         i = 5
+      end if
+   end loop
+
+
+end procedure
+--  
-----------------------------------------------------------------------------
+
+
+
+
  --  
-----------------------------------------------------------------------------
  -- writes decimal formatted signed dword to output device
  -- the output can be specified as a fraction
@@ -409,7 +470,7 @@
     D10 = HH / 10
     HH  = HH % 10

-   -- always dsiplay Zeroes
+   -- always display Zeroes
     device = "0" + D10
     device = "0" + HH
     device = ":"

--

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