00001 /* 00002 * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")" 00003 * All rights reserved. 00004 * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University) 00005 * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University) 00006 * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University) 00007 * 00008 * Permission to use, copy, modify, and distribute this software and its 00009 * documentation for any purpose, without fee, and without written agreement is 00010 * hereby granted, provided that the above copyright notice, the following 00011 * two paragraphs and the authors appear in all copies of this software. 00012 * 00013 * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR 00014 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00015 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS" 00016 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00021 * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO 00022 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 00023 * 00024 * Please maintain this header in its entirety when copying/modifying 00025 * these files. 00026 * 00027 * 00028 */ 00029 #include "pic24_all.h" 00030 00031 00039 #define SLAVE_I2C_ADDR 0x60 00040 00041 int16 getStringLength(char* psz_1) { 00042 uint16 u16_len; 00043 u16_len = 0; 00044 while (*psz_1) { 00045 psz_1++; 00046 u16_len++; 00047 } 00048 u16_len++; //contains length of string including null 00049 return u16_len; 00050 } 00051 00052 #define BUFSIZE 64 00053 char sz_1[BUFSIZE]; 00054 00055 int main (void) { 00056 uint16 u16_len; 00057 configBasic(HELLO_MSG); 00058 configI2C1(400); //configure I2C for 400 KHz 00059 while (1) { 00060 inStringEcho(sz_1,BUFSIZE); //get a string from the console 00061 if (*sz_1 == 0) continue; //don't send empty string 00062 u16_len = getStringLength(sz_1); //determine string length 00063 writeNI2C1(SLAVE_I2C_ADDR,(uint8 *)sz_1,u16_len); //send the string 00064 readNI2C1(SLAVE_I2C_ADDR, (uint8 *) sz_1,u16_len) ; //read the reversed string 00065 outString(sz_1); 00066 outString("\n"); 00067 } 00068 } 00069