Author: robhamerling
Date: Sun Nov  9 12:53:34 2008
New Revision: 532

Modified:
    trunk/unvalidated/include/peripheral/data_eeprom/pic_data_eeprom.jal

Log:

- Made checks on presence of EECON1 bits and EEADRH independent of each  
other
   (EECON1_EEPGD, EECON1_CFGS and EEADRH may each be present individually)
- Wait for write complete moved from behind to before physical write. This  
is
   like the code sample in the datasheets, and might be slightly faster.




Modified:  
trunk/unvalidated/include/peripheral/data_eeprom/pic_data_eeprom.jal
==============================================================================
--- trunk/unvalidated/include/peripheral/data_eeprom/pic_data_eeprom.jal        
 
(original)
+++ trunk/unvalidated/include/peripheral/data_eeprom/pic_data_eeprom.jal        
 
Sun Nov  9 12:53:34 2008
@@ -6,7 +6,8 @@
  -- This file is part of jallib (http://jallib.googlecode.com)
  -- Released under the BSD license  
(http://www.opensource.org/licenses/bsd-license.php)
  --
--- Description: Write/read 8-bits data to/from data-eeprom
+-- Description:
+-- Write/read 8-bits data to/from data-eeprom
  --
  -- Notes: Limited to the first 256 bytes of EEPROM memory

@@ -16,13 +17,13 @@
  procedure data_eeprom_read(byte in address, byte out data) is
     EEADR = address
     if defined(EECON1_EEPGD) == TRUE then
-      EECON1_EEPGD = FALSE                      -- select data memory
-      if defined(EECON1_CFGS) == TRUE then
-        EECON1_CFGS = FALSE                     -- select data memory
-      end if
-      if defined(EEADRH) == TRUE then
-        EEADRH = 0;                             -- reset high address
-      end if
+      EECON1_EEPGD = FALSE                      -- deselect pgm memory
+   end if
+   if defined(EECON1_CFGS) == TRUE then
+      EECON1_CFGS = FALSE                       -- deselect cfg memory
+   end if
+   if defined(EEADRH) == TRUE then              -- large memory
+      EEADRH = 0                                -- reset high address
     end if
     EECON1_RD = TRUE
     data = EEDATA
@@ -50,21 +51,21 @@
  -- Read byte from data eeprom at given address and return result
  function data_eeprom(byte in address) return byte is
     var byte data
-   data_eeprom_read(address,data)
+   data_eeprom_read(address, data)
     return data
  end function

  -- Read word from data eeprom at given address and return result
  function data_eeprom_word(byte in address) return word is
     var word data
-   data_eeprom_read_word(address,data)
+   data_eeprom_read_word(address, data)
     return data
  end function

  -- Read dword from data eeprom at given address and return result
  function data_eeprom_dword(byte in address) return dword is
     var dword data
-   data_eeprom_read_dword(address,data)
+   data_eeprom_read_dword(address, data)
     return data
  end function

@@ -75,17 +76,21 @@

     var bit gie_old                              -- GIE state

+   while EECON1_WR loop                         -- allow any previous
+     -- spin until write completed              -- write to complete
+   end loop                                     -- before this write
+
     EEADR  = address
     EEDATA = data

     if defined(EECON1_EEPGD) == TRUE then
-      EECON1_EEPGD = FALSE                      -- select data memory
-      if defined(EECON1_CFGS) == TRUE then
-        EECON1_CFGS = FALSE                     -- select data memory
-      end if
-      if defined(EEADRH) == TRUE then           -- large data memory
-        EEADRH = 0;                             -- reset high address
-      end if
+      EECON1_EEPGD = FALSE                      -- deselect pgm memory
+   end if
+   if defined(EECON1_CFGS) == TRUE then
+      EECON1_CFGS = FALSE                       -- deselect cfg memory
+   end if
+   if defined(EEADRH) == TRUE then              -- large memory
+      EEADRH = 0                                -- reset high address
     end if

     gie_old = INTCON_GIE
@@ -99,10 +104,6 @@

     INTCON_GIE = gie_old                         -- restore interrupt status
     EECON1_WREN = FALSE                          -- disable further writing
-
-   while EECON1_WR loop
-     -- spin until write completed
-   end loop

  end procedure


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