Author: eur.van.andel
Date: Tue Sep 23 01:00:04 2008
New Revision: 328

Added:
    trunk/unvalidated/include/external/co2/
    trunk/unvalidated/include/external/co2/t6603_co2.jal
    trunk/unvalidated/sample/by_device/16f877a/read_co2_t6603.jal
Modified:
    trunk/unvalidated/include/device/10f222.jal
    trunk/unvalidated/include/external/lcd/lcd_hd44780_4.jal
    trunk/unvalidated/include/peripheral/usart/serial_hardware.jal

Log:
added t6603 NDIR CO2 sensor library + sample program in by_device/16f877a


Modified: trunk/unvalidated/include/device/10f222.jal
==============================================================================
--- trunk/unvalidated/include/device/10f222.jal (original)
+++ trunk/unvalidated/include/device/10f222.jal Tue Sep 23 01:00:04 2008
@@ -296,4 +296,7 @@
         EXTERNAL = 0x10
         INTERNAL = 0x0
         }
+
+asm movwf OSCCAL
+
  --

Added: trunk/unvalidated/include/external/co2/t6603_co2.jal
==============================================================================
--- (empty file)
+++ trunk/unvalidated/include/external/co2/t6603_co2.jal        Tue Sep 23  
01:00:04 2008
@@ -0,0 +1,269 @@
+-- Title: T6603_CO2, read values from GE/Telaire T6603 CO2 sensor.
+-- Author: Eur van Andel, [EMAIL PROTECTED] Copyright (c) 2008
+-- Adapted-by:
+-- Compiler: =2.4h
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license  
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this library communicates with the T6603 GE/Telaire CO2  
sensor.
+-- This sensor uses the Telaire Tsunami-Lite Commnications Protocol
+-- (no kidding), which is a definition with zero hits on Google.
+--
+-- The brochure is here:  
www.gesensing.com/downloads/datasheets/920-419A_LR.pdf
+-- Library posted with approval from GE.
+-- Some clippings from the protocol document:
+--
+-- -------------- START OF PROTOCOL DOCUMENT CLIPPINGS   
---------------------
+--
+-- The UART communications interface expects a frame size of 8 bits, no  
parity,
+-- one stop bit, and a baud rate of 19200.
+--
+-- A communications delay of several seconds occurs when the Sensor is  
powered
+-- up or power cycled.  This communications delay time is necessary for the
+-- sensor to initialize and achieve full functionality.
+--
+--
+-- UART Commands from PC to Sensor
+-- Commands sent from a host to the Sensor have the following format:
+--
+-- <flag><address><length><command><additional_data>
+--
+-- where:
+--
+-- <flag>     the hex value 0xFF
+-- <address>  one byte hex value. The byte 0xFE is an addr that sensors  
respond.
+-- <length>   total length in bytes of the command and additional data
+-- <command>  one byte hex command, values explained below
+-- <add_data> may or may not be applicable, depending upon the command
+--
+--
+-- For example, to request Sensor identification, the following command is  
used:
+--
+--   0x FF 0xFE   0x02     0x02                 0x03
+--  <flag> <addr> <length> <command> = CMD_READ <additional data> = CO2_PPM
+--
+-- The length of the command is 0x02, since the command CMD_READ, CO2_PPM
+-- consists of the two bytes “0x02 0x01”.
+--
+--
+-- UART Response from Sensor to PC
+-- Responses returned from the Sensor to the host have the following  
format:
+--
+-- <flag><address><length><response_data>
+--
+-- <flag>      the hex value 0xFF.
+-- <address>   one byte hex value.  The byte 0xFA signifies “to master”
+-- <length>    total length in bytes of the response data
+-- <resp_data> may or may not be applicable, depending upon the command
+--
+-- In response to the above identification command CMD_READ CO2_PPM, one  
Sensor
+-- replied with the following byte stream:
+--
+-- 0xFF    0xFA       0x02     0x01  0xD5
+-- <flag>  <address>  <lenght> <resp_data>
+--
+-- The length of the response_data  is 2 bytes  (0x02).  The response is  
0x01D5, -- so 469 ppm, a normal value in a city.
+--
+-- UART Acknowledgement or <ACK> Reply
+-- Some commands require that a Sensor only confirm that the command was
+-- received and the appropriate action was taken. In this case, when a  
Sensor
+-- does not need to return data in response to a command, it will instead  
reply
+-- with an  Acknowledgement response, called an <ACK>.
+-- This is a response packet formatted as shown above, but with the  
<length>
+-- equal to 0x00, and no response data present:
+--
+-- 0xFF    0xFA      0x00
+-- <flag>  <address> <length>
+--
+--
+-- -------------- END OF PROTOCOL DOCUMENT CLIPPINGS  
-----------------------
+--
+--
+-- available functions are:
+-- get_status() return byte
+-- get_co2_ppm() return word           -- CO2 concentration in ppm
+-- get_serial_numer() return string[15]
+-- get_elevation_m() return word       -- in meters above sea level
+-- set elevation_m(var word in meters)
+--
+-- This library uses the serial_hardware and delay_any_mc libraries.
+-- These libs must be included  and initialised in the main program before
+-- including this one.
+
+const FLAG        = 0xFF
+const BRDCST      = 0xFE
+const CMD_READ    = 0x02
+const CMD_UPDATE  = 0x03
+const CMD_STATUS  = 0xB6
+
+const CO2_PPM     = 0x03
+const SERIAL      = 0x01
+const ELEVATION   = 0x0F
+
+var word CO2_global         -- global CO2 value, keeps value when garbage  
reply
+
+-- returns a word with CO2 concentration in ppm
+-- note: if sensor is busy measuring the CO2 values, it will give garbage  
reply
+-- reply is checked for garbage and if so, *PREVIOUS* ppm value is returned
+function get_co2_ppm() return word is
+var byte response[7]      -- serial number is 15 ASCII bytes, others  
shorter
+var byte n                 -- index for response[]
+var word counter           -- for timeout
+var byte char
+
+   serial_hw_write(FLAG)
+   serial_hw_write(BRDCST)
+   serial_hw_write(0x02)            -- length of the remainder of the msg
+   serial_hw_write(CMD_READ)
+   serial_hw_write(CO2_PPM)
+
+    n = 0
+    counter = 0
+    while n < 6 loop                -- response expected is 5 bytes
+      if serial_hw_read(char) then  -- we try to get 6 to clear any junk
+         response[n]= char
+         n = n + 1
+      end if
+      delay_10us(20)                -- less then half a byte frame
+      counter = counter + 1
+      if counter > 500 then         -- we wait 100 miliseconds = 170 frames
+         n = 6                      -- force end of loop
+      end if
+   end loop
+
+-- -----------------------------------------------------
+-- DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
+-- can be used to see if the sensor is really talking
+-- -----------------------------------------------------
+
+--   lcd_set_cursor(0,16)           -- 3rd line (2nd half of first line)
+--   print_byte_hex(lcd, response[0])
+--   lcd = " "
+--   print_byte_hex(lcd, response[1])
+--   lcd = " "
+--   print_byte_hex(lcd, response[2])
+--   lcd = " "
+--   print_byte_hex(lcd, response[3])
+--   lcd = " "
+--   print_byte_hex(lcd, response[4])
+--   lcd = " "
+--   print_byte_hex(lcd, response[5])
+
+-- -----------------------------------------------------
+-- DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
+-- -----------------------------------------------------
+   if response[0] == 0xFF  & response[1] == 0xFA then
+      CO2_global = response[3]
+      CO2_global = (CO2_global << 8) + response[4]
+   end if
+   return CO2_global  -- if not, send previous value
+end function
+
+-- returns status byte. bit_0 = error, bit_1 = warmup,
+-- bit_2 = calibration, bit_3 = idle
+function get_co2_status() return byte is
+var byte response[7]      -- serial number is 15 ASCII bytes, others  
shorter
+var byte n                 -- index for response[]
+var word counter           -- for timeout
+var byte char
+
+   serial_hw_write(FLAG)
+    serial_hw_write(BRDCST)
+    serial_hw_write(0x01)        -- length of the remainder of the msg
+    serial_hw_write(CMD_STATUS)
+
+   n = 0
+   counter = 0
+   while n < 5 loop           -- response expected is 4 bytes
+      if serial_hw_read(char) then
+         response[n]= char
+         n = n + 1
+      end if
+      delay_10us(20)
+      counter = counter + 1
+      if counter > 50 then
+         n = 6
+      end if
+   end loop
+
+   return response[3]            -- bit_0: error, bit_1: warmup,
+end function                  -- bit_2:calibration, bit_3: idle
+
+-- returns 8 byte ASCII string, which should be the same
+-- as the number on the sticker
+procedure get_co2_serial_number(byte out str[8]) is
+var byte response[21]
+var byte n                 -- index for response[]
+var word counter           -- for timeout
+var byte char
+
+   serial_hw_write(FLAG)
+    serial_hw_write(BRDCST)
+    serial_hw_write(0x02)        -- length of the remainder of the msg
+    serial_hw_write(CMD_READ)
+    serial_hw_write(SERIAL)
+
+    n = 0
+    counter = 0
+    while n < 19 loop          -- response expected is 18 bytes
+      if serial_hw_read(char) then
+         response[n]= char
+         n = n + 1
+      end if
+      delay_10us(20)
+      counter = counter + 1
+      if counter > 80 then       -- 27 frames
+         n = 20
+      end if
+   end loop
+
+   n = 0
+   for 8 loop                 -- serial no is not zero-padded!
+      str[n] = response[n+3]
+      n = n + 1
+   end loop
+
+end procedure
+
+-- returns programmed elevation above sea level in meters
+-- this elevation is uses to calculate CO2 concentration correctly
+function get_co2_elevation_m() return word is
+var byte response[15]      -- serial number is 15 ASCII bytes, others  
shorter
+var byte n                 -- index for response[]
+var word counter           -- for timeout
+var byte char
+var dword elevation_ft
+var word elevation_m
+
+   serial_hw_write(FLAG)
+   serial_hw_write(BRDCST)
+   serial_hw_write(0x02)        -- length of the remainder of the msg
+   serial_hw_write(CMD_READ)
+   serial_hw_write(ELEVATION)
+
+   n = 0
+   counter = 0
+   while n < 5 loop           -- response expected is 5 bytes
+      if serial_hw_read(char) then
+         response[n]= char
+         n = n + 1
+      end if
+      delay_10us(20)          -- less then half a byte frame
+      counter = counter + 1
+      if counter > 50 then    -- we wait 17 frames
+         n = 6                -- force end of loop
+      end if
+   end loop
+
+   elevation_ft = response[3]
+   elevation_ft = (elevation << 8) + response[4]      -- feet above  
sealevel
+   elevation_ft = elevation_ft * 3048                 -- meters * 10_000
+   elevation_ft = elevation_ft / 10000                -- meters above  
sealevel
+   elevation_m = elevation_ft                         -- generates warning
+   return elevation_m
+end function
+
+-- should set elevation in meters above sea level, not implemented yet
+procedure set_co2_elevation_m(word in meters) is
+end procedure
\ No newline at end of file

Modified: trunk/unvalidated/include/external/lcd/lcd_hd44780_4.jal
==============================================================================
--- trunk/unvalidated/include/external/lcd/lcd_hd44780_4.jal    (original)
+++ trunk/unvalidated/include/external/lcd/lcd_hd44780_4.jal    Tue Sep 23  
01:00:04 2008
@@ -79,17 +79,29 @@

  end procedure

+-- -------------------------------------------------
  -- Send byte to the LCD as 2 nibbles, compatible with oldskool JAL
  -- ----------------------------------------------------------

  procedure  hd44780'put(byte in c) is

-  lcdwrtnibble(c >> 4)                          -- write high nibble
-  lcdwrtnibble(c)                               -- write low nibble
+  _lcd_wrtnibble(c >> 4)                          -- write high nibble
+  _lcd_wrtnibble(c)                               -- write low nibble
    delay_10us(4)                                 -- > 37 us

  end procedure

+-- -------------------------------------------------
+-- Send byte to the LCD as 2 nibbles,
+-- ----------------------------------------------------------
+
+procedure  lcd'put(byte in c) is
+
+  _lcd_wrtnibble(c >> 4)                          -- write high nibble
+  _lcd_wrtnibble(c)                               -- write low nibble
+  delay_10us(4)                                 -- > 37 us
+
+end procedure


  -- ------------------------------------------------------------
@@ -116,7 +128,7 @@
  -- Specify row and column in base-0 notation.
  -- ------------------------------------------------------------

-procedure  lcd_setcursor(byte in row, byte in col)  is
+procedure  lcd_set_cursor(byte in row, byte in col)  is

    col = col | 0b1000_0000                       -- add offset top line
    if (row > 0) then                             -- 2nd line req'd
@@ -133,30 +145,30 @@
  -- ---------------------------------------------------------

  procedure hd44780_line0() is                  -- line 1 of max 4
-LCD_RS = low                                  -- control character follows
-  lcdwrtchar(0b1000_0000)                     -- address zero in display  
data RAM
+  LCD_RS = low                                -- control character follows
+  lcd_wrtchar(0b1000_0000)                     -- address zero in display  
data RAM
    delay_10us(150)                             -- 1.5 ms
    LCD_RS = high
  end procedure

  procedure hd44780_line1() is                  -- line 2, position 40 on  
4x20 display
-LCD_RS = low                                  --
-  lcdwrtchar(0b1010_1000)                     -- DDRAM addres = 40
-  delay_10us(150)                             --
+  LCD_RS = low
+  lcd_wrtchar(0b1010_1000)                     -- DDRAM addres = 40
+  delay_10us(150)
    LCD_RS = high
  end procedure

  procedure hd44780_line2() is                  -- line 3, position 20 on  
4x20 display
-LCD_RS = low                                  --
-  lcdwrtchar(0b1001_0100)                     -- DDRAM address = 20
-  delay_10us(150)                             --
+  LCD_RS = low
+  lcd_wrtchar(0b1001_0100)                     -- DDRAM address = 20
+  delay_10us(150)
    LCD_RS = high
  end procedure

  procedure hd44780_line3() is                  -- line 4, position 60 on  
4x20 display
-LCD_RS = low                                  --
-  lcdwrtchar(0b1101_0100)                     -- DDRAM address = 60
-  delay_10us(150)                             --
+  LCD_RS = low
+  lcd_wrtchar(0b1101_0100)                     -- DDRAM address = 60
+  delay_10us(150)
    LCD_RS = high
  end procedure


Modified: trunk/unvalidated/include/peripheral/usart/serial_hardware.jal
==============================================================================
--- trunk/unvalidated/include/peripheral/usart/serial_hardware.jal       
(original)
+++ trunk/unvalidated/include/peripheral/usart/serial_hardware.jal      Tue Sep 
 
23 01:00:04 2008
@@ -186,9 +186,8 @@
        -- can be blocked by debugging
        while ! PIR1_TXIF loop end loop
        TXREG = DX[1]
-       -- this is necessary for damned good optimized compilers
-       -- loading of the TXREG doesn't immediatly set PIR1_TXIF !!!!
-       asm nop
+       asm nop         -- this is necessary for damned good optimized compilers
+                               -- loading of the TXREG doesn't immediatly set 
PIR1_TXIF !!!!
        while ! PIR1_TXIF loop end loop
        TXREG = DX[0]
  end procedure
@@ -201,6 +200,7 @@
        -- get byte and transport to outer world
        if PIR1_RCIF then
                data = RCREG
+               PIR1_RCIF       = false                 -- [EMAIL PROTECTED] 
12-sept-08
        else
                return false  ;result = false
        end if

Added: trunk/unvalidated/sample/by_device/16f877a/read_co2_t6603.jal
==============================================================================
--- (empty file)
+++ trunk/unvalidated/sample/by_device/16f877a/read_co2_t6603.jal       Tue Sep 
 
23 01:00:04 2008
@@ -0,0 +1,71 @@
+-- Title: read CO2 values from GE/Telaire T6603 CO2 sensor, show on LCD
+-- Author: Eur van Andel, [EMAIL PROTECTED] Copyright (c) 2008, all rights  
reserved.
+-- Adapted-by:
+-- Compiler: =2.4h
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license  
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: this sample shows how to read CO2 concentration values
+-- from the GE/Telaire CO2 sensor, using the serial_hardware, delay_any_mc
+-- and t6603_co2 library. It uses a 4x16 LCD for user interaction.
+--
+-- Note: the sensors sometimes gives a wrong value, this is just after it
+-- updates the internal value. This can be overcome by polling the status  
byte
+-- until it is non-zero, then waiting for a second before polling the ppm  
value.
+-- This is not done here.
+
+-- select PIC
+include 16f877a
+
+pragma target clock    20_000_000      -- 20 MHz xtal
+pragma target OSC              HS
+pragma target WDT              disabled                -- no watchdog, please
+pragma target LVP              disabled                -- no low voltage 
programming, frees up pin_b3
+
+-- set all IO as digital
+enable_digital_io()
+
+-- ------------------- INCLUDE LIBRARIES --------------------------
+
+const usart_hw_serial          = true  -- true = RS232, false = SPI
+const serial_hw_baudrate       = 19_200
+include serial_hardware
+serial_hw_init()                               -- calculate baudrate, turn 
peripheral on
+
+
+var  bit  LCD_RS        is pin_b5       -- LCD command/data select.
+var  bit  LCD_EN        is pin_b4       -- LCD data trigger
+var byte  lcd_data_port is portb_low    -- LCD data
+portb_direction        = all_output    -- LCD data is portb_low
+include lcd_hd44780_4                  -- LCD library with 4 data lines
+include print                          -- nice formatted output
+
+delay_100ms(5)                                         -- to get the LCD up & 
running
+
+include t6603_co2
+
+-- ---------------- VARIABLES ---------------------------
+
+var word co2                                      -- in ppm
+
+-- --------------- START PROGRAM ---------------------------
+
+lcd_clearscreen()
+lcd_set_cursor(0,0)
+const byte str1[] = "CO2 monitor"
+print_string(hd44780, str1)             -- output string to LCD
+delay_100ms(30)
+
+lcd_clearscreen()
+
+forever loop
+
+       CO2 = get_co2_ppm()
+       lcd_set_cursor(0, 0)                                    -- row 1, 
position = 1
+       print_word_dec(lcd, CO2)
+       lcd="p" lcd="p" lcd="m" lcd =" " lcd =" " lcd =" "
+               
+       delay_100ms(10)                 -- for proper display function
+       
+end loop

--~--~---------~--~----~------------~-------~--~----~
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