CCS PCM C Compiler, Version 4.005, 35009               06-Feb-08 12:00

               Filename: loadControl_main.lst

               ROM used: 7913 words (97%)
                         Largest free fragment is 274
               RAM used: 140 (39%) at main() level
                         342 (96%) worst case
               Stack:    8 worst case (6 in main + 2 for interrupts)

*
0000:  NOP
0001:  MOVLW  18
0002:  MOVWF  0A
0003:  GOTO   672
0004:  MOVWF  7F
0005:  SWAPF  03,W
0006:  CLRF   03
0007:  MOVWF  21
0008:  MOVF   0A,W
0009:  MOVWF  20
000A:  CLRF   0A
000B:  MOVF   04,W
000C:  MOVWF  22
000D:  MOVF   77,W
000E:  MOVWF  23
000F:  MOVF   78,W
0010:  MOVWF  24
0011:  MOVF   79,W
0012:  MOVWF  25
0013:  MOVF   7A,W
0014:  MOVWF  26
0015:  MOVF   7B,W
0016:  MOVWF  27
0017:  BCF    03.7
0018:  BCF    03.5
0019:  MOVLW  8C
001A:  MOVWF  04
001B:  BTFSS  00.5
001C:  GOTO   01F
001D:  BTFSC  0C.5
001E:  GOTO   038
001F:  MOVLW  8C
0020:  MOVWF  04
0021:  BTFSS  00.0
0022:  GOTO   025
0023:  BTFSC  0C.0
0024:  GOTO   03B
0025:  MOVF   22,W
0026:  MOVWF  04
0027:  MOVF   23,W
0028:  MOVWF  77
0029:  MOVF   24,W
002A:  MOVWF  78
002B:  MOVF   25,W
002C:  MOVWF  79
002D:  MOVF   26,W
002E:  MOVWF  7A
002F:  MOVF   27,W
0030:  MOVWF  7B
0031:  MOVF   20,W
0032:  MOVWF  0A
0033:  SWAPF  21,W
0034:  MOVWF  03
0035:  SWAPF  7F,F
0036:  SWAPF  7F,W
0037:  RETFIE
0038:  BCF    0A.3
0039:  BCF    0A.4
003A:  GOTO   07D
003B:  BCF    0A.3
003C:  BCF    0A.4
003D:  GOTO   0FC
.................... /****************************************************************************/ 
.................... /* Copyright 2007 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.       																						  */ 
.................... /*																																					*/ 
.................... /* loadControl_main.c - main loop program															  		*/ 
.................... /*																																					*/ 
.................... /* Rev History:																															*/ 
.................... /* Initial Creation 11/2007		B.Kieft																		    */ 
.................... /*																																					*/ 
.................... /*																																					*/ 
.................... /****************************************************************************/ 
.................... #include <16f876A.h> 
.................... //////// Standard Header file for the PIC16F876A device //////////////// 
.................... #device PIC16F876A 
.................... #list 
....................  
.................... #device ADC=10 ICD=true *=16 
....................  
.................... #include <string.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STRING 
.................... #define _STRING 
.................... #include <stddef.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDDEF 
....................  
.................... #define _STDDEF 
....................  
.................... #if sizeof(int *)==1 
.................... #define ptrdiff_t int 
.................... #else 
.................... #define ptrdiff_t long 
.................... #endif 
....................  
.................... #define size_t int 
.................... #define wchar_t char 
.................... #define NULL 0 
....................  
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) 
....................  
.................... #endif 
....................  
.................... #include <ctype.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _CTYPE 
.................... #define _CTYPE 
....................  
.................... #define islower(x)  isamong(x,"abcdefghijklmnopqrstuvwxyz") 
.................... #define isupper(x)  isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ") 
.................... #define isalnum(x)  isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") 
.................... #define isalpha(x)  isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") 
.................... #define isdigit(x)  isamong(x,"0123456789") 
.................... #define isspace(x)  (x==' ') 
.................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef") 
.................... #define iscntrl(x)  (x<' ') 
.................... #define isprint(x)  (x>=' ') 
.................... #define isgraph(x)  (x>' ') 
.................... #define ispunct(x)  ((x>' ')&&!isalnum(x)) 
....................  
.................... #endif 
....................  
....................  
....................  
....................  
....................  
.................... ////////////////////////////////////////////// 
.................... //// Uncomment the following define to    //// 
.................... //// allow some functions to use a        //// 
.................... //// quicker algorithm, but use more ROM  //// 
.................... ////                                      //// 
.................... //// #define FASTER_BUT_MORE_ROM          //// 
.................... ////////////////////////////////////////////// 
....................  
....................  
....................  
.................... /*Copying functions*/ 
.................... /* standard template: 
....................    void *memmove(void *s1, void *s2, size_t n). 
....................    Copies max of n characters safely (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *memmove(void *s1,char *s2,size_t n) 
.................... { 
....................    char *sc1; 
....................    char *sc2; 
....................    sc1=s1; 
....................    sc2=s2; 
....................    if(sc2<sc1 && sc1 <sc2 +n) 
....................       for(sc1+=n,sc2+=n;0<n;--n) 
....................          *--sc1=*--sc2; 
....................    else 
....................       for(;0<n;--n) 
....................          *sc1++=*sc2++; 
....................   return s1; 
....................   } 
....................  
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? 
....................    Standard template: char *strcpy(char *s1, const char *s2) 
....................    copies the string s2 including the null character to s1*/ 
....................  
.................... char *strcopy(char *s1, char *s2) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; *s2 != 0; s++, s2++) { 
....................      *s = *s2; 
....................   } 
....................   *s = *s2; 
....................   return(s1); 
.................... } 
....................  
.................... /* standard template: 
....................    char *strncpy(char *s1, const char *s2, size_t n). 
....................    Copies max of n characters (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *strncpy(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(s1); 
.................... } 
.................... /***********************************************************/ 
....................  
.................... /*concatenation functions*/ 
.................... /* standard template: char *strcat(char *s1, const char *s2) 
.................... appends s2 to s1*/ 
....................  
.................... char *strcat(char *s1, char *s2) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0') 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) 
.................... appends not more than n characters from s2 to s1*/ 
....................  
.................... char *strncat(char *s1, char *s2, size_t n) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0' && 0<n) 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................       --n; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
....................  
.................... /***********************************************************/ 
....................  
....................  
.................... /*comparison functions*/ 
.................... /* standard template: signed int memcmp(void *s1, void *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int memcmp(void * s1,char *s2,size_t n) 
.................... { 
.................... char *su1, *su2; 
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) 
.................... { 
....................    if(*su1!=*su2) 
....................       return ((*su1<*su2)?-1:+1); 
.................... } 
.................... return 0; 
.................... } 
....................  
.................... /* standard template: int strcmp(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcmp(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
.................... /* standard template: int strcoll(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcoll(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
.................... /* standard template: 
....................    int strncmp(const char *s1, const char *s2, size_t n). 
....................    Compares max of n characters (not following 0) from s1 to s2; 
....................    returns same as strcmp */ 
....................  
.................... signed int strncmp(char *s1, char *s2, size_t n) 
.................... { 
....................    for (; n > 0; s1++, s2++, n--) 
....................       if (*s1 != *s2) 
....................          return((*s1 <*s2) ? -1: 1); 
....................       else if (*s1 == '\0') 
....................          return(0); 
....................    return(0); 
.................... } 
.................... /* standard template: 
....................    int strxfrm(const char *s1, const char *s2, size_t n). 
....................    transforms maximum of n characters from s2 and places them into s1*/ 
.................... size_t strxfrm(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................   int n1; 
....................   n1=n; 
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(n1); 
.................... } 
....................  
....................  
....................  
....................  
....................  
.................... /***********************************************************/ 
.................... /*Search functions*/ 
.................... /* standard template: void *memchr(const char *s, int c). 
....................    Finds first occurrence of c in n characters of s */ 
....................  
.................... char *memchr(void *s,int c,size_t n) 
.................... { 
....................    char uc; 
....................    char *su; 
....................    uc=c; 
*
0FD2:  BSF    03.5
0FD3:  BSF    03.6
0FD4:  MOVF   46,W
0FD5:  MOVWF  48
....................    for(su=s;0<n;++su,--n) 
0FD6:  MOVF   45,W
0FD7:  MOVWF  4A
0FD8:  MOVF   44,W
0FD9:  MOVWF  49
0FDA:  MOVF   47,W
0FDB:  SUBLW  00
0FDC:  BTFSC  03.0
0FDD:  GOTO   7F3
....................       if(*su==uc) 
0FDE:  MOVF   4A,W
0FDF:  MOVWF  7A
0FE0:  MOVF   49,W
0FE1:  MOVWF  04
0FE2:  BCF    03.7
0FE3:  BTFSC  7A.0
0FE4:  BSF    03.7
0FE5:  MOVF   48,W
0FE6:  SUBWF  00,W
0FE7:  BTFSS  03.2
0FE8:  GOTO   7EE
....................       return su; 
0FE9:  MOVF   49,W
0FEA:  MOVWF  78
0FEB:  MOVF   4A,W
0FEC:  MOVWF  79
0FED:  GOTO   7F6
0FEE:  INCF   49,F
0FEF:  BTFSC  03.2
0FF0:  INCF   4A,F
0FF1:  DECF   47,F
0FF2:  GOTO   7DA
....................    return NULL; 
0FF3:  MOVLW  00
0FF4:  MOVWF  78
0FF5:  MOVWF  79
.................... } 
0FF6:  BCF    03.5
0FF7:  BCF    03.6
0FF8:  RETLW  00
....................  
.................... /* standard template: char *strchr(const char *s, int c). 
....................    Finds first occurrence of c in s */ 
....................  
.................... char *strchr(char *s, int c) 
.................... { 
....................    for (; *s != c; s++) 
....................       if (*s == '\0') 
....................          return(0); 
....................    return(s); 
.................... } 
.................... /* standard template: 
....................    size_t strcspn(const char *s1, const char *s2). 
....................    Computes length of max initial segment of s1 that 
....................    consists entirely of characters NOT from s2*/ 
....................  
.................... int *strcspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1 - s1); 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strpbrk(const char *s1, const char *s2). 
....................    Locates first occurence of any character from s2 in s1; 
....................    returns s1 if s2 is empty string */ 
....................  
.................... char *strpbrk(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1); 
....................    return(0); 
.................... } 
....................  
....................  
.................... /* standard template: char *strrchr(const char *s, int c). 
....................    Finds last occurrence of c in s */ 
....................  
.................... char *strrchr(char *s, int c) 
.................... { 
....................    char *p; 
....................  
....................    for (p = 0; ; s++) 
....................    { 
....................       if (*s == c) 
....................          p = s; 
....................       if (*s == '\0') 
....................          return(p); 
....................    } 
.................... } 
.................... /* computes length of max initial segment of s1 consisting 
....................    entirely of characters from s2 */ 
....................  
.................... int *strspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; ; sc2++) 
....................     if (*sc2 == '\0') 
....................        return(sc1 - s1); 
....................          else if (*sc1 == *sc2) 
....................             break; 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strstr(const char *s1, const char *s2); 
....................    Locates first occurence of character sequence s2 in s1; 
....................    returns 0 if s2 is empty string 
....................  
....................    Uncomment #define FASTER_BUT_MORE_ROM at the top of the 
....................    file to use the faster algorithm */ 
.................... char *strstr(char *s1, char *s2) 
.................... { 
....................    char *s, *t; 
....................  
....................    #ifdef FASTER_BUT_MORE_ROM 
....................    if (*s2 == '\0') 
....................          return(s1); 
....................    #endif 
....................  
....................    while (*s1) 
....................    { 
....................       for(s = s1, t = s2; *t && (*s == *t); ++s, ++t); 
....................  
....................       if (*t == '\0') 
....................          return s1; 
....................       ++s1; 
....................       #ifdef FASTER_BUT_MORE_ROM 
....................          while(*s1 != '\0' && *s1 != *s2) 
....................             ++s1; 
....................       #endif 
....................    } 
....................    return 0; 
.................... } 
....................  
.................... /* standard template: char *strtok(char *s1, const char *s2). 
....................  
....................    Finds next token in s1 delimited by a character from separator 
....................    string s2 (which can be different from call to call).  First call 
....................    starts at beginning of s1 searching for first character NOT 
....................    contained in s2; returns 0 if none is found. 
....................    If one is found, it is the start of first token (return value). 
....................    Function then searches from there for a character contained in s2. 
....................    If none is found, current token extends to end of s1, and subsequent 
....................    searches for a token will return 0.  If one is found, it is 
....................    overwritten by '\0', which terminates current token.  Function saves 
....................    pointer to following character from which next search will start. 
....................    Each subsequent call, with 0 as first argument, starts searching 
....................    from saved pointer */ 
....................  
.................... char *strtok(char *s1, char *s2) 
.................... { 
....................    char *beg, *end; 
....................    static char *save; 
*
1E85:  BCF    03.5
1E86:  CLRF   29
1E87:  CLRF   2A
....................  
....................    beg = (s1)? s1: save; 
....................    beg += strspn(beg, s2); 
....................    if (*beg == '\0') 
....................    { 
....................       *save = ' '; 
....................       return(0); 
....................    } 
....................    end = strpbrk(beg, s2); 
....................    if (*end != '\0') 
....................    { 
....................       *end = '\0'; 
....................       end++; 
....................    } 
....................    save = end; 
....................    return(beg); 
.................... } 
....................  
.................... /*****************************************************************/ 
.................... /*Miscellaneous functions*/ 
.................... /* standard template 
.................... maps error number in errnum to an error message string 
.................... Returns: Pointer to string 
.................... */ 
.................... #ifdef _ERRNO 
.................... char * strerror(int errnum) 
.................... { 
.................... char s[15]; 
.................... switch( errnum) 
.................... { 
.................... case 0: 
....................    strcpy(s,"no errors"); 
....................    return s; 
.................... case EDOM : 
....................    strcpy(s,"domain error"); 
....................    return s; 
.................... case ERANGE: 
....................    strcpy(s,"range error"); 
....................    return s; 
.................... } 
.................... } 
.................... #ENDIF 
.................... /* standard template: size_t strlen(const char *s). 
....................    Computes length of s1 (preceding terminating 0) */ 
....................  
.................... int *strlen(char *s) 
.................... { 
....................    char *sc; 
....................  
....................    for (sc = s; *sc != 0; sc++); 
*
1166:  MOVF   11,W
1167:  MOVWF  13
1168:  MOVF   10,W
1169:  MOVWF  12
116A:  MOVF   13,W
116B:  MOVWF  7A
116C:  MOVF   12,W
116D:  MOVWF  04
116E:  BCF    03.7
116F:  BTFSC  7A.0
1170:  BSF    03.7
1171:  MOVF   00,F
1172:  BTFSC  03.2
1173:  GOTO   178
1174:  INCF   12,F
1175:  BTFSC  03.2
1176:  INCF   13,F
1177:  GOTO   16A
....................    return(sc - s); 
1178:  MOVF   10,W
1179:  SUBWF  12,W
117A:  MOVWF  77
117B:  MOVF   13,W
117C:  MOVWF  7A
117D:  MOVF   11,W
117E:  BTFSS  03.0
117F:  INCFSZ 11,W
1180:  SUBWF  7A,F
1181:  MOVF   77,W
1182:  MOVWF  78
1183:  MOVF   7A,W
1184:  MOVWF  79
.................... } 
....................  
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). 
....................    Compares s1 to s2 ignoring case (upper vs. lower) */ 
....................  
.................... signed int stricmp(char *s1, char *s2) 
.................... { 
....................  for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); 
*
1000:  BSF    03.6
1001:  MOVF   35,W
1002:  MOVWF  7A
1003:  MOVF   34,W
1004:  MOVWF  04
1005:  BCF    03.7
1006:  BTFSC  7A.0
1007:  BSF    03.7
1008:  MOVF   00,W
1009:  MOVWF  38
100A:  MOVF   37,W
100B:  MOVWF  7A
100C:  MOVF   36,W
100D:  MOVWF  04
100E:  BCF    03.7
100F:  BTFSC  7A.0
1010:  BSF    03.7
1011:  MOVF   00,W
1012:  SUBWF  38,W
1013:  BTFSC  03.2
1014:  GOTO   071
1015:  MOVF   35,W
1016:  MOVWF  7A
1017:  MOVF   34,W
1018:  MOVWF  04
1019:  BCF    03.7
101A:  BTFSC  7A.0
101B:  BSF    03.7
101C:  MOVF   00,W
101D:  MOVWF  39
101E:  MOVF   39,W
101F:  SUBLW  40
1020:  BTFSC  03.0
1021:  GOTO   026
1022:  MOVF   39,W
1023:  SUBLW  5A
1024:  BTFSC  03.0
1025:  GOTO   02E
1026:  MOVF   39,W
1027:  SUBLW  60
1028:  BTFSC  03.0
1029:  GOTO   088
102A:  MOVF   39,W
102B:  SUBLW  7A
102C:  BTFSS  03.0
102D:  GOTO   088
102E:  MOVF   37,W
102F:  MOVWF  7A
1030:  MOVF   36,W
1031:  MOVWF  04
1032:  BCF    03.7
1033:  BTFSC  7A.0
1034:  BSF    03.7
1035:  MOVF   00,W
1036:  MOVWF  3A
1037:  MOVF   3A,W
1038:  SUBLW  40
1039:  BTFSC  03.0
103A:  GOTO   03F
103B:  MOVF   3A,W
103C:  SUBLW  5A
103D:  BTFSC  03.0
103E:  GOTO   047
103F:  MOVF   3A,W
1040:  SUBLW  60
1041:  BTFSC  03.0
1042:  GOTO   088
1043:  MOVF   3A,W
1044:  SUBLW  7A
1045:  BTFSS  03.0
1046:  GOTO   088
1047:  MOVF   35,W
1048:  MOVWF  7A
1049:  MOVF   34,W
104A:  MOVWF  04
104B:  BCF    03.7
104C:  BTFSC  7A.0
104D:  BSF    03.7
104E:  MOVF   00,W
104F:  MOVWF  3B
1050:  MOVF   37,W
1051:  MOVWF  7A
1052:  MOVF   36,W
1053:  MOVWF  04
1054:  BCF    03.7
1055:  BTFSC  7A.0
1056:  BSF    03.7
1057:  MOVLW  20
1058:  ADDWF  00,W
1059:  SUBWF  3B,W
105A:  BTFSC  03.2
105B:  GOTO   071
105C:  MOVF   37,W
105D:  MOVWF  7A
105E:  MOVF   36,W
105F:  MOVWF  04
1060:  BCF    03.7
1061:  BTFSC  7A.0
1062:  BSF    03.7
1063:  MOVF   00,W
1064:  MOVWF  3D
1065:  MOVF   35,W
1066:  MOVWF  7A
1067:  MOVF   34,W
1068:  MOVWF  04
1069:  BCF    03.7
106A:  BTFSC  7A.0
106B:  BSF    03.7
106C:  MOVLW  20
106D:  ADDWF  00,W
106E:  SUBWF  3D,W
106F:  BTFSS  03.2
1070:  GOTO   088
....................     s1++, s2++) 
....................     if (*s1 == '\0') 
1071:  MOVF   35,W
1072:  MOVWF  7A
1073:  MOVF   34,W
1074:  MOVWF  04
1075:  BCF    03.7
1076:  BTFSC  7A.0
1077:  BSF    03.7
1078:  MOVF   00,F
1079:  BTFSS  03.2
107A:  GOTO   07E
....................        return(0); 
107B:  MOVLW  00
107C:  MOVWF  78
107D:  GOTO   0A1
107E:  MOVF   35,W
107F:  MOVWF  7A
1080:  MOVF   34,W
1081:  INCF   34,F
1082:  BTFSC  03.2
1083:  INCF   35,F
1084:  INCF   36,F
1085:  BTFSC  03.2
1086:  INCF   37,F
1087:  GOTO   001
....................  return((*s1 < *s2) ? -1: 1); 
1088:  MOVF   35,W
1089:  MOVWF  7A
108A:  MOVF   34,W
108B:  MOVWF  04
108C:  BCF    03.7
108D:  BTFSC  35.0
108E:  BSF    03.7
108F:  MOVF   00,W
1090:  MOVWF  38
1091:  MOVF   37,W
1092:  MOVWF  7A
1093:  MOVF   36,W
1094:  MOVWF  04
1095:  BCF    03.7
1096:  BTFSC  37.0
1097:  BSF    03.7
1098:  MOVF   00,W
1099:  SUBWF  38,W
109A:  BTFSC  03.0
109B:  GOTO   09F
109C:  MOVLW  FF
109D:  MOVWF  7A
109E:  GOTO   0A0
109F:  MOVLW  01
10A0:  MOVWF  78
.................... } 
10A1:  BCF    03.6
10A2:  RETLW  00
....................  
....................  
.................... /* standard template: char *strlwr(char *s). 
....................    Replaces uppercase letters by lowercase; 
....................    returns pointer to new string s */ 
....................  
.................... char *strlwr(char *s) 
.................... { 
....................    char *p; 
....................  
....................    for (p = s; *p != '\0'; p++) 
....................       if (*p >= 'A' && *p <='Z') 
....................          *p += 'a' - 'A'; 
....................    return(s); 
.................... } 
....................  
....................  
.................... /************************************************************/ 
....................  
....................  
.................... #endif 
....................  
.................... #include <stdlib.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDLIB 
.................... #define _STDLIB 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Definitions and types 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #ifndef RAND_MAX 
.................... #define RAND_MAX  32767    // The value of which is the maximum value 
....................                            // ... returned by the rand function 
.................... #endif 
....................  
.................... typedef struct { 
....................    signed int quot; 
....................    signed int rem; 
.................... } div_t; 
....................  
.................... typedef struct { 
....................    signed long quot; 
....................    signed long rem; 
.................... } ldiv_t; 
....................  
.................... #include <stddef.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDDEF 
....................  
.................... #define _STDDEF 
....................  
.................... #if sizeof(int *)==1 
.................... #define ptrdiff_t int 
.................... #else 
.................... #define ptrdiff_t long 
.................... #endif 
....................  
.................... #define size_t int 
.................... #define wchar_t char 
.................... #define NULL 0 
....................  
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) 
....................  
.................... #endif 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // String conversion functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Standard template: float atof(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... float atof(char * s); 
....................  
.................... /* Standard template: float atoe(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  * also handles E format numbers 
....................  */ 
.................... float atoe(char * s); 
....................  
.................... /* Standard template: signed int  atoi(char * s) 
....................  * converts the initial portion of the string s to a signed int 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed int atoi(char *s); 
....................  
.................... /* Syntax: signed int32  atoi32(char * s) 
....................    converts the initial portion of the string s to a signed int32 
....................    returns the converted value if any, 0 otherwise*/ 
.................... signed int32 atoi32(char *s); 
....................  
.................... /* Syntax: char *  itoa(signed int32 num, int8 base, char * s) 
....................    converts the signed int32 to a string and 
....................    returns the converted value if any, 0 otherwise*/ 
.................... char * itoa(signed int32 num, int8 base, char * s); 
....................  
.................... /* Standard template: signed long  atol(char * s) 
....................  * converts the initial portion of the string s to a signed long 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed long atol(char *s); 
....................  
.................... /* Standard template: float strtol(char * s,char *endptr) 
....................  * converts the initial portion of the string s to a float 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... float strtod(char *s,char *endptr); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base  to a signed long. 
....................  * Returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... signed long strtol(char *s,char *endptr,signed int base); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base to a unsigned long. 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... long strtoul(char *s,char *endptr,signed int base); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Pseudo-random sequence generation functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The rand function computes a sequence of pseudo-random integers in 
....................  * the range 0 to RAND_MAX 
....................  * 
....................  * Parameters: 
....................  *       (none) 
....................  * 
....................  * Returns: 
....................  *       The pseudo-random integer 
....................  */ 
.................... long rand(void); 
....................  
.................... /* The srand function uses the argument as a seed for a new sequence of 
....................  * pseudo-random numbers to be returned by subsequent calls to rand. 
....................  * 
....................  * Parameters: 
....................  *       [in] seed: The seed value to start from. You might need to pass 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  * 
....................  * Remarks 
....................  *          The srand function sets the starting point for generating 
....................  *       a series of pseudorandom integers. To reinitialize the 
....................  *       generator, use 1 as the seed argument. Any other value for 
....................  *       seed sets the generator to a random starting point. rand 
....................  *       retrieves the pseudorandom numbers that are generated. 
....................  *       Calling rand before any call to srand generates the same 
....................  *       sequence as calling srand with seed passed as 1. 
....................  *          Usually, you need to pass a time here from outer source 
....................  *       so that the numbers will be different every time you run. 
....................  */ 
.................... void srand(unsigned int32 seed); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Memory management functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Comming soon 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Communication with the environment 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The function returns 0 always 
....................  */ 
.................... signed int system(char *string); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Performs a binary search of a sorted array.. 
....................  * 
....................  * Parameters: 
....................  *       [in] key: Object to search for 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       bsearch returns a pointer to an occurrence of key in the array pointed 
....................  *       to by base. If key is not found, the function returns NULL. If the 
....................  *       array is not in order or contains duplicate records with identical keys, 
....................  *       the result is unpredictable. 
....................  */ 
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents 
....................  * of the array are sorted into ascending order according to a comparison 
....................  * function pointed to by compar. 
....................  * 
....................  * Parameters: 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  */ 
.................... //void *qsort(const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Integer arithmetic functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #define labs abs 
....................  
.................... div_t div(signed int numer,signed int denom); 
.................... ldiv_t ldiv(signed long numer,signed long denom); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte character functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte string functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Internal implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #include <stddef.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDDEF 
....................  
.................... #define _STDDEF 
....................  
.................... #if sizeof(int *)==1 
.................... #define ptrdiff_t int 
.................... #else 
.................... #define ptrdiff_t long 
.................... #endif 
....................  
.................... #define size_t int 
.................... #define wchar_t char 
.................... #define NULL 0 
....................  
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) 
....................  
.................... #endif 
....................  
.................... #include <string.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STRING 
.................... #define _STRING 
.................... #include <stddef.h> 
.................... #include <ctype.h> 
....................  
....................  
....................  
.................... ////////////////////////////////////////////// 
.................... //// Uncomment the following define to    //// 
.................... //// allow some functions to use a        //// 
.................... //// quicker algorithm, but use more ROM  //// 
.................... ////                                      //// 
.................... //// #define FASTER_BUT_MORE_ROM          //// 
.................... ////////////////////////////////////////////// 
....................  
....................  
....................  
.................... /*Copying functions*/ 
.................... /* standard template: 
....................    void *memmove(void *s1, void *s2, size_t n). 
....................    Copies max of n characters safely (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *memmove(void *s1,char *s2,size_t n) 
.................... { 
....................    char *sc1; 
....................    char *sc2; 
....................    sc1=s1; 
....................    sc2=s2; 
....................    if(sc2<sc1 && sc1 <sc2 +n) 
....................       for(sc1+=n,sc2+=n;0<n;--n) 
....................          *--sc1=*--sc2; 
....................    else 
....................       for(;0<n;--n) 
....................          *sc1++=*sc2++; 
....................   return s1; 
....................   } 
....................  
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? 
....................    Standard template: char *strcpy(char *s1, const char *s2) 
....................    copies the string s2 including the null character to s1*/ 
....................  
.................... char *strcopy(char *s1, char *s2) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; *s2 != 0; s++, s2++) { 
....................      *s = *s2; 
....................   } 
....................   *s = *s2; 
....................   return(s1); 
.................... } 
....................  
.................... /* standard template: 
....................    char *strncpy(char *s1, const char *s2, size_t n). 
....................    Copies max of n characters (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *strncpy(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(s1); 
.................... } 
.................... /***********************************************************/ 
....................  
.................... /*concatenation functions*/ 
.................... /* standard template: char *strcat(char *s1, const char *s2) 
.................... appends s2 to s1*/ 
....................  
.................... char *strcat(char *s1, char *s2) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0') 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) 
.................... appends not more than n characters from s2 to s1*/ 
....................  
.................... char *strncat(char *s1, char *s2, size_t n) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0' && 0<n) 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................       --n; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
....................  
.................... /***********************************************************/ 
....................  
....................  
.................... /*comparison functions*/ 
.................... /* standard template: signed int memcmp(void *s1, void *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int memcmp(void * s1,char *s2,size_t n) 
.................... { 
.................... char *su1, *su2; 
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) 
.................... { 
....................    if(*su1!=*su2) 
....................       return ((*su1<*su2)?-1:+1); 
.................... } 
.................... return 0; 
.................... } 
....................  
.................... /* standard template: int strcmp(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcmp(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
.................... /* standard template: int strcoll(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcoll(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
.................... /* standard template: 
....................    int strncmp(const char *s1, const char *s2, size_t n). 
....................    Compares max of n characters (not following 0) from s1 to s2; 
....................    returns same as strcmp */ 
....................  
.................... signed int strncmp(char *s1, char *s2, size_t n) 
.................... { 
....................    for (; n > 0; s1++, s2++, n--) 
....................       if (*s1 != *s2) 
....................          return((*s1 <*s2) ? -1: 1); 
....................       else if (*s1 == '\0') 
....................          return(0); 
....................    return(0); 
.................... } 
.................... /* standard template: 
....................    int strxfrm(const char *s1, const char *s2, size_t n). 
....................    transforms maximum of n characters from s2 and places them into s1*/ 
.................... size_t strxfrm(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................   int n1; 
....................   n1=n; 
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(n1); 
.................... } 
....................  
....................  
....................  
....................  
....................  
.................... /***********************************************************/ 
.................... /*Search functions*/ 
.................... /* standard template: void *memchr(const char *s, int c). 
....................    Finds first occurrence of c in n characters of s */ 
....................  
.................... char *memchr(void *s,int c,size_t n) 
.................... { 
....................    char uc; 
....................    char *su; 
....................    uc=c; 
....................    for(su=s;0<n;++su,--n) 
....................       if(*su==uc) 
....................       return su; 
....................    return NULL; 
.................... } 
....................  
.................... /* standard template: char *strchr(const char *s, int c). 
....................    Finds first occurrence of c in s */ 
....................  
.................... char *strchr(char *s, int c) 
.................... { 
....................    for (; *s != c; s++) 
....................       if (*s == '\0') 
....................          return(0); 
....................    return(s); 
.................... } 
.................... /* standard template: 
....................    size_t strcspn(const char *s1, const char *s2). 
....................    Computes length of max initial segment of s1 that 
....................    consists entirely of characters NOT from s2*/ 
....................  
.................... int *strcspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1 - s1); 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strpbrk(const char *s1, const char *s2). 
....................    Locates first occurence of any character from s2 in s1; 
....................    returns s1 if s2 is empty string */ 
....................  
.................... char *strpbrk(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1); 
....................    return(0); 
.................... } 
....................  
....................  
.................... /* standard template: char *strrchr(const char *s, int c). 
....................    Finds last occurrence of c in s */ 
....................  
.................... char *strrchr(char *s, int c) 
.................... { 
....................    char *p; 
....................  
....................    for (p = 0; ; s++) 
....................    { 
....................       if (*s == c) 
....................          p = s; 
....................       if (*s == '\0') 
....................          return(p); 
....................    } 
.................... } 
.................... /* computes length of max initial segment of s1 consisting 
....................    entirely of characters from s2 */ 
....................  
.................... int *strspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; ; sc2++) 
....................     if (*sc2 == '\0') 
....................        return(sc1 - s1); 
....................          else if (*sc1 == *sc2) 
....................             break; 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strstr(const char *s1, const char *s2); 
....................    Locates first occurence of character sequence s2 in s1; 
....................    returns 0 if s2 is empty string 
....................  
....................    Uncomment #define FASTER_BUT_MORE_ROM at the top of the 
....................    file to use the faster algorithm */ 
.................... char *strstr(char *s1, char *s2) 
.................... { 
....................    char *s, *t; 
....................  
....................    #ifdef FASTER_BUT_MORE_ROM 
....................    if (*s2 == '\0') 
....................          return(s1); 
....................    #endif 
....................  
....................    while (*s1) 
....................    { 
....................       for(s = s1, t = s2; *t && (*s == *t); ++s, ++t); 
....................  
....................       if (*t == '\0') 
....................          return s1; 
....................       ++s1; 
....................       #ifdef FASTER_BUT_MORE_ROM 
....................          while(*s1 != '\0' && *s1 != *s2) 
....................             ++s1; 
....................       #endif 
....................    } 
....................    return 0; 
.................... } 
....................  
.................... /* standard template: char *strtok(char *s1, const char *s2). 
....................  
....................    Finds next token in s1 delimited by a character from separator 
....................    string s2 (which can be different from call to call).  First call 
....................    starts at beginning of s1 searching for first character NOT 
....................    contained in s2; returns 0 if none is found. 
....................    If one is found, it is the start of first token (return value). 
....................    Function then searches from there for a character contained in s2. 
....................    If none is found, current token extends to end of s1, and subsequent 
....................    searches for a token will return 0.  If one is found, it is 
....................    overwritten by '\0', which terminates current token.  Function saves 
....................    pointer to following character from which next search will start. 
....................    Each subsequent call, with 0 as first argument, starts searching 
....................    from saved pointer */ 
....................  
.................... char *strtok(char *s1, char *s2) 
.................... { 
....................    char *beg, *end; 
....................    static char *save; 
....................  
....................    beg = (s1)? s1: save; 
....................    beg += strspn(beg, s2); 
....................    if (*beg == '\0') 
....................    { 
....................       *save = ' '; 
....................       return(0); 
....................    } 
....................    end = strpbrk(beg, s2); 
....................    if (*end != '\0') 
....................    { 
....................       *end = '\0'; 
....................       end++; 
....................    } 
....................    save = end; 
....................    return(beg); 
.................... } 
....................  
.................... /*****************************************************************/ 
.................... /*Miscellaneous functions*/ 
.................... /* standard template 
.................... maps error number in errnum to an error message string 
.................... Returns: Pointer to string 
.................... */ 
.................... #ifdef _ERRNO 
.................... char * strerror(int errnum) 
.................... { 
.................... char s[15]; 
.................... switch( errnum) 
.................... { 
.................... case 0: 
....................    strcpy(s,"no errors"); 
....................    return s; 
.................... case EDOM : 
....................    strcpy(s,"domain error"); 
....................    return s; 
.................... case ERANGE: 
....................    strcpy(s,"range error"); 
....................    return s; 
.................... } 
.................... } 
.................... #ENDIF 
.................... /* standard template: size_t strlen(const char *s). 
....................    Computes length of s1 (preceding terminating 0) */ 
....................  
.................... int *strlen(char *s) 
.................... { 
....................    char *sc; 
....................  
....................    for (sc = s; *sc != 0; sc++); 
....................    return(sc - s); 
.................... } 
....................  
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). 
....................    Compares s1 to s2 ignoring case (upper vs. lower) */ 
....................  
.................... signed int stricmp(char *s1, char *s2) 
.................... { 
....................  for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); 
....................     s1++, s2++) 
....................     if (*s1 == '\0') 
....................        return(0); 
....................  return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
....................  
.................... /* standard template: char *strlwr(char *s). 
....................    Replaces uppercase letters by lowercase; 
....................    returns pointer to new string s */ 
....................  
.................... char *strlwr(char *s) 
.................... { 
....................    char *p; 
....................  
....................    for (p = s; *p != '\0'; p++) 
....................       if (*p >= 'A' && *p <='Z') 
....................          *p += 'a' - 'A'; 
....................    return(s); 
.................... } 
....................  
....................  
.................... /************************************************************/ 
....................  
....................  
.................... #endif 
....................  
....................  
.................... div_t div(signed int numer,signed int denom) 
.................... { 
....................    div_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... ldiv_t ldiv(signed long numer,signed long denom) 
.................... { 
....................    ldiv_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... float atof(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... float atoe(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    int expsign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................    int i; 
....................    float exp = 1.0; 
....................    int expcnt = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................       // Handling the exponent 
....................       if (c=='e' || c=='E') { 
....................          c = s[ptr++]; 
....................  
....................          if(c == '-') { 
....................             expsign = 1; 
....................             c = s[ptr++]; 
....................          } 
....................          if(c == '+') 
....................             c = s[ptr++]; 
....................  
....................          while((c >= '0' && c <= '9')) { 
....................             expcnt = 10*expcnt + c - '0'; 
....................             c = s[ptr++]; 
....................          } 
....................  
....................          for(i=0;i<expcnt;i++) 
....................             exp*=10; 
....................  
....................          if(expsign==1) 
....................             result/=exp; 
....................          else 
....................             result*=exp; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... signed int atoi(char *s) 
.................... { 
....................    signed int result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    // Omit all preceeding alpha characters 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................  
....................       // Check for hexa number 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++]; 
....................             c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (sign == 1 && base == 10) 
....................        result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... signed long atol(char *s) 
.................... { 
....................    signed long result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... /* A fast routine to multiply by 10 
....................  */ 
.................... signed int32 mult_with10(int32 num) 
.................... { 
....................    return ( (num << 1) + (num << 3) ); 
.................... } 
....................  
.................... signed int32 atoi32(char *s) 
.................... { 
....................    signed int32 result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
*
066D:  BSF    03.6
066E:  CLRF   3D
....................    sign = 0; 
066F:  CLRF   3B
....................    base = 10; 
0670:  MOVLW  0A
0671:  MOVWF  3C
....................    result = 0; 
0672:  CLRF   3A
0673:  CLRF   39
0674:  CLRF   38
0675:  CLRF   37
....................  
....................    if (!s) 
0676:  MOVF   35,W
0677:  IORWF  36,W
0678:  BTFSS  03.2
0679:  GOTO   67F
....................       return 0; 
067A:  CLRF   77
067B:  CLRF   78
067C:  CLRF   79
067D:  CLRF   7A
067E:  GOTO   7D9
....................    c = s[index++]; 
067F:  MOVF   3D,W
0680:  INCF   3D,F
0681:  ADDWF  35,W
0682:  MOVWF  04
0683:  BCF    03.7
0684:  BTFSC  36.0
0685:  BSF    03.7
0686:  MOVF   00,W
0687:  MOVWF  3E
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
0688:  MOVF   3E,W
0689:  SUBLW  2D
068A:  BTFSS  03.2
068B:  GOTO   698
....................    { 
....................       sign = 1;         // Set the sign to negative 
068C:  MOVLW  01
068D:  MOVWF  3B
....................       c = s[index++]; 
068E:  MOVF   3D,W
068F:  INCF   3D,F
0690:  ADDWF  35,W
0691:  MOVWF  04
0692:  BCF    03.7
0693:  BTFSC  36.0
0694:  BSF    03.7
0695:  MOVF   00,W
0696:  MOVWF  3E
....................    } 
....................    else if (c == '+') 
0697:  GOTO   6A5
0698:  MOVF   3E,W
0699:  SUBLW  2B
069A:  BTFSS  03.2
069B:  GOTO   6A5
....................    { 
....................       c = s[index++]; 
069C:  MOVF   3D,W
069D:  INCF   3D,F
069E:  ADDWF  35,W
069F:  MOVWF  04
06A0:  BCF    03.7
06A1:  BTFSC  36.0
06A2:  BSF    03.7
06A3:  MOVF   00,W
06A4:  MOVWF  3E
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
06A5:  MOVF   3E,W
06A6:  SUBLW  2F
06A7:  BTFSC  03.0
06A8:  GOTO   7C0
06A9:  MOVF   3E,W
06AA:  SUBLW  39
06AB:  BTFSS  03.0
06AC:  GOTO   7C0
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
06AD:  MOVF   3E,W
06AE:  SUBLW  30
06AF:  BTFSS  03.2
06B0:  GOTO   6D1
06B1:  MOVF   3D,W
06B2:  ADDWF  35,W
06B3:  MOVWF  04
06B4:  BCF    03.7
06B5:  BTFSC  36.0
06B6:  BSF    03.7
06B7:  MOVF   00,W
06B8:  SUBLW  78
06B9:  BTFSC  03.2
06BA:  GOTO   6C5
06BB:  MOVF   3D,W
06BC:  ADDWF  35,W
06BD:  MOVWF  04
06BE:  BCF    03.7
06BF:  BTFSC  36.0
06C0:  BSF    03.7
06C1:  MOVF   00,W
06C2:  SUBLW  58
06C3:  BTFSS  03.2
06C4:  GOTO   6D1
....................       { 
....................          base = 16; 
06C5:  MOVLW  10
06C6:  MOVWF  3C
....................          index++; 
06C7:  INCF   3D,F
....................          c = s[index++]; 
06C8:  MOVF   3D,W
06C9:  INCF   3D,F
06CA:  ADDWF  35,W
06CB:  MOVWF  04
06CC:  BCF    03.7
06CD:  BTFSC  36.0
06CE:  BSF    03.7
06CF:  MOVF   00,W
06D0:  MOVWF  3E
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
06D1:  MOVF   3C,W
06D2:  SUBLW  0A
06D3:  BTFSS  03.2
06D4:  GOTO   727
....................       { 
....................          while (c >= '0' && c <= '9') { 
06D5:  MOVF   3E,W
06D6:  SUBLW  2F
06D7:  BTFSC  03.0
06D8:  GOTO   726
06D9:  MOVF   3E,W
06DA:  SUBLW  39
06DB:  BTFSS  03.0
06DC:  GOTO   726
....................             result = (result << 1) + (result << 3);  // result *= 10; 
06DD:  BCF    03.0
06DE:  RLF    37,W
06DF:  MOVWF  40
06E0:  RLF    38,W
06E1:  MOVWF  41
06E2:  RLF    39,W
06E3:  MOVWF  42
06E4:  RLF    3A,W
06E5:  MOVWF  43
06E6:  RLF    37,W
06E7:  MOVWF  77
06E8:  RLF    38,W
06E9:  MOVWF  78
06EA:  RLF    39,W
06EB:  MOVWF  79
06EC:  RLF    3A,W
06ED:  MOVWF  7A
06EE:  RLF    77,F
06EF:  RLF    78,F
06F0:  RLF    79,F
06F1:  RLF    7A,F
06F2:  RLF    77,F
06F3:  RLF    78,F
06F4:  RLF    79,F
06F5:  RLF    7A,F
06F6:  MOVLW  F8
06F7:  ANDWF  77,F
06F8:  MOVF   77,W
06F9:  ADDWF  40,W
06FA:  MOVWF  37
06FB:  MOVF   41,W
06FC:  MOVWF  38
06FD:  MOVF   78,W
06FE:  BTFSC  03.0
06FF:  INCFSZ 78,W
0700:  ADDWF  38,F
0701:  MOVF   42,W
0702:  MOVWF  39
0703:  MOVF   79,W
0704:  BTFSC  03.0
0705:  INCFSZ 79,W
0706:  ADDWF  39,F
0707:  MOVF   43,W
0708:  MOVWF  3A
0709:  MOVF   7A,W
070A:  BTFSC  03.0
070B:  INCFSZ 7A,W
070C:  ADDWF  3A,F
....................             result += (c - '0'); 
070D:  MOVLW  30
070E:  SUBWF  3E,W
070F:  ADDWF  37,F
0710:  MOVLW  00
0711:  BTFSC  03.0
0712:  MOVLW  01
0713:  ADDWF  38,F
0714:  MOVLW  00
0715:  BTFSC  03.0
0716:  MOVLW  01
0717:  ADDWF  39,F
0718:  MOVLW  00
0719:  BTFSC  03.0
071A:  MOVLW  01
071B:  ADDWF  3A,F
....................             c = s[index++]; 
071C:  MOVF   3D,W
071D:  INCF   3D,F
071E:  ADDWF  35,W
071F:  MOVWF  04
0720:  BCF    03.7
0721:  BTFSC  36.0
0722:  BSF    03.7
0723:  MOVF   00,W
0724:  MOVWF  3E
....................          } 
0725:  GOTO   6D5
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
0726:  GOTO   7C0
0727:  MOVF   3C,W
0728:  SUBLW  10
0729:  BTFSS  03.2
072A:  GOTO   7C0
....................       { 
....................          c = toupper(c); 
072B:  MOVF   3E,W
072C:  SUBLW  60
072D:  BTFSC  03.0
072E:  GOTO   736
072F:  MOVF   3E,W
0730:  SUBLW  7A
0731:  BTFSS  03.0
0732:  GOTO   736
0733:  MOVF   3E,W
0734:  ANDLW  DF
0735:  GOTO   737
0736:  MOVF   3E,W
0737:  MOVWF  3E
....................          while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
0738:  MOVF   3E,W
0739:  SUBLW  2F
073A:  BTFSC  03.0
073B:  GOTO   740
073C:  MOVF   3E,W
073D:  SUBLW  39
073E:  BTFSC  03.0
073F:  GOTO   748
0740:  MOVF   3E,W
0741:  SUBLW  40
0742:  BTFSC  03.0
0743:  GOTO   7C0
0744:  MOVF   3E,W
0745:  SUBLW  46
0746:  BTFSS  03.0
0747:  GOTO   7C0
....................             if (c >= '0' && c <= '9') 
0748:  MOVF   3E,W
0749:  SUBLW  2F
074A:  BTFSC  03.0
074B:  GOTO   77D
074C:  MOVF   3E,W
074D:  SUBLW  39
074E:  BTFSS  03.0
074F:  GOTO   77D
....................                result = (result << 4) + (c - '0'); 
0750:  RLF    37,W
0751:  MOVWF  40
0752:  RLF    38,W
0753:  MOVWF  41
0754:  RLF    39,W
0755:  MOVWF  42
0756:  RLF    3A,W
0757:  MOVWF  43
0758:  RLF    40,F
0759:  RLF    41,F
075A:  RLF    42,F
075B:  RLF    43,F
075C:  RLF    40,F
075D:  RLF    41,F
075E:  RLF    42,F
075F:  RLF    43,F
0760:  RLF    40,F
0761:  RLF    41,F
0762:  RLF    42,F
0763:  RLF    43,F
0764:  MOVLW  F0
0765:  ANDWF  40,F
0766:  MOVLW  30
0767:  SUBWF  3E,W
0768:  ADDWF  40,W
0769:  MOVWF  37
076A:  MOVF   41,W
076B:  MOVWF  38
076C:  MOVLW  00
076D:  BTFSC  03.0
076E:  MOVLW  01
076F:  ADDWF  38,F
0770:  MOVF   42,W
0771:  MOVWF  39
0772:  MOVLW  00
0773:  BTFSC  03.0
0774:  MOVLW  01
0775:  ADDWF  39,F
0776:  MOVF   43,W
0777:  MOVWF  3A
0778:  MOVLW  00
0779:  BTFSC  03.0
077A:  MOVLW  01
077B:  ADDWF  3A,F
....................             else 
077C:  GOTO   7AA
....................                result = (result << 4) + (c - 'A' + 10); 
077D:  RLF    37,W
077E:  MOVWF  40
077F:  RLF    38,W
0780:  MOVWF  41
0781:  RLF    39,W
0782:  MOVWF  42
0783:  RLF    3A,W
0784:  MOVWF  43
0785:  RLF    40,F
0786:  RLF    41,F
0787:  RLF    42,F
0788:  RLF    43,F
0789:  RLF    40,F
078A:  RLF    41,F
078B:  RLF    42,F
078C:  RLF    43,F
078D:  RLF    40,F
078E:  RLF    41,F
078F:  RLF    42,F
0790:  RLF    43,F
0791:  MOVLW  F0
0792:  ANDWF  40,F
0793:  MOVLW  41
0794:  SUBWF  3E,W
0795:  ADDLW  0A
0796:  ADDWF  40,W
0797:  MOVWF  37
0798:  MOVF   41,W
0799:  MOVWF  38
079A:  MOVLW  00
079B:  BTFSC  03.0
079C:  MOVLW  01
079D:  ADDWF  38,F
079E:  MOVF   42,W
079F:  MOVWF  39
07A0:  MOVLW  00
07A1:  BTFSC  03.0
07A2:  MOVLW  01
07A3:  ADDWF  39,F
07A4:  MOVF   43,W
07A5:  MOVWF  3A
07A6:  MOVLW  00
07A7:  BTFSC  03.0
07A8:  MOVLW  01
07A9:  ADDWF  3A,F
....................  
....................             c = s[index++];c = toupper(c); 
07AA:  MOVF   3D,W
07AB:  INCF   3D,F
07AC:  ADDWF  35,W
07AD:  MOVWF  04
07AE:  BCF    03.7
07AF:  BTFSC  36.0
07B0:  BSF    03.7
07B1:  MOVF   00,W
07B2:  MOVWF  3E
07B3:  SUBLW  60
07B4:  BTFSC  03.0
07B5:  GOTO   7BD
07B6:  MOVF   3E,W
07B7:  SUBLW  7A
07B8:  BTFSS  03.0
07B9:  GOTO   7BD
07BA:  MOVF   3E,W
07BB:  ANDLW  DF
07BC:  GOTO   7BE
07BD:  MOVF   3E,W
07BE:  MOVWF  3E
....................          } 
07BF:  GOTO   738
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
07C0:  MOVF   3C,W
07C1:  SUBLW  0A
07C2:  BTFSS  03.2
07C3:  GOTO   7D1
07C4:  DECFSZ 3B,W
07C5:  GOTO   7D1
....................       result = -result; 
07C6:  COMF   37,F
07C7:  COMF   38,F
07C8:  COMF   39,F
07C9:  COMF   3A,F
07CA:  INCF   37,F
07CB:  BTFSC  03.2
07CC:  INCF   38,F
07CD:  BTFSC  03.2
07CE:  INCF   39,F
07CF:  BTFSC  03.2
07D0:  INCF   3A,F
....................  
....................    return(result); 
07D1:  MOVF   37,W
07D2:  MOVWF  77
07D3:  MOVF   38,W
07D4:  MOVWF  78
07D5:  MOVF   39,W
07D6:  MOVWF  79
07D7:  MOVF   3A,W
07D8:  MOVWF  7A
.................... } 
07D9:  BCF    03.6
07DA:  RETLW  00
....................  
.................... char * itoa(signed int32 num, int8 base, char *s) 
.................... { 
....................      int32 temp=1; 
....................      int8 i,sign=0,cnt=0; 
....................      char c; 
....................  
....................      if(num<0) { 
....................          sign=1;        // Check for negative number 
....................          num*=-1; 
....................      } 
....................  
....................      while(temp>0) { 
....................          temp=(num/base); 
....................          s[cnt]=(num%base)+'0';    // Conversion 
....................  
....................          if(s[cnt]>0x39) 
....................             s[cnt]+=0x7; 
....................  
....................          cnt++; 
....................          num=temp; 
....................      } 
....................  
....................      if(sign==1) { 
....................          s[cnt]=0x2D;      // Negative sign 
....................          cnt++; 
....................      } 
....................  
....................      for(i = 0;i<(int8)(cnt/2);i++) { 
....................  
....................          c=s[i]; 
....................          s[i]=s[cnt-i-1];        // Reverse the number 
....................          s[cnt-i-1]=c; 
....................      } 
....................      s[cnt]='\0';     // End the string 
....................      return s; 
.................... } 
....................  
.................... float strtod(char *s,char *endptr) { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0, point = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c=s[ptr++]; 
....................  
....................  
....................    while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 0) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          point = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 1) { 
....................          pow10 = pow10*10; 
....................          result += (c - '0')/pow10; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '+') { 
....................          c = s[ptr++]; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    if(endptr) 
....................    { 
....................       if (ptr) { 
....................          ptr--; 
....................          *((char *)endptr)=s+ptr; 
....................       } 
....................       else 
....................          *((char *)endptr)=s; 
....................    } 
....................  
....................    return(result); 
.................... } 
....................  
.................... long strtoul(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    unsigned long x=0; 
*
1197:  CLRF   1B
1198:  CLRF   1C
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
1199:  MOVLW  30
119A:  MOVWF  1E
119B:  MOVLW  31
119C:  MOVWF  1F
119D:  MOVLW  32
119E:  MOVWF  20
119F:  MOVLW  33
11A0:  MOVWF  21
11A1:  MOVLW  34
11A2:  MOVWF  22
11A3:  MOVLW  35
11A4:  MOVWF  23
11A5:  MOVLW  36
11A6:  MOVWF  24
11A7:  MOVLW  37
11A8:  MOVWF  25
11A9:  MOVLW  38
11AA:  MOVWF  26
11AB:  MOVLW  39
11AC:  MOVWF  27
11AD:  MOVLW  61
11AE:  MOVWF  28
11AF:  MOVLW  62
11B0:  MOVWF  29
11B1:  MOVLW  63
11B2:  MOVWF  2A
11B3:  MOVLW  64
11B4:  MOVWF  2B
11B5:  MOVLW  65
11B6:  MOVWF  2C
11B7:  MOVLW  66
11B8:  MOVWF  2D
11B9:  MOVLW  67
11BA:  MOVWF  2E
11BB:  MOVLW  68
11BC:  MOVWF  2F
11BD:  MOVLW  69
11BE:  MOVWF  30
11BF:  MOVLW  6A
11C0:  MOVWF  31
11C1:  MOVLW  6B
11C2:  MOVWF  32
11C3:  MOVLW  6C
11C4:  MOVWF  33
11C5:  MOVLW  6D
11C6:  MOVWF  34
11C7:  MOVLW  6E
11C8:  MOVWF  35
11C9:  MOVLW  6F
11CA:  MOVWF  36
11CB:  MOVLW  70
11CC:  MOVWF  37
11CD:  MOVLW  71
11CE:  MOVWF  38
11CF:  MOVLW  73
11D0:  MOVWF  39
11D1:  MOVLW  74
11D2:  MOVWF  3A
11D3:  MOVLW  75
11D4:  MOVWF  3B
11D5:  MOVLW  76
11D6:  MOVWF  3C
11D7:  MOVLW  77
11D8:  MOVWF  3D
11D9:  MOVLW  78
11DA:  MOVWF  3E
11DB:  MOVLW  79
11DC:  MOVWF  3F
11DD:  MOVLW  7A
11DE:  MOVWF  40
11DF:  CLRF   41
....................    for(sc=s;isspace(*sc);++sc); 
11E0:  MOVF   11,W
11E1:  MOVWF  16
11E2:  MOVF   10,W
11E3:  MOVWF  15
11E4:  MOVF   16,W
11E5:  MOVWF  7A
11E6:  MOVF   15,W
11E7:  MOVWF  04
11E8:  BCF    03.7
11E9:  BTFSC  7A.0
11EA:  BSF    03.7
11EB:  MOVF   00,W
11EC:  SUBLW  20
11ED:  BTFSS  03.2
11EE:  GOTO   1F3
11EF:  INCF   15,F
11F0:  BTFSC  03.2
11F1:  INCF   16,F
11F2:  GOTO   1E4
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
11F3:  MOVF   16,W
11F4:  MOVWF  7A
11F5:  MOVF   15,W
11F6:  MOVWF  04
11F7:  BCF    03.7
11F8:  BTFSC  16.0
11F9:  BSF    03.7
11FA:  MOVF   00,W
11FB:  SUBLW  2D
11FC:  BTFSC  03.2
11FD:  GOTO   209
11FE:  MOVF   16,W
11FF:  MOVWF  7A
1200:  MOVF   15,W
1201:  MOVWF  04
1202:  BCF    03.7
1203:  BTFSC  16.0
1204:  BSF    03.7
1205:  MOVF   00,W
1206:  SUBLW  2B
1207:  BTFSS  03.2
1208:  GOTO   215
1209:  MOVF   16,W
120A:  MOVWF  7A
120B:  MOVF   15,W
120C:  INCF   15,F
120D:  BTFSC  03.2
120E:  INCF   16,F
120F:  MOVWF  04
1210:  BCF    03.7
1211:  BTFSC  7A.0
1212:  BSF    03.7
1213:  MOVF   00,W
1214:  GOTO   216
1215:  MOVLW  2B
1216:  MOVWF  1D
....................    if(sign=='-') 
1217:  MOVF   1D,W
1218:  SUBLW  2D
1219:  BTFSS  03.2
121A:  GOTO   22A
....................    { 
....................       if (endptr) 
121B:  MOVF   12,W
121C:  IORWF  13,W
121D:  BTFSC  03.2
121E:  GOTO   226
....................       { 
....................         *((char *)endptr)=s; 
121F:  MOVF   12,W
1220:  MOVWF  04
1221:  BCF    03.7
1222:  BTFSC  13.0
1223:  BSF    03.7
1224:  MOVF   10,W
1225:  MOVWF  00
....................       } 
....................       return 0; 
1226:  MOVLW  00
1227:  MOVWF  78
1228:  MOVWF  79
1229:  GOTO   39F
....................    } 
....................  
....................    if (base <0 || base ==1|| base >36) // invalid base 
122A:  BTFSC  14.7
122B:  GOTO   235
122C:  DECFSZ 14,W
122D:  GOTO   22F
122E:  GOTO   235
122F:  BTFSC  14.7
1230:  GOTO   245
1231:  MOVF   14,W
1232:  SUBLW  24
1233:  BTFSC  03.0
1234:  GOTO   245
....................    { 
....................       if (endptr) 
1235:  MOVF   12,W
1236:  IORWF  13,W
1237:  BTFSC  03.2
1238:  GOTO   240
....................       { 
....................         *((char *)endptr)=s; 
1239:  MOVF   12,W
123A:  MOVWF  04
123B:  BCF    03.7
123C:  BTFSC  13.0
123D:  BSF    03.7
123E:  MOVF   10,W
123F:  MOVWF  00
....................       } 
....................       return 0; 
1240:  MOVLW  00
1241:  MOVWF  78
1242:  MOVWF  79
1243:  GOTO   39F
....................    } 
....................    else if (base) 
1244:  GOTO   2DB
1245:  MOVF   14,F
1246:  BTFSC  03.2
1247:  GOTO   2A0
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
1248:  MOVF   14,W
1249:  SUBLW  10
124A:  BTFSS  03.2
124B:  GOTO   26F
124C:  MOVF   16,W
124D:  MOVWF  7A
124E:  MOVF   15,W
124F:  MOVWF  04
1250:  BCF    03.7
1251:  BTFSC  7A.0
1252:  BSF    03.7
1253:  MOVF   00,W
1254:  SUBLW  30
1255:  BTFSS  03.2
1256:  GOTO   26F
1257:  MOVLW  01
1258:  ADDWF  15,W
1259:  MOVWF  04
125A:  BCF    03.7
125B:  BTFSC  16.0
125C:  BSF    03.7
125D:  MOVF   00,W
125E:  SUBLW  78
125F:  BTFSC  03.2
1260:  GOTO   26B
1261:  MOVLW  01
1262:  ADDWF  15,W
1263:  MOVWF  04
1264:  BCF    03.7
1265:  BTFSC  16.0
1266:  BSF    03.7
1267:  MOVF   00,W
1268:  SUBLW  58
1269:  BTFSS  03.2
126A:  GOTO   26F
....................          sc+=2; 
126B:  MOVLW  02
126C:  ADDWF  15,F
126D:  BTFSC  03.0
126E:  INCF   16,F
....................       if(base==8 && *sc =='0') 
126F:  MOVF   14,W
1270:  SUBLW  08
1271:  BTFSS  03.2
1272:  GOTO   282
1273:  MOVF   16,W
1274:  MOVWF  7A
1275:  MOVF   15,W
1276:  MOVWF  04
1277:  BCF    03.7
1278:  BTFSC  7A.0
1279:  BSF    03.7
127A:  MOVF   00,W
127B:  SUBLW  30
127C:  BTFSS  03.2
127D:  GOTO   282
....................          sc+=1; 
127E:  MOVLW  01
127F:  ADDWF  15,F
1280:  BTFSC  03.0
1281:  INCF   16,F
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
1282:  MOVF   14,W
1283:  SUBLW  02
1284:  BTFSS  03.2
1285:  GOTO   29F
1286:  MOVF   16,W
1287:  MOVWF  7A
1288:  MOVF   15,W
1289:  MOVWF  04
128A:  BCF    03.7
128B:  BTFSC  7A.0
128C:  BSF    03.7
128D:  MOVF   00,W
128E:  SUBLW  30
128F:  BTFSS  03.2
1290:  GOTO   29F
1291:  MOVLW  01
1292:  ADDWF  15,W
1293:  MOVWF  04
1294:  BCF    03.7
1295:  BTFSC  16.0
1296:  BSF    03.7
1297:  MOVF   00,W
1298:  SUBLW  62
1299:  BTFSS  03.2
129A:  GOTO   29F
....................          sc+=2; 
129B:  MOVLW  02
129C:  ADDWF  15,F
129D:  BTFSC  03.0
129E:  INCF   16,F
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
129F:  GOTO   2DB
12A0:  MOVF   16,W
12A1:  MOVWF  7A
12A2:  MOVF   15,W
12A3:  MOVWF  04
12A4:  BCF    03.7
12A5:  BTFSC  7A.0
12A6:  BSF    03.7
12A7:  MOVF   00,W
12A8:  SUBLW  30
12A9:  BTFSC  03.2
12AA:  GOTO   2AE
....................       base=10; 
12AB:  MOVLW  0A
12AC:  MOVWF  14
....................    else if (sc[1]=='x' || sc[1]=='X') 
12AD:  GOTO   2DB
12AE:  MOVLW  01
12AF:  ADDWF  15,W
12B0:  MOVWF  04
12B1:  BCF    03.7
12B2:  BTFSC  16.0
12B3:  BSF    03.7
12B4:  MOVF   00,W
12B5:  SUBLW  78
12B6:  BTFSC  03.2
12B7:  GOTO   2C2
12B8:  MOVLW  01
12B9:  ADDWF  15,W
12BA:  MOVWF  04
12BB:  BCF    03.7
12BC:  BTFSC  16.0
12BD:  BSF    03.7
12BE:  MOVF   00,W
12BF:  SUBLW  58
12C0:  BTFSS  03.2
12C1:  GOTO   2C9
....................       base =16,sc+=2; 
12C2:  MOVLW  10
12C3:  MOVWF  14
12C4:  MOVLW  02
12C5:  ADDWF  15,F
12C6:  BTFSC  03.0
12C7:  INCF   16,F
....................    else if(sc[1]=='b') 
12C8:  GOTO   2DB
12C9:  MOVLW  01
12CA:  ADDWF  15,W
12CB:  MOVWF  04
12CC:  BCF    03.7
12CD:  BTFSC  16.0
12CE:  BSF    03.7
12CF:  MOVF   00,W
12D0:  SUBLW  62
12D1:  BTFSS  03.2
12D2:  GOTO   2D9
....................       base=2,sc+=2; 
12D3:  MOVLW  02
12D4:  MOVWF  14
12D5:  ADDWF  15,F
12D6:  BTFSC  03.0
12D7:  INCF   16,F
....................    else 
12D8:  GOTO   2DB
....................       base=8; 
12D9:  MOVLW  08
12DA:  MOVWF  14
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
12DB:  MOVF   16,W
12DC:  MOVWF  18
12DD:  MOVF   15,W
12DE:  MOVWF  17
12DF:  MOVF   16,W
12E0:  MOVWF  7A
12E1:  MOVF   15,W
12E2:  MOVWF  04
12E3:  BCF    03.7
12E4:  BTFSC  7A.0
12E5:  BSF    03.7
12E6:  MOVF   00,W
12E7:  SUBLW  30
12E8:  BTFSS  03.2
12E9:  GOTO   2EE
12EA:  INCF   15,F
12EB:  BTFSC  03.2
12EC:  INCF   16,F
12ED:  GOTO   2DF
....................    sd=memchr(digits,tolower(*sc),base); 
12EE:  MOVF   16,W
12EF:  MOVWF  7A
12F0:  MOVF   15,W
12F1:  MOVWF  04
12F2:  BCF    03.7
12F3:  BTFSC  16.0
12F4:  BSF    03.7
12F5:  MOVF   00,W
12F6:  MOVWF  42
12F7:  SUBLW  40
12F8:  BTFSC  03.0
12F9:  GOTO   301
12FA:  MOVF   42,W
12FB:  SUBLW  5A
12FC:  BTFSS  03.0
12FD:  GOTO   301
12FE:  MOVF   42,W
12FF:  IORLW  20
1300:  GOTO   302
1301:  MOVF   42,W
1302:  MOVWF  43
1303:  MOVLW  01
1304:  MOVWF  45
1305:  MOVLW  9E
1306:  MOVWF  44
1307:  MOVF   42,W
1308:  MOVWF  46
1309:  MOVF   14,W
130A:  MOVWF  47
130B:  BCF    0A.4
130C:  BSF    0A.3
130D:  BCF    03.5
130E:  BCF    03.6
130F:  CALL   7D2
1310:  BSF    0A.4
1311:  BCF    0A.3
1312:  MOVF   79,W
1313:  BSF    03.5
1314:  BSF    03.6
1315:  MOVWF  1A
1316:  MOVF   78,W
1317:  MOVWF  19
....................    for(; sd!=0; ) 
1318:  MOVF   19,F
1319:  BTFSS  03.2
131A:  GOTO   31E
131B:  MOVF   1A,F
131C:  BTFSC  03.2
131D:  GOTO   379
....................    { 
....................       x=x*base+(int16)(sd-digits); 
131E:  CLRF   7A
131F:  MOVF   14,W
1320:  MOVWF  77
1321:  BTFSC  14.7
1322:  DECF   7A,F
1323:  MOVWF  42
1324:  MOVF   7A,W
1325:  MOVWF  43
1326:  MOVF   1C,W
1327:  MOVWF  45
1328:  MOVF   1B,W
1329:  MOVWF  44
132A:  MOVF   43,W
132B:  MOVWF  47
132C:  MOVF   42,W
132D:  MOVWF  46
132E:  BCF    03.5
132F:  BCF    03.6
1330:  GOTO   0A3
1331:  MOVF   79,W
1332:  BSF    03.5
1333:  BSF    03.6
1334:  MOVWF  44
1335:  MOVF   78,W
1336:  MOVWF  43
1337:  MOVLW  9E
1338:  SUBWF  19,W
1339:  MOVWF  77
133A:  MOVF   1A,W
133B:  MOVWF  7A
133C:  MOVLW  01
133D:  BTFSS  03.0
133E:  MOVLW  02
133F:  SUBWF  7A,F
1340:  MOVF   77,W
1341:  ADDWF  43,W
1342:  MOVWF  78
1343:  MOVF   44,W
1344:  BTFSC  03.0
1345:  INCFSZ 44,W
1346:  ADDWF  7A,F
1347:  MOVF   78,W
1348:  MOVWF  1B
1349:  MOVF   7A,W
134A:  MOVWF  1C
....................       ++sc; 
134B:  INCF   15,F
134C:  BTFSC  03.2
134D:  INCF   16,F
....................       sd=memchr(digits,tolower(*sc),base); 
134E:  MOVF   16,W
134F:  MOVWF  7A
1350:  MOVF   15,W
1351:  MOVWF  04
1352:  BCF    03.7
1353:  BTFSC  16.0
1354:  BSF    03.7
1355:  MOVF   00,W
1356:  MOVWF  42
1357:  SUBLW  40
1358:  BTFSC  03.0
1359:  GOTO   361
135A:  MOVF   42,W
135B:  SUBLW  5A
135C:  BTFSS  03.0
135D:  GOTO   361
135E:  MOVF   42,W
135F:  IORLW  20
1360:  GOTO   362
1361:  MOVF   42,W
1362:  MOVWF  43
1363:  MOVLW  01
1364:  MOVWF  45
1365:  MOVLW  9E
1366:  MOVWF  44
1367:  MOVF   42,W
1368:  MOVWF  46
1369:  MOVF   14,W
136A:  MOVWF  47
136B:  BCF    0A.4
136C:  BSF    0A.3
136D:  BCF    03.5
136E:  BCF    03.6
136F:  CALL   7D2
1370:  BSF    0A.4
1371:  BCF    0A.3
1372:  MOVF   79,W
1373:  BSF    03.5
1374:  BSF    03.6
1375:  MOVWF  1A
1376:  MOVF   78,W
1377:  MOVWF  19
....................    } 
1378:  GOTO   318
....................    if(s1==sc) 
1379:  MOVF   15,W
137A:  SUBWF  17,W
137B:  BTFSS  03.2
137C:  GOTO   390
137D:  MOVF   16,W
137E:  SUBWF  18,W
137F:  BTFSS  03.2
1380:  GOTO   390
....................    { 
....................       if (endptr) 
1381:  MOVF   12,W
1382:  IORWF  13,W
1383:  BTFSC  03.2
1384:  GOTO   38C
....................       { 
....................         *((char *)endptr)=s; 
1385:  MOVF   12,W
1386:  MOVWF  04
1387:  BCF    03.7
1388:  BTFSC  13.0
1389:  BSF    03.7
138A:  MOVF   10,W
138B:  MOVWF  00
....................       } 
....................    return 0; 
138C:  MOVLW  00
138D:  MOVWF  78
138E:  MOVWF  79
138F:  GOTO   39F
....................    } 
....................    if (endptr) 
1390:  MOVF   12,W
1391:  IORWF  13,W
1392:  BTFSC  03.2
1393:  GOTO   39B
....................         *((char *)endptr)=sc; 
1394:  MOVF   12,W
1395:  MOVWF  04
1396:  BCF    03.7
1397:  BTFSC  13.0
1398:  BSF    03.7
1399:  MOVF   15,W
139A:  MOVWF  00
....................    return x; 
139B:  MOVF   1B,W
139C:  MOVWF  78
139D:  MOVF   1C,W
139E:  MOVWF  79
.................... } 
....................  
....................  
.................... signed long strtol(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    signed long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................  
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(;sd!=0;) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if(sign=='-') 
....................       x  =-x; 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
.................... signed int system(char *string) 
.................... { 
....................    return 0; 
.................... } 
....................  
.................... int mblen(char *s,size_t n) 
.................... { 
....................    return strlen(s); 
.................... } 
....................  
.................... int mbtowc(wchar_t *pwc,char *s,size_t n) 
.................... { 
....................    *pwc=*s; 
....................    return 1; 
.................... } 
....................  
.................... int wctomb(char *s,wchar_t wchar) 
.................... { 
....................    *s=wchar; 
....................    return 1; 
.................... } 
....................  
.................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n) 
.................... { 
....................    strncpy(pwcs,s,n); 
....................    return strlen(pwcs); 
.................... } 
....................  
.................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n) 
.................... { 
....................    strncpy(s,pwcs,n); 
....................    return strlen(s); 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // The random number implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... unsigned int32 _Randseed; 
....................  
.................... long rand(void) 
.................... { 
....................    _Randseed = _Randseed * 1103515245 + 12345; 
....................    return ((unsigned long)(_Randseed >> 16) % RAND_MAX); 
.................... } 
....................  
.................... void srand(unsigned int32 seed) 
.................... { 
....................    _Randseed = seed; 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... typedef signed int (*_Cmpfun)(char * p1,char * p2); 
....................  
.................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) { 
....................    int m,j,i,l; 
....................    short done; 
....................    BYTE t[16]; 
....................  
....................    m = qitems/2; 
....................    while( m > 0 ) { 
....................      for(j=0; j<(qitems-m); ++j) { 
....................         i = j; 
....................         do 
....................         { 
....................            done=TRUE; 
....................            l = i+m; 
....................            if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) { 
....................               memcpy(t, qdata+i*qsize, qsize); 
....................               memcpy(qdata+i*qsize, qdata+l*qsize, qsize); 
....................               memcpy(qdata+l*qsize, t, qsize); 
....................               if(m <= i) 
....................                 i -= m; 
....................                 done = FALSE; 
....................            } 
....................         } while(!done); 
....................      } 
....................      m = m/2; 
....................    } 
.................... } 
....................  
....................  
.................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp) 
.................... { 
....................    char *p, *q; 
....................    size_t n; 
....................    size_t pivot; 
....................    signed int val; 
....................  
....................    p = base; 
....................    n = num; 
....................  
....................    while (n > 0) 
....................    { 
....................       pivot = n >> 1; 
....................       q = p + width * pivot; 
....................  
....................       val = (*cmp)(key, q); 
....................  
....................       if (val < 0) 
....................          n = pivot; 
....................       else if (val == 0) 
....................          return ((char *)q); 
....................       else { 
....................          p = q + width; 
....................          n -= pivot + 1; 
....................       } 
....................    } 
....................  
....................    return NULL;      // There's no match 
.................... } 
....................  
....................  
.................... #endif 
....................  
.................... #include <stdio.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDIO 
.................... #define _STDIO 
.................... #include <string.h> 
.................... //////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services            //// 
.................... //// This source code may only be used by licensed users of the CCS C   //// 
.................... //// compiler.  This source code may only be distributed to other       //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction  //// 
.................... //// or distribution is permitted without written permission.           //// 
.................... //// Derivative programs created using this software in object code     //// 
.................... //// form are not restricted in any way.                                //// 
.................... //////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STRING 
.................... #define _STRING 
.................... #include <stddef.h> 
.................... #include <ctype.h> 
....................  
....................  
....................  
.................... ////////////////////////////////////////////// 
.................... //// Uncomment the following define to    //// 
.................... //// allow some functions to use a        //// 
.................... //// quicker algorithm, but use more ROM  //// 
.................... ////                                      //// 
.................... //// #define FASTER_BUT_MORE_ROM          //// 
.................... ////////////////////////////////////////////// 
....................  
....................  
....................  
.................... /*Copying functions*/ 
.................... /* standard template: 
....................    void *memmove(void *s1, void *s2, size_t n). 
....................    Copies max of n characters safely (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *memmove(void *s1,char *s2,size_t n) 
.................... { 
....................    char *sc1; 
....................    char *sc2; 
....................    sc1=s1; 
....................    sc2=s2; 
....................    if(sc2<sc1 && sc1 <sc2 +n) 
....................       for(sc1+=n,sc2+=n;0<n;--n) 
....................          *--sc1=*--sc2; 
....................    else 
....................       for(;0<n;--n) 
....................          *sc1++=*sc2++; 
....................   return s1; 
....................   } 
....................  
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? 
....................    Standard template: char *strcpy(char *s1, const char *s2) 
....................    copies the string s2 including the null character to s1*/ 
....................  
.................... char *strcopy(char *s1, char *s2) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; *s2 != 0; s++, s2++) { 
....................      *s = *s2; 
....................   } 
....................   *s = *s2; 
....................   return(s1); 
.................... } 
....................  
.................... /* standard template: 
....................    char *strncpy(char *s1, const char *s2, size_t n). 
....................    Copies max of n characters (not following ending '\0') 
....................    from s2 in s1; if s2 has less than n characters, appends 0 */ 
....................  
.................... char *strncpy(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................  
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(s1); 
.................... } 
.................... /***********************************************************/ 
....................  
.................... /*concatenation functions*/ 
.................... /* standard template: char *strcat(char *s1, const char *s2) 
.................... appends s2 to s1*/ 
....................  
.................... char *strcat(char *s1, char *s2) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0') 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) 
.................... appends not more than n characters from s2 to s1*/ 
....................  
.................... char *strncat(char *s1, char *s2, size_t n) 
.................... { 
....................    char *s; 
....................  
....................    for (s = s1; *s != '\0'; ++s); 
....................    while(*s2 != '\0' && 0<n) 
....................    { 
....................       *s = *s2; 
....................       ++s; 
....................       ++s2; 
....................       --n; 
....................    } 
....................  
....................    *s = '\0'; 
....................    return(s1); 
.................... } 
....................  
.................... /***********************************************************/ 
....................  
....................  
.................... /*comparison functions*/ 
.................... /* standard template: signed int memcmp(void *s1, void *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int memcmp(void * s1,char *s2,size_t n) 
.................... { 
.................... char *su1, *su2; 
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) 
.................... { 
....................    if(*su1!=*su2) 
....................       return ((*su1<*su2)?-1:+1); 
.................... } 
.................... return 0; 
.................... } 
....................  
.................... /* standard template: int strcmp(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcmp(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
.................... /* standard template: int strcoll(const char *s1, const char *s2). 
....................    Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ 
....................  
.................... signed int strcoll(char *s1, char *s2) 
.................... { 
....................    for (; *s1 == *s2; s1++, s2++) 
....................       if (*s1 == '\0') 
....................          return(0); 
....................    return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
.................... /* standard template: 
....................    int strncmp(const char *s1, const char *s2, size_t n). 
....................    Compares max of n characters (not following 0) from s1 to s2; 
....................    returns same as strcmp */ 
....................  
.................... signed int strncmp(char *s1, char *s2, size_t n) 
.................... { 
....................    for (; n > 0; s1++, s2++, n--) 
....................       if (*s1 != *s2) 
....................          return((*s1 <*s2) ? -1: 1); 
....................       else if (*s1 == '\0') 
....................          return(0); 
....................    return(0); 
.................... } 
.................... /* standard template: 
....................    int strxfrm(const char *s1, const char *s2, size_t n). 
....................    transforms maximum of n characters from s2 and places them into s1*/ 
.................... size_t strxfrm(char *s1, char *s2, size_t n) 
.................... { 
....................   char *s; 
....................   int n1; 
....................   n1=n; 
....................   for (s = s1; n > 0 && *s2 != '\0'; n--) 
....................      *s++ = *s2++; 
....................   for (; n > 0; n--) 
....................      *s++ = '\0'; 
....................  
....................   return(n1); 
.................... } 
....................  
....................  
....................  
....................  
....................  
.................... /***********************************************************/ 
.................... /*Search functions*/ 
.................... /* standard template: void *memchr(const char *s, int c). 
....................    Finds first occurrence of c in n characters of s */ 
....................  
.................... char *memchr(void *s,int c,size_t n) 
.................... { 
....................    char uc; 
....................    char *su; 
....................    uc=c; 
....................    for(su=s;0<n;++su,--n) 
....................       if(*su==uc) 
....................       return su; 
....................    return NULL; 
.................... } 
....................  
.................... /* standard template: char *strchr(const char *s, int c). 
....................    Finds first occurrence of c in s */ 
....................  
.................... char *strchr(char *s, int c) 
.................... { 
....................    for (; *s != c; s++) 
....................       if (*s == '\0') 
....................          return(0); 
....................    return(s); 
.................... } 
.................... /* standard template: 
....................    size_t strcspn(const char *s1, const char *s2). 
....................    Computes length of max initial segment of s1 that 
....................    consists entirely of characters NOT from s2*/ 
....................  
.................... int *strcspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1 - s1); 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strpbrk(const char *s1, const char *s2). 
....................    Locates first occurence of any character from s2 in s1; 
....................    returns s1 if s2 is empty string */ 
....................  
.................... char *strpbrk(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; *sc2 != 0; sc2++) 
....................          if (*sc1 == *sc2) 
....................             return(sc1); 
....................    return(0); 
.................... } 
....................  
....................  
.................... /* standard template: char *strrchr(const char *s, int c). 
....................    Finds last occurrence of c in s */ 
....................  
.................... char *strrchr(char *s, int c) 
.................... { 
....................    char *p; 
....................  
....................    for (p = 0; ; s++) 
....................    { 
....................       if (*s == c) 
....................          p = s; 
....................       if (*s == '\0') 
....................          return(p); 
....................    } 
.................... } 
.................... /* computes length of max initial segment of s1 consisting 
....................    entirely of characters from s2 */ 
....................  
.................... int *strspn(char *s1, char *s2) 
.................... { 
....................    char *sc1, *sc2; 
....................  
....................    for (sc1 = s1; *sc1 != 0; sc1++) 
....................       for (sc2 = s2; ; sc2++) 
....................     if (*sc2 == '\0') 
....................        return(sc1 - s1); 
....................          else if (*sc1 == *sc2) 
....................             break; 
....................    return(sc1 - s1); 
.................... } 
.................... /* standard template: 
....................    char *strstr(const char *s1, const char *s2); 
....................    Locates first occurence of character sequence s2 in s1; 
....................    returns 0 if s2 is empty string 
....................  
....................    Uncomment #define FASTER_BUT_MORE_ROM at the top of the 
....................    file to use the faster algorithm */ 
.................... char *strstr(char *s1, char *s2) 
.................... { 
....................    char *s, *t; 
....................  
....................    #ifdef FASTER_BUT_MORE_ROM 
....................    if (*s2 == '\0') 
....................          return(s1); 
....................    #endif 
....................  
....................    while (*s1) 
....................    { 
....................       for(s = s1, t = s2; *t && (*s == *t); ++s, ++t); 
....................  
....................       if (*t == '\0') 
....................          return s1; 
....................       ++s1; 
....................       #ifdef FASTER_BUT_MORE_ROM 
....................          while(*s1 != '\0' && *s1 != *s2) 
....................             ++s1; 
....................       #endif 
....................    } 
....................    return 0; 
.................... } 
....................  
.................... /* standard template: char *strtok(char *s1, const char *s2). 
....................  
....................    Finds next token in s1 delimited by a character from separator 
....................    string s2 (which can be different from call to call).  First call 
....................    starts at beginning of s1 searching for first character NOT 
....................    contained in s2; returns 0 if none is found. 
....................    If one is found, it is the start of first token (return value). 
....................    Function then searches from there for a character contained in s2. 
....................    If none is found, current token extends to end of s1, and subsequent 
....................    searches for a token will return 0.  If one is found, it is 
....................    overwritten by '\0', which terminates current token.  Function saves 
....................    pointer to following character from which next search will start. 
....................    Each subsequent call, with 0 as first argument, starts searching 
....................    from saved pointer */ 
....................  
.................... char *strtok(char *s1, char *s2) 
.................... { 
....................    char *beg, *end; 
....................    static char *save; 
....................  
....................    beg = (s1)? s1: save; 
....................    beg += strspn(beg, s2); 
....................    if (*beg == '\0') 
....................    { 
....................       *save = ' '; 
....................       return(0); 
....................    } 
....................    end = strpbrk(beg, s2); 
....................    if (*end != '\0') 
....................    { 
....................       *end = '\0'; 
....................       end++; 
....................    } 
....................    save = end; 
....................    return(beg); 
.................... } 
....................  
.................... /*****************************************************************/ 
.................... /*Miscellaneous functions*/ 
.................... /* standard template 
.................... maps error number in errnum to an error message string 
.................... Returns: Pointer to string 
.................... */ 
.................... #ifdef _ERRNO 
.................... char * strerror(int errnum) 
.................... { 
.................... char s[15]; 
.................... switch( errnum) 
.................... { 
.................... case 0: 
....................    strcpy(s,"no errors"); 
....................    return s; 
.................... case EDOM : 
....................    strcpy(s,"domain error"); 
....................    return s; 
.................... case ERANGE: 
....................    strcpy(s,"range error"); 
....................    return s; 
.................... } 
.................... } 
.................... #ENDIF 
.................... /* standard template: size_t strlen(const char *s). 
....................    Computes length of s1 (preceding terminating 0) */ 
....................  
.................... int *strlen(char *s) 
.................... { 
....................    char *sc; 
....................  
....................    for (sc = s; *sc != 0; sc++); 
....................    return(sc - s); 
.................... } 
....................  
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). 
....................    Compares s1 to s2 ignoring case (upper vs. lower) */ 
....................  
.................... signed int stricmp(char *s1, char *s2) 
.................... { 
....................  for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); 
....................     s1++, s2++) 
....................     if (*s1 == '\0') 
....................        return(0); 
....................  return((*s1 < *s2) ? -1: 1); 
.................... } 
....................  
....................  
.................... /* standard template: char *strlwr(char *s). 
....................    Replaces uppercase letters by lowercase; 
....................    returns pointer to new string s */ 
....................  
.................... char *strlwr(char *s) 
.................... { 
....................    char *p; 
....................  
....................    for (p = s; *p != '\0'; p++) 
....................       if (*p >= 'A' && *p <='Z') 
....................          *p += 'a' - 'A'; 
....................    return(s); 
.................... } 
....................  
....................  
.................... /************************************************************/ 
....................  
....................  
.................... #endif 
....................  
.................... #ifndef getc 
.................... #define getc getch 
.................... #define getchar getch 
.................... #define puts(s) {printf(s); putchar(13); putchar(10);} 
.................... #define putc putchar 
.................... #endif 
.................... /* maps error number to an error message. Writes a sequence of characters to 
.................... stderr stream thus: if s is not null then string pointed to by s follwed by 
.................... a colon (:) and a space and the appropriate error message returned by strerror 
.................... function with argument errno 
....................  
.................... Returns: no value 
.................... */ 
....................  
.................... #ifdef _ERRNO 
.................... void perror(char *s) 
.................... { 
....................   if(s) 
....................   fprintf(STDERR,"%s: ",s); 
....................   fprintf(STDERR,"%s\r\n",strerror(errno)); 
.................... } 
.................... #endif 
.................... #endif 
....................  
....................  
.................... #use delay(clock=4000000, restart_wdt) 
*
0434:  MOVLW  90
0435:  MOVWF  04
0436:  BSF    03.7
0437:  MOVF   00,W
0438:  BTFSC  03.2
0439:  GOTO   44B
043A:  MOVLW  01
043B:  MOVWF  78
043C:  MOVLW  BF
043D:  MOVWF  77
043E:  CLRWDT
043F:  DECFSZ 77,F
0440:  GOTO   43E
0441:  DECFSZ 78,F
0442:  GOTO   43C
0443:  MOVLW  4A
0444:  MOVWF  77
0445:  DECFSZ 77,F
0446:  GOTO   445
0447:  NOP
0448:  CLRWDT
0449:  DECFSZ 00,F
044A:  GOTO   43A
044B:  RETLW  00
....................  
.................... #include "loadControl_main.h" 
.................... /****************************************************************************/ 
.................... /* Copyright 2007 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.       																						  */ 
.................... /*																																					*/ 
.................... /* Rev History:																															*/ 
.................... /* Initial Creation 11/2007		B.Kieft																		    */ 
.................... /*																																					*/ 
.................... /*																																					*/ 
.................... /****************************************************************************/ 
.................... #ifndef PH_PROBE_H 
.................... #define PH_PROBE_H 
....................  
.................... #define HI  1 
.................... #define LO  0 
....................  
.................... #define ON  1 
.................... #define OFF 0 
....................  
.................... #define MAX_SPI_CHARS 11 
....................  
.................... // 
.................... // Interface Specification Parameters 
.................... // 
.................... int16 startup_oc_threshold = 0; 
*
1E88:  CLRF   2F
1E89:  CLRF   30
.................... int16 steady_oc_threshold = 0; 
1E8A:  CLRF   31
1E8B:  CLRF   32
.................... int16 startup_oc_time = 0; 
1E8C:  CLRF   33
1E8D:  CLRF   34
.................... int8 RS485_ID=0;  
1E8E:  CLRF   35
.................... int8 eeprom_written = 0;      // Data was written to EEPROM, so initialize from there if equal 
1E8F:  CLRF   36
....................                               // to 10011001 (or 0x99) 
.................... int8 relay_status_closed = 0; // 0 == False == open circuit 
1E90:  CLRF   37
....................  
.................... // Used to store the location of interface params in EEPROM 
.................... #define EE_startup_oc_threshold  0  //size=2 
.................... #define EE_steady_oc_threshold   2  //size=2 
.................... #define EE_startup_oc_time       4  //size=2 
.................... #define EE_RS485_ID              5  //size=1 
.................... #define EE_relay_status_closed   6  //size=1 
.................... #define EE_eeprom_written        7  //size=1 
....................  
....................  
.................... // 
.................... //Error parameters  
.................... // 
.................... int16 error_status = 0; 
1E91:  CLRF   38
1E92:  CLRF   39
.................... int16 slave_errors = 0; 
1E93:  CLRF   3A
1E94:  CLRF   3B
.................... // MSB 
.................... Boolean flash_write_err_slave = false; 
1E95:  BCF    3C.0
.................... Boolean flash_write_err       = false; 
1E96:  BCF    3C.1
.................... Boolean ground_fault_err      = false; 
1E97:  BCF    3C.2
.................... Boolean over_temp_err         = false; 
1E98:  BCF    3C.3
.................... Boolean over_curr_err         = false; 
1E99:  BCF    3C.4
.................... Boolean switch_err            = false; 
1E9A:  BCF    3C.5
.................... Boolean invld_cmd_err         = false; 
1E9B:  BCF    3C.6
.................... Boolean invld_param_err       = false; 
1E9C:  BCF    3C.7
.................... Boolean invld_cksum_err       = false; 
1E9D:  BCF    3D.0
.................... Boolean wdt_reset_err         = false; 
1E9E:  BCF    3D.1
.................... Boolean slv_cmd_err           = false; 
1E9F:  BCF    3D.2
.................... //LSB 
.................... // 
....................  
....................  
.................... // Constant Definitions 
.................... static const int16 VREF = 4096;        // 4.096 reference voltage 
.................... static const int8 RSENSE = 200;        // .2 Ohm Rsense 
.................... static const int8 CURRDIVISOR = 5;     // 5 V/V amplification 
.................... //static const float GF_RSENSE = 402; 
.................... //static const float GF_VSCALE = 4.048; 
.................... //static const float GF_VREF   = 4.096;        
....................  
.................... const char empty_string[1] = {""}; 
.................... const int8 sw_version[] = "1.0";  
.................... // 
....................  
.................... static int32 adc_value_glob;           // Stores A/D conversion values for SPI bus transmission 
1EA0:  CLRF   3E
1EA1:  CLRF   3F
1EA2:  CLRF   40
1EA3:  CLRF   41
.................... int16 overcurrent_adc_val = 0;         // Stores max A/D output for high priority overcurrent checking 
1EA4:  CLRF   42
1EA5:  CLRF   43
.................... int16 overcurrent_adc_val_startup = 0; // Stores max A/D output for startup overcurrent checking 
1EA6:  CLRF   44
1EA7:  CLRF   45
.................... char response_message[30];             // String for storing node response back to MVC 
....................  
.................... int8 serial_delay_msec = 3;            // delay for clocking 485 bits 
1EA8:  MOVLW  03
1EA9:  MOVWF  64
.................... int8 spi_data = 0; 
1EAA:  CLRF   65
....................  
.................... Boolean master          = true;        // Master on SPI bus 
1EAB:  BSF    3D.3
.................... Boolean cmd_received    = false;       // RS485 command received 
1EAC:  BCF    3D.4
.................... Boolean wdt_reset       = false;       // Latest reset due to WDT reset 
1EAD:  BCF    3D.5
.................... Boolean startup_elapsed = false;       // The time set for the startup current has elapsed 
1EAE:  BCF    3D.6
.................... Boolean slave_is_on     = false;       // The slave PIC is powered up 
1EAF:  BCF    3D.7
.................... Boolean load_is_on      = false;       // The load has been powered up 
1EB0:  BCF    66.0
.................... Boolean sleep_enabled   = false;       // The master is allowed to sleep 
1EB1:  BCF    66.1
....................  
.................... //*** DEBUG - to be removed 
.................... int8 rtos_pin = LO;  
1EB2:  CLRF   67
.................... //*** DEBUG - to be removed 
....................  
.................... // Function Definitions 
.................... void do_adc_voltage_calcs(int16); 
.................... void do_adc_current_calcs(int16, int16, int8, int8); 
....................  
.................... void write_eeprom8(int8, int8); 
.................... int16 read_eeprom16(int8); 
.................... void write_eeprom16(int8, int16); 
.................... void clear_errors(Boolean); 
.................... void check_slave_on(); 
.................... void check_slave_off(); 
.................... void calculate_errors(); 
.................... #endif 
....................  
.................... #include "RS485.c" 
.................... /****************************************************************************/ 
.................... /* Copyright 2007 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.       																						  */ 
.................... /*	 																																				*/ 
.................... /* RS485.c - handles serial communications. Includes ISR for serial buffer  */ 
.................... /*																																				  */ 
.................... /* Rev History:																															*/ 
.................... /* Initial Creation 11/2007		B.Kieft																		    */ 
.................... /*																																					*/ 
.................... /*																																					*/ 
.................... /****************************************************************************/ 
....................  
....................  
.................... #include <stdlib.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDLIB 
.................... #define _STDLIB 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Definitions and types 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #ifndef RAND_MAX 
.................... #define RAND_MAX  32767    // The value of which is the maximum value 
....................                            // ... returned by the rand function 
.................... #endif 
....................  
.................... typedef struct { 
....................    signed int quot; 
....................    signed int rem; 
.................... } div_t; 
....................  
.................... typedef struct { 
....................    signed long quot; 
....................    signed long rem; 
.................... } ldiv_t; 
....................  
.................... #include <stddef.h> 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // String conversion functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Standard template: float atof(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... float atof(char * s); 
....................  
.................... /* Standard template: float atoe(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  * also handles E format numbers 
....................  */ 
.................... float atoe(char * s); 
....................  
.................... /* Standard template: signed int  atoi(char * s) 
....................  * converts the initial portion of the string s to a signed int 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed int atoi(char *s); 
....................  
.................... /* Syntax: signed int32  atoi32(char * s) 
....................    converts the initial portion of the string s to a signed int32 
....................    returns the converted value if any, 0 otherwise*/ 
.................... signed int32 atoi32(char *s); 
....................  
.................... /* Syntax: char *  itoa(signed int32 num, int8 base, char * s) 
....................    converts the signed int32 to a string and 
....................    returns the converted value if any, 0 otherwise*/ 
.................... char * itoa(signed int32 num, int8 base, char * s); 
....................  
.................... /* Standard template: signed long  atol(char * s) 
....................  * converts the initial portion of the string s to a signed long 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed long atol(char *s); 
....................  
.................... /* Standard template: float strtol(char * s,char *endptr) 
....................  * converts the initial portion of the string s to a float 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... float strtod(char *s,char *endptr); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base  to a signed long. 
....................  * Returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... signed long strtol(char *s,char *endptr,signed int base); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base to a unsigned long. 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... long strtoul(char *s,char *endptr,signed int base); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Pseudo-random sequence generation functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The rand function computes a sequence of pseudo-random integers in 
....................  * the range 0 to RAND_MAX 
....................  * 
....................  * Parameters: 
....................  *       (none) 
....................  * 
....................  * Returns: 
....................  *       The pseudo-random integer 
....................  */ 
.................... long rand(void); 
....................  
.................... /* The srand function uses the argument as a seed for a new sequence of 
....................  * pseudo-random numbers to be returned by subsequent calls to rand. 
....................  * 
....................  * Parameters: 
....................  *       [in] seed: The seed value to start from. You might need to pass 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  * 
....................  * Remarks 
....................  *          The srand function sets the starting point for generating 
....................  *       a series of pseudorandom integers. To reinitialize the 
....................  *       generator, use 1 as the seed argument. Any other value for 
....................  *       seed sets the generator to a random starting point. rand 
....................  *       retrieves the pseudorandom numbers that are generated. 
....................  *       Calling rand before any call to srand generates the same 
....................  *       sequence as calling srand with seed passed as 1. 
....................  *          Usually, you need to pass a time here from outer source 
....................  *       so that the numbers will be different every time you run. 
....................  */ 
.................... void srand(unsigned int32 seed); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Memory management functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Comming soon 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Communication with the environment 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The function returns 0 always 
....................  */ 
.................... signed int system(char *string); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Performs a binary search of a sorted array.. 
....................  * 
....................  * Parameters: 
....................  *       [in] key: Object to search for 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       bsearch returns a pointer to an occurrence of key in the array pointed 
....................  *       to by base. If key is not found, the function returns NULL. If the 
....................  *       array is not in order or contains duplicate records with identical keys, 
....................  *       the result is unpredictable. 
....................  */ 
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents 
....................  * of the array are sorted into ascending order according to a comparison 
....................  * function pointed to by compar. 
....................  * 
....................  * Parameters: 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  */ 
.................... //void *qsort(const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Integer arithmetic functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #define labs abs 
....................  
.................... div_t div(signed int numer,signed int denom); 
.................... ldiv_t ldiv(signed long numer,signed long denom); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte character functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte string functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Internal implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #include <stddef.h> 
.................... #include <string.h> 
....................  
.................... div_t div(signed int numer,signed int denom) 
.................... { 
....................    div_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... ldiv_t ldiv(signed long numer,signed long denom) 
.................... { 
....................    ldiv_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... float atof(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... float atoe(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    int expsign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................    int i; 
....................    float exp = 1.0; 
....................    int expcnt = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................       // Handling the exponent 
....................       if (c=='e' || c=='E') { 
....................          c = s[ptr++]; 
....................  
....................          if(c == '-') { 
....................             expsign = 1; 
....................             c = s[ptr++]; 
....................          } 
....................          if(c == '+') 
....................             c = s[ptr++]; 
....................  
....................          while((c >= '0' && c <= '9')) { 
....................             expcnt = 10*expcnt + c - '0'; 
....................             c = s[ptr++]; 
....................          } 
....................  
....................          for(i=0;i<expcnt;i++) 
....................             exp*=10; 
....................  
....................          if(expsign==1) 
....................             result/=exp; 
....................          else 
....................             result*=exp; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... signed int atoi(char *s) 
.................... { 
....................    signed int result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    // Omit all preceeding alpha characters 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................  
....................       // Check for hexa number 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++]; 
....................             c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (sign == 1 && base == 10) 
....................        result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... signed long atol(char *s) 
.................... { 
....................    signed long result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... /* A fast routine to multiply by 10 
....................  */ 
.................... signed int32 mult_with10(int32 num) 
.................... { 
....................    return ( (num << 1) + (num << 3) ); 
.................... } 
....................  
.................... signed int32 atoi32(char *s) 
.................... { 
....................    signed int32 result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') { 
....................             result = (result << 1) + (result << 3);  // result *= 10; 
....................             result += (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... char * itoa(signed int32 num, int8 base, char *s) 
.................... { 
....................      int32 temp=1; 
....................      int8 i,sign=0,cnt=0; 
....................      char c; 
....................  
....................      if(num<0) { 
....................          sign=1;        // Check for negative number 
....................          num*=-1; 
....................      } 
....................  
....................      while(temp>0) { 
....................          temp=(num/base); 
....................          s[cnt]=(num%base)+'0';    // Conversion 
....................  
....................          if(s[cnt]>0x39) 
....................             s[cnt]+=0x7; 
....................  
....................          cnt++; 
....................          num=temp; 
....................      } 
....................  
....................      if(sign==1) { 
....................          s[cnt]=0x2D;      // Negative sign 
....................          cnt++; 
....................      } 
....................  
....................      for(i = 0;i<(int8)(cnt/2);i++) { 
....................  
....................          c=s[i]; 
....................          s[i]=s[cnt-i-1];        // Reverse the number 
....................          s[cnt-i-1]=c; 
....................      } 
....................      s[cnt]='\0';     // End the string 
....................      return s; 
.................... } 
....................  
.................... float strtod(char *s,char *endptr) { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0, point = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c=s[ptr++]; 
....................  
....................  
....................    while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 0) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          point = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 1) { 
....................          pow10 = pow10*10; 
....................          result += (c - '0')/pow10; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '+') { 
....................          c = s[ptr++]; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    if(endptr) 
....................    { 
....................       if (ptr) { 
....................          ptr--; 
....................          *((char *)endptr)=s+ptr; 
....................       } 
....................       else 
....................          *((char *)endptr)=s; 
....................    } 
....................  
....................    return(result); 
.................... } 
....................  
.................... long strtoul(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    unsigned long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if(sign=='-') 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................  
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(; sd!=0; ) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
....................  
.................... signed long strtol(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    signed long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................  
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(;sd!=0;) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if(sign=='-') 
....................       x  =-x; 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
.................... signed int system(char *string) 
.................... { 
....................    return 0; 
.................... } 
....................  
.................... int mblen(char *s,size_t n) 
.................... { 
....................    return strlen(s); 
.................... } 
....................  
.................... int mbtowc(wchar_t *pwc,char *s,size_t n) 
.................... { 
....................    *pwc=*s; 
....................    return 1; 
.................... } 
....................  
.................... int wctomb(char *s,wchar_t wchar) 
.................... { 
....................    *s=wchar; 
....................    return 1; 
.................... } 
....................  
.................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n) 
.................... { 
....................    strncpy(pwcs,s,n); 
....................    return strlen(pwcs); 
.................... } 
....................  
.................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n) 
.................... { 
....................    strncpy(s,pwcs,n); 
....................    return strlen(s); 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // The random number implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... unsigned int32 _Randseed; 
....................  
.................... long rand(void) 
.................... { 
....................    _Randseed = _Randseed * 1103515245 + 12345; 
....................    return ((unsigned long)(_Randseed >> 16) % RAND_MAX); 
.................... } 
....................  
.................... void srand(unsigned int32 seed) 
.................... { 
....................    _Randseed = seed; 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... typedef signed int (*_Cmpfun)(char * p1,char * p2); 
....................  
.................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) { 
....................    int m,j,i,l; 
....................    short done; 
....................    BYTE t[16]; 
....................  
....................    m = qitems/2; 
....................    while( m > 0 ) { 
....................      for(j=0; j<(qitems-m); ++j) { 
....................         i = j; 
....................         do 
....................         { 
....................            done=TRUE; 
....................            l = i+m; 
....................            if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) { 
....................               memcpy(t, qdata+i*qsize, qsize); 
....................               memcpy(qdata+i*qsize, qdata+l*qsize, qsize); 
....................               memcpy(qdata+l*qsize, t, qsize); 
....................               if(m <= i) 
....................                 i -= m; 
....................                 done = FALSE; 
....................            } 
....................         } while(!done); 
....................      } 
....................      m = m/2; 
....................    } 
.................... } 
....................  
....................  
.................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp) 
.................... { 
....................    char *p, *q; 
....................    size_t n; 
....................    size_t pivot; 
....................    signed int val; 
....................  
....................    p = base; 
....................    n = num; 
....................  
....................    while (n > 0) 
....................    { 
....................       pivot = n >> 1; 
....................       q = p + width * pivot; 
....................  
....................       val = (*cmp)(key, q); 
....................  
....................       if (val < 0) 
....................          n = pivot; 
....................       else if (val == 0) 
....................          return ((char *)q); 
....................       else { 
....................          p = q + width; 
....................          n -= pivot + 1; 
....................       } 
....................    } 
....................  
....................    return NULL;      // There's no match 
.................... } 
....................  
....................  
.................... #endif 
....................  
....................  
....................  
.................... #ifndef RS485_DRIVER 
.................... #define RS485_DRIVER 
....................  
.................... #ifndef RS485_RX_PIN 
.................... #define RS485_RX_PIN       PIN_C7   // Data receive pin 
.................... #endif 
....................  
.................... #ifndef RS485_TX_PIN 
.................... #define RS485_TX_PIN       PIN_C6   // Data transmit pin 
.................... #endif 
....................  
.................... #ifndef RS485_RX_ENABLE 
.................... #define RS485_RX_ENABLE    PIN_B5   // Controls RE pin.  Should keep low. 
.................... #endif 
....................  
.................... #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN,bits=8, stream=RS485,errors, RESTART_WDT, DISABLE_INTS)//rcv 
*
0046:  CLRWDT
0047:  BTFSS  0C.5
0048:  GOTO   046
0049:  MOVF   18,W
004A:  MOVWF  68
004B:  MOVF   1A,W
004C:  MOVWF  78
004D:  BTFSS  68.1
004E:  GOTO   051
004F:  BCF    18.4
0050:  BSF    18.4
0051:  RETLW  00
*
10EF:  BTFSS  0C.4
10F0:  GOTO   0EF
10F1:  BSF    03.6
10F2:  MOVF   67,W
10F3:  BCF    03.6
10F4:  MOVWF  19
10F5:  BCF    0A.3
10F6:  BSF    0A.4
10F7:  GOTO   118 (RETURN)
*
1EB3:  CLRF   68
.................... #define RS485_wait_time 20                     // Wait time in milliseconds 
.................... #bit    rs485_collision = rs232_errors.6 
....................  
.................... int new_message; 
....................  
.................... static const int incoming_485_buffer_len = 12; //  /aaccCPPPPP<cr lf> - where a=address, c= command, p=param. Capital = optional 
.................... static const int cmd_start_pos = 3;            // location in incoming buffer that would mark the beginning of a command 
.................... int8 rs485_InBuffer[incoming_485_buffer_len]; 
.................... int index; 
....................  
.................... char* commandStr[3];            //To store incoming command string 
.................... char* paramStr[5];              //To store incoming parameter string           
.................... int8 incoming_checksum = 0x00;  //To store incoming checksum 
1EB4:  CLRF   6B
.................... int8 to_address = 0;            //Initialize to impossible address 
1EB5:  CLRF   6C
.................... int32 parameter;                //To store the int parameter 
.................... Boolean Receiving = false;      //Have received a start of message char? 
1EB6:  BCF    66.2
.................... Boolean bad_command = false;    //Definately an invalid command (e.g. cmd is a numeric char) 
1EB7:  BCF    66.3
.................... Boolean bad_param = false;      //Definately an invalid command (e.g. param is an alpha char) 
1EB8:  BCF    66.4
.................... Boolean is_status_cmd = false;  //status command has two chars, others have only 1 
1EB9:  BCF    66.5
....................  
....................  
....................  
.................... // Purpose:    Enable data reception 
.................... // Inputs:     None 
.................... // Outputs:    None 
.................... void RCV_ON(void) { 
....................   while(kbhit(RS485)) {fgetc(RS485);} // Clear RX buffer. Clear RDA interrupt flag. Clear overrun error flag.  
*
07F2:  BTFSS  0C.5
07F3:  GOTO   7F6
07F4:  CALL   046
07F5:  GOTO   7F2
....................   output_low(RS485_RX_ENABLE); 
07F6:  BSF    03.5
07F7:  BCF    06.5
07F8:  BCF    03.5
07F9:  BCF    06.5
.................... } 
07FA:  RETLW  00
....................  
.................... // Purpose:    Disable data reception 
.................... // Inputs:     None 
.................... // Outputs:    None 
.................... void RCV_OFF(void) { 
....................    output_high(RS485_RX_ENABLE); 
07FB:  BSF    03.5
07FC:  BCF    06.5
07FD:  BCF    03.5
07FE:  BSF    06.5
.................... } 
07FF:  RETLW  00
....................  
....................  
.................... // Purpose:    Initialize RS485 communication. Call this before 
.................... //             using any other RS485 functions. 
.................... // Inputs:     None 
.................... // Outputs:    None 
.................... #SEPARATE 
.................... void rs485_init() { 
....................    //RS485_ID = 1; //*** DEBUG    
....................    RCV_ON(); 
*
0CEB:  BCF    0A.3
0CEC:  CALL   7F2
0CED:  BSF    0A.3
....................    new_message=FALSE; 
0CEE:  CLRF   69
....................    enable_interrupts(INT_RDA); 
0CEF:  BSF    03.5
0CF0:  BSF    0C.5
....................    enable_interrupts(GLOBAL); 
0CF1:  MOVLW  C0
0CF2:  BCF    03.5
0CF3:  IORWF  0B,F
.................... } 
0CF4:  BSF    0A.3
0CF5:  BCF    0A.4
0CF6:  GOTO   535 (RETURN)
....................  
....................  
.................... // Purpose:    Send a message over the RS485 bus 
.................... // Inputs:     1) len 
.................... //             2) data (acknowlege, time to close) 
.................... // Outputs:    TRUE if successful 
.................... //             FALSE if failed 
.................... // Note:      
.................... #SEPARATE 
.................... int1 rs485_send_message(int8 len, int8* data) { 
....................    int8 try, i, cs; 
....................    int1 ret = FALSE; 
*
10F8:  BSF    03.6
10F9:  BCF    65.0
....................  
....................    RCV_OFF(); 
10FA:  BCF    0A.4
10FB:  BCF    03.6
10FC:  CALL   7FB
10FD:  BSF    0A.4
....................  
....................    for(try=0; try<5; ++try) { 
10FE:  BSF    03.6
10FF:  CLRF   62
1100:  MOVF   62,W
1101:  SUBLW  04
1102:  BTFSS  03.0
1103:  GOTO   13A
....................       rs485_collision = 0; 
1104:  BCF    03.6
1105:  BCF    68.6
....................  
....................       for(i=0; i<len; ++i) { 
1106:  BSF    03.6
1107:  CLRF   63
1108:  MOVF   5F,W
1109:  SUBWF  63,W
110A:  BTFSC  03.0
110B:  GOTO   11E
....................        //  cs ^= *data; 
....................          fputc(*data, RS485); 
110C:  MOVF   61,W
110D:  MOVWF  7A
110E:  MOVF   60,W
110F:  MOVWF  04
1110:  BCF    03.7
1111:  BTFSC  61.0
1112:  BSF    03.7
1113:  MOVF   00,W
1114:  MOVWF  66
1115:  MOVWF  67
1116:  BCF    03.6
1117:  GOTO   0EF
....................          ++data; 
1118:  BSF    03.6
1119:  INCF   60,F
111A:  BTFSC  03.2
111B:  INCF   61,F
....................       } 
111C:  INCF   63,F
111D:  GOTO   108
....................              
....................       if(!rs485_collision) { 
111E:  BCF    03.6
111F:  BTFSC  68.6
1120:  GOTO   12E
....................       delay_ms(serial_delay_msec);  
1121:  MOVF   64,W
1122:  BSF    03.5
1123:  BSF    03.6
1124:  MOVWF  10
1125:  BCF    0A.4
1126:  BCF    03.5
1127:  BCF    03.6
1128:  CALL   434
1129:  BSF    0A.4
....................          ret = TRUE; 
112A:  BSF    03.6
112B:  BSF    65.0
....................          break; 
112C:  GOTO   13A
112D:  BCF    03.6
....................       } 
....................       delay_ms(serial_delay_msec); 
112E:  MOVF   64,W
112F:  BSF    03.5
1130:  BSF    03.6
1131:  MOVWF  10
1132:  BCF    0A.4
1133:  BCF    03.5
1134:  BCF    03.6
1135:  CALL   434
1136:  BSF    0A.4
....................    } 
1137:  BSF    03.6
1138:  INCF   62,F
1139:  GOTO   100
....................    RCV_ON(); 
113A:  BCF    0A.4
113B:  BCF    03.6
113C:  CALL   7F2
113D:  BSF    0A.4
....................    return(ret); 
113E:  MOVLW  00
113F:  BSF    03.6
1140:  BTFSC  65.0
1141:  MOVLW  01
1142:  MOVWF  78
.................... } 
1143:  BCF    03.6
1144:  BCF    0A.3
1145:  BSF    0A.4
1146:  GOTO   4AD (RETURN)
....................  
....................  
.................... // Purpose:    Interrupt service routine for handling incoming RS485 data 
.................... // data format: See TBD interface spec 
.................... #int_rda 
.................... void incomming_rs485() 
.................... { 
.................... 	   int i; 
.................... 	    
.................... 	   // Check for start of message character 
....................      rs485_InBuffer[index] = fgetc(); 
*
007D:  MOVLW  A0
007E:  ADDWF  6A,W
007F:  MOVWF  04
0080:  BCF    03.7
0081:  BSF    03.5
0082:  BSF    03.6
0083:  CLRF   59
0084:  MOVF   04,W
0085:  MOVWF  58
0086:  BCF    59.0
0087:  BTFSC  03.7
0088:  BSF    59.0
0089:  BCF    03.5
008A:  BCF    03.6
008B:  CALL   046
008C:  BSF    03.5
008D:  BSF    03.6
008E:  MOVF   58,W
008F:  MOVWF  04
0090:  BCF    03.7
0091:  BTFSC  59.0
0092:  BSF    03.7
0093:  MOVF   78,W
0094:  MOVWF  00
....................      if(rs485_InBuffer[index] == '/')  
0095:  MOVLW  A0
0096:  BCF    03.5
0097:  BCF    03.6
0098:  ADDWF  6A,W
0099:  MOVWF  04
009A:  BCF    03.7
009B:  MOVF   00,W
009C:  SUBLW  2F
009D:  BTFSS  03.2
009E:  GOTO   0B3
....................      { 
....................      	 // Initialize variables 
....................        Receiving = true;	 
009F:  BSF    66.2
....................        index = 0; 
00A0:  CLRF   6A
....................         
....................        // Clear the buffer... 
....................        for(i=0; i < incoming_485_buffer_len; i++) 
00A1:  BSF    03.5
00A2:  BSF    03.6
00A3:  CLRF   55
00A4:  MOVF   55,W
00A5:  SUBLW  0B
00A6:  BTFSS  03.0
00A7:  GOTO   0AF
....................        { 
....................          rs485_InBuffer[i] = null;	 
00A8:  MOVLW  A0
00A9:  ADDWF  55,W
00AA:  MOVWF  04
00AB:  BCF    03.7
00AC:  CLRF   00
....................        } 
00AD:  INCF   55,F
00AE:  GOTO   0A4
....................        rs485_InBuffer[0]= '/'; 
00AF:  MOVLW  2F
00B0:  BCF    03.6
00B1:  MOVWF  20
00B2:  BCF    03.5
....................      } 
....................       
....................      if(Receiving)  
00B3:  BTFSS  66.2
00B4:  GOTO   0F8
....................      { 
....................      	 // Check for message termination character and for minimum message length 
....................        if( (rs485_InBuffer[index] == '\r') && (index > 4) ) //Smallest message is currently "/aaCE" where aa is the 485 address/ID 
00B5:  MOVLW  A0
00B6:  ADDWF  6A,W
00B7:  MOVWF  04
00B8:  BCF    03.7
00B9:  MOVF   00,W
00BA:  SUBLW  0D
00BB:  BTFSS  03.2
00BC:  GOTO   0F0
00BD:  MOVF   6A,W
00BE:  SUBLW  04
00BF:  BTFSC  03.0
00C0:  GOTO   0F0
....................        { 
....................          Receiving = false;  // Done receiving 
00C1:  BCF    66.2
....................          index = 0;          // Reset index  
00C2:  CLRF   6A
....................          new_message=TRUE;   // Anncounce the receipt of a new message 
00C3:  MOVLW  01
00C4:  MOVWF  69
....................  
....................  
....................          // Convert ascii to int for to_address 
....................          if( (isdigit(rs485_InBuffer[1])) && (isdigit(rs485_InBuffer[2])) ) 
00C5:  BSF    03.5
00C6:  MOVF   21,W
00C7:  SUBLW  2F
00C8:  BTFSC  03.0
00C9:  GOTO   0EE
00CA:  MOVF   21,W
00CB:  SUBLW  39
00CC:  BTFSS  03.0
00CD:  GOTO   0EE
00CE:  MOVF   22,W
00CF:  SUBLW  2F
00D0:  BTFSC  03.0
00D1:  GOTO   0EE
00D2:  MOVF   22,W
00D3:  SUBLW  39
00D4:  BTFSS  03.0
00D5:  GOTO   0EE
....................          { 
....................            to_address = (((rs485_InBuffer[1] - '0')*10) + (rs485_InBuffer[2]- '0'));          
00D6:  MOVLW  30
00D7:  SUBWF  21,W
00D8:  BSF    03.6
00D9:  MOVWF  57
00DA:  MOVWF  58
00DB:  MOVLW  0A
00DC:  MOVWF  59
00DD:  BCF    03.5
00DE:  BCF    03.6
00DF:  GOTO   052
00E0:  MOVF   78,W
00E1:  BSF    03.5
00E2:  BSF    03.6
00E3:  MOVWF  58
00E4:  MOVLW  30
00E5:  BCF    03.6
00E6:  SUBWF  22,W
00E7:  BSF    03.6
00E8:  ADDWF  58,W
00E9:  BCF    03.5
00EA:  BCF    03.6
00EB:  MOVWF  6C
....................          } 
....................          else 
00EC:  GOTO   0F0
00ED:  BSF    03.5
....................          { 
....................            // Invalid address 
....................            new_message=false;    
00EE:  BCF    03.5
00EF:  CLRF   69
....................          } 
....................  
.................... //         //         
.................... //         // Convert ascii to hex for incoming_checksum 
.................... //         // 
.................... //         if( (isxdigit(rs485_InBuffer[5])) && (isxdigit(rs485_InBuffer[6])) ) 
.................... //          { 
.................... //           if (rs485_InBuffer[6] > '9')  
.................... //            { 
.................... //             rs485_InBuffer[6] += 9; 
.................... //            } 
.................... //           rs485_InBuffer[6] &= 0x0F; 
.................... // 
.................... //           if (rs485_InBuffer[5] > '9')  
.................... //            {  
.................... //             rs485_InBuffer[5] += 9; 
.................... //            } 
.................... //           
.................... //           rs485_InBuffer[5] &= 0x0F; 
.................... //           incoming_checksum =( (rs485_InBuffer[5]<<1)|(rs485_InBuffer[6]) );          
.................... //          } 
.................... //         else 
.................... //          { 
.................... //           bad_checksum = true;     
.................... //          } 
....................                  
....................  
....................         } // End of message processing 
....................          
....................         index += 1; 
00F0:  MOVLW  01
00F1:  ADDWF  6A,F
....................         if(index > incoming_485_buffer_len) // Check to see if we've filled the buffer 
00F2:  MOVF   6A,W
00F3:  SUBLW  0C
00F4:  BTFSC  03.0
00F5:  GOTO   0F8
....................         { 
....................          Receiving = false;  // Stop receiving and... 
00F6:  BCF    66.2
....................          index = 0;          // Reset index        		 
00F7:  CLRF   6A
....................         } 
....................        
....................       } 
....................  
.................... } 
....................  
....................  
.................... // Purpose:    Do more in depth checking on incoming 485  
.................... //             buffer contents to see if a valid message  
.................... //             has been received 
.................... // Inputs:     1) Boolean wait 
.................... //             
.................... // Outputs:    TRUE if new message available 
.................... //             FALSE if not 
.................... // Note:      
00F8:  BCF    0C.5
00F9:  BCF    0A.3
00FA:  BCF    0A.4
00FB:  GOTO   025
.................... #SEPARATE 
.................... int1 rs485_get_new_message(int1 wait) 
.................... { 
....................   while(wait && (new_message==FALSE)) {} 
*
0E59:  BSF    03.6
0E5A:  MOVF   34,F
0E5B:  BTFSC  03.2
0E5C:  GOTO   665
0E5D:  BCF    03.6
0E5E:  MOVF   69,F
0E5F:  BTFSC  03.2
0E60:  GOTO   663
0E61:  BSF    03.6
0E62:  GOTO   665
0E63:  GOTO   659
0E64:  BSF    03.6
....................  
....................   // if the ISR doesn't think a new message is in, return false 
....................   if(new_message==FALSE) 
0E65:  BCF    03.6
0E66:  MOVF   69,F
0E67:  BTFSS  03.2
0E68:  GOTO   66D
....................   { 
....................     return FALSE; 
0E69:  MOVLW  00
0E6A:  MOVWF  78
0E6B:  GOTO   792
....................   } 
....................   else			 
0E6C:  GOTO   792
....................   { 
....................     //Check if message is for this address 
....................     if( to_address == RS485_ID )		 
0E6D:  MOVF   35,W
0E6E:  SUBWF  6C,W
0E6F:  BTFSS  03.2
0E70:  GOTO   78E
....................    	{ 
....................       //First check for status commands 
....................       if( (rs485_InBuffer[cmd_start_pos] == '?') && (isalpha(rs485_InBuffer[cmd_start_pos + 1])) && (isalpha(rs485_InBuffer[cmd_start_pos + 2])) )  
0E71:  BSF    03.5
0E72:  MOVF   23,W
0E73:  SUBLW  3F
0E74:  BTFSS  03.2
0E75:  GOTO   6FA
0E76:  MOVF   24,W
0E77:  SUBLW  40
0E78:  BTFSC  03.0
0E79:  GOTO   67E
0E7A:  MOVF   24,W
0E7B:  SUBLW  5A
0E7C:  BTFSC  03.0
0E7D:  GOTO   686
0E7E:  MOVF   24,W
0E7F:  SUBLW  60
0E80:  BTFSC  03.0
0E81:  GOTO   6FA
0E82:  MOVF   24,W
0E83:  SUBLW  7A
0E84:  BTFSS  03.0
0E85:  GOTO   6FA
0E86:  MOVF   25,W
0E87:  SUBLW  40
0E88:  BTFSC  03.0
0E89:  GOTO   68E
0E8A:  MOVF   25,W
0E8B:  SUBLW  5A
0E8C:  BTFSC  03.0
0E8D:  GOTO   696
0E8E:  MOVF   25,W
0E8F:  SUBLW  60
0E90:  BTFSC  03.0
0E91:  GOTO   6FA
0E92:  MOVF   25,W
0E93:  SUBLW  7A
0E94:  BTFSS  03.0
0E95:  GOTO   6FA
....................       { 
....................         sprintf(commandStr, "%c%c%c",rs485_InBuffer[cmd_start_pos] , rs485_InBuffer[cmd_start_pos + 1], rs485_InBuffer[cmd_start_pos + 2]); 
0E96:  BCF    03.5
0E97:  CLRF   6E
0E98:  MOVLW  71
0E99:  MOVWF  6D
0E9A:  BSF    03.5
0E9B:  MOVF   23,W
0E9C:  BCF    03.5
0E9D:  BSF    03.6
0E9E:  MOVWF  63
0E9F:  BCF    0A.3
0EA0:  BCF    03.6
0EA1:  CALL   4B9
0EA2:  BSF    0A.3
0EA3:  BSF    03.5
0EA4:  MOVF   24,W
0EA5:  BCF    03.5
0EA6:  BSF    03.6
0EA7:  MOVWF  63
0EA8:  BCF    0A.3
0EA9:  BCF    03.6
0EAA:  CALL   4B9
0EAB:  BSF    0A.3
0EAC:  BSF    03.5
0EAD:  MOVF   25,W
0EAE:  BCF    03.5
0EAF:  BSF    03.6
0EB0:  MOVWF  63
0EB1:  BCF    0A.3
0EB2:  BCF    03.6
0EB3:  CALL   4B9
0EB4:  BSF    0A.3
*
1EBA:  CLRF   6D
1EBB:  CLRF   6E
....................  
....................    	    // Check for ground fault command here to get the channel number 
....................    	    if( ((rs485_InBuffer[cmd_start_pos + 1] == 'F') && (rs485_InBuffer[cmd_start_pos + 2] == 'C')) || ((rs485_InBuffer[cmd_start_pos + 1] == 'f') && (rs485_InBuffer[cmd_start_pos + 2] == 'c'))  ) { 
*
0EB5:  BSF    03.5
0EB6:  MOVF   24,W
0EB7:  SUBLW  46
0EB8:  BTFSS  03.2
0EB9:  GOTO   6BE
0EBA:  MOVF   25,W
0EBB:  SUBLW  43
0EBC:  BTFSC  03.2
0EBD:  GOTO   6C6
0EBE:  MOVF   24,W
0EBF:  SUBLW  66
0EC0:  BTFSS  03.2
0EC1:  GOTO   6F2
0EC2:  MOVF   25,W
0EC3:  SUBLW  63
0EC4:  BTFSS  03.2
0EC5:  GOTO   6F2
....................           // Check for a parameter that's a number 
....................           if( isdigit(rs485_InBuffer[cmd_start_pos+3]) ) { 
0EC6:  MOVF   26,W
0EC7:  SUBLW  2F
0EC8:  BTFSC  03.0
0EC9:  GOTO   6ED
0ECA:  MOVF   26,W
0ECB:  SUBLW  39
0ECC:  BTFSS  03.0
0ECD:  GOTO   6ED
....................             sprintf(paramStr, "%c",rs485_InBuffer[cmd_start_pos+3]); 
0ECE:  BCF    03.5
0ECF:  CLRF   6E
0ED0:  MOVLW  AC
0ED1:  MOVWF  6D
0ED2:  BSF    03.5
0ED3:  MOVF   26,W
0ED4:  BCF    03.5
0ED5:  BSF    03.6
0ED6:  MOVWF  63
0ED7:  BCF    0A.3
0ED8:  BCF    03.6
0ED9:  CALL   4B9
0EDA:  BSF    0A.3
....................    	        parameter = atoi32(paramStr);   	 
0EDB:  BSF    03.6
0EDC:  CLRF   36
0EDD:  MOVLW  AC
0EDE:  MOVWF  35
0EDF:  BCF    0A.3
0EE0:  BCF    03.6
0EE1:  CALL   66D
0EE2:  BSF    0A.3
0EE3:  MOVF   7A,W
0EE4:  BSF    03.5
0EE5:  MOVWF  39
0EE6:  MOVF   79,W
0EE7:  MOVWF  38
0EE8:  MOVF   78,W
0EE9:  MOVWF  37
0EEA:  MOVF   77,W
0EEB:  MOVWF  36
....................    	      } else { 
0EEC:  GOTO   6F2
....................    	      	parameter = -1; 
0EED:  MOVLW  FF
0EEE:  MOVWF  39
0EEF:  MOVWF  38
0EF0:  MOVWF  37
0EF1:  MOVWF  36
....................    	      }   	 
....................    	    }  
....................    	    new_message=FALSE; 
0EF2:  BCF    03.5
0EF3:  CLRF   69
....................    	    is_status_cmd = true; 
0EF4:  BSF    66.5
....................         return TRUE;       	 
0EF5:  MOVLW  01
0EF6:  MOVWF  78
0EF7:  GOTO   792
....................       } 
....................       // Then check for set or control commands 
....................       else if( (isalpha(rs485_InBuffer[cmd_start_pos])) && (isalpha(rs485_InBuffer[cmd_start_pos+1])) ) 
0EF8:  GOTO   78D
0EF9:  BSF    03.5
0EFA:  MOVF   23,W
0EFB:  SUBLW  40
0EFC:  BTFSC  03.0
0EFD:  GOTO   702
0EFE:  MOVF   23,W
0EFF:  SUBLW  5A
0F00:  BTFSC  03.0
0F01:  GOTO   70A
0F02:  MOVF   23,W
0F03:  SUBLW  60
0F04:  BTFSC  03.0
0F05:  GOTO   789
0F06:  MOVF   23,W
0F07:  SUBLW  7A
0F08:  BTFSS  03.0
0F09:  GOTO   789
0F0A:  MOVF   24,W
0F0B:  SUBLW  40
0F0C:  BTFSC  03.0
0F0D:  GOTO   712
0F0E:  MOVF   24,W
0F0F:  SUBLW  5A
0F10:  BTFSC  03.0
0F11:  GOTO   71A
0F12:  MOVF   24,W
0F13:  SUBLW  60
0F14:  BTFSC  03.0
0F15:  GOTO   789
0F16:  MOVF   24,W
0F17:  SUBLW  7A
0F18:  BTFSS  03.0
0F19:  GOTO   789
....................       {  
....................       	// Grab the command 
....................         sprintf(commandStr, "%c%c",rs485_InBuffer[cmd_start_pos], rs485_InBuffer[cmd_start_pos+1]); 
0F1A:  BCF    03.5
0F1B:  CLRF   6E
0F1C:  MOVLW  71
0F1D:  MOVWF  6D
0F1E:  BSF    03.5
0F1F:  MOVF   23,W
0F20:  BCF    03.5
0F21:  BSF    03.6
0F22:  MOVWF  63
0F23:  BCF    0A.3
0F24:  BCF    03.6
0F25:  CALL   4B9
0F26:  BSF    0A.3
0F27:  BSF    03.5
0F28:  MOVF   24,W
0F29:  BCF    03.5
0F2A:  BSF    03.6
0F2B:  MOVWF  63
0F2C:  BCF    0A.3
0F2D:  BCF    03.6
0F2E:  CALL   4B9
0F2F:  BSF    0A.3
....................         // Check for a parameter that's a number (or at least starts with one) 
....................         if( isdigit(rs485_InBuffer[cmd_start_pos+2]) ) { 
0F30:  BSF    03.5
0F31:  MOVF   25,W
0F32:  SUBLW  2F
0F33:  BTFSC  03.0
0F34:  GOTO   77C
0F35:  MOVF   25,W
0F36:  SUBLW  39
0F37:  BTFSS  03.0
0F38:  GOTO   77C
....................           sprintf(paramStr, "%c%c%c%c%c",rs485_InBuffer[cmd_start_pos+2],rs485_InBuffer[cmd_start_pos+3],rs485_InBuffer[cmd_start_pos+4],rs485_InBuffer[cmd_start_pos+5],rs485_InBuffer[cmd_start_pos+6]); 
0F39:  BCF    03.5
0F3A:  CLRF   6E
0F3B:  MOVLW  AC
0F3C:  MOVWF  6D
0F3D:  BSF    03.5
0F3E:  MOVF   25,W
0F3F:  BCF    03.5
0F40:  BSF    03.6
0F41:  MOVWF  63
0F42:  BCF    0A.3
0F43:  BCF    03.6
0F44:  CALL   4B9
0F45:  BSF    0A.3
0F46:  BSF    03.5
0F47:  MOVF   26,W
0F48:  BCF    03.5
0F49:  BSF    03.6
0F4A:  MOVWF  63
0F4B:  BCF    0A.3
0F4C:  BCF    03.6
0F4D:  CALL   4B9
0F4E:  BSF    0A.3
0F4F:  BSF    03.5
0F50:  MOVF   27,W
0F51:  BCF    03.5
0F52:  BSF    03.6
0F53:  MOVWF  63
0F54:  BCF    0A.3
0F55:  BCF    03.6
0F56:  CALL   4B9
0F57:  BSF    0A.3
0F58:  BSF    03.5
0F59:  MOVF   28,W
0F5A:  BCF    03.5
0F5B:  BSF    03.6
0F5C:  MOVWF  63
0F5D:  BCF    0A.3
0F5E:  BCF    03.6
0F5F:  CALL   4B9
0F60:  BSF    0A.3
0F61:  BSF    03.5
0F62:  MOVF   29,W
0F63:  BCF    03.5
0F64:  BSF    03.6
0F65:  MOVWF  63
0F66:  BCF    0A.3
0F67:  BCF    03.6
0F68:  CALL   4B9
0F69:  BSF    0A.3
....................    	      parameter = atoi32(paramStr); 
0F6A:  BSF    03.6
0F6B:  CLRF   36
0F6C:  MOVLW  AC
0F6D:  MOVWF  35
0F6E:  BCF    0A.3
0F6F:  BCF    03.6
0F70:  CALL   66D
0F71:  BSF    0A.3
0F72:  MOVF   7A,W
0F73:  BSF    03.5
0F74:  MOVWF  39
0F75:  MOVF   79,W
0F76:  MOVWF  38
0F77:  MOVF   78,W
0F78:  MOVWF  37
0F79:  MOVF   77,W
0F7A:  MOVWF  36
....................    	    } else { 
0F7B:  GOTO   781
....................    	    	parameter = -1; 
0F7C:  MOVLW  FF
0F7D:  MOVWF  39
0F7E:  MOVWF  38
0F7F:  MOVWF  37
0F80:  MOVWF  36
....................    	    } 
....................    	    new_message=FALSE; 
0F81:  BCF    03.5
0F82:  CLRF   69
....................    	    is_status_cmd = false; 
0F83:  BCF    66.5
....................         return TRUE;       	        	 
0F84:  MOVLW  01
0F85:  MOVWF  78
0F86:  GOTO   792
....................       } 	 
....................       else 
0F87:  GOTO   78D
0F88:  BSF    03.5
....................       { 
....................       	// No valid command received so return 
....................         return false; 
0F89:  MOVLW  00
0F8A:  MOVWF  78
0F8B:  BCF    03.5
0F8C:  GOTO   792
....................       } 
....................    
....................  
....................  
....................     } 
....................     //message not for this address. Clear new message flag and return false 
....................     else	 
0F8D:  GOTO   792
....................     { 
....................       new_message=FALSE; 
0F8E:  CLRF   69
....................       return FALSE; 
0F8F:  MOVLW  00
0F90:  MOVWF  78
0F91:  GOTO   792
....................     } 
....................     
....................     
....................   } // end of "new message in" if block 
....................     
.................... } 
0F92:  BSF    0A.3
0F93:  BSF    0A.4
0F94:  GOTO   50C (RETURN)
....................  
....................  
.................... // Purpose:    Wait for wait time for the RS485 bus to become idle 
.................... // Inputs:     TRUE - restart the watch dog timer to prevent reset 
.................... //             FALSE - watch dog timer not restarted 
.................... // Outputs:    None 
.................... #SEPARATE 
.................... void rs485_wait_for_bus(int1 clrwdt) 
.................... { 
....................    int16 i; 
....................  
....................    RCV_OFF(); 
*
10BE:  BCF    0A.4
10BF:  CALL   7FB
10C0:  BSF    0A.4
....................    for(i=0; i <= (rs485_wait_time*20); ++i) 
10C1:  BSF    03.6
10C2:  CLRF   61
10C3:  CLRF   60
10C4:  MOVF   61,W
10C5:  SUBLW  01
10C6:  BTFSS  03.0
10C7:  GOTO   0E8
10C8:  BTFSS  03.2
10C9:  GOTO   0CE
10CA:  MOVF   60,W
10CB:  SUBLW  90
10CC:  BTFSS  03.0
10CD:  GOTO   0E8
....................    { 
....................       if(!input(RS485_RX_PIN))//this is inverted as in the original file 
10CE:  BCF    03.6
10CF:  BSF    6F.7
10D0:  MOVF   6F,W
10D1:  BSF    03.5
10D2:  MOVWF  07
10D3:  BCF    03.5
10D4:  BTFSC  07.7
10D5:  GOTO   0DB
*
1EBC:  MOVLW  FF
1EBD:  MOVWF  6F
....................          i = 0; 
*
10D6:  BSF    03.6
10D7:  CLRF   61
10D8:  CLRF   60
....................       else 
10D9:  GOTO   0E1
10DA:  BCF    03.6
....................          delay_us(50); 
10DB:  CLRWDT
10DC:  MOVLW  10
10DD:  MOVWF  77
10DE:  DECFSZ 77,F
10DF:  GOTO   0DE
10E0:  BSF    03.6
....................  
....................       if(clrwdt) 
10E1:  MOVF   5F,F
10E2:  BTFSS  03.2
....................          restart_wdt(); 
10E3:  CLRWDT
....................    } 
10E4:  INCF   60,F
10E5:  BTFSC  03.2
10E6:  INCF   61,F
10E7:  GOTO   0C4
.................... 	RCV_ON(); 
10E8:  BCF    0A.4
10E9:  BCF    03.6
10EA:  CALL   7F2
10EB:  BSF    0A.4
.................... } 
10EC:  BCF    0A.3
10ED:  BSF    0A.4
10EE:  GOTO   4A4 (RETURN)
....................  
.................... //*** DEBUG -- will be replaced eventually by send_485_message 
.................... //#SEPARATE 
.................... //void send_response(char* s) 
.................... //{ 
.................... //   int8 size; 
.................... //    
.................... //   for(size=0; s[size]!='\0'; ++size); 
.................... // 
.................... //   rs485_wait_for_bus(false); 
.................... //   while(!rs485_send_message(size, s)) 
.................... //   {     
.................... //    delay_ms(10); 
.................... //   } 
.................... //} 
.................... //*** DEBUG 
....................  
.................... // Purpose:    Sends 485 string in format compliant with interface spec 
.................... // Inputs:     Char * - data to send 
.................... //             
.................... // Outputs:    None 
.................... #SEPARATE 
.................... void send_485_response(char* p) 
.................... { 
....................   int8 size; 
....................   char final_string[40]; 
....................  
....................   // Do error calculations and query the slave if necessary 
....................   calculate_errors(); 
....................  
....................   // Form up the string to comply with interface spec 
....................   sprintf(final_string, "*%02u%s%LX\r\n", RS485_ID, p, error_status); 
*
143D:  MOVLW  01
143E:  MOVWF  6E
143F:  MOVLW  37
1440:  MOVWF  6D
1441:  MOVLW  2A
1442:  BSF    03.6
1443:  MOVWF  63
1444:  BCF    0A.4
1445:  BCF    03.6
1446:  CALL   4B9
1447:  BSF    0A.4
1448:  MOVF   35,W
1449:  BSF    03.6
144A:  MOVWF  5F
144B:  MOVLW  01
144C:  MOVWF  60
144D:  BCF    0A.4
144E:  BSF    0A.3
144F:  BCF    03.6
1450:  CALL   069
1451:  BSF    0A.4
1452:  BCF    0A.3
1453:  BSF    03.6
1454:  MOVF   34,W
1455:  MOVWF  04
1456:  BCF    03.7
1457:  BTFSC  35.0
1458:  BSF    03.7
1459:  MOVLW  00
145A:  IORWF  00,W
145B:  BTFSC  03.2
145C:  GOTO   471
145D:  CLRF   60
145E:  MOVF   04,W
145F:  MOVWF  5F
1460:  BCF    60.0
1461:  BTFSC  03.7
1462:  BSF    60.0
1463:  MOVF   00,W
1464:  MOVWF  63
1465:  BCF    0A.4
1466:  BCF    03.6
1467:  CALL   4B9
1468:  BSF    0A.4
1469:  BSF    03.6
146A:  MOVF   5F,W
146B:  MOVWF  04
146C:  BCF    03.7
146D:  BTFSC  60.0
146E:  BSF    03.7
146F:  INCF   04,F
1470:  GOTO   459
1471:  BCF    03.6
1472:  MOVF   39,W
1473:  BSF    03.6
1474:  MOVWF  61
1475:  MOVLW  37
1476:  MOVWF  62
1477:  BCF    0A.4
1478:  BSF    0A.3
1479:  BCF    03.6
147A:  CALL   0B2
147B:  BSF    0A.4
147C:  BCF    0A.3
147D:  MOVF   38,W
147E:  BSF    03.6
147F:  MOVWF  61
1480:  MOVLW  37
1481:  MOVWF  62
1482:  BCF    0A.4
1483:  BSF    0A.3
1484:  BCF    03.6
1485:  CALL   0B2
1486:  BSF    0A.4
1487:  BCF    0A.3
1488:  MOVLW  0D
1489:  BSF    03.6
148A:  MOVWF  63
148B:  BCF    0A.4
148C:  BCF    03.6
148D:  CALL   4B9
148E:  BSF    0A.4
148F:  MOVLW  0A
1490:  BSF    03.6
1491:  MOVWF  63
1492:  BCF    0A.4
1493:  BCF    03.6
1494:  CALL   4B9
1495:  BSF    0A.4
....................    
....................   // Grab the size 
....................   for(size=0; final_string[size]!='\0'; ++size); 
1496:  BSF    03.6
1497:  CLRF   36
1498:  MOVLW  37
1499:  ADDWF  36,W
149A:  MOVWF  04
149B:  BSF    03.7
149C:  MOVF   00,F
149D:  BTFSC  03.2
149E:  GOTO   4A1
149F:  INCF   36,F
14A0:  GOTO   498
....................   
....................   // And send it out 
....................   rs485_wait_for_bus(false); 
14A1:  CLRF   5F
14A2:  BCF    03.6
14A3:  GOTO   0BE
....................   while(!rs485_send_message(size, final_string)) 
....................   {     
14A4:  BSF    03.6
14A5:  MOVF   36,W
14A6:  MOVWF  5F
14A7:  MOVLW  01
14A8:  MOVWF  61
14A9:  MOVLW  37
14AA:  MOVWF  60
14AB:  BCF    03.6
14AC:  GOTO   0F8
14AD:  MOVF   78,F
14AE:  BTFSS  03.2
14AF:  GOTO   4BA
....................    delay_ms(10); 
14B0:  MOVLW  0A
14B1:  BSF    03.5
14B2:  BSF    03.6
14B3:  MOVWF  10
14B4:  BCF    0A.4
14B5:  BCF    03.5
14B6:  BCF    03.6
14B7:  CALL   434
14B8:  BSF    0A.4
....................   } 
14B9:  GOTO   4A4
....................    
....................   // Finally, clear all non-persistent errors   
....................   clear_errors(false); 
14BA:  BSF    03.6
14BB:  CLRF   5F
14BC:  BCF    0A.4
14BD:  BSF    0A.3
14BE:  BCF    03.6
14BF:  CALL   0DB
14C0:  BSF    0A.4
14C1:  BCF    0A.3
....................     
.................... } 
14C2:  RETLW  00
....................  
.................... //#endif 
....................  
.................... #include "spi.c" 
.................... /****************************************************************************/ 
.................... /* Copyright 2007 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.       																						  */ 
.................... /*	 																																				*/ 
.................... /* SPI.c - handles SPI communications.                                      */ 
.................... /*																																				  */ 
.................... /* Rev History:																															*/ 
.................... /* Initial Creation 11/2007		B.Kieft																	    	*/ 
.................... /*																																					*/ 
.................... /*																																					*/ 
.................... /****************************************************************************/ 
....................  
....................  
.................... #include <stdlib.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDLIB 
.................... #define _STDLIB 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Definitions and types 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #ifndef RAND_MAX 
.................... #define RAND_MAX  32767    // The value of which is the maximum value 
....................                            // ... returned by the rand function 
.................... #endif 
....................  
.................... typedef struct { 
....................    signed int quot; 
....................    signed int rem; 
.................... } div_t; 
....................  
.................... typedef struct { 
....................    signed long quot; 
....................    signed long rem; 
.................... } ldiv_t; 
....................  
.................... #include <stddef.h> 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // String conversion functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Standard template: float atof(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... float atof(char * s); 
....................  
.................... /* Standard template: float atoe(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  * also handles E format numbers 
....................  */ 
.................... float atoe(char * s); 
....................  
.................... /* Standard template: signed int  atoi(char * s) 
....................  * converts the initial portion of the string s to a signed int 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed int atoi(char *s); 
....................  
.................... /* Syntax: signed int32  atoi32(char * s) 
....................    converts the initial portion of the string s to a signed int32 
....................    returns the converted value if any, 0 otherwise*/ 
.................... signed int32 atoi32(char *s); 
....................  
.................... /* Syntax: char *  itoa(signed int32 num, int8 base, char * s) 
....................    converts the signed int32 to a string and 
....................    returns the converted value if any, 0 otherwise*/ 
.................... char * itoa(signed int32 num, int8 base, char * s); 
....................  
.................... /* Standard template: signed long  atol(char * s) 
....................  * converts the initial portion of the string s to a signed long 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed long atol(char *s); 
....................  
.................... /* Standard template: float strtol(char * s,char *endptr) 
....................  * converts the initial portion of the string s to a float 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... float strtod(char *s,char *endptr); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base  to a signed long. 
....................  * Returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... signed long strtol(char *s,char *endptr,signed int base); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base to a unsigned long. 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... long strtoul(char *s,char *endptr,signed int base); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Pseudo-random sequence generation functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The rand function computes a sequence of pseudo-random integers in 
....................  * the range 0 to RAND_MAX 
....................  * 
....................  * Parameters: 
....................  *       (none) 
....................  * 
....................  * Returns: 
....................  *       The pseudo-random integer 
....................  */ 
.................... long rand(void); 
....................  
.................... /* The srand function uses the argument as a seed for a new sequence of 
....................  * pseudo-random numbers to be returned by subsequent calls to rand. 
....................  * 
....................  * Parameters: 
....................  *       [in] seed: The seed value to start from. You might need to pass 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  * 
....................  * Remarks 
....................  *          The srand function sets the starting point for generating 
....................  *       a series of pseudorandom integers. To reinitialize the 
....................  *       generator, use 1 as the seed argument. Any other value for 
....................  *       seed sets the generator to a random starting point. rand 
....................  *       retrieves the pseudorandom numbers that are generated. 
....................  *       Calling rand before any call to srand generates the same 
....................  *       sequence as calling srand with seed passed as 1. 
....................  *          Usually, you need to pass a time here from outer source 
....................  *       so that the numbers will be different every time you run. 
....................  */ 
.................... void srand(unsigned int32 seed); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Memory management functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Comming soon 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Communication with the environment 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The function returns 0 always 
....................  */ 
.................... signed int system(char *string); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Performs a binary search of a sorted array.. 
....................  * 
....................  * Parameters: 
....................  *       [in] key: Object to search for 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       bsearch returns a pointer to an occurrence of key in the array pointed 
....................  *       to by base. If key is not found, the function returns NULL. If the 
....................  *       array is not in order or contains duplicate records with identical keys, 
....................  *       the result is unpredictable. 
....................  */ 
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents 
....................  * of the array are sorted into ascending order according to a comparison 
....................  * function pointed to by compar. 
....................  * 
....................  * Parameters: 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  */ 
.................... //void *qsort(const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Integer arithmetic functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #define labs abs 
....................  
.................... div_t div(signed int numer,signed int denom); 
.................... ldiv_t ldiv(signed long numer,signed long denom); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte character functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte string functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Internal implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #include <stddef.h> 
.................... #include <string.h> 
....................  
.................... div_t div(signed int numer,signed int denom) 
.................... { 
....................    div_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... ldiv_t ldiv(signed long numer,signed long denom) 
.................... { 
....................    ldiv_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... float atof(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... float atoe(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    int expsign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................    int i; 
....................    float exp = 1.0; 
....................    int expcnt = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................       // Handling the exponent 
....................       if (c=='e' || c=='E') { 
....................          c = s[ptr++]; 
....................  
....................          if(c == '-') { 
....................             expsign = 1; 
....................             c = s[ptr++]; 
....................          } 
....................          if(c == '+') 
....................             c = s[ptr++]; 
....................  
....................          while((c >= '0' && c <= '9')) { 
....................             expcnt = 10*expcnt + c - '0'; 
....................             c = s[ptr++]; 
....................          } 
....................  
....................          for(i=0;i<expcnt;i++) 
....................             exp*=10; 
....................  
....................          if(expsign==1) 
....................             result/=exp; 
....................          else 
....................             result*=exp; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... signed int atoi(char *s) 
.................... { 
....................    signed int result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    // Omit all preceeding alpha characters 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................  
....................       // Check for hexa number 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++]; 
....................             c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (sign == 1 && base == 10) 
....................        result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... signed long atol(char *s) 
.................... { 
....................    signed long result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... /* A fast routine to multiply by 10 
....................  */ 
.................... signed int32 mult_with10(int32 num) 
.................... { 
....................    return ( (num << 1) + (num << 3) ); 
.................... } 
....................  
.................... signed int32 atoi32(char *s) 
.................... { 
....................    signed int32 result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') { 
....................             result = (result << 1) + (result << 3);  // result *= 10; 
....................             result += (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... char * itoa(signed int32 num, int8 base, char *s) 
.................... { 
....................      int32 temp=1; 
....................      int8 i,sign=0,cnt=0; 
....................      char c; 
....................  
....................      if(num<0) { 
....................          sign=1;        // Check for negative number 
....................          num*=-1; 
....................      } 
....................  
....................      while(temp>0) { 
....................          temp=(num/base); 
....................          s[cnt]=(num%base)+'0';    // Conversion 
....................  
....................          if(s[cnt]>0x39) 
....................             s[cnt]+=0x7; 
....................  
....................          cnt++; 
....................          num=temp; 
....................      } 
....................  
....................      if(sign==1) { 
....................          s[cnt]=0x2D;      // Negative sign 
....................          cnt++; 
....................      } 
....................  
....................      for(i = 0;i<(int8)(cnt/2);i++) { 
....................  
....................          c=s[i]; 
....................          s[i]=s[cnt-i-1];        // Reverse the number 
....................          s[cnt-i-1]=c; 
....................      } 
....................      s[cnt]='\0';     // End the string 
....................      return s; 
.................... } 
....................  
.................... float strtod(char *s,char *endptr) { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0, point = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c=s[ptr++]; 
....................  
....................  
....................    while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 0) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          point = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 1) { 
....................          pow10 = pow10*10; 
....................          result += (c - '0')/pow10; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '+') { 
....................          c = s[ptr++]; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    if(endptr) 
....................    { 
....................       if (ptr) { 
....................          ptr--; 
....................          *((char *)endptr)=s+ptr; 
....................       } 
....................       else 
....................          *((char *)endptr)=s; 
....................    } 
....................  
....................    return(result); 
.................... } 
....................  
.................... long strtoul(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    unsigned long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if(sign=='-') 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................  
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(; sd!=0; ) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
....................  
.................... signed long strtol(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    signed long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................  
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(;sd!=0;) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if(sign=='-') 
....................       x  =-x; 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
.................... signed int system(char *string) 
.................... { 
....................    return 0; 
.................... } 
....................  
.................... int mblen(char *s,size_t n) 
.................... { 
....................    return strlen(s); 
.................... } 
....................  
.................... int mbtowc(wchar_t *pwc,char *s,size_t n) 
.................... { 
....................    *pwc=*s; 
....................    return 1; 
.................... } 
....................  
.................... int wctomb(char *s,wchar_t wchar) 
.................... { 
....................    *s=wchar; 
....................    return 1; 
.................... } 
....................  
.................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n) 
.................... { 
....................    strncpy(pwcs,s,n); 
....................    return strlen(pwcs); 
.................... } 
....................  
.................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n) 
.................... { 
....................    strncpy(s,pwcs,n); 
....................    return strlen(s); 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // The random number implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... unsigned int32 _Randseed; 
....................  
.................... long rand(void) 
.................... { 
....................    _Randseed = _Randseed * 1103515245 + 12345; 
....................    return ((unsigned long)(_Randseed >> 16) % RAND_MAX); 
.................... } 
....................  
.................... void srand(unsigned int32 seed) 
.................... { 
....................    _Randseed = seed; 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... typedef signed int (*_Cmpfun)(char * p1,char * p2); 
....................  
.................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) { 
....................    int m,j,i,l; 
....................    short done; 
....................    BYTE t[16]; 
....................  
....................    m = qitems/2; 
....................    while( m > 0 ) { 
....................      for(j=0; j<(qitems-m); ++j) { 
....................         i = j; 
....................         do 
....................         { 
....................            done=TRUE; 
....................            l = i+m; 
....................            if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) { 
....................               memcpy(t, qdata+i*qsize, qsize); 
....................               memcpy(qdata+i*qsize, qdata+l*qsize, qsize); 
....................               memcpy(qdata+l*qsize, t, qsize); 
....................               if(m <= i) 
....................                 i -= m; 
....................                 done = FALSE; 
....................            } 
....................         } while(!done); 
....................      } 
....................      m = m/2; 
....................    } 
.................... } 
....................  
....................  
.................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp) 
.................... { 
....................    char *p, *q; 
....................    size_t n; 
....................    size_t pivot; 
....................    signed int val; 
....................  
....................    p = base; 
....................    n = num; 
....................  
....................    while (n > 0) 
....................    { 
....................       pivot = n >> 1; 
....................       q = p + width * pivot; 
....................  
....................       val = (*cmp)(key, q); 
....................  
....................       if (val < 0) 
....................          n = pivot; 
....................       else if (val == 0) 
....................          return ((char *)q); 
....................       else { 
....................          p = q + width; 
....................          n -= pivot + 1; 
....................       } 
....................    } 
....................  
....................    return NULL;      // There's no match 
.................... } 
....................  
....................  
.................... #endif 
....................  
....................  
.................... // Purpose: Sends spi string 
.................... #SEPARATE 
.................... void SPI_strwrite(char *s) 
.................... { 
.................... 	int count = 0; 
*
0541:  BSF    03.6
0542:  CLRF   36
....................   while( (*s != 0) && (count < MAX_SPI_CHARS) ) { 
0543:  MOVF   35,W
0544:  MOVWF  7A
0545:  MOVF   34,W
0546:  MOVWF  04
0547:  BCF    03.7
0548:  BTFSC  7A.0
0549:  BSF    03.7
054A:  MOVF   00,F
054B:  BTFSC  03.2
054C:  GOTO   56A
054D:  MOVF   36,W
054E:  SUBLW  0A
054F:  BTFSS  03.0
0550:  GOTO   56A
....................   spi_write(*s++); 
0551:  MOVF   35,W
0552:  MOVWF  7A
0553:  MOVF   34,W
0554:  INCF   34,F
0555:  BTFSC  03.2
0556:  INCF   35,F
0557:  MOVWF  04
0558:  BCF    03.7
0559:  BTFSC  7A.0
055A:  BSF    03.7
055B:  MOVF   00,W
055C:  MOVWF  37
055D:  BCF    03.6
055E:  MOVF   13,W
055F:  BSF    03.6
0560:  MOVF   37,W
0561:  BCF    03.6
0562:  MOVWF  13
0563:  BSF    03.5
0564:  BTFSS  14.0
0565:  GOTO   564
....................   count++; 
0566:  BCF    03.5
0567:  BSF    03.6
0568:  INCF   36,F
....................   } 
0569:  GOTO   543
.................... } 
056A:  BCF    03.6
056B:  RETLW  00
....................  
.................... // Purpose: Reads spi string with clocks 
.................... #SEPARATE 
.................... void SPI_strread(char *s) 
.................... { 
.................... 	int spi_char = 0; 
*
0FA6:  BSF    03.6
0FA7:  CLRF   61
.................... 	char spi_buff_in[MAX_SPI_CHARS]; 
.................... 	 
....................   while( (s[spi_char] = spi_read(0)) && (spi_char < MAX_SPI_CHARS) ) { 
0FA8:  MOVF   61,W
0FA9:  ADDWF  5F,W
0FAA:  MOVWF  04
0FAB:  BCF    03.7
0FAC:  BTFSC  60.0
0FAD:  BSF    03.7
0FAE:  BCF    03.6
0FAF:  MOVF   13,W
0FB0:  CLRF   13
0FB1:  BSF    03.5
0FB2:  BTFSS  14.0
0FB3:  GOTO   7B2
0FB4:  BCF    03.5
0FB5:  MOVF   13,W
0FB6:  MOVWF  00
0FB7:  XORLW  00
0FB8:  BTFSC  03.2
0FB9:  GOTO   7C9
0FBA:  BSF    03.6
0FBB:  MOVF   61,W
0FBC:  SUBLW  0A
0FBD:  BTFSC  03.0
0FBE:  GOTO   7C1
0FBF:  BCF    03.6
0FC0:  GOTO   7C9
....................     spi_char++;	 
0FC1:  INCF   61,F
....................     delay_us(500);  
0FC2:  CLRWDT
0FC3:  MOVLW  A6
0FC4:  MOVWF  77
0FC5:  DECFSZ 77,F
0FC6:  GOTO   7C5
....................   } 
0FC7:  GOTO   7A8
0FC8:  BCF    03.6
.................... } 
0FC9:  RETLW  00
....................  
.................... // Purpose: Reads spi string with no clocks 
.................... #SEPARATE 
.................... void SPI_slave_strread(char *s) 
.................... { 
.................... 	int spi_char = 0; 
*
0649:  BSF    03.6
064A:  CLRF   12
.................... 	char spi_buff_in[MAX_SPI_CHARS]; 
.................... 	 
.................... 	while(!spi_data_is_in()); 
064B:  BSF    03.5
064C:  BCF    03.6
064D:  BTFSS  14.0
064E:  GOTO   64D
....................   while( (s[spi_char] = spi_read()) && (spi_char < MAX_SPI_CHARS) ) { 
064F:  BCF    03.5
0650:  BSF    03.6
0651:  MOVF   12,W
0652:  ADDWF  10,W
0653:  MOVWF  04
0654:  BCF    03.7
0655:  BTFSC  11.0
0656:  BSF    03.7
0657:  BCF    03.6
0658:  MOVF   13,W
0659:  MOVWF  00
065A:  XORLW  00
065B:  BTFSC  03.2
065C:  GOTO   66C
065D:  BSF    03.6
065E:  MOVF   12,W
065F:  SUBLW  0A
0660:  BTFSC  03.0
0661:  GOTO   664
0662:  BCF    03.6
0663:  GOTO   66C
....................     spi_char++;	 
0664:  INCF   12,F
....................     delay_us(50);  
0665:  CLRWDT
0666:  MOVLW  10
0667:  MOVWF  77
0668:  DECFSZ 77,F
0669:  GOTO   668
....................   } 
066A:  GOTO   651
066B:  BCF    03.6
.................... } 
066C:  RETLW  00
....................  
.................... #include "Command_Handler.c" 
.................... /****************************************************************************/ 
.................... /* Copyright 2007 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.       																						  */ 
.................... /*																																					*/ 
.................... /* Command_Handler.c - Handles all incoming RS485nds												*/ 
.................... /*																																					*/ 
.................... /* Rev History:																															*/ 
.................... /* Initial Creation 11/2007		B.Kieft							     											*/ 
.................... /*																																					*/ 
.................... /*																																					*/ 
.................... /****************************************************************************/ 
....................  
.................... #include <stdlib.h> 
.................... /////////////////////////////////////////////////////////////////////////// 
.................... ////        (C) Copyright 1996,2003 Custom Computer Services           //// 
.................... //// This source code may only be used by licensed users of the CCS C  //// 
.................... //// compiler.  This source code may only be distributed to other      //// 
.................... //// licensed users of the CCS C compiler.  No other use, reproduction //// 
.................... //// or distribution is permitted without written permission.          //// 
.................... //// Derivative programs created using this software in object code    //// 
.................... //// form are not restricted in any way.                               //// 
.................... /////////////////////////////////////////////////////////////////////////// 
....................  
.................... #ifndef _STDLIB 
.................... #define _STDLIB 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Definitions and types 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #ifndef RAND_MAX 
.................... #define RAND_MAX  32767    // The value of which is the maximum value 
....................                            // ... returned by the rand function 
.................... #endif 
....................  
.................... typedef struct { 
....................    signed int quot; 
....................    signed int rem; 
.................... } div_t; 
....................  
.................... typedef struct { 
....................    signed long quot; 
....................    signed long rem; 
.................... } ldiv_t; 
....................  
.................... #include <stddef.h> 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // String conversion functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Standard template: float atof(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... float atof(char * s); 
....................  
.................... /* Standard template: float atoe(char * s) 
....................  * converts the initial portion of the string s to a float. 
....................  * returns the converted value if any, 0 otherwise 
....................  * also handles E format numbers 
....................  */ 
.................... float atoe(char * s); 
....................  
.................... /* Standard template: signed int  atoi(char * s) 
....................  * converts the initial portion of the string s to a signed int 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed int atoi(char *s); 
....................  
.................... /* Syntax: signed int32  atoi32(char * s) 
....................    converts the initial portion of the string s to a signed int32 
....................    returns the converted value if any, 0 otherwise*/ 
.................... signed int32 atoi32(char *s); 
....................  
.................... /* Syntax: char *  itoa(signed int32 num, int8 base, char * s) 
....................    converts the signed int32 to a string and 
....................    returns the converted value if any, 0 otherwise*/ 
.................... char * itoa(signed int32 num, int8 base, char * s); 
....................  
.................... /* Standard template: signed long  atol(char * s) 
....................  * converts the initial portion of the string s to a signed long 
....................  * returns the converted value if any, 0 otherwise 
....................  */ 
.................... signed long atol(char *s); 
....................  
.................... /* Standard template: float strtol(char * s,char *endptr) 
....................  * converts the initial portion of the string s to a float 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... float strtod(char *s,char *endptr); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base  to a signed long. 
....................  * Returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... signed long strtol(char *s,char *endptr,signed int base); 
....................  
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) 
....................  * converts the initial portion of the string s, represented as an 
....................  * integral value of radix base to a unsigned long. 
....................  * returns the converted value if any, 0 otherwise 
....................  * the final string is returned in the endptr, if endptr is not null 
....................  */ 
.................... long strtoul(char *s,char *endptr,signed int base); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Pseudo-random sequence generation functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The rand function computes a sequence of pseudo-random integers in 
....................  * the range 0 to RAND_MAX 
....................  * 
....................  * Parameters: 
....................  *       (none) 
....................  * 
....................  * Returns: 
....................  *       The pseudo-random integer 
....................  */ 
.................... long rand(void); 
....................  
.................... /* The srand function uses the argument as a seed for a new sequence of 
....................  * pseudo-random numbers to be returned by subsequent calls to rand. 
....................  * 
....................  * Parameters: 
....................  *       [in] seed: The seed value to start from. You might need to pass 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  * 
....................  * Remarks 
....................  *          The srand function sets the starting point for generating 
....................  *       a series of pseudorandom integers. To reinitialize the 
....................  *       generator, use 1 as the seed argument. Any other value for 
....................  *       seed sets the generator to a random starting point. rand 
....................  *       retrieves the pseudorandom numbers that are generated. 
....................  *       Calling rand before any call to srand generates the same 
....................  *       sequence as calling srand with seed passed as 1. 
....................  *          Usually, you need to pass a time here from outer source 
....................  *       so that the numbers will be different every time you run. 
....................  */ 
.................... void srand(unsigned int32 seed); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Memory management functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Comming soon 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Communication with the environment 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* The function returns 0 always 
....................  */ 
.................... signed int system(char *string); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities 
.................... //--------------------------------------------------------------------------- 
....................  
.................... /* Performs a binary search of a sorted array.. 
....................  * 
....................  * Parameters: 
....................  *       [in] key: Object to search for 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       bsearch returns a pointer to an occurrence of key in the array pointed 
....................  *       to by base. If key is not found, the function returns NULL. If the 
....................  *       array is not in order or contains duplicate records with identical keys, 
....................  *       the result is unpredictable. 
....................  */ 
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents 
....................  * of the array are sorted into ascending order according to a comparison 
....................  * function pointed to by compar. 
....................  * 
....................  * Parameters: 
....................  *       [in] base: Pointer to base of search data 
....................  *       [in] num: Number of elements 
....................  *       [in] width: Width of elements 
....................  *       [in] compare: Function that compares two elements 
....................  * 
....................  * Returns: 
....................  *       (none) 
....................  */ 
.................... //void *qsort(const void *base, size_t num, size_t width, 
.................... //              int (*compare)(const void *, const void *)); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Integer arithmetic functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #define labs abs 
....................  
.................... div_t div(signed int numer,signed int denom); 
.................... ldiv_t ldiv(signed long numer,signed long denom); 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte character functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Multibyte string functions 
.................... //--------------------------------------------------------------------------- 
....................  
.................... // Not supported 
....................  
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Internal implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... #include <stddef.h> 
.................... #include <string.h> 
....................  
.................... div_t div(signed int numer,signed int denom) 
.................... { 
....................    div_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... ldiv_t ldiv(signed long numer,signed long denom) 
.................... { 
....................    ldiv_t val; 
....................    val.quot = numer / denom; 
....................    val.rem = numer - (denom * val.quot); 
....................    return (val); 
.................... } 
....................  
.................... float atof(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... float atoe(char * s) 
.................... { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0; 
....................    int expsign = 0; 
....................    char c; 
....................    int ptr = 0; 
....................    int i; 
....................    float exp = 1.0; 
....................    int expcnt = 0; 
....................  
....................    c = s[ptr++]; 
....................  
....................    if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................       if(c == '+') 
....................          c = s[ptr++]; 
....................  
....................       while((c >= '0' && c <= '9')) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          c = s[ptr++]; 
....................          while((c >= '0' && c <= '9')) { 
....................              pow10 = pow10*10; 
....................              result += (c - '0')/pow10; 
....................              c = s[ptr++]; 
....................          } 
....................       } 
....................  
....................       // Handling the exponent 
....................       if (c=='e' || c=='E') { 
....................          c = s[ptr++]; 
....................  
....................          if(c == '-') { 
....................             expsign = 1; 
....................             c = s[ptr++]; 
....................          } 
....................          if(c == '+') 
....................             c = s[ptr++]; 
....................  
....................          while((c >= '0' && c <= '9')) { 
....................             expcnt = 10*expcnt + c - '0'; 
....................             c = s[ptr++]; 
....................          } 
....................  
....................          for(i=0;i<expcnt;i++) 
....................             exp*=10; 
....................  
....................          if(expsign==1) 
....................             result/=exp; 
....................          else 
....................             result*=exp; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    return(result); 
.................... } 
....................  
.................... signed int atoi(char *s) 
.................... { 
....................    signed int result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    // Omit all preceeding alpha characters 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................  
....................       // Check for hexa number 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++]; 
....................             c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (sign == 1 && base == 10) 
....................        result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... signed long atol(char *s) 
.................... { 
....................    signed long result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') 
....................          { 
....................             result = 10*result + (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... /* A fast routine to multiply by 10 
....................  */ 
.................... signed int32 mult_with10(int32 num) 
.................... { 
....................    return ( (num << 1) + (num << 3) ); 
.................... } 
....................  
.................... signed int32 atoi32(char *s) 
.................... { 
....................    signed int32 result; 
....................    int sign, base, index; 
....................    char c; 
....................  
....................    index = 0; 
....................    sign = 0; 
....................    base = 10; 
....................    result = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c = s[index++]; 
....................  
....................    // increase index if either positive or negative sign is detected 
....................    if (c == '-') 
....................    { 
....................       sign = 1;         // Set the sign to negative 
....................       c = s[index++]; 
....................    } 
....................    else if (c == '+') 
....................    { 
....................       c = s[index++]; 
....................    } 
....................  
....................    if (c >= '0' && c <= '9') 
....................    { 
....................       if (c == '0' && (s[index] == 'x' || s[index] == 'X')) 
....................       { 
....................          base = 16; 
....................          index++; 
....................          c = s[index++]; 
....................       } 
....................  
....................       // The number is a decimal number 
....................       if (base == 10) 
....................       { 
....................          while (c >= '0' && c <= '9') { 
....................             result = (result << 1) + (result << 3);  // result *= 10; 
....................             result += (c - '0'); 
....................             c = s[index++]; 
....................          } 
....................       } 
....................       else if (base == 16)    // The number is a hexa number 
....................       { 
....................          c = toupper(c); 
....................          while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F')) 
....................          { 
....................             if (c >= '0' && c <= '9') 
....................                result = (result << 4) + (c - '0'); 
....................             else 
....................                result = (result << 4) + (c - 'A' + 10); 
....................  
....................             c = s[index++];c = toupper(c); 
....................          } 
....................       } 
....................    } 
....................  
....................    if (base == 10 && sign == 1) 
....................       result = -result; 
....................  
....................    return(result); 
.................... } 
....................  
.................... char * itoa(signed int32 num, int8 base, char *s) 
.................... { 
....................      int32 temp=1; 
....................      int8 i,sign=0,cnt=0; 
....................      char c; 
....................  
....................      if(num<0) { 
....................          sign=1;        // Check for negative number 
....................          num*=-1; 
....................      } 
....................  
....................      while(temp>0) { 
....................          temp=(num/base); 
....................          s[cnt]=(num%base)+'0';    // Conversion 
....................  
....................          if(s[cnt]>0x39) 
....................             s[cnt]+=0x7; 
....................  
....................          cnt++; 
....................          num=temp; 
....................      } 
....................  
....................      if(sign==1) { 
....................          s[cnt]=0x2D;      // Negative sign 
....................          cnt++; 
....................      } 
....................  
....................      for(i = 0;i<(int8)(cnt/2);i++) { 
....................  
....................          c=s[i]; 
....................          s[i]=s[cnt-i-1];        // Reverse the number 
....................          s[cnt-i-1]=c; 
....................      } 
....................      s[cnt]='\0';     // End the string 
....................      return s; 
.................... } 
....................  
.................... float strtod(char *s,char *endptr) { 
....................    float pow10 = 1.0; 
....................    float result = 0.0; 
....................    int sign = 0, point = 0; 
....................    char c; 
....................    int ptr = 0; 
....................  
....................    if (!s) 
....................       return 0; 
....................    c=s[ptr++]; 
....................  
....................  
....................    while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { 
....................       if(c == '-') { 
....................          sign = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 0) { 
....................          result = 10*result + c - '0'; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '.') { 
....................          point = 1; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       while((c >= '0' && c <= '9') && point == 1) { 
....................          pow10 = pow10*10; 
....................          result += (c - '0')/pow10; 
....................          c = s[ptr++]; 
....................       } 
....................  
....................       if (c == '+') { 
....................          c = s[ptr++]; 
....................       } 
....................    } 
....................  
....................    if (sign == 1) 
....................       result = -1*result; 
....................    if(endptr) 
....................    { 
....................       if (ptr) { 
....................          ptr--; 
....................          *((char *)endptr)=s+ptr; 
....................       } 
....................       else 
....................          *((char *)endptr)=s; 
....................    } 
....................  
....................    return(result); 
.................... } 
....................  
.................... long strtoul(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    unsigned long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if(sign=='-') 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................  
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(; sd!=0; ) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
....................  
.................... signed long strtol(char *s,char *endptr,signed int base) 
.................... { 
....................    char *sc,*s1,*sd; 
....................    signed long x=0; 
....................    char sign; 
....................    char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; 
....................    for(sc=s;isspace(*sc);++sc); 
....................    sign=*sc=='-'||*sc=='+'?*sc++:'+'; 
....................    if (base <0 || base ==1|| base >36) // invalid base 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................       return 0; 
....................    } 
....................    else if (base) 
....................    { 
....................       if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) 
....................          sc+=2; 
....................       if(base==8 && *sc =='0') 
....................          sc+=1; 
....................       if(base==2 && *sc =='0'&&sc[1]=='b') 
....................          sc+=2; 
....................  
....................    } 
....................    else if(*sc!='0') // base is 0, find base 
....................       base=10; 
....................    else if (sc[1]=='x' || sc[1]=='X') 
....................       base =16,sc+=2; 
....................    else if(sc[1]=='b') 
....................       base=2,sc+=2; 
....................    else 
....................       base=8; 
....................    for (s1=sc;*sc=='0';++sc);// skip leading zeroes 
....................  
....................    sd=memchr(digits,tolower(*sc),base); 
....................    for(;sd!=0;) 
....................    { 
....................       x=x*base+(int16)(sd-digits); 
....................       ++sc; 
....................       sd=memchr(digits,tolower(*sc),base); 
....................    } 
....................    if(s1==sc) 
....................    { 
....................       if (endptr) 
....................       { 
....................         *((char *)endptr)=s; 
....................       } 
....................    return 0; 
....................    } 
....................    if(sign=='-') 
....................       x  =-x; 
....................    if (endptr) 
....................         *((char *)endptr)=sc; 
....................    return x; 
.................... } 
....................  
.................... signed int system(char *string) 
.................... { 
....................    return 0; 
.................... } 
....................  
.................... int mblen(char *s,size_t n) 
.................... { 
....................    return strlen(s); 
.................... } 
....................  
.................... int mbtowc(wchar_t *pwc,char *s,size_t n) 
.................... { 
....................    *pwc=*s; 
....................    return 1; 
.................... } 
....................  
.................... int wctomb(char *s,wchar_t wchar) 
.................... { 
....................    *s=wchar; 
....................    return 1; 
.................... } 
....................  
.................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n) 
.................... { 
....................    strncpy(pwcs,s,n); 
....................    return strlen(pwcs); 
.................... } 
....................  
.................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n) 
.................... { 
....................    strncpy(s,pwcs,n); 
....................    return strlen(s); 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // The random number implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... unsigned int32 _Randseed; 
....................  
.................... long rand(void) 
.................... { 
....................    _Randseed = _Randseed * 1103515245 + 12345; 
....................    return ((unsigned long)(_Randseed >> 16) % RAND_MAX); 
.................... } 
....................  
.................... void srand(unsigned int32 seed) 
.................... { 
....................    _Randseed = seed; 
.................... } 
....................  
.................... //--------------------------------------------------------------------------- 
.................... // Searching and sorting utilities implementation 
.................... //--------------------------------------------------------------------------- 
....................  
.................... typedef signed int (*_Cmpfun)(char * p1,char * p2); 
....................  
.................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) { 
....................    int m,j,i,l; 
....................    short done; 
....................    BYTE t[16]; 
....................  
....................    m = qitems/2; 
....................    while( m > 0 ) { 
....................      for(j=0; j<(qitems-m); ++j) { 
....................         i = j; 
....................         do 
....................         { 
....................            done=TRUE; 
....................            l = i+m; 
....................            if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) { 
....................               memcpy(t, qdata+i*qsize, qsize); 
....................               memcpy(qdata+i*qsize, qdata+l*qsize, qsize); 
....................               memcpy(qdata+l*qsize, t, qsize); 
....................               if(m <= i) 
....................                 i -= m; 
....................                 done = FALSE; 
....................            } 
....................         } while(!done); 
....................      } 
....................      m = m/2; 
....................    } 
.................... } 
....................  
....................  
.................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp) 
.................... { 
....................    char *p, *q; 
....................    size_t n; 
....................    size_t pivot; 
....................    signed int val; 
....................  
....................    p = base; 
....................    n = num; 
....................  
....................    while (n > 0) 
....................    { 
....................       pivot = n >> 1; 
....................       q = p + width * pivot; 
....................  
....................       val = (*cmp)(key, q); 
....................  
....................       if (val < 0) 
....................          n = pivot; 
....................       else if (val == 0) 
....................          return ((char *)q); 
....................       else { 
....................          p = q + width; 
....................          n -= pivot + 1; 
....................       } 
....................    } 
....................  
....................    return NULL;      // There's no match 
.................... } 
....................  
....................  
.................... #endif 
....................  
.................... #include "loadControl_main.h" 
.................... /****************************************************************************/ 
.................... /* Copyright 2007 MBARI.                                                    */ 
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */ 
.................... /* All rights reserved.       																						  */ 
.................... /*																																					*/ 
.................... /* Rev History:																															*/ 
.................... /* Initial Creation 11/2007		B.Kieft																		    */ 
.................... /*																																					*/ 
.................... /*																																					*/ 
.................... /****************************************************************************/ 
.................... #ifndef PH_PROBE_H 
.................... #define PH_PROBE_H 
....................  
.................... #define HI  1 
.................... #define LO  0 
....................  
.................... #define ON  1 
.................... #define OFF 0 
....................  
.................... #define MAX_SPI_CHARS 11 
....................  
.................... // 
.................... // Interface Specification Parameters 
.................... // 
.................... int16 startup_oc_threshold = 0; 
.................... int16 steady_oc_threshold = 0; 
.................... int16 startup_oc_time = 0; 
.................... int8 RS485_ID=0;  
.................... int8 eeprom_written = 0;      // Data was written to EEPROM, so initialize from there if equal 
....................                               // to 10011001 (or 0x99) 
.................... int8 relay_status_closed = 0; // 0 == False == open circuit 
....................  
.................... // Used to store the location of interface params in EEPROM 
.................... #define EE_startup_oc_threshold  0  //size=2 
.................... #define EE_steady_oc_threshold   2  //size=2 
.................... #define EE_startup_oc_time       4  //size=2 
.................... #define EE_RS485_ID              5  //size=1 
.................... #define EE_relay_status_closed   6  //size=1 
.................... #define EE_eeprom_written        7  //size=1 
....................  
....................  
.................... // 
.................... //Error parameters  
.................... // 
.................... int16 error_status = 0; 
.................... int16 slave_errors = 0; 
.................... // MSB 
.................... Boolean flash_write_err_slave = false; 
.................... Boolean flash_write_err       = false; 
.................... Boolean ground_fault_err      = false; 
.................... Boolean over_temp_err         = false; 
.................... Boolean over_curr_err         = false; 
.................... Boolean switch_err            = false; 
.................... Boolean invld_cmd_err         = false; 
.................... Boolean invld_param_err       = false; 
.................... Boolean invld_cksum_err       = false; 
.................... Boolean wdt_reset_err         = false; 
.................... Boolean slv_cmd_err           = false; 
.................... //LSB 
.................... // 
....................  
....................  
.................... // Constant Definitions 
.................... static const int16 VREF = 4096;        // 4.096 reference voltage 
.................... static const int8 RSENSE = 200;        // .2 Ohm Rsense 
.................... static const int8 CURRDIVISOR = 5;     // 5 V/V amplification 
.................... //static const float GF_RSENSE = 402; 
.................... //static const float GF_VSCALE = 4.048; 
.................... //static const float GF_VREF   = 4.096;        
....................  
.................... const char empty_string[1] = {""}; 
.................... const int8 sw_version[] = "1.0";  
.................... // 
....................  
.................... static int32 adc_value_glob;           // Stores A/D conversion values for SPI bus transmission 
.................... int16 overcurrent_adc_val = 0;         // Stores max A/D output for high priority overcurrent checking 
.................... int16 overcurrent_adc_val_startup = 0; // Stores max A/D output for startup overcurrent checking 
.................... char response_message[30];             // String for storing node response back to MVC 
....................  
.................... int8 serial_delay_msec = 3;            // delay for clocking 485 bits 
.................... int8 spi_data = 0; 
....................  
.................... Boolean master          = true;        // Master on SPI bus 
.................... Boolean cmd_received    = false;       // RS485 command received 
.................... Boolean wdt_reset       = false;       // Latest reset due to WDT reset 
.................... Boolean startup_elapsed = false;       // The time set for the startup current has elapsed 
.................... Boolean slave_is_on     = false;       // The slave PIC is powered up 
.................... Boolean load_is_on      = false;       // The load has been powered up 
.................... Boolean sleep_enabled   = false;       // The master is allowed to sleep 
....................  
.................... //*** DEBUG - to be removed 
.................... int8 rtos_pin = LO;  
.................... //*** DEBUG - to be removed 
....................  
.................... // Function Definitions 
.................... void do_adc_voltage_calcs(int16); 
.................... void do_adc_current_calcs(int16, int16, int8, int8); 
....................  
.................... void write_eeprom8(int8, int8); 
.................... int16 read_eeprom16(int8); 
.................... void write_eeprom16(int8, int16); 
.................... void clear_errors(Boolean); 
.................... void check_slave_on(); 
.................... void check_slave_off(); 
.................... void calculate_errors(); 
.................... #endif 
....................  
....................  
.................... char received_spi_data_mastr[MAX_SPI_CHARS]; 
.................... char sent_spi_data_mastr[MAX_SPI_CHARS]; 
....................  
.................... ////// 
.................... ////// Control Commands 
.................... #SEPARATE 
.................... void handle_load_power() { 
.................... 	// Commanded to turn OFF load 
.................... 	if(parameter == 0) { 
*
14C3:  BSF    03.5
14C4:  MOVF   36,F
14C5:  BTFSS  03.2
14C6:  GOTO   518
14C7:  MOVF   37,F
14C8:  BTFSS  03.2
14C9:  GOTO   518
14CA:  MOVF   38,F
14CB:  BTFSS  03.2
14CC:  GOTO   518
14CD:  MOVF   39,F
14CE:  BTFSS  03.2
14CF:  GOTO   518
....................     check_slave_on(); // Make sure slave is powered 
14D0:  BCF    0A.4
14D1:  BSF    0A.3
14D2:  BCF    03.5
14D3:  CALL   795
14D4:  BSF    0A.4
14D5:  BCF    0A.3
....................     spi_write(70);    // Command slave to turn OFF load 
14D6:  MOVF   13,W
14D7:  MOVLW  46
14D8:  MOVWF  13
14D9:  BSF    03.5
14DA:  BTFSS  14.0
14DB:  GOTO   4DA
....................     delay_ms(50);     // Pause for slave to respond 
14DC:  MOVLW  32
14DD:  BSF    03.6
14DE:  MOVWF  10
14DF:  BCF    0A.4
14E0:  BCF    03.5
14E1:  BCF    03.6
14E2:  CALL   434
14E3:  BSF    0A.4
....................      
....................     // Check the response from the slave 
....................     SPI_strread(received_spi_data_mastr); 
14E4:  BSF    03.6
14E5:  CLRF   60
14E6:  MOVLW  BA
14E7:  MOVWF  5F
14E8:  BCF    0A.4
14E9:  BSF    0A.3
14EA:  BCF    03.6
14EB:  CALL   7A6
14EC:  BSF    0A.4
14ED:  BCF    0A.3
....................     if( atoi32(received_spi_data_mastr) !=  70) { 
14EE:  BSF    03.6
14EF:  CLRF   36
14F0:  MOVLW  BA
14F1:  MOVWF  35
14F2:  BCF    0A.4
14F3:  BCF    03.6
14F4:  CALL   66D
14F5:  BSF    0A.4
14F6:  MOVF   7A,W
14F7:  BSF    03.6
14F8:  MOVWF  37
14F9:  MOVF   79,W
14FA:  MOVWF  36
14FB:  MOVF   78,W
14FC:  MOVWF  35
14FD:  MOVF   77,W
14FE:  MOVWF  34
14FF:  SUBLW  46
1500:  BTFSS  03.2
1501:  GOTO   50B
1502:  MOVF   35,F
1503:  BTFSS  03.2
1504:  GOTO   50B
1505:  MOVF   36,F
1506:  BTFSS  03.2
1507:  GOTO   50B
1508:  MOVF   37,F
1509:  BTFSC  03.2
150A:  GOTO   50F
....................       // Set slave error 
.................... 	    slv_cmd_err = true;  	    	      	 
150B:  BCF    03.6
150C:  BSF    3D.2
....................     } 
....................     else { 
150D:  GOTO   516
150E:  BSF    03.6
....................     	// No errors  
....................     	load_is_on = false; 
150F:  BCF    03.6
1510:  BCF    66.0
....................   	  check_slave_off();  // now safe to turn off slave 
1511:  BCF    0A.4
1512:  BSF    0A.3
1513:  CALL   7CA
1514:  BSF    0A.4
1515:  BCF    0A.3
....................     } 
.................... 	} 
.................... 	// Commanded to turn ON load 
.................... 	else if(parameter == 1) { 
1516:  GOTO   580
1517:  BSF    03.5
1518:  DECFSZ 36,W
1519:  GOTO   57E
151A:  MOVF   37,F
151B:  BTFSS  03.2
151C:  GOTO   57E
151D:  MOVF   38,F
151E:  BTFSS  03.2
151F:  GOTO   57E
1520:  MOVF   39,F
1521:  BTFSS  03.2
1522:  GOTO   57E
....................   	output_bit(PIN_B4, HI); // Turn on slave processor 
1523:  BCF    03.5
1524:  BSF    06.4
1525:  BSF    03.5
1526:  BCF    06.4
....................   	slave_is_on = true; 
1527:  BCF    03.5
1528:  BSF    3D.7
.................... 		delay_ms(300);          // Time for slave to boot up and initialize ~ 170 ms. Worst case observed ~ 300 ms.  
1529:  MOVLW  02
152A:  BSF    03.6
152B:  MOVWF  34
152C:  MOVLW  96
152D:  BSF    03.5
152E:  MOVWF  10
152F:  BCF    0A.4
1530:  BCF    03.5
1531:  BCF    03.6
1532:  CALL   434
1533:  BSF    0A.4
1534:  BSF    03.6
1535:  DECFSZ 34,F
1536:  GOTO   52C
.................... 		 
....................     spi_write(71);          // Command slave to turn ON load                
1537:  BCF    03.6
1538:  MOVF   13,W
1539:  MOVLW  47
153A:  MOVWF  13
153B:  BSF    03.5
153C:  BTFSS  14.0
153D:  GOTO   53C
....................     delay_ms(50);           //Pause for slave to respond 
153E:  MOVLW  32
153F:  BSF    03.6
1540:  MOVWF  10
1541:  BCF    0A.4
1542:  BCF    03.5
1543:  BCF    03.6
1544:  CALL   434
1545:  BSF    0A.4
....................  
....................     // Check the response from the slave     
....................     SPI_strread(received_spi_data_mastr); 
1546:  BSF    03.6
1547:  CLRF   60
1548:  MOVLW  BA
1549:  MOVWF  5F
154A:  BCF    0A.4
154B:  BSF    0A.3
154C:  BCF    03.6
154D:  CALL   7A6
154E:  BSF    0A.4
154F:  BCF    0A.3
....................     if( atoi32(received_spi_data_mastr) !=  71) { 
1550:  BSF    03.6
1551:  CLRF   36
1552:  MOVLW  BA
1553:  MOVWF  35
1554:  BCF    0A.4
1555:  BCF    03.6
1556:  CALL   66D
1557:  BSF    0A.4
1558:  MOVF   7A,W
1559:  BSF    03.6
155A:  MOVWF  37
155B:  MOVF   79,W
155C:  MOVWF  36
155D:  MOVF   78,W
155E:  MOVWF  35
155F:  MOVF   77,W
1560:  MOVWF  34
1561:  SUBLW  47
1562:  BTFSS  03.2
1563:  GOTO   56D
1564:  MOVF   35,F
1565:  BTFSS  03.2
1566:  GOTO   56D
1567:  MOVF   36,F
1568:  BTFSS  03.2
1569:  GOTO   56D
156A:  MOVF   37,F
156B:  BTFSC  03.2
156C:  GOTO   571
....................     	// Set slave error 
....................   	  slv_cmd_err = true;       	     	 
156D:  BCF    03.6
156E:  BSF    3D.2
....................     }    
....................     else { 
156F:  GOTO   57C
1570:  BSF    03.6
....................     	// No errors. The load is on 
....................     	load_is_on = true; 
1571:  BCF    03.6
1572:  BSF    66.0
....................     	delay_ms(25); // give slave time to check for overcurrent 
1573:  MOVLW  19
1574:  BSF    03.5
1575:  BSF    03.6
1576:  MOVWF  10
1577:  BCF    0A.4
1578:  BCF    03.5
1579:  BCF    03.6
157A:  CALL   434
157B:  BSF    0A.4
....................     }  
.................... 	} 
.................... 	else { 
157C:  GOTO   580
157D:  BSF    03.5
....................     //set error 
....................   	invld_param_err = true;		 
157E:  BCF    03.5
157F:  BSF    3C.7
.................... 	} 
....................  
....................   // Send response 
....................   send_485_response(empty_string[0]);	 
1580:  BSF    03.6
1581:  CLRF   35
1582:  CLRF   34
1583:  BCF    03.6
1584:  CALL   147
.................... } 
1585:  BSF    0A.3
1586:  BSF    0A.4
1587:  GOTO   521 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_comm_relay() { 
....................   if(parameter == 0) { 
1588:  BSF    03.5
1589:  MOVF   36,F
158A:  BTFSS  03.2
158B:  GOTO   5A8
158C:  MOVF   37,F
158D:  BTFSS  03.2
158E:  GOTO   5A8
158F:  MOVF   38,F
1590:  BTFSS  03.2
1591:  GOTO   5A8
1592:  MOVF   39,F
1593:  BTFSS  03.2
1594:  GOTO   5A8
....................     output_bit(PIN_B1, HI);  
1595:  BCF    03.5
1596:  BSF    06.1
1597:  BSF    03.5
1598:  BCF    06.1
....................     delay_ms(8);           // Hold time for latching relay 
1599:  MOVLW  08
159A:  BSF    03.6
159B:  MOVWF  10
159C:  BCF    0A.4
159D:  BCF    03.5
159E:  BCF    03.6
159F:  CALL   434
15A0:  BSF    0A.4
....................     output_bit(PIN_B1, LO);  
15A1:  BCF    06.1
15A2:  BSF    03.5
15A3:  BCF    06.1
....................     relay_status_closed = 0;     
15A4:  BCF    03.5
15A5:  CLRF   37
....................   } 
....................   else if(parameter == 1) { 
15A6:  GOTO   5C9
15A7:  BSF    03.5
15A8:  DECFSZ 36,W
15A9:  GOTO   5C7
15AA:  MOVF   37,F
15AB:  BTFSS  03.2
15AC:  GOTO   5C7
15AD:  MOVF   38,F
15AE:  BTFSS  03.2
15AF:  GOTO   5C7
15B0:  MOVF   39,F
15B1:  BTFSS  03.2
15B2:  GOTO   5C7
....................     output_bit(PIN_B2, HI);  
15B3:  BCF    03.5
15B4:  BSF    06.2
15B5:  BSF    03.5
15B6:  BCF    06.2
....................     delay_ms(8);           // Hold time for latching relay 
15B7:  MOVLW  08
15B8:  BSF    03.6
15B9:  MOVWF  10
15BA:  BCF    0A.4
15BB:  BCF    03.5
15BC:  BCF    03.6
15BD:  CALL   434
15BE:  BSF    0A.4
....................     output_bit(PIN_B2, LO);  
15BF:  BCF    06.2
15C0:  BSF    03.5
15C1:  BCF    06.2
....................     relay_status_closed = 1; 
15C2:  MOVLW  01
15C3:  BCF    03.5
15C4:  MOVWF  37
....................   } 
....................   else { 
15C5:  GOTO   5C9
15C6:  BSF    03.5
....................   	//set error 
....................   	invld_param_err = true; 
15C7:  BCF    03.5
15C8:  BSF    3C.7
....................   } 
....................   // Save the parameter to flash 
....................   write_eeprom8(EE_relay_status_closed, relay_status_closed); 
15C9:  MOVLW  06
15CA:  BSF    03.6
15CB:  MOVWF  39
15CC:  BCF    03.6
15CD:  MOVF   37,W
15CE:  BSF    03.6
15CF:  MOVWF  3A
15D0:  BCF    0A.4
15D1:  BCF    03.6
15D2:  CALL   186
15D3:  BSF    0A.4
....................   // Now read it back just to be sure... 
....................   if( (relay_status_closed != read_eeprom(EE_relay_status_closed)) ) {     
15D4:  MOVLW  06
15D5:  BSF    03.6
15D6:  MOVWF  0D
15D7:  BSF    03.5
15D8:  BCF    0C.7
15D9:  BSF    0C.0
15DA:  BCF    03.5
15DB:  MOVF   0C,W
15DC:  BCF    03.6
15DD:  SUBWF  37,W
15DE:  BTFSC  03.2
15DF:  GOTO   5E1
....................     // There was an error. 
....................     flash_write_err = true; 
15E0:  BSF    3C.1
....................   }   
....................   // Send response 
....................   send_485_response(empty_string[0]);    
15E1:  BSF    03.6
15E2:  CLRF   35
15E3:  CLRF   34
15E4:  BCF    03.6
15E5:  CALL   147
.................... } 
15E6:  BSF    0A.3
15E7:  BSF    0A.4
15E8:  GOTO   533 (RETURN)
....................  
.................... #SEPARATE 
.................... void handle_sleep_enable() { 
....................   if(parameter == 0) { 
15E9:  BSF    03.5
15EA:  MOVF   36,F
15EB:  BTFSS  03.2
15EC:  GOTO   5FA
15ED:  MOVF   37,F
15EE:  BTFSS  03.2
15EF:  GOTO   5FA
15F0:  MOVF   38,F
15F1:  BTFSS  03.2
15F2:  GOTO   5FA
15F3:  MOVF   39,F
15F4:  BTFSS  03.2
15F5:  GOTO   5FA
....................     sleep_enabled = false; 
15F6:  BCF    03.5
15F7:  BCF    66.1
....................   } 
....................   else if(parameter == 1) { 
15F8:  GOTO   60B
15F9:  BSF    03.5
15FA:  DECFSZ 36,W
15FB:  GOTO   609
15FC:  MOVF   37,F
15FD:  BTFSS  03.2
15FE:  GOTO   609
15FF:  MOVF   38,F
1600:  BTFSS  03.2
1601:  GOTO   609
1602:  MOVF   39,F
1603:  BTFSS  03.2
1604:  GOTO   609
....................     sleep_enabled = true; 
1605:  BCF    03.5
1606:  BSF    66.1
....................   } 
....................   else { 
1607:  GOTO   60B
1608:  BSF    03.5
....................   	//invalid parameter 
.................... 	  invld_param_err = true; 
1609:  BCF    03.5
160A:  BSF    3C.7
....................   } 
....................   // Send response 
....................   send_485_response(empty_string[0]);   	 
160B:  BSF    03.6
160C:  CLRF   35
160D:  CLRF   34
160E:  BCF    03.6
160F:  CALL   147
.................... } 
1610:  BSF    0A.3
1611:  BSF    0A.4
1612:  GOTO   545 (RETURN)
....................  
.................... #SEPARATE 
.................... void handle_clear_errors() { 
....................   check_slave_on(); // Make sure slave is powered 
1613:  BCF    0A.4
1614:  BSF    0A.3
1615:  CALL   795
1616:  BSF    0A.4
1617:  BCF    0A.3
....................   spi_write(81);    // Command slave to turn OFF load 
1618:  MOVF   13,W
1619:  MOVLW  51
161A:  MOVWF  13
161B:  BSF    03.5
161C:  BTFSS  14.0
161D:  GOTO   61C
....................   delay_ms(50);     // Pause for slave to respond 
161E:  MOVLW  32
161F:  BSF    03.6
1620:  MOVWF  10
1621:  BCF    0A.4
1622:  BCF    03.5
1623:  BCF    03.6
1624:  CALL   434
1625:  BSF    0A.4
....................     
....................   // Check the response from the slave 
....................   SPI_strread(received_spi_data_mastr); 
1626:  BSF    03.6
1627:  CLRF   60
1628:  MOVLW  BA
1629:  MOVWF  5F
162A:  BCF    0A.4
162B:  BSF    0A.3
162C:  BCF    03.6
162D:  CALL   7A6
162E:  BSF    0A.4
162F:  BCF    0A.3
....................   if( atoi32(received_spi_data_mastr) !=  81) { 
1630:  BSF    03.6
1631:  CLRF   36
1632:  MOVLW  BA
1633:  MOVWF  35
1634:  BCF    0A.4
1635:  BCF    03.6
1636:  CALL   66D
1637:  BSF    0A.4
1638:  MOVF   7A,W
1639:  BSF    03.6
163A:  MOVWF  37
163B:  MOVF   79,W
163C:  MOVWF  36
163D:  MOVF   78,W
163E:  MOVWF  35
163F:  MOVF   77,W
1640:  MOVWF  34
1641:  SUBLW  51
1642:  BTFSS  03.2
1643:  GOTO   64D
1644:  MOVF   35,F
1645:  BTFSS  03.2
1646:  GOTO   64D
1647:  MOVF   36,F
1648:  BTFSS  03.2
1649:  GOTO   64D
164A:  MOVF   37,F
164B:  BTFSC  03.2
164C:  GOTO   651
....................     // Set slave error 
.................... 	  slv_cmd_err = true;  	    	      	 
164D:  BCF    03.6
164E:  BSF    3D.2
....................   } 
....................   else { 
164F:  GOTO   659
1650:  BSF    03.6
....................     // No errors so clear the master now 
.................... 	  clear_errors(true);  
1651:  MOVLW  01
1652:  MOVWF  5F
1653:  BCF    0A.4
1654:  BSF    0A.3
1655:  BCF    03.6
1656:  CALL   0DB
1657:  BSF    0A.4
1658:  BCF    0A.3
....................   } 
....................   // Send response 
....................   send_485_response(empty_string[0]); 
1659:  BSF    03.6
165A:  CLRF   35
165B:  CLRF   34
165C:  BCF    03.6
165D:  CALL   147
....................   check_slave_off();	 
165E:  BCF    0A.4
165F:  BSF    0A.3
1660:  CALL   7CA
1661:  BSF    0A.4
1662:  BCF    0A.3
.................... } 
1663:  BSF    0A.3
1664:  BSF    0A.4
1665:  GOTO   557 (RETURN)
....................  
.................... ////// 
.................... ////// Read Status Commands 
.................... #SEPARATE 
.................... void handle_read_bus_voltage() {   
....................   output_bit(PIN_C2, HI); // Flip on the reference voltage 
1666:  BSF    07.2
1667:  BCF    6F.2
1668:  MOVF   6F,W
1669:  BSF    03.5
166A:  MOVWF  07
....................   set_adc_channel(0);	 
166B:  MOVLW  00
166C:  MOVWF  78
166D:  BCF    03.5
166E:  MOVF   1F,W
166F:  ANDLW  C7
1670:  IORWF  78,W
1671:  MOVWF  1F
....................   delay_ms(9);            // Reference voltage circuit rise time 
1672:  MOVLW  09
1673:  BSF    03.5
1674:  BSF    03.6
1675:  MOVWF  10
1676:  BCF    0A.4
1677:  BCF    03.5
1678:  BCF    03.6
1679:  CALL   434
167A:  BSF    0A.4
....................   do_adc_voltage_calcs(25); 
167B:  BSF    03.6
167C:  CLRF   35
167D:  MOVLW  19
167E:  MOVWF  34
167F:  BCF    0A.4
1680:  BCF    03.6
1681:  CALL   44C
1682:  BSF    0A.4
....................   output_bit(PIN_C2, LO); // Turn off the reference voltage 
1683:  BCF    07.2
1684:  BCF    6F.2
1685:  MOVF   6F,W
1686:  BSF    03.5
1687:  MOVWF  07
....................    
....................   sprintf(response_message, "%5.3w",adc_value_glob);  
1688:  BCF    03.5
1689:  CLRF   6E
168A:  MOVLW  46
168B:  MOVWF  6D
168C:  MOVLW  05
168D:  MOVWF  04
168E:  MOVF   41,W
168F:  BSF    03.6
1690:  MOVWF  37
1691:  BCF    03.6
1692:  MOVF   40,W
1693:  BSF    03.6
1694:  MOVWF  36
1695:  BCF    03.6
1696:  MOVF   3F,W
1697:  BSF    03.6
1698:  MOVWF  35
1699:  BCF    03.6
169A:  MOVF   3E,W
169B:  BSF    03.6
169C:  MOVWF  34
169D:  MOVLW  03
169E:  MOVWF  38
169F:  BCF    0A.4
16A0:  BCF    03.6
16A1:  CALL   4C8
16A2:  BSF    0A.4
....................   send_485_response(response_message); 
16A3:  BSF    03.6
16A4:  CLRF   35
16A5:  MOVLW  46
16A6:  MOVWF  34
16A7:  BCF    03.6
16A8:  CALL   147
....................    
.................... } 
16A9:  BSF    0A.3
16AA:  BSF    0A.4
16AB:  GOTO   569 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_read_load_voltage() {    
....................   check_slave_on(); // Make sure slave is powered 
16AC:  BCF    0A.4
16AD:  BSF    0A.3
16AE:  CALL   795
16AF:  BSF    0A.4
16B0:  BCF    0A.3
....................   spi_write(50);               
16B1:  MOVF   13,W
16B2:  MOVLW  32
16B3:  MOVWF  13
16B4:  BSF    03.5
16B5:  BTFSS  14.0
16B6:  GOTO   6B5
....................   delay_ms(50);     //Pause for slave to do calculation 
16B7:  MOVLW  32
16B8:  BSF    03.6
16B9:  MOVWF  10
16BA:  BCF    0A.4
16BB:  BCF    03.5
16BC:  BCF    03.6
16BD:  CALL   434
16BE:  BSF    0A.4
....................      
....................   SPI_strread(received_spi_data_mastr); 
16BF:  BSF    03.6
16C0:  CLRF   60
16C1:  MOVLW  BA
16C2:  MOVWF  5F
16C3:  BCF    0A.4
16C4:  BSF    0A.3
16C5:  BCF    03.6
16C6:  CALL   7A6
16C7:  BSF    0A.4
16C8:  BCF    0A.3
....................   check_slave_off(); // See if it's ok to turn slave off 
16C9:  BCF    0A.4
16CA:  BSF    0A.3
16CB:  CALL   7CA
16CC:  BSF    0A.4
16CD:  BCF    0A.3
....................    
....................   sprintf(response_message, "%s",received_spi_data_mastr);  
16CE:  CLRF   6E
16CF:  MOVLW  46
16D0:  MOVWF  6D
16D1:  MOVLW  BA
16D2:  MOVWF  04
16D3:  BCF    03.7
16D4:  MOVLW  00
16D5:  IORWF  00,W
16D6:  BTFSC  03.2
16D7:  GOTO   6EE
16D8:  BSF    03.6
16D9:  CLRF   35
16DA:  MOVF   04,W
16DB:  MOVWF  34
16DC:  BCF    35.0
16DD:  BTFSC  03.7
16DE:  BSF    35.0
16DF:  MOVF   00,W
16E0:  MOVWF  63
16E1:  BCF    0A.4
16E2:  BCF    03.6
16E3:  CALL   4B9
16E4:  BSF    0A.4
16E5:  BSF    03.6
16E6:  MOVF   34,W
16E7:  MOVWF  04
16E8:  BCF    03.7
16E9:  BTFSC  35.0
16EA:  BSF    03.7
16EB:  INCF   04,F
16EC:  BCF    03.6
16ED:  GOTO   6D4
....................   send_485_response(response_message);    
16EE:  BSF    03.6
16EF:  CLRF   35
16F0:  MOVLW  46
16F1:  MOVWF  34
16F2:  BCF    03.6
16F3:  CALL   147
.................... } 
16F4:  BSF    0A.3
16F5:  BSF    0A.4
16F6:  GOTO   57B (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_read_bus_current() { 
....................   output_bit(PIN_C2, HI); // Turn on the reference voltage 
16F7:  BSF    07.2
16F8:  BCF    6F.2
16F9:  MOVF   6F,W
16FA:  BSF    03.5
16FB:  MOVWF  07
....................   set_adc_channel(1);	 
16FC:  MOVLW  08
16FD:  MOVWF  78
16FE:  BCF    03.5
16FF:  MOVF   1F,W
1700:  ANDLW  C7
1701:  IORWF  78,W
1702:  MOVWF  1F
....................   delay_ms(9);            // Reference voltage circuit rise time 
1703:  MOVLW  09
1704:  BSF    03.5
1705:  BSF    03.6
1706:  MOVWF  10
1707:  BCF    0A.4
1708:  BCF    03.5
1709:  BCF    03.6
170A:  CALL   434
170B:  BSF    0A.4
....................  
....................   do_adc_current_calcs(VREF, VREF, RSENSE, CURRDIVISOR); // In this case, VREF == VSCALE 
170C:  MOVLW  10
170D:  BSF    03.6
170E:  MOVWF  35
170F:  CLRF   34
1710:  MOVWF  37
1711:  CLRF   36
1712:  MOVLW  C8
1713:  MOVWF  38
1714:  MOVLW  05
1715:  MOVWF  39
1716:  BCF    0A.4
1717:  BCF    03.6
1718:  CALL   56C
1719:  BSF    0A.4
....................   output_bit(PIN_C2, LO); // Turn off the reference voltage	 
171A:  BCF    07.2
171B:  BCF    6F.2
171C:  MOVF   6F,W
171D:  BSF    03.5
171E:  MOVWF  07
....................    
....................   sprintf(response_message, "%5.3w",adc_value_glob);  
171F:  BCF    03.5
1720:  CLRF   6E
1721:  MOVLW  46
1722:  MOVWF  6D
1723:  MOVLW  05
1724:  MOVWF  04
1725:  MOVF   41,W
1726:  BSF    03.6
1727:  MOVWF  37
1728:  BCF    03.6
1729:  MOVF   40,W
172A:  BSF    03.6
172B:  MOVWF  36
172C:  BCF    03.6
172D:  MOVF   3F,W
172E:  BSF    03.6
172F:  MOVWF  35
1730:  BCF    03.6
1731:  MOVF   3E,W
1732:  BSF    03.6
1733:  MOVWF  34
1734:  MOVLW  03
1735:  MOVWF  38
1736:  BCF    0A.4
1737:  BCF    03.6
1738:  CALL   4C8
1739:  BSF    0A.4
....................   send_485_response(response_message); 
173A:  BSF    03.6
173B:  CLRF   35
173C:  MOVLW  46
173D:  MOVWF  34
173E:  BCF    03.6
173F:  CALL   147
.................... } 
1740:  BSF    0A.3
1741:  BSF    0A.4
1742:  GOTO   58D (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_read_load_current() {  
....................   check_slave_on(); // Make sure slave is powered  	 
1743:  BCF    0A.4
1744:  BSF    0A.3
1745:  CALL   795
1746:  BSF    0A.4
1747:  BCF    0A.3
....................   spi_write(51);                 
1748:  MOVF   13,W
1749:  MOVLW  33
174A:  MOVWF  13
174B:  BSF    03.5
174C:  BTFSS  14.0
174D:  GOTO   74C
....................   delay_ms(50);     //Takes approx 32 msec to complete transaction 
174E:  MOVLW  32
174F:  BSF    03.6
1750:  MOVWF  10
1751:  BCF    0A.4
1752:  BCF    03.5
1753:  BCF    03.6
1754:  CALL   434
1755:  BSF    0A.4
....................  
....................   // Get repsonse from slave 
....................   SPI_strread(received_spi_data_mastr); 
1756:  BSF    03.6
1757:  CLRF   60
1758:  MOVLW  BA
1759:  MOVWF  5F
175A:  BCF    0A.4
175B:  BSF    0A.3
175C:  BCF    03.6
175D:  CALL   7A6
175E:  BSF    0A.4
175F:  BCF    0A.3
....................   sprintf(response_message, "%s",received_spi_data_mastr);  
1760:  CLRF   6E
1761:  MOVLW  46
1762:  MOVWF  6D
1763:  MOVLW  BA
1764:  MOVWF  04
1765:  BCF    03.7
1766:  MOVLW  00
1767:  IORWF  00,W
1768:  BTFSC  03.2
1769:  GOTO   780
176A:  BSF    03.6
176B:  CLRF   35
176C:  MOVF   04,W
176D:  MOVWF  34
176E:  BCF    35.0
176F:  BTFSC  03.7
1770:  BSF    35.0
1771:  MOVF   00,W
1772:  MOVWF  63
1773:  BCF    0A.4
1774:  BCF    03.6
1775:  CALL   4B9
1776:  BSF    0A.4
1777:  BSF    03.6
1778:  MOVF   34,W
1779:  MOVWF  04
177A:  BCF    03.7
177B:  BTFSC  35.0
177C:  BSF    03.7
177D:  INCF   04,F
177E:  BCF    03.6
177F:  GOTO   766
....................  	send_485_response(response_message);  
1780:  BSF    03.6
1781:  CLRF   35
1782:  MOVLW  46
1783:  MOVWF  34
1784:  BCF    03.6
1785:  CALL   147
....................   check_slave_off(); // See if it's ok to turn slave off 	 
1786:  BCF    0A.4
1787:  BSF    0A.3
1788:  CALL   7CA
1789:  BSF    0A.4
178A:  BCF    0A.3
.................... } 
178B:  BSF    0A.3
178C:  BSF    0A.4
178D:  GOTO   59F (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_read_gf_current() {  
....................   if( (parameter >= 0) && (parameter <= 3) ) {	 
*
1800:  BSF    03.5
1801:  MOVF   39,F
1802:  BTFSS  03.2
1803:  GOTO   080
1804:  MOVF   38,F
1805:  BTFSS  03.2
1806:  GOTO   080
1807:  MOVF   37,F
1808:  BTFSS  03.2
1809:  GOTO   080
180A:  MOVF   36,W
180B:  SUBLW  03
180C:  BTFSS  03.0
180D:  GOTO   080
....................     check_slave_on(); // Make sure slave is powered    	 
180E:  BCF    0A.4
180F:  BCF    03.5
1810:  CALL   795
1811:  BSF    0A.4
....................     spi_write(parameter+1);    	 
1812:  MOVLW  01
1813:  BSF    03.5
1814:  ADDWF  36,W
1815:  BCF    03.5
1816:  BSF    03.6
1817:  MOVWF  34
1818:  BSF    03.5
1819:  BCF    03.6
181A:  MOVF   37,W
181B:  BCF    03.5
181C:  BSF    03.6
181D:  MOVWF  35
181E:  MOVLW  00
181F:  BTFSC  03.0
1820:  MOVLW  01
1821:  ADDWF  35,F
1822:  BSF    03.5
1823:  BCF    03.6
1824:  MOVF   38,W
1825:  BCF    03.5
1826:  BSF    03.6
1827:  MOVWF  36
1828:  MOVLW  00
1829:  BTFSC  03.0
182A:  MOVLW  01
182B:  ADDWF  36,F
182C:  BSF    03.5
182D:  BCF    03.6
182E:  MOVF   39,W
182F:  BCF    03.5
1830:  BSF    03.6
1831:  MOVWF  37
1832:  MOVLW  00
1833:  BTFSC  03.0
1834:  MOVLW  01
1835:  ADDWF  37,F
1836:  BCF    03.6
1837:  MOVF   13,W
1838:  BSF    03.6
1839:  MOVF   34,W
183A:  BCF    03.6
183B:  MOVWF  13
183C:  BSF    03.5
183D:  BTFSS  14.0
183E:  GOTO   03D
....................    
....................     delay_ms(50); //Takes approx 32 msec to complete transaction 
183F:  MOVLW  32
1840:  BSF    03.6
1841:  MOVWF  10
1842:  BCF    0A.4
1843:  BCF    0A.3
1844:  BCF    03.5
1845:  BCF    03.6
1846:  CALL   434
1847:  BSF    0A.4
1848:  BSF    0A.3
....................    
....................     // Get repsonse from slave and send response on 
....................     SPI_strread(received_spi_data_mastr); 
1849:  BSF    03.6
184A:  CLRF   60
184B:  MOVLW  BA
184C:  MOVWF  5F
184D:  BCF    0A.4
184E:  BCF    03.6
184F:  CALL   7A6
1850:  BSF    0A.4
....................     sprintf(response_message, "%s",received_spi_data_mastr);  
1851:  CLRF   6E
1852:  MOVLW  46
1853:  MOVWF  6D
1854:  MOVLW  BA
1855:  MOVWF  04
1856:  BCF    03.7
1857:  MOVLW  00
1858:  IORWF  00,W
1859:  BTFSC  03.2
185A:  GOTO   073
185B:  BSF    03.6
185C:  CLRF   35
185D:  MOVF   04,W
185E:  MOVWF  34
185F:  BCF    35.0
1860:  BTFSC  03.7
1861:  BSF    35.0
1862:  MOVF   00,W
1863:  MOVWF  63
1864:  BCF    0A.4
1865:  BCF    0A.3
1866:  BCF    03.6
1867:  CALL   4B9
1868:  BSF    0A.4
1869:  BSF    0A.3
186A:  BSF    03.6
186B:  MOVF   34,W
186C:  MOVWF  04
186D:  BCF    03.7
186E:  BTFSC  35.0
186F:  BSF    03.7
1870:  INCF   04,F
1871:  BCF    03.6
1872:  GOTO   057
....................    	send_485_response(response_message);      
1873:  BSF    03.6
1874:  CLRF   35
1875:  MOVLW  46
1876:  MOVWF  34
1877:  BCF    0A.3
1878:  BCF    03.6
1879:  CALL   147
187A:  BSF    0A.3
....................     check_slave_off(); // See if it's ok to turn slave off   	 
187B:  BCF    0A.4
187C:  CALL   7CA
187D:  BSF    0A.4
....................   } 
....................   else { 
187E:  GOTO   089
187F:  BSF    03.5
....................     //Invalid Parameter 
....................   	invld_param_err = true; 
1880:  BCF    03.5
1881:  BSF    3C.7
....................     send_485_response(empty_string[0]); 
1882:  BSF    03.6
1883:  CLRF   35
1884:  CLRF   34
1885:  BCF    0A.3
1886:  BCF    03.6
1887:  CALL   147
1888:  BSF    0A.3
....................   }   
.................... } 
1889:  BSF    0A.3
188A:  BSF    0A.4
188B:  GOTO   5B0 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_read_startup_oc_threshold() {  
....................   sprintf(response_message, "%Lu",startup_oc_threshold);   
*
178E:  CLRF   6E
178F:  MOVLW  46
1790:  MOVWF  6D
1791:  MOVLW  10
1792:  MOVWF  04
1793:  MOVF   30,W
1794:  BSF    03.6
1795:  MOVWF  35
1796:  BCF    03.6
1797:  MOVF   2F,W
1798:  BSF    03.6
1799:  MOVWF  34
179A:  BCF    0A.4
179B:  BSF    0A.3
179C:  BCF    03.6
179D:  CALL   000
179E:  BSF    0A.4
179F:  BCF    0A.3
....................   send_485_response(response_message);	 
17A0:  BSF    03.6
17A1:  CLRF   35
17A2:  MOVLW  46
17A3:  MOVWF  34
17A4:  BCF    03.6
17A5:  CALL   147
.................... } 
17A6:  BSF    0A.3
17A7:  BSF    0A.4
17A8:  GOTO   5C2 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_read_q_oc_threshold() { 
....................   sprintf(response_message, "%Lu",steady_oc_threshold);   
17A9:  CLRF   6E
17AA:  MOVLW  46
17AB:  MOVWF  6D
17AC:  MOVLW  10
17AD:  MOVWF  04
17AE:  MOVF   32,W
17AF:  BSF    03.6
17B0:  MOVWF  35
17B1:  BCF    03.6
17B2:  MOVF   31,W
17B3:  BSF    03.6
17B4:  MOVWF  34
17B5:  BCF    0A.4
17B6:  BSF    0A.3
17B7:  BCF    03.6
17B8:  CALL   000
17B9:  BSF    0A.4
17BA:  BCF    0A.3
....................   send_485_response(response_message);	 
17BB:  BSF    03.6
17BC:  CLRF   35
17BD:  MOVLW  46
17BE:  MOVWF  34
17BF:  BCF    03.6
17C0:  CALL   147
.................... } 
17C1:  BSF    0A.3
17C2:  BSF    0A.4
17C3:  GOTO   5D5 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_read_startup_oc_time() {  
....................   sprintf(response_message, "%Lu",startup_oc_time);   
17C4:  CLRF   6E
17C5:  MOVLW  46
17C6:  MOVWF  6D
17C7:  MOVLW  10
17C8:  MOVWF  04
17C9:  MOVF   34,W
17CA:  BSF    03.6
17CB:  MOVWF  35
17CC:  BCF    03.6
17CD:  MOVF   33,W
17CE:  BSF    03.6
17CF:  MOVWF  34
17D0:  BCF    0A.4
17D1:  BSF    0A.3
17D2:  BCF    03.6
17D3:  CALL   000
17D4:  BSF    0A.4
17D5:  BCF    0A.3
....................   send_485_response(response_message);	 
17D6:  BSF    03.6
17D7:  CLRF   35
17D8:  MOVLW  46
17D9:  MOVWF  34
17DA:  BCF    03.6
17DB:  CALL   147
.................... } 
17DC:  BSF    0A.3
17DD:  BSF    0A.4
17DE:  GOTO   5E8 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_read_comm_realy_status() {  
....................   sprintf(response_message, "%u", relay_status_closed);   
17DF:  CLRF   6E
17E0:  MOVLW  46
17E1:  MOVWF  6D
17E2:  MOVF   37,W
17E3:  BSF    03.6
17E4:  MOVWF  5F
17E5:  MOVLW  1B
17E6:  MOVWF  60
17E7:  BCF    0A.4
17E8:  BSF    0A.3
17E9:  BCF    03.6
17EA:  CALL   069
17EB:  BSF    0A.4
17EC:  BCF    0A.3
....................   send_485_response(response_message);	 
17ED:  BSF    03.6
17EE:  CLRF   35
17EF:  MOVLW  46
17F0:  MOVWF  34
17F1:  BCF    03.6
17F2:  CALL   147
.................... } 
17F3:  BSF    0A.3
17F4:  BSF    0A.4
17F5:  GOTO   5FB (RETURN)
....................  
.................... #SEPARATE 
.................... void handle_read_device_serial_number() {  
....................   send_485_response(empty_string[0]);  
17F6:  BSF    03.6
17F7:  CLRF   35
17F8:  CLRF   34
17F9:  BCF    03.6
17FA:  CALL   147
.................... } 
17FB:  BSF    0A.3
17FC:  BSF    0A.4
17FD:  GOTO   60E (RETURN)
....................  
.................... #SEPARATE 
.................... void handle_sw_version() { 
....................   sprintf(response_message, "%s", sw_version);   
*
188C:  CLRF   6E
188D:  MOVLW  46
188E:  MOVWF  6D
188F:  BSF    03.6
1890:  CLRF   34
1891:  MOVF   34,W
1892:  BCF    0A.4
1893:  BCF    0A.3
1894:  BCF    03.6
1895:  CALL   03E
1896:  BSF    0A.4
1897:  BSF    0A.3
1898:  IORLW  00
1899:  BTFSC  03.2
189A:  GOTO   0A7
189B:  BSF    03.6
189C:  INCF   34,F
189D:  MOVWF  63
189E:  BCF    0A.4
189F:  BCF    0A.3
18A0:  BCF    03.6
18A1:  CALL   4B9
18A2:  BSF    0A.4
18A3:  BSF    0A.3
18A4:  BSF    03.6
18A5:  GOTO   091
18A6:  BCF    03.6
....................   send_485_response(response_message);	 
18A7:  BSF    03.6
18A8:  CLRF   35
18A9:  MOVLW  46
18AA:  MOVWF  34
18AB:  BCF    0A.3
18AC:  BCF    03.6
18AD:  CALL   147
18AE:  BSF    0A.3
.................... } 
18AF:  BSF    0A.3
18B0:  BSF    0A.4
18B1:  GOTO   620 (RETURN)
....................  
....................  
.................... ////// 
.................... ////// Set Threshold Commands 
.................... #SEPARATE 
.................... void handle_oc_threshold_startup() { 
....................   if( (parameter >= 0) && (parameter <= 10000) ) { 
*
1922:  BSF    03.5
1923:  MOVF   39,F
1924:  BTFSS  03.2
1925:  GOTO   233
1926:  MOVF   38,F
1927:  BTFSS  03.2
1928:  GOTO   233
1929:  MOVF   37,W
192A:  SUBLW  27
192B:  BTFSS  03.0
192C:  GOTO   233
192D:  BTFSS  03.2
192E:  GOTO   133
192F:  MOVF   36,W
1930:  SUBLW  10
1931:  BTFSS  03.0
1932:  GOTO   233
....................   	check_slave_on();                  // Make sure slave is powered 
1933:  BCF    0A.4
1934:  BCF    03.5
1935:  CALL   795
1936:  BSF    0A.4
....................     spi_write(60);                     // Send Command and parameter 
1937:  MOVF   13,W
1938:  MOVLW  3C
1939:  MOVWF  13
193A:  BSF    03.5
193B:  BTFSS  14.0
193C:  GOTO   13B
....................     sprintf(sent_spi_data_mastr, "%Lu ",parameter); // Note kluge. Have to send space char as termination. Should use interrupt on slave 
193D:  BCF    03.5
193E:  CLRF   6E
193F:  MOVLW  C5
1940:  MOVWF  6D
1941:  MOVLW  41
1942:  MOVWF  04
1943:  BSF    03.5
1944:  MOVF   39,W
1945:  BCF    03.5
1946:  BSF    03.6
1947:  MOVWF  37
1948:  BSF    03.5
1949:  BCF    03.6
194A:  MOVF   38,W
194B:  BCF    03.5
194C:  BSF    03.6
194D:  MOVWF  36
194E:  BSF    03.5
194F:  BCF    03.6
1950:  MOVF   37,W
1951:  BCF    03.5
1952:  BSF    03.6
1953:  MOVWF  35
1954:  BSF    03.5
1955:  BCF    03.6
1956:  MOVF   36,W
1957:  BCF    03.5
1958:  BSF    03.6
1959:  MOVWF  34
195A:  BCF    03.6
195B:  CALL   0B2
195C:  MOVLW  20
195D:  BSF    03.6
195E:  MOVWF  63
195F:  BCF    0A.4
1960:  BCF    0A.3
1961:  BCF    03.6
1962:  CALL   4B9
1963:  BSF    0A.4
1964:  BSF    0A.3
....................     SPI_strwrite(sent_spi_data_mastr); 
1965:  BSF    03.6
1966:  CLRF   35
1967:  MOVLW  C5
1968:  MOVWF  34
1969:  BCF    0A.4
196A:  BCF    0A.3
196B:  BCF    03.6
196C:  CALL   541
196D:  BSF    0A.4
196E:  BSF    0A.3
....................  
....................     delay_ms(50);                      // Wait for response and read 
196F:  MOVLW  32
1970:  BSF    03.5
1971:  BSF    03.6
1972:  MOVWF  10
1973:  BCF    0A.4
1974:  BCF    0A.3
1975:  BCF    03.5
1976:  BCF    03.6
1977:  CALL   434
1978:  BSF    0A.4
1979:  BSF    0A.3
....................     SPI_strread(received_spi_data_mastr); 
197A:  BSF    03.6
197B:  CLRF   60
197C:  MOVLW  BA
197D:  MOVWF  5F
197E:  BCF    0A.4
197F:  BCF    03.6
1980:  CALL   7A6
1981:  BSF    0A.4
....................     delay_ms(3);       // Allow slave to do int32 math routines before sending a 485 response         
1982:  MOVLW  03
1983:  BSF    03.5
1984:  BSF    03.6
1985:  MOVWF  10
1986:  BCF    0A.4
1987:  BCF    0A.3
1988:  BCF    03.5
1989:  BCF    03.6
198A:  CALL   434
198B:  BSF    0A.4
198C:  BSF    0A.3
....................      
....................                                        // Check for errors 
....................     if( atoi32(received_spi_data_mastr) ==  parameter) { 
198D:  BSF    03.6
198E:  CLRF   36
198F:  MOVLW  BA
1990:  MOVWF  35
1991:  BCF    0A.4
1992:  BCF    0A.3
1993:  BCF    03.6
1994:  CALL   66D
1995:  BSF    0A.4
1996:  BSF    0A.3
1997:  MOVF   7A,W
1998:  BSF    03.6
1999:  MOVWF  37
199A:  MOVF   79,W
199B:  MOVWF  36
199C:  MOVF   78,W
199D:  MOVWF  35
199E:  MOVF   77,W
199F:  MOVWF  34
19A0:  BSF    03.5
19A1:  BCF    03.6
19A2:  MOVF   36,W
19A3:  BCF    03.5
19A4:  BSF    03.6
19A5:  SUBWF  34,W
19A6:  BTFSS  03.2
19A7:  GOTO   206
19A8:  BSF    03.5
19A9:  BCF    03.6
19AA:  MOVF   37,W
19AB:  BCF    03.5
19AC:  BSF    03.6
19AD:  SUBWF  35,W
19AE:  BTFSS  03.2
19AF:  GOTO   206
19B0:  BSF    03.5
19B1:  BCF    03.6
19B2:  MOVF   38,W
19B3:  BCF    03.5
19B4:  BSF    03.6
19B5:  SUBWF  36,W
19B6:  BTFSS  03.2
19B7:  GOTO   206
19B8:  BSF    03.5
19B9:  BCF    03.6
19BA:  MOVF   39,W
19BB:  BCF    03.5
19BC:  BSF    03.6
19BD:  SUBWF  37,W
19BE:  BTFSS  03.2
19BF:  GOTO   206
....................    	                                   // Success 
....................       startup_oc_threshold = parameter;// Slave has threshold so it's now safe to store it in the master 
19C0:  BSF    03.5
19C1:  BCF    03.6
19C2:  MOVF   37,W
19C3:  BCF    03.5
19C4:  MOVWF  30
19C5:  BSF    03.5
19C6:  MOVF   36,W
19C7:  BCF    03.5
19C8:  MOVWF  2F
....................       // Save the parameter to flash 
....................       write_eeprom16(EE_startup_oc_threshold, startup_oc_threshold); 
19C9:  BSF    03.6
19CA:  CLRF   34
19CB:  BCF    03.6
19CC:  MOVF   30,W
19CD:  BSF    03.6
19CE:  MOVWF  36
19CF:  BCF    03.6
19D0:  MOVF   2F,W
19D1:  BSF    03.6
19D2:  MOVWF  35
19D3:  BCF    0A.4
19D4:  BCF    0A.3
19D5:  BCF    03.6
19D6:  CALL   1A2
19D7:  BSF    0A.4
19D8:  BSF    0A.3
....................       // Now read it back just to be sure... 
....................       if( (startup_oc_threshold != read_eeprom16(EE_startup_oc_threshold)) ) {     
19D9:  BSF    03.6
19DA:  CLRF   34
19DB:  BCF    0A.4
19DC:  BCF    0A.3
19DD:  BCF    03.6
19DE:  CALL   16F
19DF:  BSF    0A.4
19E0:  BSF    0A.3
19E1:  MOVF   79,W
19E2:  MOVWF  7A
19E3:  MOVF   78,W
19E4:  SUBWF  2F,W
19E5:  BTFSS  03.2
19E6:  GOTO   1EB
19E7:  MOVF   7A,W
19E8:  SUBWF  30,W
19E9:  BTFSC  03.2
19EA:  GOTO   1EC
....................         // There was an error. 
....................         flash_write_err = true; 
19EB:  BSF    3C.1
....................       }   
....................       // Send response 
....................    	  sprintf(response_message, "%Lu", startup_oc_threshold);  
19EC:  CLRF   6E
19ED:  MOVLW  46
19EE:  MOVWF  6D
19EF:  MOVLW  10
19F0:  MOVWF  04
19F1:  MOVF   30,W
19F2:  BSF    03.6
19F3:  MOVWF  35
19F4:  BCF    03.6
19F5:  MOVF   2F,W
19F6:  BSF    03.6
19F7:  MOVWF  34
19F8:  BCF    0A.4
19F9:  BCF    03.6
19FA:  CALL   000
19FB:  BSF    0A.4
....................    	  send_485_response(response_message);    	 
19FC:  BSF    03.6
19FD:  CLRF   35
19FE:  MOVLW  46
19FF:  MOVWF  34
1A00:  BCF    0A.3
1A01:  BCF    03.6
1A02:  CALL   147
1A03:  BSF    0A.3
....................     } 
....................     else { 
1A04:  GOTO   22E
1A05:  BSF    03.6
....................     	// Send slave error here 
....................    	  slv_cmd_err = true; 
1A06:  BCF    03.6
1A07:  BSF    3D.2
....................    	  sprintf(response_message, "%Lu", parameter);  
1A08:  CLRF   6E
1A09:  MOVLW  46
1A0A:  MOVWF  6D
1A0B:  MOVLW  41
1A0C:  MOVWF  04
1A0D:  BSF    03.5
1A0E:  MOVF   39,W
1A0F:  BCF    03.5
1A10:  BSF    03.6
1A11:  MOVWF  37
1A12:  BSF    03.5
1A13:  BCF    03.6
1A14:  MOVF   38,W
1A15:  BCF    03.5
1A16:  BSF    03.6
1A17:  MOVWF  36
1A18:  BSF    03.5
1A19:  BCF    03.6
1A1A:  MOVF   37,W
1A1B:  BCF    03.5
1A1C:  BSF    03.6
1A1D:  MOVWF  35
1A1E:  BSF    03.5
1A1F:  BCF    03.6
1A20:  MOVF   36,W
1A21:  BCF    03.5
1A22:  BSF    03.6
1A23:  MOVWF  34
1A24:  BCF    03.6
1A25:  CALL   0B2
....................    	  send_485_response(response_message); 
1A26:  BSF    03.6
1A27:  CLRF   35
1A28:  MOVLW  46
1A29:  MOVWF  34
1A2A:  BCF    0A.3
1A2B:  BCF    03.6
1A2C:  CALL   147
1A2D:  BSF    0A.3
....................     } 
....................     check_slave_off(); // See if it's ok to turn slave off     
1A2E:  BCF    0A.4
1A2F:  CALL   7CA
1A30:  BSF    0A.4
....................   } 
....................   else { 
1A31:  GOTO   23C
1A32:  BSF    03.5
....................   	//Out of range. Send parameter error here 
....................   	invld_param_err = true; 
1A33:  BCF    03.5
1A34:  BSF    3C.7
....................     send_485_response(empty_string[0]);	  	 
1A35:  BSF    03.6
1A36:  CLRF   35
1A37:  CLRF   34
1A38:  BCF    0A.3
1A39:  BCF    03.6
1A3A:  CALL   147
1A3B:  BSF    0A.3
....................   }    
.................... } 
1A3C:  BSF    0A.3
1A3D:  BSF    0A.4
1A3E:  GOTO   631 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_oc_threshold_q() { 
....................   if( (parameter >= 0) && (parameter <= 10000) ) { 
1A3F:  BSF    03.5
1A40:  MOVF   39,F
1A41:  BTFSS  03.2
1A42:  GOTO   333
1A43:  MOVF   38,F
1A44:  BTFSS  03.2
1A45:  GOTO   333
1A46:  MOVF   37,W
1A47:  SUBLW  27
1A48:  BTFSS  03.0
1A49:  GOTO   333
1A4A:  BTFSS  03.2
1A4B:  GOTO   250
1A4C:  MOVF   36,W
1A4D:  SUBLW  10
1A4E:  BTFSS  03.0
1A4F:  GOTO   333
....................   	check_slave_on();                  // Make sure slave is powered     
1A50:  BCF    0A.4
1A51:  BCF    03.5
1A52:  CALL   795
1A53:  BSF    0A.4
....................     spi_write(61);                     //Send Command and parameter 
1A54:  MOVF   13,W
1A55:  MOVLW  3D
1A56:  MOVWF  13
1A57:  BSF    03.5
1A58:  BTFSS  14.0
1A59:  GOTO   258
....................     sprintf(sent_spi_data_mastr, "%Lu ",parameter); // Note kluge. Have to send space char as termination. Should use interrupt on slave 
1A5A:  BCF    03.5
1A5B:  CLRF   6E
1A5C:  MOVLW  C5
1A5D:  MOVWF  6D
1A5E:  MOVLW  41
1A5F:  MOVWF  04
1A60:  BSF    03.5
1A61:  MOVF   39,W
1A62:  BCF    03.5
1A63:  BSF    03.6
1A64:  MOVWF  37
1A65:  BSF    03.5
1A66:  BCF    03.6
1A67:  MOVF   38,W
1A68:  BCF    03.5
1A69:  BSF    03.6
1A6A:  MOVWF  36
1A6B:  BSF    03.5
1A6C:  BCF    03.6
1A6D:  MOVF   37,W
1A6E:  BCF    03.5
1A6F:  BSF    03.6
1A70:  MOVWF  35
1A71:  BSF    03.5
1A72:  BCF    03.6
1A73:  MOVF   36,W
1A74:  BCF    03.5
1A75:  BSF    03.6
1A76:  MOVWF  34
1A77:  BCF    03.6
1A78:  CALL   0B2
1A79:  MOVLW  20
1A7A:  BSF    03.6
1A7B:  MOVWF  63
1A7C:  BCF    0A.4
1A7D:  BCF    0A.3
1A7E:  BCF    03.6
1A7F:  CALL   4B9
1A80:  BSF    0A.4
1A81:  BSF    0A.3
....................     SPI_strwrite(sent_spi_data_mastr); 
1A82:  BSF    03.6
1A83:  CLRF   35
1A84:  MOVLW  C5
1A85:  MOVWF  34
1A86:  BCF    0A.4
1A87:  BCF    0A.3
1A88:  BCF    03.6
1A89:  CALL   541
1A8A:  BSF    0A.4
1A8B:  BSF    0A.3
....................  
....................     delay_ms(50);                      // Wait for response and read 
1A8C:  MOVLW  32
1A8D:  BSF    03.5
1A8E:  BSF    03.6
1A8F:  MOVWF  10
1A90:  BCF    0A.4
1A91:  BCF    0A.3
1A92:  BCF    03.5
1A93:  BCF    03.6
1A94:  CALL   434
1A95:  BSF    0A.4
1A96:  BSF    0A.3
....................     SPI_strread(received_spi_data_mastr); 
1A97:  BSF    03.6
1A98:  CLRF   60
1A99:  MOVLW  BA
1A9A:  MOVWF  5F
1A9B:  BCF    0A.4
1A9C:  BCF    03.6
1A9D:  CALL   7A6
1A9E:  BSF    0A.4
....................     delay_ms(3);       // Allow slave to do int32 math routines before sending a 485 response     
1A9F:  MOVLW  03
1AA0:  BSF    03.5
1AA1:  BSF    03.6
1AA2:  MOVWF  10
1AA3:  BCF    0A.4
1AA4:  BCF    0A.3
1AA5:  BCF    03.5
1AA6:  BCF    03.6
1AA7:  CALL   434
1AA8:  BSF    0A.4
1AA9:  BSF    0A.3
....................  
....................                                            // Check for errors 
....................     if( atoi32(received_spi_data_mastr) ==  parameter) { 
1AAA:  BSF    03.6
1AAB:  CLRF   36
1AAC:  MOVLW  BA
1AAD:  MOVWF  35
1AAE:  BCF    0A.4
1AAF:  BCF    0A.3
1AB0:  BCF    03.6
1AB1:  CALL   66D
1AB2:  BSF    0A.4
1AB3:  BSF    0A.3
1AB4:  MOVF   7A,W
1AB5:  BSF    03.6
1AB6:  MOVWF  37
1AB7:  MOVF   79,W
1AB8:  MOVWF  36
1AB9:  MOVF   78,W
1ABA:  MOVWF  35
1ABB:  MOVF   77,W
1ABC:  MOVWF  34
1ABD:  BSF    03.5
1ABE:  BCF    03.6
1ABF:  MOVF   36,W
1AC0:  BCF    03.5
1AC1:  BSF    03.6
1AC2:  SUBWF  34,W
1AC3:  BTFSS  03.2
1AC4:  GOTO   325
1AC5:  BSF    03.5
1AC6:  BCF    03.6
1AC7:  MOVF   37,W
1AC8:  BCF    03.5
1AC9:  BSF    03.6
1ACA:  SUBWF  35,W
1ACB:  BTFSS  03.2
1ACC:  GOTO   325
1ACD:  BSF    03.5
1ACE:  BCF    03.6
1ACF:  MOVF   38,W
1AD0:  BCF    03.5
1AD1:  BSF    03.6
1AD2:  SUBWF  36,W
1AD3:  BTFSS  03.2
1AD4:  GOTO   325
1AD5:  BSF    03.5
1AD6:  BCF    03.6
1AD7:  MOVF   39,W
1AD8:  BCF    03.5
1AD9:  BSF    03.6
1ADA:  SUBWF  37,W
1ADB:  BTFSS  03.2
1ADC:  GOTO   325
....................    	                                   // Success. Send ack 
....................       steady_oc_threshold = parameter; // Slave has threshold so it's now safe to store it in the master 
1ADD:  BSF    03.5
1ADE:  BCF    03.6
1ADF:  MOVF   37,W
1AE0:  BCF    03.5
1AE1:  MOVWF  32
1AE2:  BSF    03.5
1AE3:  MOVF   36,W
1AE4:  BCF    03.5
1AE5:  MOVWF  31
....................       // Save the parameter to flash 
....................       write_eeprom16(EE_steady_oc_threshold, steady_oc_threshold); 
1AE6:  MOVLW  02
1AE7:  BSF    03.6
1AE8:  MOVWF  34
1AE9:  BCF    03.6
1AEA:  MOVF   32,W
1AEB:  BSF    03.6
1AEC:  MOVWF  36
1AED:  BCF    03.6
1AEE:  MOVF   31,W
1AEF:  BSF    03.6
1AF0:  MOVWF  35
1AF1:  BCF    0A.4
1AF2:  BCF    0A.3
1AF3:  BCF    03.6
1AF4:  CALL   1A2
1AF5:  BSF    0A.4
1AF6:  BSF    0A.3
....................       // Now read it back just to be sure... 
....................       if( (steady_oc_threshold != read_eeprom16(EE_steady_oc_threshold)) ) {     
1AF7:  MOVLW  02
1AF8:  BSF    03.6
1AF9:  MOVWF  34
1AFA:  BCF    0A.4
1AFB:  BCF    0A.3
1AFC:  BCF    03.6
1AFD:  CALL   16F
1AFE:  BSF    0A.4
1AFF:  BSF    0A.3
1B00:  MOVF   79,W
1B01:  MOVWF  7A
1B02:  MOVF   78,W
1B03:  SUBWF  31,W
1B04:  BTFSS  03.2
1B05:  GOTO   30A
1B06:  MOVF   7A,W
1B07:  SUBWF  32,W
1B08:  BTFSC  03.2
1B09:  GOTO   30B
....................         // There was an error. 
....................         flash_write_err = true; 
1B0A:  BSF    3C.1
....................       }         
....................       // Send response 
....................    	  sprintf(response_message, "%Lu", steady_oc_threshold);  
1B0B:  CLRF   6E
1B0C:  MOVLW  46
1B0D:  MOVWF  6D
1B0E:  MOVLW  10
1B0F:  MOVWF  04
1B10:  MOVF   32,W
1B11:  BSF    03.6
1B12:  MOVWF  35
1B13:  BCF    03.6
1B14:  MOVF   31,W
1B15:  BSF    03.6
1B16:  MOVWF  34
1B17:  BCF    0A.4
1B18:  BCF    03.6
1B19:  CALL   000
1B1A:  BSF    0A.4
....................    	  send_485_response(response_message);    	 
1B1B:  BSF    03.6
1B1C:  CLRF   35
1B1D:  MOVLW  46
1B1E:  MOVWF  34
1B1F:  BCF    0A.3
1B20:  BCF    03.6
1B21:  CALL   147
1B22:  BSF    0A.3
....................     } 
....................     else { 
1B23:  GOTO   32E
1B24:  BSF    03.6
....................     	// Send slave error here 
....................    	  slv_cmd_err = true; 
1B25:  BCF    03.6
1B26:  BSF    3D.2
....................       send_485_response(empty_string[0]);	   	   
1B27:  BSF    03.6
1B28:  CLRF   35
1B29:  CLRF   34
1B2A:  BCF    0A.3
1B2B:  BCF    03.6
1B2C:  CALL   147
1B2D:  BSF    0A.3
....................     }    
....................     check_slave_off(); // See if it's ok to turn slave off      
1B2E:  BCF    0A.4
1B2F:  CALL   7CA
1B30:  BSF    0A.4
....................   } 
....................   else { 
1B31:  GOTO   33C
1B32:  BSF    03.5
....................   	//Out of range. Send parameter error here 
....................   	invld_param_err = true; 
1B33:  BCF    03.5
1B34:  BSF    3C.7
....................     send_485_response(empty_string[0]);  }   
1B35:  BSF    03.6
1B36:  CLRF   35
1B37:  CLRF   34
1B38:  BCF    0A.3
1B39:  BCF    03.6
1B3A:  CALL   147
1B3B:  BSF    0A.3
.................... } 
1B3C:  BSF    0A.3
1B3D:  BSF    0A.4
1B3E:  GOTO   642 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_oc_time_startup() { 
....................   if( (parameter >= 0) && (parameter <= 10000) ) { 
1B3F:  BSF    03.5
1B40:  MOVF   39,F
1B41:  BTFSS  03.2
1B42:  GOTO   428
1B43:  MOVF   38,F
1B44:  BTFSS  03.2
1B45:  GOTO   428
1B46:  MOVF   37,W
1B47:  SUBLW  27
1B48:  BTFSS  03.0
1B49:  GOTO   428
1B4A:  BTFSS  03.2
1B4B:  GOTO   350
1B4C:  MOVF   36,W
1B4D:  SUBLW  10
1B4E:  BTFSS  03.0
1B4F:  GOTO   428
....................   	check_slave_on();                  // Make sure slave is powered         
1B50:  BCF    0A.4
1B51:  BCF    03.5
1B52:  CALL   795
1B53:  BSF    0A.4
....................     spi_write(62);                     //Send Command and parameter 
1B54:  MOVF   13,W
1B55:  MOVLW  3E
1B56:  MOVWF  13
1B57:  BSF    03.5
1B58:  BTFSS  14.0
1B59:  GOTO   358
....................     sprintf(sent_spi_data_mastr, "%Lu ",parameter); // Note kluge. Have to send space char as termination. Should use interrupt on slave 
1B5A:  BCF    03.5
1B5B:  CLRF   6E
1B5C:  MOVLW  C5
1B5D:  MOVWF  6D
1B5E:  MOVLW  41
1B5F:  MOVWF  04
1B60:  BSF    03.5
1B61:  MOVF   39,W
1B62:  BCF    03.5
1B63:  BSF    03.6
1B64:  MOVWF  37
1B65:  BSF    03.5
1B66:  BCF    03.6
1B67:  MOVF   38,W
1B68:  BCF    03.5
1B69:  BSF    03.6
1B6A:  MOVWF  36
1B6B:  BSF    03.5
1B6C:  BCF    03.6
1B6D:  MOVF   37,W
1B6E:  BCF    03.5
1B6F:  BSF    03.6
1B70:  MOVWF  35
1B71:  BSF    03.5
1B72:  BCF    03.6
1B73:  MOVF   36,W
1B74:  BCF    03.5
1B75:  BSF    03.6
1B76:  MOVWF  34
1B77:  BCF    03.6
1B78:  CALL   0B2
1B79:  MOVLW  20
1B7A:  BSF    03.6
1B7B:  MOVWF  63
1B7C:  BCF    0A.4
1B7D:  BCF    0A.3
1B7E:  BCF    03.6
1B7F:  CALL   4B9
1B80:  BSF    0A.4
1B81:  BSF    0A.3
....................     SPI_strwrite(sent_spi_data_mastr); 
1B82:  BSF    03.6
1B83:  CLRF   35
1B84:  MOVLW  C5
1B85:  MOVWF  34
1B86:  BCF    0A.4
1B87:  BCF    0A.3
1B88:  BCF    03.6
1B89:  CALL   541
1B8A:  BSF    0A.4
1B8B:  BSF    0A.3
....................  
....................     delay_ms(50);                      // Wait for response and read 
1B8C:  MOVLW  32
1B8D:  BSF    03.5
1B8E:  BSF    03.6
1B8F:  MOVWF  10
1B90:  BCF    0A.4
1B91:  BCF    0A.3
1B92:  BCF    03.5
1B93:  BCF    03.6
1B94:  CALL   434
1B95:  BSF    0A.4
1B96:  BSF    0A.3
....................     SPI_strread(received_spi_data_mastr); 
1B97:  BSF    03.6
1B98:  CLRF   60
1B99:  MOVLW  BA
1B9A:  MOVWF  5F
1B9B:  BCF    0A.4
1B9C:  BCF    03.6
1B9D:  CALL   7A6
1B9E:  BSF    0A.4
....................      
....................                                        // Check for errors 
....................     if( atoi32(received_spi_data_mastr) ==  parameter) { 
1B9F:  BSF    03.6
1BA0:  CLRF   36
1BA1:  MOVLW  BA
1BA2:  MOVWF  35
1BA3:  BCF    0A.4
1BA4:  BCF    0A.3
1BA5:  BCF    03.6
1BA6:  CALL   66D
1BA7:  BSF    0A.4
1BA8:  BSF    0A.3
1BA9:  MOVF   7A,W
1BAA:  BSF    03.6
1BAB:  MOVWF  37
1BAC:  MOVF   79,W
1BAD:  MOVWF  36
1BAE:  MOVF   78,W
1BAF:  MOVWF  35
1BB0:  MOVF   77,W
1BB1:  MOVWF  34
1BB2:  BSF    03.5
1BB3:  BCF    03.6
1BB4:  MOVF   36,W
1BB5:  BCF    03.5
1BB6:  BSF    03.6
1BB7:  SUBWF  34,W
1BB8:  BTFSS  03.2
1BB9:  GOTO   41A
1BBA:  BSF    03.5
1BBB:  BCF    03.6
1BBC:  MOVF   37,W
1BBD:  BCF    03.5
1BBE:  BSF    03.6
1BBF:  SUBWF  35,W
1BC0:  BTFSS  03.2
1BC1:  GOTO   41A
1BC2:  BSF    03.5
1BC3:  BCF    03.6
1BC4:  MOVF   38,W
1BC5:  BCF    03.5
1BC6:  BSF    03.6
1BC7:  SUBWF  36,W
1BC8:  BTFSS  03.2
1BC9:  GOTO   41A
1BCA:  BSF    03.5
1BCB:  BCF    03.6
1BCC:  MOVF   39,W
1BCD:  BCF    03.5
1BCE:  BSF    03.6
1BCF:  SUBWF  37,W
1BD0:  BTFSS  03.2
1BD1:  GOTO   41A
....................    	                                   // Success. Send ack 
....................       startup_oc_time = parameter;     // Slave has threshold so it's now safe to store it in the master 	       
1BD2:  BSF    03.5
1BD3:  BCF    03.6
1BD4:  MOVF   37,W
1BD5:  BCF    03.5
1BD6:  MOVWF  34
1BD7:  BSF    03.5
1BD8:  MOVF   36,W
1BD9:  BCF    03.5
1BDA:  MOVWF  33
....................       // Save the parameter to flash 
....................       write_eeprom16(EE_startup_oc_time, startup_oc_time); 
1BDB:  MOVLW  04
1BDC:  BSF    03.6
1BDD:  MOVWF  34
1BDE:  BCF    03.6
1BDF:  MOVF   34,W
1BE0:  BSF    03.6
1BE1:  MOVWF  36
1BE2:  BCF    03.6
1BE3:  MOVF   33,W
1BE4:  BSF    03.6
1BE5:  MOVWF  35
1BE6:  BCF    0A.4
1BE7:  BCF    0A.3
1BE8:  BCF    03.6
1BE9:  CALL   1A2
1BEA:  BSF    0A.4
1BEB:  BSF    0A.3
....................       // Now read it back just to be sure... 
....................       if( (startup_oc_time != read_eeprom16(EE_startup_oc_time)) ) {     
1BEC:  MOVLW  04
1BED:  BSF    03.6
1BEE:  MOVWF  34
1BEF:  BCF    0A.4
1BF0:  BCF    0A.3
1BF1:  BCF    03.6
1BF2:  CALL   16F
1BF3:  BSF    0A.4
1BF4:  BSF    0A.3
1BF5:  MOVF   79,W
1BF6:  MOVWF  7A
1BF7:  MOVF   78,W
1BF8:  SUBWF  33,W
1BF9:  BTFSS  03.2
1BFA:  GOTO   3FF
1BFB:  MOVF   7A,W
1BFC:  SUBWF  34,W
1BFD:  BTFSC  03.2
1BFE:  GOTO   400
....................         // There was an error. 
....................         flash_write_err = true; 
1BFF:  BSF    3C.1
....................       }   
....................       // Send response                              
....................    	  sprintf(response_message, "%Lu", startup_oc_time);  
1C00:  CLRF   6E
1C01:  MOVLW  46
1C02:  MOVWF  6D
1C03:  MOVLW  10
1C04:  MOVWF  04
1C05:  MOVF   34,W
1C06:  BSF    03.6
1C07:  MOVWF  35
1C08:  BCF    03.6
1C09:  MOVF   33,W
1C0A:  BSF    03.6
1C0B:  MOVWF  34
1C0C:  BCF    0A.4
1C0D:  BCF    03.6
1C0E:  CALL   000
1C0F:  BSF    0A.4
....................    	  send_485_response(response_message);    	 
1C10:  BSF    03.6
1C11:  CLRF   35
1C12:  MOVLW  46
1C13:  MOVWF  34
1C14:  BCF    0A.3
1C15:  BCF    03.6
1C16:  CALL   147
1C17:  BSF    0A.3
....................     } 
....................     else { 
1C18:  GOTO   423
1C19:  BSF    03.6
....................     	// Send slave error here 
....................    	  slv_cmd_err = true; 
1C1A:  BCF    03.6
1C1B:  BSF    3D.2
....................    	  send_485_response(empty_string[0]); 
1C1C:  BSF    03.6
1C1D:  CLRF   35
1C1E:  CLRF   34
1C1F:  BCF    0A.3
1C20:  BCF    03.6
1C21:  CALL   147
1C22:  BSF    0A.3
....................     }         
....................     check_slave_off(); // See if it's ok to turn slave off     
1C23:  BCF    0A.4
1C24:  CALL   7CA
1C25:  BSF    0A.4
....................   } 
....................   else { 
1C26:  GOTO   431
1C27:  BSF    03.5
....................   	//Out of range. Send parameter error here 
....................   	invld_param_err = true; 
1C28:  BCF    03.5
1C29:  BSF    3C.7
....................     send_485_response(empty_string[0]); 
1C2A:  BSF    03.6
1C2B:  CLRF   35
1C2C:  CLRF   34
1C2D:  BCF    0A.3
1C2E:  BCF    03.6
1C2F:  CALL   147
1C30:  BSF    0A.3
....................   }   
.................... } 
1C31:  BSF    0A.3
1C32:  BSF    0A.4
1C33:  GOTO   653 (RETURN)
....................  
....................  
.................... #SEPARATE 
.................... void handle_set_address() { 
....................   if( (parameter >= 0) && (parameter <= 99) ) { 
1C34:  BSF    03.5
1C35:  MOVF   39,F
1C36:  BTFSS  03.2
1C37:  GOTO   461
1C38:  MOVF   38,F
1C39:  BTFSS  03.2
1C3A:  GOTO   461
1C3B:  MOVF   37,F
1C3C:  BTFSS  03.2
1C3D:  GOTO   461
1C3E:  MOVF   36,W
1C3F:  SUBLW  63
1C40:  BTFSS  03.0
1C41:  GOTO   461
....................     RS485_ID = parameter;   
1C42:  MOVF   36,W
1C43:  BCF    03.5
1C44:  MOVWF  35
....................  
....................     // Save the parameter to flash 
....................     write_eeprom8(EE_RS485_ID, RS485_ID); 
1C45:  MOVLW  05
1C46:  BSF    03.6
1C47:  MOVWF  39
1C48:  BCF    03.6
1C49:  MOVF   35,W
1C4A:  BSF    03.6
1C4B:  MOVWF  3A
1C4C:  BCF    0A.4
1C4D:  BCF    0A.3
1C4E:  BCF    03.6
1C4F:  CALL   186
1C50:  BSF    0A.4
1C51:  BSF    0A.3
....................     // Now read it back just to be sure... 
....................     if( (RS485_ID != read_eeprom(EE_RS485_ID)) ) {     
1C52:  MOVLW  05
1C53:  BSF    03.6
1C54:  MOVWF  0D
1C55:  BSF    03.5
1C56:  BCF    0C.7
1C57:  BSF    0C.0
1C58:  BCF    03.5
1C59:  MOVF   0C,W
1C5A:  BCF    03.6
1C5B:  SUBWF  35,W
1C5C:  BTFSC  03.2
1C5D:  GOTO   45F
....................       // There was an error. 
....................       flash_write_err = true; 
1C5E:  BSF    3C.1
....................     }             
....................   } 
....................   else { 
1C5F:  GOTO   463
1C60:  BSF    03.5
....................   	//Out of range. Send parameter error here 
....................   	invld_param_err = true;  
1C61:  BCF    03.5
1C62:  BSF    3C.7
....................   } 
....................   // Send response    
....................   sprintf(response_message, "%Lu", parameter);      
1C63:  CLRF   6E
1C64:  MOVLW  46
1C65:  MOVWF  6D
1C66:  MOVLW  41
1C67:  MOVWF  04
1C68:  BSF    03.5
1C69:  MOVF   39,W
1C6A:  BCF    03.5
1C6B:  BSF    03.6
1C6C:  MOVWF  37
1C6D:  BSF    03.5
1C6E:  BCF    03.6
1C6F:  MOVF   38,W
1C70:  BCF    03.5
1C71:  BSF    03.6
1C72:  MOVWF  36
1C73:  BSF    03.5
1C74:  BCF    03.6
1C75:  MOVF   37,W
1C76:  BCF    03.5
1C77:  BSF    03.6
1C78:  MOVWF  35
1C79:  BSF    03.5
1C7A:  BCF    03.6
1C7B:  MOVF   36,W
1C7C:  BCF    03.5
1C7D:  BSF    03.6
1C7E:  MOVWF  34
1C7F:  BCF    03.6
1C80:  CALL   0B2
....................   send_485_response(response_message);    
1C81:  BSF    03.6
1C82:  CLRF   35
1C83:  MOVLW  46
1C84:  MOVWF  34
1C85:  BCF    0A.3
1C86:  BCF    03.6
1C87:  CALL   147
1C88:  BSF    0A.3
.................... } 
1C89:  BSF    0A.3
1C8A:  BSF    0A.4
1C8B:  GOTO   664 (RETURN)
....................         	   
....................  
....................  
....................  
.................... #if DEBUG 
.................... #fuses XT,WDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP 
.................... #else 
.................... #fuses XT,WDT,NOPROTECT,PUT,NOLVP 
.................... #endif 
....................  
.................... #define  RS485_USE_EXT_INT    FALSE 
....................  
....................  
.................... // Purpose: ISR that checks for over-current condition when the load is on 
.................... #SEPARATE 
.................... #INT_TIMER1                      
.................... void high_priority_isr() {                     
....................   set_adc_channel(4);	       // Set A/D channel    
*
00FC:  MOVLW  20
00FD:  MOVWF  78
00FE:  MOVF   1F,W
00FF:  ANDLW  C7
0100:  IORWF  78,W
0101:  MOVWF  1F
....................   read_adc(ADC_START_ONLY); 	                          
0102:  BSF    1F.2
....................   // set_timer1(0xFD95);  // sets timer to interrupt in 5 ms (100 Hz waveform) 
....................   set_timer1(0xF641);  // sets timer to interrupt in 20 ms (25 Hz waveform)    
0103:  MOVLW  F6
0104:  MOVWF  0F
0105:  MOVLW  41
0106:  MOVWF  0E
....................   if(rtos_pin == HI) 
0107:  DECFSZ 67,W
0108:  GOTO   10B
....................     rtos_pin = LO; 
0109:  CLRF   67
....................   else 
010A:  GOTO   10D
....................     rtos_pin = HI; 
010B:  MOVLW  01
010C:  MOVWF  67
....................     output_bit(PIN_C1, rtos_pin); // *** DEBUG 
010D:  MOVF   67,F
010E:  BTFSS  03.2
010F:  GOTO   112
0110:  BCF    07.1
0111:  GOTO   113
0112:  BSF    07.1
0113:  BCF    6F.1
0114:  MOVF   6F,W
0115:  BSF    03.5
0116:  MOVWF  07
....................  
....................   if(read_adc(ADC_READ_ONLY) > overcurrent_adc_val) { 
0117:  BCF    03.5
0118:  BTFSC  1F.2
0119:  GOTO   118
011A:  MOVF   1E,W
011B:  MOVWF  7A
011C:  BSF    03.5
011D:  MOVF   1E,W
011E:  BSF    03.6
011F:  MOVWF  55
0120:  MOVF   7A,W
0121:  MOVWF  56
0122:  BCF    03.5
0123:  BCF    03.6
0124:  MOVF   43,W
0125:  BSF    03.5
0126:  BSF    03.6
0127:  SUBWF  56,W
0128:  BTFSS  03.0
0129:  GOTO   141
012A:  BTFSS  03.2
012B:  GOTO   137
012C:  MOVF   55,W
012D:  BCF    03.5
012E:  BCF    03.6
012F:  SUBWF  42,W
0130:  BTFSS  03.0
0131:  GOTO   135
0132:  BSF    03.5
0133:  BSF    03.6
0134:  GOTO   141
0135:  BSF    03.5
0136:  BSF    03.6
....................     over_curr_err = true; 
0137:  BCF    03.5
0138:  BCF    03.6
0139:  BSF    3C.4
....................     output_bit(PIN_C2, HI); // *** DEBUG   
013A:  BSF    07.2
013B:  BCF    6F.2
013C:  MOVF   6F,W
013D:  BSF    03.5
013E:  MOVWF  07
....................   } 
....................   else { 
013F:  GOTO   148
0140:  BSF    03.6
....................  	  output_bit(PIN_C2, LO); // *** DEBUG   
0141:  BCF    03.5
0142:  BCF    03.6
0143:  BCF    07.2
0144:  BCF    6F.2
0145:  MOVF   6F,W
0146:  BSF    03.5
0147:  MOVWF  07
....................   } 
....................  
.................... } 
....................  
.................... //*** DEBUG 
.................... //#INT_AD 
.................... //void adc_isr() { 
.................... //  adc_ready = true; 
.................... //  output_bit(PIN_C2, HI); // *** DEBUG   
.................... //} 
.................... //*** DEBUG 
....................  
....................  
.................... // Purpose: Does A/D calculation of current from MAX4081. Stores value in global 
0148:  BCF    03.5
0149:  BCF    0C.0
014A:  BCF    0A.3
014B:  BCF    0A.4
014C:  GOTO   025
.................... void do_adc_current_calcs(int16 vref, int16 vscale, int8 rsense, int8 currDiv) { 
....................   adc_value_glob = read_adc();   
*
056C:  BSF    1F.2
056D:  BTFSC  1F.2
056E:  GOTO   56D
056F:  BSF    03.5
0570:  MOVF   1E,W
0571:  BCF    03.5
0572:  MOVWF  3E
0573:  MOVF   1E,W
0574:  MOVWF  3F
0575:  CLRF   40
0576:  CLRF   41
....................  
....................   adc_value_glob = (adc_value_glob * 1000 / 1023) * vscale;      // scale to vscale    
0577:  MOVF   41,W
0578:  BSF    03.6
0579:  MOVWF  42
057A:  BCF    03.6
057B:  MOVF   40,W
057C:  BSF    03.6
057D:  MOVWF  41
057E:  BCF    03.6
057F:  MOVF   3F,W
0580:  BSF    03.6
0581:  MOVWF  40
0582:  BCF    03.6
0583:  MOVF   3E,W
0584:  BSF    03.6
0585:  MOVWF  3F
0586:  CLRF   46
0587:  CLRF   45
0588:  MOVLW  03
0589:  MOVWF  44
058A:  MOVLW  E8
058B:  MOVWF  43
058C:  BCF    03.6
058D:  CALL   1B8
058E:  MOVF   7A,W
058F:  BSF    03.6
0590:  MOVWF  3D
0591:  MOVF   79,W
0592:  MOVWF  3C
0593:  MOVF   78,W
0594:  MOVWF  3B
0595:  MOVF   77,W
0596:  MOVWF  3A
0597:  MOVF   3D,W
0598:  MOVWF  44
0599:  MOVF   3C,W
059A:  MOVWF  43
059B:  MOVF   3B,W
059C:  MOVWF  42
059D:  MOVF   3A,W
059E:  MOVWF  41
059F:  CLRF   48
05A0:  CLRF   47
05A1:  MOVLW  03
05A2:  MOVWF  46
05A3:  MOVLW  FF
05A4:  MOVWF  45
05A5:  BCF    03.6
05A6:  CALL   1E4
05A7:  MOVF   7A,W
05A8:  BSF    03.6
05A9:  MOVWF  3E
05AA:  MOVF   79,W
05AB:  MOVWF  3D
05AC:  MOVF   78,W
05AD:  MOVWF  3C
05AE:  MOVF   77,W
05AF:  MOVWF  3B
05B0:  MOVF   3E,W
05B1:  MOVWF  42
05B2:  MOVF   3D,W
05B3:  MOVWF  41
05B4:  MOVF   3C,W
05B5:  MOVWF  40
05B6:  MOVF   3B,W
05B7:  MOVWF  3F
05B8:  CLRF   46
05B9:  CLRF   45
05BA:  MOVF   37,W
05BB:  MOVWF  44
05BC:  MOVF   36,W
05BD:  MOVWF  43
05BE:  BCF    03.6
05BF:  CALL   1B8
05C0:  MOVF   7A,W
05C1:  MOVWF  41
05C2:  MOVF   79,W
05C3:  MOVWF  40
05C4:  MOVF   78,W
05C5:  MOVWF  3F
05C6:  MOVF   77,W
05C7:  MOVWF  3E
....................   // If there's no voltage present, no need to continue 
....................   if(adc_value_glob == 0) { 
05C8:  MOVF   3E,F
05C9:  BTFSS  03.2
05CA:  GOTO   5D5
05CB:  MOVF   3F,F
05CC:  BTFSS  03.2
05CD:  GOTO   5D5
05CE:  MOVF   40,F
05CF:  BTFSS  03.2
05D0:  GOTO   5D5
05D1:  MOVF   41,F
05D2:  BTFSS  03.2
05D3:  GOTO   5D5
....................   	return; 
05D4:  GOTO   648
....................   } 
....................   adc_value_glob = adc_value_glob - (((int32)vref * 1000) / 2);    // subtract Vref/2 since ref1B is grounded     
05D5:  BSF    03.6
05D6:  CLRF   3D
05D7:  CLRF   3C
05D8:  MOVF   35,W
05D9:  MOVWF  3B
05DA:  MOVF   34,W
05DB:  MOVWF  3A
05DC:  MOVF   3D,W
05DD:  MOVWF  42
05DE:  MOVF   3C,W
05DF:  MOVWF  41
05E0:  MOVF   35,W
05E1:  MOVWF  40
05E2:  MOVF   34,W
05E3:  MOVWF  3F
05E4:  CLRF   46
05E5:  CLRF   45
05E6:  MOVLW  03
05E7:  MOVWF  44
05E8:  MOVLW  E8
05E9:  MOVWF  43
05EA:  BCF    03.6
05EB:  CALL   1B8
05EC:  MOVF   7A,W
05ED:  BSF    03.6
05EE:  MOVWF  3E
05EF:  MOVF   79,W
05F0:  MOVWF  3D
05F1:  MOVF   78,W
05F2:  MOVWF  3C
05F3:  MOVF   77,W
05F4:  MOVWF  3B
05F5:  BCF    03.0
05F6:  RRF    3E,W
05F7:  MOVWF  7A
05F8:  RRF    3D,W
05F9:  MOVWF  79
05FA:  RRF    3C,W
05FB:  MOVWF  78
05FC:  RRF    3B,W
05FD:  MOVWF  77
05FE:  BCF    03.6
05FF:  SUBWF  3E,F
0600:  MOVF   78,W
0601:  BTFSS  03.0
0602:  INCFSZ 78,W
0603:  SUBWF  3F,F
0604:  MOVF   79,W
0605:  BTFSS  03.0
0606:  INCFSZ 79,W
0607:  SUBWF  40,F
0608:  MOVF   7A,W
0609:  BTFSS  03.0
060A:  INCFSZ 7A,W
060B:  SUBWF  41,F
....................   adc_value_glob = adc_value_glob / currDiv;                       // Divide by 5V/V apmplification  
060C:  MOVF   41,W
060D:  BSF    03.6
060E:  MOVWF  44
060F:  BCF    03.6
0610:  MOVF   40,W
0611:  BSF    03.6
0612:  MOVWF  43
0613:  BCF    03.6
0614:  MOVF   3F,W
0615:  BSF    03.6
0616:  MOVWF  42
0617:  BCF    03.6
0618:  MOVF   3E,W
0619:  BSF    03.6
061A:  MOVWF  41
061B:  CLRF   48
061C:  CLRF   47
061D:  CLRF   46
061E:  MOVF   39,W
061F:  MOVWF  45
0620:  BCF    03.6
0621:  CALL   1E4
0622:  MOVF   7A,W
0623:  MOVWF  41
0624:  MOVF   79,W
0625:  MOVWF  40
0626:  MOVF   78,W
0627:  MOVWF  3F
0628:  MOVF   77,W
0629:  MOVWF  3E
....................   adc_value_glob = (adc_value_glob / rsense);                      // Divide by Rsense 
062A:  MOVF   41,W
062B:  BSF    03.6
062C:  MOVWF  44
062D:  BCF    03.6
062E:  MOVF   40,W
062F:  BSF    03.6
0630:  MOVWF  43
0631:  BCF    03.6
0632:  MOVF   3F,W
0633:  BSF    03.6
0634:  MOVWF  42
0635:  BCF    03.6
0636:  MOVF   3E,W
0637:  BSF    03.6
0638:  MOVWF  41
0639:  CLRF   48
063A:  CLRF   47
063B:  CLRF   46
063C:  MOVF   38,W
063D:  MOVWF  45
063E:  BCF    03.6
063F:  CALL   1E4
0640:  MOVF   7A,W
0641:  MOVWF  41
0642:  MOVF   79,W
0643:  MOVWF  40
0644:  MOVF   78,W
0645:  MOVWF  3F
0646:  MOVF   77,W
0647:  MOVWF  3E
.................... }  
0648:  RETLW  00
....................  
.................... // Purpose: Does A/D calculation of voltage through divider and scales to vscale. 
.................... // Stores value in global 
.................... void do_adc_voltage_calcs(int16 vscale) { 
....................   adc_value_glob = read_adc();     
*
044C:  BSF    1F.2
044D:  BTFSC  1F.2
044E:  GOTO   44D
044F:  BSF    03.5
0450:  MOVF   1E,W
0451:  BCF    03.5
0452:  MOVWF  3E
0453:  MOVF   1E,W
0454:  MOVWF  3F
0455:  CLRF   40
0456:  CLRF   41
....................   adc_value_glob = (adc_value_glob * 1000 / 1023) * (int32)vscale; // scale for 0-vscale Volts	 
0457:  MOVF   41,W
0458:  BSF    03.6
0459:  MOVWF  42
045A:  BCF    03.6
045B:  MOVF   40,W
045C:  BSF    03.6
045D:  MOVWF  41
045E:  BCF    03.6
045F:  MOVF   3F,W
0460:  BSF    03.6
0461:  MOVWF  40
0462:  BCF    03.6
0463:  MOVF   3E,W
0464:  BSF    03.6
0465:  MOVWF  3F
0466:  CLRF   46
0467:  CLRF   45
0468:  MOVLW  03
0469:  MOVWF  44
046A:  MOVLW  E8
046B:  MOVWF  43
046C:  BCF    03.6
046D:  CALL   1B8
046E:  MOVF   7A,W
046F:  BSF    03.6
0470:  MOVWF  39
0471:  MOVF   79,W
0472:  MOVWF  38
0473:  MOVF   78,W
0474:  MOVWF  37
0475:  MOVF   77,W
0476:  MOVWF  36
0477:  MOVF   39,W
0478:  MOVWF  44
0479:  MOVF   38,W
047A:  MOVWF  43
047B:  MOVF   37,W
047C:  MOVWF  42
047D:  MOVF   36,W
047E:  MOVWF  41
047F:  CLRF   48
0480:  CLRF   47
0481:  MOVLW  03
0482:  MOVWF  46
0483:  MOVLW  FF
0484:  MOVWF  45
0485:  BCF    03.6
0486:  CALL   1E4
0487:  MOVF   7A,W
0488:  BSF    03.6
0489:  MOVWF  3A
048A:  MOVF   79,W
048B:  MOVWF  39
048C:  MOVF   78,W
048D:  MOVWF  38
048E:  MOVF   77,W
048F:  MOVWF  37
0490:  MOVF   34,W
0491:  MOVWF  77
0492:  MOVF   35,W
0493:  MOVWF  78
0494:  CLRF   79
0495:  CLRF   7A
0496:  MOVF   7A,W
0497:  MOVWF  3E
0498:  MOVF   79,W
0499:  MOVWF  3D
049A:  MOVF   35,W
049B:  MOVWF  3C
049C:  MOVF   34,W
049D:  MOVWF  3B
049E:  MOVF   3A,W
049F:  MOVWF  42
04A0:  MOVF   39,W
04A1:  MOVWF  41
04A2:  MOVF   38,W
04A3:  MOVWF  40
04A4:  MOVF   37,W
04A5:  MOVWF  3F
04A6:  MOVF   3E,W
04A7:  MOVWF  46
04A8:  MOVF   3D,W
04A9:  MOVWF  45
04AA:  MOVF   35,W
04AB:  MOVWF  44
04AC:  MOVF   34,W
04AD:  MOVWF  43
04AE:  BCF    03.6
04AF:  CALL   1B8
04B0:  MOVF   7A,W
04B1:  MOVWF  41
04B2:  MOVF   79,W
04B3:  MOVWF  40
04B4:  MOVF   78,W
04B5:  MOVWF  3F
04B6:  MOVF   77,W
04B7:  MOVWF  3E
.................... } 
04B8:  RETLW  00
....................  
.................... // Purpose: Reads a bytes from data EEPROM 
.................... #SEPARATE 
.................... int8 read_eeprom8(int8 address) { 
....................   return(read_eeprom(address)); 
*
0164:  BSF    03.6
0165:  MOVF   38,W
0166:  MOVWF  0D
0167:  BSF    03.5
0168:  BCF    0C.7
0169:  BSF    0C.0
016A:  BCF    03.5
016B:  MOVF   0C,W
016C:  MOVWF  78
.................... } 
016D:  BCF    03.6
016E:  RETLW  00
....................  
.................... // Purpose: Writes a byte to data EEPROM 
.................... void write_eeprom8(int8 address, int8 data) { 
....................   write_eeprom(address, data); 
*
0186:  BSF    03.6
0187:  MOVF   39,W
0188:  MOVWF  0D
0189:  MOVF   3A,W
018A:  MOVWF  0C
018B:  BSF    03.5
018C:  BCF    0C.7
018D:  BSF    0C.2
018E:  BCF    03.5
018F:  BCF    03.6
0190:  MOVF   0B,W
0191:  MOVWF  77
0192:  BCF    0B.7
0193:  BSF    03.5
0194:  BSF    03.6
0195:  MOVLW  55
0196:  MOVWF  0D
0197:  MOVLW  AA
0198:  MOVWF  0D
0199:  BSF    0C.1
019A:  BTFSC  0C.1
019B:  GOTO   19A
019C:  BCF    0C.2
019D:  MOVF   77,W
019E:  BCF    03.5
019F:  BCF    03.6
01A0:  IORWF  0B,F
.................... } 
01A1:  RETLW  00
....................  
.................... // Purpose: Reads two bytes from data EEPROM 
.................... int16 read_eeprom16(int8 address) { 
....................   union { 
....................     int8 bytes[2]; 
....................     int16 val; 
....................   } data; 
....................  
....................   data.bytes[0]=read_eeprom8(address++); 
*
016F:  BSF    03.6
0170:  MOVF   34,W
0171:  INCF   34,F
0172:  MOVWF  37
0173:  MOVWF  38
0174:  BCF    03.6
0175:  CALL   164
0176:  MOVF   78,W
0177:  BSF    03.6
0178:  MOVWF  35
....................   data.bytes[1]=read_eeprom8(address); 
0179:  MOVF   34,W
017A:  MOVWF  38
017B:  BCF    03.6
017C:  CALL   164
017D:  MOVF   78,W
017E:  BSF    03.6
017F:  MOVWF  36
....................  
....................   return(data.val); 
0180:  MOVF   35,W
0181:  MOVWF  78
0182:  MOVF   36,W
0183:  MOVWF  79
.................... } 
0184:  BCF    03.6
0185:  RETLW  00
....................  
....................  
.................... // Purpose: Writes 2 bytes to Data EEPROM at location "address" 
.................... void write_eeprom16(int8 address, int16 data) { 
....................   write_eeprom8(address++, make8(data,0)); 
*
01A2:  BSF    03.6
01A3:  MOVF   34,W
01A4:  INCF   34,F
01A5:  MOVWF  37
01A6:  MOVF   35,W
01A7:  MOVWF  38
01A8:  MOVF   37,W
01A9:  MOVWF  39
01AA:  MOVF   35,W
01AB:  MOVWF  3A
01AC:  BCF    03.6
01AD:  CALL   186
....................   write_eeprom8(address, make8(data,1)); 
01AE:  BSF    03.6
01AF:  MOVF   36,W
01B0:  MOVWF  37
01B1:  MOVF   34,W
01B2:  MOVWF  39
01B3:  MOVF   36,W
01B4:  MOVWF  3A
01B5:  BCF    03.6
01B6:  CALL   186
.................... } 
01B7:  RETLW  00
....................  
....................  
.................... // Purpose: Clears all errors if true. Otherwise, just clears non-persistent errors 
.................... void clear_errors(Boolean clear_persistent) { 
....................   // Clear the persistent errors if necessary 
....................   if(clear_persistent) { 
*
08DB:  BSF    03.6
08DC:  MOVF   5F,F
08DD:  BTFSC  03.2
08DE:  GOTO   0E8
....................     flash_write_err_slave = false; 
08DF:  BCF    03.6
08E0:  BCF    3C.0
....................     flash_write_err       = false; 
08E1:  BCF    3C.1
....................     ground_fault_err      = false; 
08E2:  BCF    3C.2
....................     over_temp_err         = false; 
08E3:  BCF    3C.3
....................     over_curr_err         = false; 
08E4:  BCF    3C.4
....................     switch_err            = false; 
08E5:  BCF    3C.5
....................     wdt_reset_err         = false; 
08E6:  BCF    3D.1
08E7:  BSF    03.6
....................   } 
....................   // And clear all other errors  
....................   invld_cmd_err           = false; 
08E8:  BCF    03.6
08E9:  BCF    3C.6
....................   invld_param_err         = false; 
08EA:  BCF    3C.7
....................   invld_cksum_err         = false; 
08EB:  BCF    3D.0
....................   slv_cmd_err             = false; 
08EC:  BCF    3D.2
.................... } 
08ED:  RETLW  00
....................  
....................  
.................... // Purpose: If the slave isn't on, this routine turns it on and leaves it on 
.................... void check_slave_on() { 
.................... 	if(!slave_is_on) { 
*
0F95:  BTFSC  3D.7
0F96:  GOTO   7A5
....................     output_bit(PIN_B4, HI); // Turn on slave processor 
0F97:  BSF    06.4
0F98:  BSF    03.5
0F99:  BCF    06.4
....................     slave_is_on = true; 
0F9A:  BCF    03.5
0F9B:  BSF    3D.7
....................   	delay_ms(150);          // Time for slave to boot up and initialize ~ 150 msec with no need to wait for overcurrent checking 
0F9C:  MOVLW  96
0F9D:  BSF    03.5
0F9E:  BSF    03.6
0F9F:  MOVWF  10
0FA0:  BCF    0A.3
0FA1:  BCF    03.5
0FA2:  BCF    03.6
0FA3:  CALL   434
0FA4:  BSF    0A.3
.................... 	} 
.................... } 
0FA5:  RETLW  00
....................  
....................  
.................... // Purpose: Removes power from the slave if the load is off 
.................... void check_slave_off() { 
.................... 	if(!load_is_on) { 
*
0FCA:  BTFSC  66.0
0FCB:  GOTO   7D1
....................    	output_bit(PIN_B4, LO);  
0FCC:  BCF    06.4
0FCD:  BSF    03.5
0FCE:  BCF    06.4
....................   	slave_is_on = false;   	 
0FCF:  BCF    03.5
0FD0:  BCF    3D.7
.................... 	} 
.................... } 
0FD1:  RETLW  00
....................  
....................  
.................... // Purpose: This routine gets called once per cycle to add in any errors  
.................... //          that the slave may have detected.  
.................... void calculate_errors() {              	 
....................   // Get any slave errors	 
.................... 	if(slave_is_on) { 
*
1147:  BTFSS  3D.7
1148:  GOTO   3AB
....................     spi_write(80);                 
1149:  MOVF   13,W
114A:  MOVLW  50
114B:  MOVWF  13
114C:  BSF    03.5
114D:  BTFSS  14.0
114E:  GOTO   14D
....................     delay_ms(50);     //Takes approx 32 msec to complete transaction 
114F:  MOVLW  32
1150:  BSF    03.6
1151:  MOVWF  10
1152:  BCF    0A.4
1153:  BCF    03.5
1154:  BCF    03.6
1155:  CALL   434
1156:  BSF    0A.4
....................    
....................     // Get repsonse from slave 
....................     SPI_strread(received_spi_data_mastr); 
1157:  BSF    03.6
1158:  CLRF   60
1159:  MOVLW  BA
115A:  MOVWF  5F
115B:  BCF    0A.4
115C:  BSF    0A.3
115D:  BCF    03.6
115E:  CALL   7A6
115F:  BSF    0A.4
1160:  BCF    0A.3
....................  
....................     // Verify that we got some sort of number back 
....................     if(strlen(received_spi_data_mastr) > 3) { 
1161:  BSF    03.5
1162:  BSF    03.6
1163:  CLRF   11
1164:  MOVLW  BA
1165:  MOVWF  10
*
1185:  MOVF   79,W
1186:  MOVWF  11
1187:  MOVF   78,W
1188:  MOVWF  10
1189:  MOVF   11,F
118A:  BTFSS  03.2
118B:  GOTO   190
118C:  MOVF   10,W
118D:  SUBLW  03
118E:  BTFSC  03.0
118F:  GOTO   3A8
....................       slave_errors = strtoul(received_spi_data_mastr,null,16); 
1190:  CLRF   11
1191:  MOVLW  BA
1192:  MOVWF  10
1193:  CLRF   13
1194:  CLRF   12
1195:  MOVLW  10
1196:  MOVWF  14
*
139F:  MOVF   79,W
13A0:  BCF    03.5
13A1:  BCF    03.6
13A2:  MOVWF  3B
13A3:  MOVF   78,W
13A4:  MOVWF  3A
....................     } 
....................     else { 
13A5:  GOTO   3AB
13A6:  BSF    03.5
13A7:  BSF    03.6
....................       slv_cmd_err = true; 
13A8:  BCF    03.5
13A9:  BCF    03.6
13AA:  BSF    3D.2
....................     } 
....................   } 
....................    
....................   //Calculate error bytes for the master 
....................   error_status =( 
....................                 (flash_write_err_slave << 10) | 
....................                 (flash_write_err   << 9) | 
....................                 (ground_fault_err  << 8) | 
....................                 (over_temp_err     << 7) | 
....................                 (over_curr_err     << 6) | 
....................                 (switch_err        << 5) | 
....................                 (invld_cmd_err     << 4) | 
....................                 (invld_param_err   << 3) | 
....................                 (invld_cksum_err   << 2) | 
....................                 (wdt_reset_err     << 1) | 
....................                 (slv_cmd_err       ) 
....................                 );   
13AB:  MOVLW  00
13AC:  BTFSC  3C.0
13AD:  MOVLW  01
13AE:  BSF    03.5
13AF:  BSF    03.6
13B0:  CLRF   11
13B1:  MOVLW  00
13B2:  BCF    03.5
13B3:  BCF    03.6
13B4:  BTFSC  3C.1
13B5:  MOVLW  01
13B6:  MOVLW  00
13B7:  BSF    03.5
13B8:  BSF    03.6
13B9:  IORWF  11,W
13BA:  MOVWF  13
13BB:  MOVLW  00
13BC:  BCF    03.5
13BD:  BCF    03.6
13BE:  BTFSC  3C.2
13BF:  MOVLW  01
13C0:  MOVLW  00
13C1:  BSF    03.5
13C2:  BSF    03.6
13C3:  IORWF  13,W
13C4:  MOVWF  15
13C5:  MOVLW  00
13C6:  BCF    03.5
13C7:  BCF    03.6
13C8:  BTFSC  3C.3
13C9:  MOVLW  01
13CA:  MOVWF  77
13CB:  RRF    77,W
13CC:  CLRF   77
13CD:  BTFSC  03.0
13CE:  BSF    77.7
13CF:  MOVF   77,W
13D0:  BSF    03.5
13D1:  BSF    03.6
13D2:  IORWF  15,W
13D3:  MOVWF  17
13D4:  MOVLW  00
13D5:  BCF    03.5
13D6:  BCF    03.6
13D7:  BTFSC  3C.4
13D8:  MOVLW  01
13D9:  MOVWF  77
13DA:  SWAPF  77,F
13DB:  RLF    77,F
13DC:  RLF    77,F
13DD:  MOVLW  C0
13DE:  ANDWF  77,F
13DF:  MOVF   77,W
13E0:  BSF    03.5
13E1:  BSF    03.6
13E2:  IORWF  17,W
13E3:  MOVWF  19
13E4:  MOVLW  00
13E5:  BCF    03.5
13E6:  BCF    03.6
13E7:  BTFSC  3C.5
13E8:  MOVLW  01
13E9:  MOVWF  77
13EA:  SWAPF  77,F
13EB:  RLF    77,F
13EC:  MOVLW  E0
13ED:  ANDWF  77,F
13EE:  MOVF   77,W
13EF:  BSF    03.5
13F0:  BSF    03.6
13F1:  IORWF  19,W
13F2:  MOVWF  1B
13F3:  MOVLW  00
13F4:  BCF    03.5
13F5:  BCF    03.6
13F6:  BTFSC  3C.6
13F7:  MOVLW  01
13F8:  MOVWF  77
13F9:  SWAPF  77,F
13FA:  MOVLW  F0
13FB:  ANDWF  77,F
13FC:  MOVF   77,W
13FD:  BSF    03.5
13FE:  BSF    03.6
13FF:  IORWF  1B,W
1400:  MOVWF  1D
1401:  MOVLW  00
1402:  BCF    03.5
1403:  BCF    03.6
1404:  BTFSC  3C.7
1405:  MOVLW  01
1406:  MOVWF  77
1407:  RLF    77,F
1408:  RLF    77,F
1409:  RLF    77,F
140A:  MOVLW  F8
140B:  ANDWF  77,F
140C:  MOVF   77,W
140D:  BSF    03.5
140E:  BSF    03.6
140F:  IORWF  1D,W
1410:  MOVWF  1F
1411:  MOVLW  00
1412:  BCF    03.5
1413:  BCF    03.6
1414:  BTFSC  3D.0
1415:  MOVLW  01
1416:  MOVWF  77
1417:  RLF    77,F
1418:  RLF    77,F
1419:  MOVLW  FC
141A:  ANDWF  77,F
141B:  MOVF   77,W
141C:  BSF    03.5
141D:  BSF    03.6
141E:  IORWF  1F,W
141F:  MOVWF  21
1420:  MOVLW  00
1421:  BCF    03.5
1422:  BCF    03.6
1423:  BTFSC  3D.1
1424:  MOVLW  01
1425:  MOVWF  77
1426:  BCF    03.0
1427:  RLF    77,F
1428:  MOVF   77,W
1429:  BSF    03.5
142A:  BSF    03.6
142B:  IORWF  21,W
142C:  MOVWF  23
142D:  MOVLW  00
142E:  BCF    03.5
142F:  BCF    03.6
1430:  BTFSC  3D.2
1431:  MOVLW  01
1432:  BSF    03.5
1433:  BSF    03.6
1434:  IORWF  23,W
1435:  BCF    03.5
1436:  BCF    03.6
1437:  MOVWF  38
1438:  CLRF   39
....................    
....................   // Then OR with the master errors 
....................   error_status |= slave_errors;   
1439:  MOVF   3A,W
143A:  IORWF  38,F
143B:  MOVF   3B,W
143C:  IORWF  39,F
.................... } 
....................  
.................... // Purpose: Calculates overcurrent thresholds as read out by the A/D 
.................... //          and stores them in globals 
.................... #SEPARATE 
.................... void calc_adc_val_nominal() { 
....................   overcurrent_adc_val = ( (((((((int32)steady_oc_threshold * (int32)RSENSE) * (int32)CURRDIVISOR) + (((int32)VREF / 2) * 1000)) / VREF) * 1023) / 1000) ); 
*
0228:  BSF    03.6
0229:  CLRF   13
022A:  CLRF   12
022B:  BCF    03.6
022C:  MOVF   32,W
022D:  BSF    03.6
022E:  MOVWF  11
022F:  BCF    03.6
0230:  MOVF   31,W
0231:  BSF    03.6
0232:  MOVWF  10
0233:  MOVF   13,W
0234:  MOVWF  42
0235:  MOVF   12,W
0236:  MOVWF  41
0237:  MOVF   11,W
0238:  MOVWF  40
0239:  MOVF   10,W
023A:  MOVWF  3F
023B:  CLRF   46
023C:  CLRF   45
023D:  CLRF   44
023E:  MOVLW  C8
023F:  MOVWF  43
0240:  BCF    03.6
0241:  CALL   1B8
0242:  MOVF   7A,W
0243:  BSF    03.6
0244:  MOVWF  14
0245:  MOVF   79,W
0246:  MOVWF  13
0247:  MOVF   78,W
0248:  MOVWF  12
0249:  MOVF   77,W
024A:  MOVWF  11
024B:  MOVF   14,W
024C:  MOVWF  42
024D:  MOVF   13,W
024E:  MOVWF  41
024F:  MOVF   12,W
0250:  MOVWF  40
0251:  MOVF   11,W
0252:  MOVWF  3F
0253:  CLRF   46
0254:  CLRF   45
0255:  CLRF   44
0256:  MOVLW  05
0257:  MOVWF  43
0258:  BCF    03.6
0259:  CALL   1B8
025A:  MOVF   7A,W
025B:  BSF    03.6
025C:  MOVWF  15
025D:  MOVF   79,W
025E:  MOVWF  14
025F:  MOVF   78,W
0260:  MOVWF  13
0261:  MOVF   77,W
0262:  MOVWF  12
0263:  MOVWF  16
0264:  MOVLW  40
0265:  ADDWF  13,W
0266:  MOVWF  17
0267:  MOVF   14,W
0268:  MOVWF  18
0269:  MOVLW  1F
026A:  BTFSC  03.0
026B:  MOVLW  20
026C:  ADDWF  18,F
026D:  MOVF   15,W
026E:  MOVWF  19
026F:  MOVLW  00
0270:  BTFSC  03.0
0271:  MOVLW  01
0272:  ADDWF  19,F
0273:  CLRF   1D
0274:  RRF    19,W
0275:  MOVWF  1C
0276:  RRF    18,W
0277:  MOVWF  1B
0278:  RRF    17,W
0279:  MOVWF  1A
027A:  RRF    1C,F
027B:  RRF    1B,F
027C:  RRF    1A,F
027D:  RRF    1C,F
027E:  RRF    1B,F
027F:  RRF    1A,F
0280:  RRF    1C,F
0281:  RRF    1B,F
0282:  RRF    1A,F
0283:  MOVLW  0F
0284:  ANDWF  1C,F
0285:  MOVF   1D,W
0286:  MOVWF  42
0287:  MOVF   1C,W
0288:  MOVWF  41
0289:  MOVF   1B,W
028A:  MOVWF  40
028B:  MOVF   1A,W
028C:  MOVWF  3F
028D:  CLRF   46
028E:  CLRF   45
028F:  MOVLW  03
0290:  MOVWF  44
0291:  MOVLW  FF
0292:  MOVWF  43
0293:  BCF    03.6
0294:  CALL   1B8
0295:  MOVF   7A,W
0296:  BSF    03.6
0297:  MOVWF  1E
0298:  MOVF   79,W
0299:  MOVWF  1D
029A:  MOVF   78,W
029B:  MOVWF  1C
029C:  MOVF   77,W
029D:  MOVWF  1B
029E:  MOVF   1E,W
029F:  MOVWF  44
02A0:  MOVF   1D,W
02A1:  MOVWF  43
02A2:  MOVF   1C,W
02A3:  MOVWF  42
02A4:  MOVF   1B,W
02A5:  MOVWF  41
02A6:  CLRF   48
02A7:  CLRF   47
02A8:  MOVLW  03
02A9:  MOVWF  46
02AA:  MOVLW  E8
02AB:  MOVWF  45
02AC:  BCF    03.6
02AD:  CALL   1E4
02AE:  MOVF   78,W
02AF:  MOVWF  43
02B0:  MOVF   77,W
02B1:  MOVWF  42
.................... } 
02B2:  RETLW  00
....................  
.................... // Purpose: Calculates overcurrent thresholds as read out by the A/D 
.................... //          and stores them in globals 
.................... #SEPARATE 
.................... void calc_adc_val_startup() { 
....................   overcurrent_adc_val_startup = ( (((((((int32)startup_oc_threshold * (int32)RSENSE) * (int32)CURRDIVISOR) + (((int32)VREF / 2) * 1000)) / VREF) * 1023) / 1000) ); 
02B3:  BSF    03.6
02B4:  CLRF   13
02B5:  CLRF   12
02B6:  BCF    03.6
02B7:  MOVF   30,W
02B8:  BSF    03.6
02B9:  MOVWF  11
02BA:  BCF    03.6
02BB:  MOVF   2F,W
02BC:  BSF    03.6
02BD:  MOVWF  10
02BE:  MOVF   13,W
02BF:  MOVWF  42
02C0:  MOVF   12,W
02C1:  MOVWF  41
02C2:  MOVF   11,W
02C3:  MOVWF  40
02C4:  MOVF   10,W
02C5:  MOVWF  3F
02C6:  CLRF   46
02C7:  CLRF   45
02C8:  CLRF   44
02C9:  MOVLW  C8
02CA:  MOVWF  43
02CB:  BCF    03.6
02CC:  CALL   1B8
02CD:  MOVF   7A,W
02CE:  BSF    03.6
02CF:  MOVWF  14
02D0:  MOVF   79,W
02D1:  MOVWF  13
02D2:  MOVF   78,W
02D3:  MOVWF  12
02D4:  MOVF   77,W
02D5:  MOVWF  11
02D6:  MOVF   14,W
02D7:  MOVWF  42
02D8:  MOVF   13,W
02D9:  MOVWF  41
02DA:  MOVF   12,W
02DB:  MOVWF  40
02DC:  MOVF   11,W
02DD:  MOVWF  3F
02DE:  CLRF   46
02DF:  CLRF   45
02E0:  CLRF   44
02E1:  MOVLW  05
02E2:  MOVWF  43
02E3:  BCF    03.6
02E4:  CALL   1B8
02E5:  MOVF   7A,W
02E6:  BSF    03.6
02E7:  MOVWF  15
02E8:  MOVF   79,W
02E9:  MOVWF  14
02EA:  MOVF   78,W
02EB:  MOVWF  13
02EC:  MOVF   77,W
02ED:  MOVWF  12
02EE:  MOVWF  16
02EF:  MOVLW  40
02F0:  ADDWF  13,W
02F1:  MOVWF  17
02F2:  MOVF   14,W
02F3:  MOVWF  18
02F4:  MOVLW  1F
02F5:  BTFSC  03.0
02F6:  MOVLW  20
02F7:  ADDWF  18,F
02F8:  MOVF   15,W
02F9:  MOVWF  19
02FA:  MOVLW  00
02FB:  BTFSC  03.0
02FC:  MOVLW  01
02FD:  ADDWF  19,F
02FE:  CLRF   1D
02FF:  RRF    19,W
0300:  MOVWF  1C
0301:  RRF    18,W
0302:  MOVWF  1B
0303:  RRF    17,W
0304:  MOVWF  1A
0305:  RRF    1C,F
0306:  RRF    1B,F
0307:  RRF    1A,F
0308:  RRF    1C,F
0309:  RRF    1B,F
030A:  RRF    1A,F
030B:  RRF    1C,F
030C:  RRF    1B,F
030D:  RRF    1A,F
030E:  MOVLW  0F
030F:  ANDWF  1C,F
0310:  MOVF   1D,W
0311:  MOVWF  42
0312:  MOVF   1C,W
0313:  MOVWF  41
0314:  MOVF   1B,W
0315:  MOVWF  40
0316:  MOVF   1A,W
0317:  MOVWF  3F
0318:  CLRF   46
0319:  CLRF   45
031A:  MOVLW  03
031B:  MOVWF  44
031C:  MOVLW  FF
031D:  MOVWF  43
031E:  BCF    03.6
031F:  CALL   1B8
0320:  MOVF   7A,W
0321:  BSF    03.6
0322:  MOVWF  1E
0323:  MOVF   79,W
0324:  MOVWF  1D
0325:  MOVF   78,W
0326:  MOVWF  1C
0327:  MOVF   77,W
0328:  MOVWF  1B
0329:  MOVF   1E,W
032A:  MOVWF  44
032B:  MOVF   1D,W
032C:  MOVWF  43
032D:  MOVF   1C,W
032E:  MOVWF  42
032F:  MOVF   1B,W
0330:  MOVWF  41
0331:  CLRF   48
0332:  CLRF   47
0333:  MOVLW  03
0334:  MOVWF  46
0335:  MOVLW  E8
0336:  MOVWF  45
0337:  BCF    03.6
0338:  CALL   1E4
0339:  MOVF   78,W
033A:  MOVWF  45
033B:  MOVF   77,W
033C:  MOVWF  44
.................... } 
033D:  RETLW  00
....................  
....................  
.................... // Purpose: Holds software in infinite loop to allow watchdog to reset 
.................... #SEPARATE 
.................... void software_reset() { 
....................   for(;;) { 
....................     null; 
....................   } 
*
0FF9:  GOTO   7F9
.................... } 
0FFA:  BSF    0A.3
0FFB:  BSF    0A.4
0FFC:  GOTO   6EC (RETURN)
....................  
.................... // Purpose: Removes and re-applies power to the islolated controller 
.................... #SEPARATE 
.................... void slave_reset() { 
....................   output_bit(PIN_B4, LO); // Turn off PIC   
....................   delay_ms(1000); 
....................   output_bit(PIN_B4, HI); // Turn on PIC   
.................... } 
....................  
.................... // Purpose: Initialization for elements common to both PICs 
.................... #SEPARATE 
.................... void initializeLC() { 
....................   // Set up the system clocks and watchdog 
....................   setup_wdt(WDT_288MS); // See fuses WDT also 
*
014D:  MOVLW  0C
014E:  MOVWF  77
014F:  MOVLW  07
0150:  CLRF   01
0151:  MOVLW  81
0152:  MOVWF  04
0153:  BCF    03.7
0154:  MOVF   00,W
0155:  ANDLW  F0
0156:  IORLW  07
0157:  MOVWF  00
0158:  CLRWDT
0159:  MOVF   00,W
015A:  ANDLW  F7
015B:  BTFSC  77.3
015C:  ANDLW  F0
015D:  IORWF  77,W
015E:  MOVWF  00
....................    
....................   // Using timer 1 for "real time" ground fault detection interrupts 
....................   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);  
015F:  MOVLW  B5
0160:  MOVWF  10
.................... } 
0161:  BSF    0A.3
0162:  BSF    0A.4
0163:  GOTO   6DB (RETURN)
....................  
.................... // External interrupt does nothing (currently) to simply return execution back to where it 
.................... // left off after the sleep() command 
.................... //#INT_EXT 
.................... //void ext_isr() { 
.................... //	null; 
.................... //} 
....................  
....................  
.................... // Purpose: Initialization for the Master (non-iso) PIC 
.................... #SEPARATE 
.................... void initializeMaster() {   
....................   // Initialize Outputs/Inputs 
....................   set_tris_a(0x0F); // Pins A3-A0 inputs. Pins A5-A4 outputs 
*
0CF7:  MOVLW  0F
0CF8:  BSF    03.5
0CF9:  MOVWF  05
....................   set_tris_b(0xC1); // Pins B7, B6, B0 inputs. Pins B5, B4, B3, B2, B1 outputs 
0CFA:  MOVLW  C1
0CFB:  MOVWF  06
....................   set_tris_c(0x93); // Pins C7, C4, C1, C0 inputs. Pins C6, C5, C3, C2 outputs 
0CFC:  MOVLW  93
0CFD:  MOVWF  07
0CFE:  BCF    03.5
0CFF:  MOVWF  6F
....................  
....................   // Set outputs low 
....................   output_bit(PIN_A4, LO); 
0D00:  BCF    05.4
0D01:  BSF    03.5
0D02:  BCF    05.4
....................   output_bit(PIN_A5, LO); 
0D03:  BCF    03.5
0D04:  BCF    05.5
0D05:  BSF    03.5
0D06:  BCF    05.5
....................   output_bit(PIN_B1, LO); 
0D07:  BCF    03.5
0D08:  BCF    06.1
0D09:  BSF    03.5
0D0A:  BCF    06.1
....................   output_bit(PIN_B2, LO); 
0D0B:  BCF    03.5
0D0C:  BCF    06.2
0D0D:  BSF    03.5
0D0E:  BCF    06.2
....................   output_bit(PIN_B3, LO); 
0D0F:  BCF    03.5
0D10:  BCF    06.3
0D11:  BSF    03.5
0D12:  BCF    06.3
....................   output_bit(PIN_B4, LO); 
0D13:  BCF    03.5
0D14:  BCF    06.4
0D15:  BSF    03.5
0D16:  BCF    06.4
....................   output_bit(PIN_B5, LO); 
0D17:  BCF    03.5
0D18:  BCF    06.5
0D19:  BSF    03.5
0D1A:  BCF    06.5
.................... 	output_bit(PIN_C2, LO); 
0D1B:  BCF    03.5
0D1C:  BCF    07.2
0D1D:  BCF    6F.2
0D1E:  MOVF   6F,W
0D1F:  BSF    03.5
0D20:  MOVWF  07
.................... 	output_bit(PIN_C3, LO); 
0D21:  BCF    03.5
0D22:  BCF    07.3
0D23:  BCF    6F.3
0D24:  MOVF   6F,W
0D25:  BSF    03.5
0D26:  MOVWF  07
....................   output_bit(PIN_C5, LO); 
0D27:  BCF    03.5
0D28:  BCF    07.5
0D29:  BCF    6F.5
0D2A:  MOVF   6F,W
0D2B:  BSF    03.5
0D2C:  MOVWF  07
.................... 	output_bit(PIN_C6, LO);   
0D2D:  BCF    03.5
0D2E:  BCF    07.6
0D2F:  BCF    6F.6
0D30:  MOVF   6F,W
0D31:  BSF    03.5
0D32:  MOVWF  07
....................  
....................   // Initialize Serial and enable interrupts 
....................   rs485_init(); 
0D33:  BCF    03.5
0D34:  GOTO   4EB
....................  
.................... //  // Setup interrupt for wakeup from sleep //*** DEBUG 
.................... //  ext_int_edge(H_TO_L);        
.................... //  enable_interrupts(INT_EXT); // turn on interrupt 
....................      
....................   // Initialize SPI bus 
....................   SETUP_SPI(SPI_SS_DISABLED | SPI_MASTER | SPI_L_TO_H);  
0D35:  BCF    14.5
0D36:  BCF    6F.5
0D37:  MOVF   6F,W
0D38:  BSF    03.5
0D39:  MOVWF  07
0D3A:  BCF    03.5
0D3B:  BSF    6F.4
0D3C:  MOVF   6F,W
0D3D:  BSF    03.5
0D3E:  MOVWF  07
0D3F:  BCF    03.5
0D40:  BCF    6F.3
0D41:  MOVF   6F,W
0D42:  BSF    03.5
0D43:  MOVWF  07
0D44:  MOVLW  21
0D45:  BCF    03.5
0D46:  MOVWF  14
0D47:  MOVLW  00
0D48:  BSF    03.5
0D49:  MOVWF  14
....................  
....................   // Set up analog input for AN0 and AN1 
....................   setup_adc(ADC_CLOCK_INTERNAL); 
0D4A:  BCF    1F.6
0D4B:  BCF    03.5
0D4C:  BSF    1F.6
0D4D:  BSF    1F.7
0D4E:  BSF    03.5
0D4F:  BSF    1F.7
0D50:  BCF    03.5
0D51:  BSF    1F.0
....................   setup_adc_ports(AN0_AN1_VREF_VREF); // A0 A1 VRef+=A3 VRef-=A2 
0D52:  BSF    03.5
0D53:  BSF    1F.0
0D54:  BCF    1F.1
0D55:  BSF    1F.2
0D56:  BSF    1F.3
....................  
....................  
....................   // Check for parameters stored in data EEPROM and 
....................   // initialze from there if set 
....................   if( read_eeprom(EE_eeprom_written) == 0x99 ) { 
0D57:  MOVLW  07
0D58:  BCF    03.5
0D59:  BSF    03.6
0D5A:  MOVWF  0D
0D5B:  BSF    03.5
0D5C:  BCF    0C.7
0D5D:  BSF    0C.0
0D5E:  BCF    03.5
0D5F:  MOVF   0C,W
0D60:  SUBLW  99
0D61:  BTFSS  03.2
0D62:  GOTO   598
....................   	startup_oc_threshold = read_eeprom16(EE_startup_oc_threshold); 
0D63:  CLRF   34
0D64:  BCF    0A.3
0D65:  BCF    03.6
0D66:  CALL   16F
0D67:  BSF    0A.3
0D68:  MOVF   79,W
0D69:  MOVWF  30
0D6A:  MOVF   78,W
0D6B:  MOVWF  2F
....................     steady_oc_threshold = read_eeprom16(EE_steady_oc_threshold); 
0D6C:  MOVLW  02
0D6D:  BSF    03.6
0D6E:  MOVWF  34
0D6F:  BCF    0A.3
0D70:  BCF    03.6
0D71:  CALL   16F
0D72:  BSF    0A.3
0D73:  MOVF   79,W
0D74:  MOVWF  32
0D75:  MOVF   78,W
0D76:  MOVWF  31
....................     startup_oc_time = read_eeprom16(EE_startup_oc_time); 
0D77:  MOVLW  04
0D78:  BSF    03.6
0D79:  MOVWF  34
0D7A:  BCF    0A.3
0D7B:  BCF    03.6
0D7C:  CALL   16F
0D7D:  BSF    0A.3
0D7E:  MOVF   79,W
0D7F:  MOVWF  34
0D80:  MOVF   78,W
0D81:  MOVWF  33
....................     RS485_ID = read_eeprom(EE_RS485_ID); 
0D82:  MOVLW  05
0D83:  BSF    03.6
0D84:  MOVWF  0D
0D85:  BSF    03.5
0D86:  BCF    0C.7
0D87:  BSF    0C.0
0D88:  BCF    03.5
0D89:  MOVF   0C,W
0D8A:  BCF    03.6
0D8B:  MOVWF  35
....................     relay_status_closed = read_eeprom(EE_relay_status_closed);      
0D8C:  MOVLW  06
0D8D:  BSF    03.6
0D8E:  MOVWF  0D
0D8F:  BSF    03.5
0D90:  BCF    0C.7
0D91:  BSF    0C.0
0D92:  BCF    03.5
0D93:  MOVF   0C,W
0D94:  BCF    03.6
0D95:  MOVWF  37
....................      
.................... //    sprintf(response_message, "use EE\r\n"); //*** DEBUG 
.................... //    send_response(response_message);    	   //*** DEBUG 
....................   } 
....................   else { // Write the interface parameters to flash for the first time 
0D96:  GOTO   632
0D97:  BSF    03.6
....................     write_eeprom16(EE_startup_oc_threshold, startup_oc_threshold); 
0D98:  CLRF   34
0D99:  BCF    03.6
0D9A:  MOVF   30,W
0D9B:  BSF    03.6
0D9C:  MOVWF  36
0D9D:  BCF    03.6
0D9E:  MOVF   2F,W
0D9F:  BSF    03.6
0DA0:  MOVWF  35
0DA1:  BCF    0A.3
0DA2:  BCF    03.6
0DA3:  CALL   1A2
0DA4:  BSF    0A.3
....................     write_eeprom16(EE_steady_oc_threshold, steady_oc_threshold); 
0DA5:  MOVLW  02
0DA6:  BSF    03.6
0DA7:  MOVWF  34
0DA8:  BCF    03.6
0DA9:  MOVF   32,W
0DAA:  BSF    03.6
0DAB:  MOVWF  36
0DAC:  BCF    03.6
0DAD:  MOVF   31,W
0DAE:  BSF    03.6
0DAF:  MOVWF  35
0DB0:  BCF    0A.3
0DB1:  BCF    03.6
0DB2:  CALL   1A2
0DB3:  BSF    0A.3
....................     write_eeprom16(EE_startup_oc_time, startup_oc_time); 
0DB4:  MOVLW  04
0DB5:  BSF    03.6
0DB6:  MOVWF  34
0DB7:  BCF    03.6
0DB8:  MOVF   34,W
0DB9:  BSF    03.6
0DBA:  MOVWF  36
0DBB:  BCF    03.6
0DBC:  MOVF   33,W
0DBD:  BSF    03.6
0DBE:  MOVWF  35
0DBF:  BCF    0A.3
0DC0:  BCF    03.6
0DC1:  CALL   1A2
0DC2:  BSF    0A.3
....................     write_eeprom8(EE_RS485_ID, RS485_ID); 
0DC3:  MOVLW  05
0DC4:  BSF    03.6
0DC5:  MOVWF  39
0DC6:  BCF    03.6
0DC7:  MOVF   35,W
0DC8:  BSF    03.6
0DC9:  MOVWF  3A
0DCA:  BCF    0A.3
0DCB:  BCF    03.6
0DCC:  CALL   186
0DCD:  BSF    0A.3
....................     write_eeprom8(EE_relay_status_closed, relay_status_closed); 
0DCE:  MOVLW  06
0DCF:  BSF    03.6
0DD0:  MOVWF  39
0DD1:  BCF    03.6
0DD2:  MOVF   37,W
0DD3:  BSF    03.6
0DD4:  MOVWF  3A
0DD5:  BCF    0A.3
0DD6:  BCF    03.6
0DD7:  CALL   186
0DD8:  BSF    0A.3
....................  
....................     // Now read it back just to be sure... 
....................     if( (startup_oc_threshold != read_eeprom16(EE_startup_oc_threshold)) || 
....................         (steady_oc_threshold != read_eeprom16(EE_steady_oc_threshold))   || 
....................         (startup_oc_time != read_eeprom16(EE_startup_oc_time))           || 
....................         (RS485_ID != read_eeprom(EE_RS485_ID))                           || 
....................         (relay_status_closed != read_eeprom(EE_relay_status_closed)) ) { 
0DD9:  BSF    03.6
0DDA:  CLRF   34
0DDB:  BCF    0A.3
0DDC:  BCF    03.6
0DDD:  CALL   16F
0DDE:  BSF    0A.3
0DDF:  MOVF   79,W
0DE0:  MOVWF  7A
0DE1:  MOVF   78,W
0DE2:  SUBWF  2F,W
0DE3:  BTFSS  03.2
0DE4:  GOTO   623
0DE5:  MOVF   7A,W
0DE6:  SUBWF  30,W
0DE7:  BTFSS  03.2
0DE8:  GOTO   623
0DE9:  MOVLW  02
0DEA:  BSF    03.6
0DEB:  MOVWF  34
0DEC:  BCF    0A.3
0DED:  BCF    03.6
0DEE:  CALL   16F
0DEF:  BSF    0A.3
0DF0:  MOVF   79,W
0DF1:  MOVWF  7A
0DF2:  MOVF   78,W
0DF3:  SUBWF  31,W
0DF4:  BTFSS  03.2
0DF5:  GOTO   623
0DF6:  MOVF   7A,W
0DF7:  SUBWF  32,W
0DF8:  BTFSS  03.2
0DF9:  GOTO   623
0DFA:  MOVLW  04
0DFB:  BSF    03.6
0DFC:  MOVWF  34
0DFD:  BCF    0A.3
0DFE:  BCF    03.6
0DFF:  CALL   16F
0E00:  BSF    0A.3
0E01:  MOVF   79,W
0E02:  MOVWF  7A
0E03:  MOVF   78,W
0E04:  SUBWF  33,W
0E05:  BTFSS  03.2
0E06:  GOTO   623
0E07:  MOVF   7A,W
0E08:  SUBWF  34,W
0E09:  BTFSS  03.2
0E0A:  GOTO   623
0E0B:  MOVLW  05
0E0C:  BSF    03.6
0E0D:  MOVWF  0D
0E0E:  BSF    03.5
0E0F:  BCF    0C.7
0E10:  BSF    0C.0
0E11:  BCF    03.5
0E12:  MOVF   0C,W
0E13:  BCF    03.6
0E14:  SUBWF  35,W
0E15:  BTFSS  03.2
0E16:  GOTO   623
0E17:  MOVLW  06
0E18:  BSF    03.6
0E19:  MOVWF  0D
0E1A:  BSF    03.5
0E1B:  BCF    0C.7
0E1C:  BSF    0C.0
0E1D:  BCF    03.5
0E1E:  MOVF   0C,W
0E1F:  BCF    03.6
0E20:  SUBWF  37,W
0E21:  BTFSC  03.2
0E22:  GOTO   625
....................       // There was an error. Set the error bit and  
....................       // don't initialize from flash on boot 
....................       flash_write_err = true; 
0E23:  BSF    3C.1
....................     } 
....................     else { 
0E24:  GOTO   632
....................       // Write "secret code" in order to initialize  
....................       // parameters from flash upon boot next time 
....................       eeprom_written = 0x99; // set to 10011001 (or 0x99) for safety 
0E25:  MOVLW  99
0E26:  MOVWF  36
....................       write_eeprom8(EE_eeprom_written, eeprom_written); 
0E27:  MOVLW  07
0E28:  BSF    03.6
0E29:  MOVWF  39
0E2A:  BCF    03.6
0E2B:  MOVF   36,W
0E2C:  BSF    03.6
0E2D:  MOVWF  3A
0E2E:  BCF    0A.3
0E2F:  BCF    03.6
0E30:  CALL   186
0E31:  BSF    0A.3
....................     }  	 
....................   } 
....................  
....................   // Always initialize the comms relays to a known state.  
....................   if(relay_status_closed == 1) { 
0E32:  DECFSZ 37,W
0E33:  GOTO   644
....................     output_bit(PIN_B2, HI);  
0E34:  BSF    06.2
0E35:  BSF    03.5
0E36:  BCF    06.2
....................     delay_ms(8);           // Hold time for latching relay 
0E37:  MOVLW  08
0E38:  BSF    03.6
0E39:  MOVWF  10
0E3A:  BCF    0A.3
0E3B:  BCF    03.5
0E3C:  BCF    03.6
0E3D:  CALL   434
0E3E:  BSF    0A.3
....................     output_bit(PIN_B2, LO);   	 
0E3F:  BCF    06.2
0E40:  BSF    03.5
0E41:  BCF    06.2
....................   } 
....................   // circuit is set open 
....................   else { 
0E42:  GOTO   652
0E43:  BCF    03.5
....................     output_bit(PIN_B1, HI);  
0E44:  BSF    06.1
0E45:  BSF    03.5
0E46:  BCF    06.1
....................     delay_ms(8);           // Hold time for latching relay 
0E47:  MOVLW  08
0E48:  BSF    03.6
0E49:  MOVWF  10
0E4A:  BCF    0A.3
0E4B:  BCF    03.5
0E4C:  BCF    03.6
0E4D:  CALL   434
0E4E:  BSF    0A.3
....................     output_bit(PIN_B1, LO);   	 
0E4F:  BCF    06.1
0E50:  BSF    03.5
0E51:  BCF    06.1
....................   } 
....................  
....................  
....................   // Check for WDT reboot 
....................   if(wdt_reset) { 
0E52:  BCF    03.5
0E53:  BTFSS  3D.5
0E54:  GOTO   656
....................     // Set error bit for next transmission 
....................     wdt_reset_err = true;    
0E55:  BSF    3D.1
....................   }   
....................   //*** DEBUG - to be removed. Should interface spec include "alphabet soup" on power up? 
.................... //  sprintf(response_message, "MBARI Load Controller v1.0\r\n"); 
.................... //  send_response(response_message);   
.................... //  sprintf(response_message, "Enter Command"); 
.................... //  send_485_response(response_message); 
....................   //*** DEBUG 	 
.................... } 
0E56:  BSF    0A.3
0E57:  BSF    0A.4
0E58:  GOTO   505 (RETURN)
....................  
.................... // Purpose: Initialization for the Slave (iso) PIC 
.................... #SEPARATE 
.................... void initializeSlave() { 
....................  
....................   // Initialize SPI bus. SS_DISABLED since A5 is potentially a high input. 
....................   // See Document: DS39582B-page 71 for more info 
....................   SETUP_SPI(SPI_SS_DISABLED | SPI_SLAVE | SPI_L_TO_H);  
*
033E:  BCF    14.5
033F:  BCF    6F.5
0340:  MOVF   6F,W
0341:  BSF    03.5
0342:  MOVWF  07
0343:  BCF    03.5
0344:  BSF    6F.4
0345:  MOVF   6F,W
0346:  BSF    03.5
0347:  MOVWF  07
0348:  BCF    03.5
0349:  BSF    6F.3
034A:  MOVF   6F,W
034B:  BSF    03.5
034C:  MOVWF  07
034D:  MOVLW  25
034E:  BCF    03.5
034F:  MOVWF  14
0350:  MOVLW  00
0351:  BSF    03.5
0352:  MOVWF  14
....................  
....................   // Initialize Outputs/Inputs 
....................   set_tris_a(0x2F); // Pins A5, A3, A2, A1, A0 inputs. Pin A4 output 
0353:  MOVLW  2F
0354:  MOVWF  05
....................   set_tris_b(0xC0); // Pins B7, B6 inputs. Pins B5, B4, B3, B2, B1, B0 outputs. 
0355:  MOVLW  C0
0356:  MOVWF  06
....................   set_tris_c(0x19); // Pins C4, C3, C0 inputs. Pins C7, C6, C5, C2, C1 outputs. 
0357:  MOVLW  19
0358:  MOVWF  07
0359:  BCF    03.5
035A:  MOVWF  6F
....................  
....................   // Set outputs low 
....................   output_bit(PIN_A4, LO); 
035B:  BCF    05.4
035C:  BSF    03.5
035D:  BCF    05.4
....................   output_bit(PIN_B5, LO); 
035E:  BCF    03.5
035F:  BCF    06.5
0360:  BSF    03.5
0361:  BCF    06.5
....................   output_bit(PIN_B4, LO); 
0362:  BCF    03.5
0363:  BCF    06.4
0364:  BSF    03.5
0365:  BCF    06.4
....................   output_bit(PIN_B3, LO); 
0366:  BCF    03.5
0367:  BCF    06.3
0368:  BSF    03.5
0369:  BCF    06.3
....................   output_bit(PIN_B2, LO); 
036A:  BCF    03.5
036B:  BCF    06.2
036C:  BSF    03.5
036D:  BCF    06.2
....................   output_bit(PIN_B1, LO); 
036E:  BCF    03.5
036F:  BCF    06.1
0370:  BSF    03.5
0371:  BCF    06.1
....................   output_bit(PIN_B0, LO); 
0372:  BCF    03.5
0373:  BCF    06.0
0374:  BSF    03.5
0375:  BCF    06.0
.................... 	output_bit(PIN_C1, LO); 
0376:  BCF    03.5
0377:  BCF    07.1
0378:  BCF    6F.1
0379:  MOVF   6F,W
037A:  BSF    03.5
037B:  MOVWF  07
.................... 	output_bit(PIN_C2, LO); 
037C:  BCF    03.5
037D:  BCF    07.2
037E:  BCF    6F.2
037F:  MOVF   6F,W
0380:  BSF    03.5
0381:  MOVWF  07
.................... 	output_bit(PIN_C5, LO);	 
0382:  BCF    03.5
0383:  BCF    07.5
0384:  BCF    6F.5
0385:  MOVF   6F,W
0386:  BSF    03.5
0387:  MOVWF  07
....................   output_bit(PIN_C6, LO); 
0388:  BCF    03.5
0389:  BCF    07.6
038A:  BCF    6F.6
038B:  MOVF   6F,W
038C:  BSF    03.5
038D:  MOVWF  07
....................   output_bit(PIN_C7, LO); 
038E:  BCF    03.5
038F:  BCF    07.7
0390:  BCF    6F.7
0391:  MOVF   6F,W
0392:  BSF    03.5
0393:  MOVWF  07
....................      
....................   // Set up analog input for AN0, AN1, AN5 
....................   setup_adc(ADC_CLOCK_INTERNAL); 
0394:  BCF    1F.6
0395:  BCF    03.5
0396:  BSF    1F.6
0397:  BSF    1F.7
0398:  BSF    03.5
0399:  BSF    1F.7
039A:  BCF    03.5
039B:  BSF    1F.0
....................   setup_adc_ports(AN0_AN1_AN4_VREF_VREF); // A0 A1 A5 VRef+=A3 VRef-=A2   
039C:  BSF    03.5
039D:  BCF    1F.0
039E:  BCF    1F.1
039F:  BCF    1F.2
03A0:  BSF    1F.3
....................    
....................   // Check for parameters stored in data EEPROM and 
....................   // initialze from there if set 
....................   if( read_eeprom(EE_eeprom_written) == 0x99 ) { 
03A1:  MOVLW  07
03A2:  BCF    03.5
03A3:  BSF    03.6
03A4:  MOVWF  0D
03A5:  BSF    03.5
03A6:  BCF    0C.7
03A7:  BSF    0C.0
03A8:  BCF    03.5
03A9:  MOVF   0C,W
03AA:  SUBLW  99
03AB:  BTFSS  03.2
03AC:  GOTO   3C8
....................   	startup_oc_threshold = read_eeprom16(EE_startup_oc_threshold); 
03AD:  CLRF   34
03AE:  BCF    03.6
03AF:  CALL   16F
03B0:  MOVF   79,W
03B1:  MOVWF  30
03B2:  MOVF   78,W
03B3:  MOVWF  2F
....................     steady_oc_threshold = read_eeprom16(EE_steady_oc_threshold); 
03B4:  MOVLW  02
03B5:  BSF    03.6
03B6:  MOVWF  34
03B7:  BCF    03.6
03B8:  CALL   16F
03B9:  MOVF   79,W
03BA:  MOVWF  32
03BB:  MOVF   78,W
03BC:  MOVWF  31
....................     startup_oc_time = read_eeprom16(EE_startup_oc_time); 
03BD:  MOVLW  04
03BE:  BSF    03.6
03BF:  MOVWF  34
03C0:  BCF    03.6
03C1:  CALL   16F
03C2:  MOVF   79,W
03C3:  MOVWF  34
03C4:  MOVF   78,W
03C5:  MOVWF  33
....................   } 
....................   else { // Write the interface parameters to flash for the first time 
03C6:  GOTO   426
03C7:  BSF    03.6
....................     write_eeprom16(EE_startup_oc_threshold, startup_oc_threshold); 
03C8:  CLRF   34
03C9:  BCF    03.6
03CA:  MOVF   30,W
03CB:  BSF    03.6
03CC:  MOVWF  36
03CD:  BCF    03.6
03CE:  MOVF   2F,W
03CF:  BSF    03.6
03D0:  MOVWF  35
03D1:  BCF    03.6
03D2:  CALL   1A2
....................     write_eeprom16(EE_steady_oc_threshold, steady_oc_threshold); 
03D3:  MOVLW  02
03D4:  BSF    03.6
03D5:  MOVWF  34
03D6:  BCF    03.6
03D7:  MOVF   32,W
03D8:  BSF    03.6
03D9:  MOVWF  36
03DA:  BCF    03.6
03DB:  MOVF   31,W
03DC:  BSF    03.6
03DD:  MOVWF  35
03DE:  BCF    03.6
03DF:  CALL   1A2
....................     write_eeprom16(EE_startup_oc_time, startup_oc_time); 
03E0:  MOVLW  04
03E1:  BSF    03.6
03E2:  MOVWF  34
03E3:  BCF    03.6
03E4:  MOVF   34,W
03E5:  BSF    03.6
03E6:  MOVWF  36
03E7:  BCF    03.6
03E8:  MOVF   33,W
03E9:  BSF    03.6
03EA:  MOVWF  35
03EB:  BCF    03.6
03EC:  CALL   1A2
....................  
....................     // Now read it back just to be sure... 
....................     if( (startup_oc_threshold != read_eeprom16(EE_startup_oc_threshold)) || 
....................         (steady_oc_threshold != read_eeprom16(EE_steady_oc_threshold))   || 
....................         (startup_oc_time != read_eeprom16(EE_startup_oc_time)) ) {     
03ED:  BSF    03.6
03EE:  CLRF   34
03EF:  BCF    03.6
03F0:  CALL   16F
03F1:  MOVF   79,W
03F2:  MOVWF  7A
03F3:  MOVF   78,W
03F4:  SUBWF  2F,W
03F5:  BTFSS  03.2
03F6:  GOTO   419
03F7:  MOVF   7A,W
03F8:  SUBWF  30,W
03F9:  BTFSS  03.2
03FA:  GOTO   419
03FB:  MOVLW  02
03FC:  BSF    03.6
03FD:  MOVWF  34
03FE:  BCF    03.6
03FF:  CALL   16F
0400:  MOVF   79,W
0401:  MOVWF  7A
0402:  MOVF   78,W
0403:  SUBWF  31,W
0404:  BTFSS  03.2
0405:  GOTO   419
0406:  MOVF   7A,W
0407:  SUBWF  32,W
0408:  BTFSS  03.2
0409:  GOTO   419
040A:  MOVLW  04
040B:  BSF    03.6
040C:  MOVWF  34
040D:  BCF    03.6
040E:  CALL   16F
040F:  MOVF   79,W
0410:  MOVWF  7A
0411:  MOVF   78,W
0412:  SUBWF  33,W
0413:  BTFSS  03.2
0414:  GOTO   419
0415:  MOVF   7A,W
0416:  SUBWF  34,W
0417:  BTFSC  03.2
0418:  GOTO   41B
....................       // There was an error. Set the error bit and  
....................       // don't initialize from flash on boot 
....................       flash_write_err_slave = true; 
0419:  BSF    3C.0
....................     } 
....................     else { 
041A:  GOTO   426
....................       // Write "secret code" in order to initialize  
....................       // parameters from flash upon boot next time 
....................       eeprom_written = 0x99; // set to 10011001 (or 0x99) for safety 
041B:  MOVLW  99
041C:  MOVWF  36
....................       write_eeprom8(EE_eeprom_written, eeprom_written); 
041D:  MOVLW  07
041E:  BSF    03.6
041F:  MOVWF  39
0420:  BCF    03.6
0421:  MOVF   36,W
0422:  BSF    03.6
0423:  MOVWF  3A
0424:  BCF    03.6
0425:  CALL   186
....................     }  	 
....................   } 
....................  
....................   // Check for WDT reboot 
....................   if(wdt_reset) { 
0426:  BTFSS  3D.5
0427:  GOTO   429
....................     // Set error bit 
....................     wdt_reset_err = true; 
0428:  BSF    3D.1
....................   } 
....................  
....................   // Set ADC allowable maximum 
....................   calc_adc_val_nominal(); 
0429:  CALL   228
....................   calc_adc_val_startup(); 
042A:  CALL   2B3
....................  
....................   // Set interrupt masking 
....................   enable_interrupts(GLOBAL); 
042B:  MOVLW  C0
042C:  IORWF  0B,F
....................   disable_interrupts(INT_AD);    //disables A/D interrupt 
042D:  BSF    03.5
042E:  BCF    0C.6
....................   enable_interrupts(INT_TIMER1); // fires up the timer interrupt   
042F:  BSF    0C.0
.................... } 
0430:  BCF    03.5
0431:  BSF    0A.3
0432:  BCF    0A.4
0433:  GOTO   0F4 (RETURN)
....................  
....................  
.................... // Purpose: Main control loop for Master (non-iso) PIC 
.................... #SEPARATE 
.................... void mainMaster() { 
....................   // 
....................   // Interface Specification Command Definitions: 
....................   // 
....................   // Control Command definitions 
....................   int8 load_power[]="LD"; 
*
1C8C:  MOVLW  4C
1C8D:  BSF    03.5
1C8E:  MOVWF  50
1C8F:  MOVLW  44
1C90:  MOVWF  51
1C91:  CLRF   52
....................   int8 comm_relay[]="CR"; 
1C92:  MOVLW  43
1C93:  MOVWF  53
1C94:  MOVLW  52
1C95:  MOVWF  54
1C96:  CLRF   55
....................   int8 sleep_enable[]="SE"; 
1C97:  MOVLW  53
1C98:  MOVWF  56
1C99:  MOVLW  45
1C9A:  MOVWF  57
1C9B:  CLRF   58
....................   int8 clear_errors[]="CE"; 
1C9C:  MOVLW  43
1C9D:  MOVWF  59
1C9E:  MOVLW  45
1C9F:  MOVWF  5A
1CA0:  CLRF   5B
....................    
....................   //Read Status Command definitions 
....................   int8 read_bus_voltage[]="?BV"; 
1CA1:  MOVLW  3F
1CA2:  MOVWF  5C
1CA3:  MOVLW  42
1CA4:  MOVWF  5D
1CA5:  MOVLW  56
1CA6:  MOVWF  5E
1CA7:  CLRF   5F
....................   int8 read_load_voltage[]= "?LV"; 
1CA8:  MOVLW  3F
1CA9:  MOVWF  60
1CAA:  MOVLW  4C
1CAB:  MOVWF  61
1CAC:  MOVLW  56
1CAD:  MOVWF  62
1CAE:  CLRF   63
....................   int8 read_bus_current[]= "?BC"; 
1CAF:  MOVLW  3F
1CB0:  MOVWF  64
1CB1:  MOVLW  42
1CB2:  MOVWF  65
1CB3:  MOVLW  43
1CB4:  MOVWF  66
1CB5:  CLRF   67
....................   int8 read_load_current[]= "?LC"; 
1CB6:  MOVLW  3F
1CB7:  MOVWF  68
1CB8:  MOVLW  4C
1CB9:  MOVWF  69
1CBA:  MOVLW  43
1CBB:  MOVWF  6A
1CBC:  CLRF   6B
....................   int8 read_gf_current[]= "?FC"; 
1CBD:  MOVLW  3F
1CBE:  MOVWF  6C
1CBF:  MOVLW  46
1CC0:  MOVWF  6D
1CC1:  MOVLW  43
1CC2:  MOVWF  6E
1CC3:  CLRF   6F
....................   int8 read_startup_oc_threshold[]= "?SO"; 
1CC4:  MOVLW  3F
1CC5:  BCF    03.5
1CC6:  BSF    03.6
1CC7:  MOVWF  10
1CC8:  MOVLW  53
1CC9:  MOVWF  11
1CCA:  MOVLW  4F
1CCB:  MOVWF  12
1CCC:  CLRF   13
....................   int8 read_q_oc_threshold[]= "?SS"; 
1CCD:  MOVLW  3F
1CCE:  MOVWF  14
1CCF:  MOVLW  53
1CD0:  MOVWF  15
1CD1:  MOVWF  16
1CD2:  CLRF   17
....................   int8 read_startup_oc_time[]= "?TP"; 
1CD3:  MOVLW  3F
1CD4:  MOVWF  18
1CD5:  MOVLW  54
1CD6:  MOVWF  19
1CD7:  MOVLW  50
1CD8:  MOVWF  1A
1CD9:  CLRF   1B
....................   int8 read_comm_realy_status[]= "?CR"; 
1CDA:  MOVLW  3F
1CDB:  MOVWF  1C
1CDC:  MOVLW  43
1CDD:  MOVWF  1D
1CDE:  MOVLW  52
1CDF:  MOVWF  1E
1CE0:  CLRF   1F
....................   int8 read_device_serial_number[]= "?SN"; 
1CE1:  MOVLW  3F
1CE2:  MOVWF  20
1CE3:  MOVLW  53
1CE4:  MOVWF  21
1CE5:  MOVLW  4E
1CE6:  MOVWF  22
1CE7:  CLRF   23
....................   int8 read_version[]= "?VR"; 
1CE8:  MOVLW  3F
1CE9:  MOVWF  24
1CEA:  MOVLW  56
1CEB:  MOVWF  25
1CEC:  MOVLW  52
1CED:  MOVWF  26
1CEE:  CLRF   27
....................    
....................   //Threshold Command definitions 
....................   int8 oc_threshold_startup[]="SO"; 
1CEF:  MOVLW  53
1CF0:  MOVWF  28
1CF1:  MOVLW  4F
1CF2:  MOVWF  29
1CF3:  CLRF   2A
....................   int8 oc_threshold_q[]= "SS"; 
1CF4:  MOVLW  53
1CF5:  MOVWF  2B
1CF6:  MOVWF  2C
1CF7:  CLRF   2D
....................   int8 oc_time_startup[]="TP"; 
1CF8:  MOVLW  54
1CF9:  MOVWF  2E
1CFA:  MOVLW  50
1CFB:  MOVWF  2F
1CFC:  CLRF   30
....................   int8 set_address[]="SN"; 
1CFD:  MOVLW  53
1CFE:  MOVWF  31
1CFF:  MOVLW  4E
1D00:  MOVWF  32
1D01:  CLRF   33
....................    
....................   // Initialize the PIC 
....................   initializeMaster(); 
1D02:  BCF    0A.4
1D03:  BCF    03.6
1D04:  GOTO   4F7
1D05:  BSF    0A.4
....................  
....................   /* Begin Loop */         
....................   for(;;) 
.................... 	{  
.................... 	  // strobe the dog 
.................... 	  restart_wdt();  
1D06:  CLRWDT
.................... 	 
.................... 	  // Check for new RS485 command 
....................  		if(rs485_get_new_message(false))  
1D07:  BSF    03.6
1D08:  CLRF   34
1D09:  BCF    0A.4
1D0A:  BCF    03.6
1D0B:  GOTO   659
1D0C:  BSF    0A.4
1D0D:  MOVF   78,F
1D0E:  BTFSC  03.2
1D0F:  GOTO   66E
.................... 	 	{ 
.................... 	    cmd_received = true; 
1D10:  BSF    3D.4
....................   	         
.................... 	 	  // Check to see which command was received... 
.................... 	 	  // And call associated handler 
....................       if(!stricmp(commandStr,load_power)) { 
1D11:  BSF    03.6
1D12:  CLRF   35
1D13:  MOVLW  71
1D14:  MOVWF  34
1D15:  CLRF   37
1D16:  MOVLW  D0
1D17:  MOVWF  36
1D18:  BCF    0A.3
1D19:  BCF    03.6
1D1A:  CALL   000
1D1B:  BSF    0A.3
1D1C:  MOVF   78,F
1D1D:  BTFSS  03.2
1D1E:  GOTO   523
....................         handle_load_power(); 
1D1F:  BCF    0A.3
1D20:  GOTO   4C3
1D21:  BSF    0A.3
....................       } 
....................       else if(!stricmp(commandStr,comm_relay)) { 
1D22:  GOTO   66E
1D23:  BSF    03.6
1D24:  CLRF   35
1D25:  MOVLW  71
1D26:  MOVWF  34
1D27:  CLRF   37
1D28:  MOVLW  D3
1D29:  MOVWF  36
1D2A:  BCF    0A.3
1D2B:  BCF    03.6
1D2C:  CALL   000
1D2D:  BSF    0A.3
1D2E:  MOVF   78,F
1D2F:  BTFSS  03.2
1D30:  GOTO   535
....................      	  handle_comm_relay(); 
1D31:  BCF    0A.3
1D32:  GOTO   588
1D33:  BSF    0A.3
....................       }   
....................       else if(!stricmp(commandStr,sleep_enable)) { 
1D34:  GOTO   66E
1D35:  BSF    03.6
1D36:  CLRF   35
1D37:  MOVLW  71
1D38:  MOVWF  34
1D39:  CLRF   37
1D3A:  MOVLW  D6
1D3B:  MOVWF  36
1D3C:  BCF    0A.3
1D3D:  BCF    03.6
1D3E:  CALL   000
1D3F:  BSF    0A.3
1D40:  MOVF   78,F
1D41:  BTFSS  03.2
1D42:  GOTO   547
....................      	  handle_sleep_enable(); 
1D43:  BCF    0A.3
1D44:  GOTO   5E9
1D45:  BSF    0A.3
....................       } 
....................       else if(!stricmp(commandStr,clear_errors)) { 
1D46:  GOTO   66E
1D47:  BSF    03.6
1D48:  CLRF   35
1D49:  MOVLW  71
1D4A:  MOVWF  34
1D4B:  CLRF   37
1D4C:  MOVLW  D9
1D4D:  MOVWF  36
1D4E:  BCF    0A.3
1D4F:  BCF    03.6
1D50:  CALL   000
1D51:  BSF    0A.3
1D52:  MOVF   78,F
1D53:  BTFSS  03.2
1D54:  GOTO   559
....................      	  handle_clear_errors(); 
1D55:  BCF    0A.3
1D56:  GOTO   613
1D57:  BSF    0A.3
....................       }       
....................       else if(!stricmp(commandStr,read_bus_voltage)) { 
1D58:  GOTO   66E
1D59:  BSF    03.6
1D5A:  CLRF   35
1D5B:  MOVLW  71
1D5C:  MOVWF  34
1D5D:  CLRF   37
1D5E:  MOVLW  DC
1D5F:  MOVWF  36
1D60:  BCF    0A.3
1D61:  BCF    03.6
1D62:  CALL   000
1D63:  BSF    0A.3
1D64:  MOVF   78,F
1D65:  BTFSS  03.2
1D66:  GOTO   56B
....................      	  handle_read_bus_voltage(); 
1D67:  BCF    0A.3
1D68:  GOTO   666
1D69:  BSF    0A.3
....................       }   
....................       else if(!stricmp(commandStr,read_load_voltage)) { 
1D6A:  GOTO   66E
1D6B:  BSF    03.6
1D6C:  CLRF   35
1D6D:  MOVLW  71
1D6E:  MOVWF  34
1D6F:  CLRF   37
1D70:  MOVLW  E0
1D71:  MOVWF  36
1D72:  BCF    0A.3
1D73:  BCF    03.6
1D74:  CALL   000
1D75:  BSF    0A.3
1D76:  MOVF   78,F
1D77:  BTFSS  03.2
1D78:  GOTO   57D
....................      	  handle_read_load_voltage(); 
1D79:  BCF    0A.3
1D7A:  GOTO   6AC
1D7B:  BSF    0A.3
....................       } 
....................       else if(!stricmp(commandStr,read_bus_current)) { 
1D7C:  GOTO   66E
1D7D:  BSF    03.6
1D7E:  CLRF   35
1D7F:  MOVLW  71
1D80:  MOVWF  34
1D81:  CLRF   37
1D82:  MOVLW  E4
1D83:  MOVWF  36
1D84:  BCF    0A.3
1D85:  BCF    03.6
1D86:  CALL   000
1D87:  BSF    0A.3
1D88:  MOVF   78,F
1D89:  BTFSS  03.2
1D8A:  GOTO   58F
....................      	  handle_read_bus_current(); 
1D8B:  BCF    0A.3
1D8C:  GOTO   6F7
1D8D:  BSF    0A.3
....................       }       
....................       else if(!stricmp(commandStr,read_load_current)) { 
1D8E:  GOTO   66E
1D8F:  BSF    03.6
1D90:  CLRF   35
1D91:  MOVLW  71
1D92:  MOVWF  34
1D93:  CLRF   37
1D94:  MOVLW  E8
1D95:  MOVWF  36
1D96:  BCF    0A.3
1D97:  BCF    03.6
1D98:  CALL   000
1D99:  BSF    0A.3
1D9A:  MOVF   78,F
1D9B:  BTFSS  03.2
1D9C:  GOTO   5A1
....................      	  handle_read_load_current(); 
1D9D:  BCF    0A.3
1D9E:  GOTO   743
1D9F:  BSF    0A.3
....................       }   
....................       else if(!stricmp(commandStr,read_gf_current)) { 
1DA0:  GOTO   66E
1DA1:  BSF    03.6
1DA2:  CLRF   35
1DA3:  MOVLW  71
1DA4:  MOVWF  34
1DA5:  CLRF   37
1DA6:  MOVLW  EC
1DA7:  MOVWF  36
1DA8:  BCF    0A.3
1DA9:  BCF    03.6
1DAA:  CALL   000
1DAB:  BSF    0A.3
1DAC:  MOVF   78,F
1DAD:  BTFSS  03.2
1DAE:  GOTO   5B1
....................      	  handle_read_gf_current(); 
1DAF:  GOTO   000
....................       } 
....................       else if(!stricmp(commandStr,read_startup_oc_threshold)) { 
1DB0:  GOTO   66E
1DB1:  BSF    03.6
1DB2:  CLRF   35
1DB3:  MOVLW  71
1DB4:  MOVWF  34
1DB5:  MOVLW  01
1DB6:  MOVWF  37
1DB7:  MOVLW  10
1DB8:  MOVWF  36
1DB9:  BCF    0A.3
1DBA:  BCF    03.6
1DBB:  CALL   000
1DBC:  BSF    0A.3
1DBD:  MOVF   78,F
1DBE:  BTFSS  03.2
1DBF:  GOTO   5C4
....................      	  handle_read_startup_oc_threshold(); 
1DC0:  BCF    0A.3
1DC1:  GOTO   78E
1DC2:  BSF    0A.3
....................       }   
....................       else if(!stricmp(commandStr,read_q_oc_threshold)) { 
1DC3:  GOTO   66E
1DC4:  BSF    03.6
1DC5:  CLRF   35
1DC6:  MOVLW  71
1DC7:  MOVWF  34
1DC8:  MOVLW  01
1DC9:  MOVWF  37
1DCA:  MOVLW  14
1DCB:  MOVWF  36
1DCC:  BCF    0A.3
1DCD:  BCF    03.6
1DCE:  CALL   000
1DCF:  BSF    0A.3
1DD0:  MOVF   78,F
1DD1:  BTFSS  03.2
1DD2:  GOTO   5D7
....................      	  handle_read_q_oc_threshold(); 
1DD3:  BCF    0A.3
1DD4:  GOTO   7A9
1DD5:  BSF    0A.3
....................       } 
....................       else if(!stricmp(commandStr,read_startup_oc_time)) { 
1DD6:  GOTO   66E
1DD7:  BSF    03.6
1DD8:  CLRF   35
1DD9:  MOVLW  71
1DDA:  MOVWF  34
1DDB:  MOVLW  01
1DDC:  MOVWF  37
1DDD:  MOVLW  18
1DDE:  MOVWF  36
1DDF:  BCF    0A.3
1DE0:  BCF    03.6
1DE1:  CALL   000
1DE2:  BSF    0A.3
1DE3:  MOVF   78,F
1DE4:  BTFSS  03.2
1DE5:  GOTO   5EA
....................      	  handle_read_startup_oc_time(); 
1DE6:  BCF    0A.3
1DE7:  GOTO   7C4
1DE8:  BSF    0A.3
....................       }   
....................       else if(!stricmp(commandStr,read_comm_realy_status)) { 
1DE9:  GOTO   66E
1DEA:  BSF    03.6
1DEB:  CLRF   35
1DEC:  MOVLW  71
1DED:  MOVWF  34
1DEE:  MOVLW  01
1DEF:  MOVWF  37
1DF0:  MOVLW  1C
1DF1:  MOVWF  36
1DF2:  BCF    0A.3
1DF3:  BCF    03.6
1DF4:  CALL   000
1DF5:  BSF    0A.3
1DF6:  MOVF   78,F
1DF7:  BTFSS  03.2
1DF8:  GOTO   5FD
....................      	  handle_read_comm_realy_status(); 
1DF9:  BCF    0A.3
1DFA:  GOTO   7DF
1DFB:  BSF    0A.3
....................       } 
....................       else if(!stricmp(commandStr,read_device_serial_number)) { 
1DFC:  GOTO   66E
1DFD:  BSF    03.6
1DFE:  CLRF   35
1DFF:  MOVLW  71
1E00:  MOVWF  34
1E01:  MOVLW  01
1E02:  MOVWF  37
1E03:  MOVLW  20
1E04:  MOVWF  36
1E05:  BCF    0A.3
1E06:  BCF    03.6
1E07:  CALL   000
1E08:  BSF    0A.3
1E09:  MOVF   78,F
1E0A:  BTFSS  03.2
1E0B:  GOTO   610
....................      	  handle_read_device_serial_number(); 
1E0C:  BCF    0A.3
1E0D:  GOTO   7F6
1E0E:  BSF    0A.3
....................       }   
....................       else if(!stricmp(commandStr,read_version)) { 
1E0F:  GOTO   66E
1E10:  BSF    03.6
1E11:  CLRF   35
1E12:  MOVLW  71
1E13:  MOVWF  34
1E14:  MOVLW  01
1E15:  MOVWF  37
1E16:  MOVLW  24
1E17:  MOVWF  36
1E18:  BCF    0A.3
1E19:  BCF    03.6
1E1A:  CALL   000
1E1B:  BSF    0A.3
1E1C:  MOVF   78,F
1E1D:  BTFSS  03.2
1E1E:  GOTO   621
....................      	  handle_sw_version(); 
1E1F:  GOTO   08C
....................       } 
....................       else if(!stricmp(commandStr,oc_threshold_startup)) { 
1E20:  GOTO   66E
1E21:  BSF    03.6
1E22:  CLRF   35
1E23:  MOVLW  71
1E24:  MOVWF  34
1E25:  MOVLW  01
1E26:  MOVWF  37
1E27:  MOVLW  28
1E28:  MOVWF  36
1E29:  BCF    0A.3
1E2A:  BCF    03.6
1E2B:  CALL   000
1E2C:  BSF    0A.3
1E2D:  MOVF   78,F
1E2E:  BTFSS  03.2
1E2F:  GOTO   632
....................      	  handle_oc_threshold_startup(); 
1E30:  GOTO   122
....................       }   
....................       else if(!stricmp(commandStr,oc_threshold_q)) { 
1E31:  GOTO   66E
1E32:  BSF    03.6
1E33:  CLRF   35
1E34:  MOVLW  71
1E35:  MOVWF  34
1E36:  MOVLW  01
1E37:  MOVWF  37
1E38:  MOVLW  2B
1E39:  MOVWF  36
1E3A:  BCF    0A.3
1E3B:  BCF    03.6
1E3C:  CALL   000
1E3D:  BSF    0A.3
1E3E:  MOVF   78,F
1E3F:  BTFSS  03.2
1E40:  GOTO   643
....................      	  handle_oc_threshold_q(); 
1E41:  GOTO   23F
....................       } 
....................       else if(!stricmp(commandStr,oc_time_startup)) { 
1E42:  GOTO   66E
1E43:  BSF    03.6
1E44:  CLRF   35
1E45:  MOVLW  71
1E46:  MOVWF  34
1E47:  MOVLW  01
1E48:  MOVWF  37
1E49:  MOVLW  2E
1E4A:  MOVWF  36
1E4B:  BCF    0A.3
1E4C:  BCF    03.6
1E4D:  CALL   000
1E4E:  BSF    0A.3
1E4F:  MOVF   78,F
1E50:  BTFSS  03.2
1E51:  GOTO   654
....................      	  handle_oc_time_startup(); 
1E52:  GOTO   33F
....................       }   
....................       else if(!stricmp(commandStr,set_address)) { 
1E53:  GOTO   66E
1E54:  BSF    03.6
1E55:  CLRF   35
1E56:  MOVLW  71
1E57:  MOVWF  34
1E58:  MOVLW  01
1E59:  MOVWF  37
1E5A:  MOVLW  31
1E5B:  MOVWF  36
1E5C:  BCF    0A.3
1E5D:  BCF    03.6
1E5E:  CALL   000
1E5F:  BSF    0A.3
1E60:  MOVF   78,F
1E61:  BTFSS  03.2
1E62:  GOTO   665
....................      	  handle_set_address(); 
1E63:  GOTO   434
....................       }                                          
....................       //...Or if the command is invalid 
....................       else {  
1E64:  GOTO   66E
....................       	// Send a command error 
....................   	    invld_cmd_err = true; 
1E65:  BSF    3C.6
....................   	    send_485_response(empty_string[0]); 
1E66:  BSF    03.6
1E67:  CLRF   35
1E68:  CLRF   34
1E69:  BCF    0A.3
1E6A:  BCF    03.6
1E6B:  CALL   147
1E6C:  BSF    0A.3
....................         // wait for a new command 
....................         cmd_received = false; 
1E6D:  BCF    3D.4
....................       } 
.................... 		}	// Check for new command 
.................... 		 
.................... 	  //*** DEBUG - The rest of the functionality (e.g. BIT) goes here	   
....................      
....................  
....................    
....................   } // Close of main control loop 
1E6E:  GOTO   506
.................... 	 
.................... } 
1E6F:  BSF    0A.3
1E70:  BSF    0A.4
1E71:  GOTO   6EA (RETURN)
....................  
....................  
.................... // Purpose: Main control loop for Slave (iso) PIC 
.................... #SEPARATE 
.................... void mainSlave() { 
.................... static const int32 GF_RSENSE = 402; // 402 ohms 
.................... static const int16 GF_VSCALE = 4048;   // 4.048 reference voltage 
....................  
....................   int8 spi_cmd_buff[1] = {28}; 
*
08EE:  MOVLW  1C
08EF:  BSF    03.5
08F0:  MOVWF  50
....................   char sent_spi_data_slave[MAX_SPI_CHARS]; 
....................   char received_spi_data_slave[MAX_SPI_CHARS]; // *** DEBUG 
....................    
....................   // Initialize the PIC 
....................   initializeSlave(); 
08F1:  BCF    0A.3
08F2:  BCF    03.5
08F3:  GOTO   33E
08F4:  BSF    0A.3
....................    
....................   // Begin the main loop.  
....................   // This loop waits for a SPI bus command from the Master 
....................   for(;;) { 
....................   	 
....................     // strobe the dog 
.................... 	  restart_wdt();  
08F5:  CLRWDT
....................  
....................     // Check for new SPI command 
....................     if( spi_data_is_in() ) { 
08F6:  BSF    03.5
08F7:  BTFSS  14.0
08F8:  GOTO   4E6
....................     	spi_cmd_buff[0] = spi_read();  
08F9:  BCF    03.5
08FA:  MOVF   13,W
08FB:  BSF    03.5
08FC:  MOVWF  50
....................  
....................       // Handle Read GF Currents 
....................       // Chan 0 
....................       if( spi_cmd_buff[0] == 1 ) { 
08FD:  DECFSZ 50,W
08FE:  GOTO   15F
....................         set_adc_channel(1);	 
08FF:  MOVLW  08
0900:  MOVWF  78
0901:  BCF    03.5
0902:  MOVF   1F,W
0903:  ANDLW  C7
0904:  IORWF  78,W
0905:  MOVWF  1F
....................         output_bit(PIN_B1, HI);  // Switch GF channel on 
0906:  BSF    06.1
0907:  BSF    03.5
0908:  BCF    06.1
....................         delay_ms(1);             // Rise time to AN1 ~ .25 msec 
0909:  MOVLW  01
090A:  BSF    03.6
090B:  MOVWF  10
090C:  BCF    0A.3
090D:  BCF    03.5
090E:  BCF    03.6
090F:  CALL   434
0910:  BSF    0A.3
....................         //do_adc_current_calcs(VREF, GF_VSCALE, GF_RSENSE, CURRDIVISOR); // Calculate current 
....................         do_adc_voltage_calcs(GF_VSCALE); 
0911:  MOVLW  0F
0912:  BSF    03.6
0913:  MOVWF  35
0914:  MOVLW  D0
0915:  MOVWF  34
0916:  BCF    0A.3
0917:  BCF    03.6
0918:  CALL   44C
0919:  BSF    0A.3
....................         output_bit(PIN_B1, LO);  // Switch GF channel off 
091A:  BCF    06.1
091B:  BSF    03.5
091C:  BCF    06.1
....................         sprintf(sent_spi_data_slave, "%5.3w",(adc_value_glob/1000));     // Send back the results 
091D:  BCF    03.5
091E:  MOVF   41,W
091F:  BSF    03.6
0920:  MOVWF  44
0921:  BCF    03.6
0922:  MOVF   40,W
0923:  BSF    03.6
0924:  MOVWF  43
0925:  BCF    03.6
0926:  MOVF   3F,W
0927:  BSF    03.6
0928:  MOVWF  42
0929:  BCF    03.6
092A:  MOVF   3E,W
092B:  BSF    03.6
092C:  MOVWF  41
092D:  CLRF   48
092E:  CLRF   47
092F:  MOVLW  03
0930:  MOVWF  46
0931:  MOVLW  E8
0932:  MOVWF  45
0933:  BCF    0A.3
0934:  BCF    03.6
0935:  CALL   1E4
0936:  BSF    0A.3
0937:  MOVF   7A,W
0938:  BSF    03.6
0939:  MOVWF  13
093A:  MOVF   79,W
093B:  MOVWF  12
093C:  MOVF   78,W
093D:  MOVWF  11
093E:  MOVF   77,W
093F:  MOVWF  10
0940:  BCF    03.6
0941:  CLRF   6E
0942:  MOVLW  D1
0943:  MOVWF  6D
0944:  MOVLW  05
0945:  MOVWF  04
0946:  BSF    03.6
0947:  MOVF   13,W
0948:  MOVWF  37
0949:  MOVF   12,W
094A:  MOVWF  36
094B:  MOVF   11,W
094C:  MOVWF  35
094D:  MOVF   10,W
094E:  MOVWF  34
094F:  MOVLW  03
0950:  MOVWF  38
0951:  BCF    0A.3
0952:  BCF    03.6
0953:  CALL   4C8
0954:  BSF    0A.3
....................         SPI_strwrite(sent_spi_data_slave);  	               
0955:  BSF    03.6
0956:  CLRF   35
0957:  MOVLW  D1
0958:  MOVWF  34
0959:  BCF    0A.3
095A:  BCF    03.6
095B:  CALL   541
095C:  BSF    0A.3
....................     	}  
....................       // Chan 1    	 
....................       else if( spi_cmd_buff[0] == 2 ) { 
095D:  GOTO   4E5
095E:  BSF    03.5
095F:  MOVF   50,W
0960:  SUBLW  02
0961:  BTFSS  03.2
0962:  GOTO   1C3
....................         set_adc_channel(1);	 
0963:  MOVLW  08
0964:  MOVWF  78
0965:  BCF    03.5
0966:  MOVF   1F,W
0967:  ANDLW  C7
0968:  IORWF  78,W
0969:  MOVWF  1F
....................         output_bit(PIN_B2, HI);  // Switch GF channel on 
096A:  BSF    06.2
096B:  BSF    03.5
096C:  BCF    06.2
....................         delay_ms(1);             // Rise time to AN1 ~ .25 msec 
096D:  MOVLW  01
096E:  BSF    03.6
096F:  MOVWF  10
0970:  BCF    0A.3
0971:  BCF    03.5
0972:  BCF    03.6
0973:  CALL   434
0974:  BSF    0A.3
....................         //do_adc_current_calcs(VREF, GF_VSCALE, GF_RSENSE, CURRDIVISOR); // Calculate current            
....................         do_adc_voltage_calcs(GF_VSCALE); 
0975:  MOVLW  0F
0976:  BSF    03.6
0977:  MOVWF  35
0978:  MOVLW  D0
0979:  MOVWF  34
097A:  BCF    0A.3
097B:  BCF    03.6
097C:  CALL   44C
097D:  BSF    0A.3
....................         output_bit(PIN_B2, LO);  // Switch GF channel off 
097E:  BCF    06.2
097F:  BSF    03.5
0980:  BCF    06.2
....................  
....................         sprintf(sent_spi_data_slave, "%5.3w",(adc_value_glob/1000));     // Send back the results 
0981:  BCF    03.5
0982:  MOVF   41,W
0983:  BSF    03.6
0984:  MOVWF  44
0985:  BCF    03.6
0986:  MOVF   40,W
0987:  BSF    03.6
0988:  MOVWF  43
0989:  BCF    03.6
098A:  MOVF   3F,W
098B:  BSF    03.6
098C:  MOVWF  42
098D:  BCF    03.6
098E:  MOVF   3E,W
098F:  BSF    03.6
0990:  MOVWF  41
0991:  CLRF   48
0992:  CLRF   47
0993:  MOVLW  03
0994:  MOVWF  46
0995:  MOVLW  E8
0996:  MOVWF  45
0997:  BCF    0A.3
0998:  BCF    03.6
0999:  CALL   1E4
099A:  BSF    0A.3
099B:  MOVF   7A,W
099C:  BSF    03.6
099D:  MOVWF  13
099E:  MOVF   79,W
099F:  MOVWF  12
09A0:  MOVF   78,W
09A1:  MOVWF  11
09A2:  MOVF   77,W
09A3:  MOVWF  10
09A4:  BCF    03.6
09A5:  CLRF   6E
09A6:  MOVLW  D1
09A7:  MOVWF  6D
09A8:  MOVLW  05
09A9:  MOVWF  04
09AA:  BSF    03.6
09AB:  MOVF   13,W
09AC:  MOVWF  37
09AD:  MOVF   12,W
09AE:  MOVWF  36
09AF:  MOVF   11,W
09B0:  MOVWF  35
09B1:  MOVF   10,W
09B2:  MOVWF  34
09B3:  MOVLW  03
09B4:  MOVWF  38
09B5:  BCF    0A.3
09B6:  BCF    03.6
09B7:  CALL   4C8
09B8:  BSF    0A.3
....................         SPI_strwrite(sent_spi_data_slave);       		 
09B9:  BSF    03.6
09BA:  CLRF   35
09BB:  MOVLW  D1
09BC:  MOVWF  34
09BD:  BCF    0A.3
09BE:  BCF    03.6
09BF:  CALL   541
09C0:  BSF    0A.3
....................     	}     	 
....................     	// Chan 2 
....................     	else if( spi_cmd_buff[0] == 3 ) {   
09C1:  GOTO   4E5
09C2:  BSF    03.5
09C3:  MOVF   50,W
09C4:  SUBLW  03
09C5:  BTFSS  03.2
09C6:  GOTO   227
....................         set_adc_channel(1);	 
09C7:  MOVLW  08
09C8:  MOVWF  78
09C9:  BCF    03.5
09CA:  MOVF   1F,W
09CB:  ANDLW  C7
09CC:  IORWF  78,W
09CD:  MOVWF  1F
....................         output_bit(PIN_B3, HI);  // Switch GF channel on 
09CE:  BSF    06.3
09CF:  BSF    03.5
09D0:  BCF    06.3
....................         delay_ms(1);             // Rise time to AN1 ~ .25 msec 
09D1:  MOVLW  01
09D2:  BSF    03.6
09D3:  MOVWF  10
09D4:  BCF    0A.3
09D5:  BCF    03.5
09D6:  BCF    03.6
09D7:  CALL   434
09D8:  BSF    0A.3
....................         //do_adc_current_calcs(VREF, GF_VSCALE, GF_RSENSE, CURRDIVISOR); // Calculate current 
....................         do_adc_voltage_calcs(GF_VSCALE); 
09D9:  MOVLW  0F
09DA:  BSF    03.6
09DB:  MOVWF  35
09DC:  MOVLW  D0
09DD:  MOVWF  34
09DE:  BCF    0A.3
09DF:  BCF    03.6
09E0:  CALL   44C
09E1:  BSF    0A.3
....................         output_bit(PIN_B3, LO);  // Switch GF channel off 
09E2:  BCF    06.3
09E3:  BSF    03.5
09E4:  BCF    06.3
....................  
....................         sprintf(sent_spi_data_slave, "%5.3w",(adc_value_glob/1000));     // Send back the results 
09E5:  BCF    03.5
09E6:  MOVF   41,W
09E7:  BSF    03.6
09E8:  MOVWF  44
09E9:  BCF    03.6
09EA:  MOVF   40,W
09EB:  BSF    03.6
09EC:  MOVWF  43
09ED:  BCF    03.6
09EE:  MOVF   3F,W
09EF:  BSF    03.6
09F0:  MOVWF  42
09F1:  BCF    03.6
09F2:  MOVF   3E,W
09F3:  BSF    03.6
09F4:  MOVWF  41
09F5:  CLRF   48
09F6:  CLRF   47
09F7:  MOVLW  03
09F8:  MOVWF  46
09F9:  MOVLW  E8
09FA:  MOVWF  45
09FB:  BCF    0A.3
09FC:  BCF    03.6
09FD:  CALL   1E4
09FE:  BSF    0A.3
09FF:  MOVF   7A,W
0A00:  BSF    03.6
0A01:  MOVWF  13
0A02:  MOVF   79,W
0A03:  MOVWF  12
0A04:  MOVF   78,W
0A05:  MOVWF  11
0A06:  MOVF   77,W
0A07:  MOVWF  10
0A08:  BCF    03.6
0A09:  CLRF   6E
0A0A:  MOVLW  D1
0A0B:  MOVWF  6D
0A0C:  MOVLW  05
0A0D:  MOVWF  04
0A0E:  BSF    03.6
0A0F:  MOVF   13,W
0A10:  MOVWF  37
0A11:  MOVF   12,W
0A12:  MOVWF  36
0A13:  MOVF   11,W
0A14:  MOVWF  35
0A15:  MOVF   10,W
0A16:  MOVWF  34
0A17:  MOVLW  03
0A18:  MOVWF  38
0A19:  BCF    0A.3
0A1A:  BCF    03.6
0A1B:  CALL   4C8
0A1C:  BSF    0A.3
....................         SPI_strwrite(sent_spi_data_slave);            		 
0A1D:  BSF    03.6
0A1E:  CLRF   35
0A1F:  MOVLW  D1
0A20:  MOVWF  34
0A21:  BCF    0A.3
0A22:  BCF    03.6
0A23:  CALL   541
0A24:  BSF    0A.3
....................     	} 
....................     	// Chan 3 
....................     	else if( spi_cmd_buff[0] == 4 ) { 
0A25:  GOTO   4E5
0A26:  BSF    03.5
0A27:  MOVF   50,W
0A28:  SUBLW  04
0A29:  BTFSS  03.2
0A2A:  GOTO   28B
....................         set_adc_channel(1);	 
0A2B:  MOVLW  08
0A2C:  MOVWF  78
0A2D:  BCF    03.5
0A2E:  MOVF   1F,W
0A2F:  ANDLW  C7
0A30:  IORWF  78,W
0A31:  MOVWF  1F
....................         output_bit(PIN_B4, HI);  // Switch GF channel on 
0A32:  BSF    06.4
0A33:  BSF    03.5
0A34:  BCF    06.4
....................         delay_ms(1);             // Rise time to AN1 ~ .25 msec 
0A35:  MOVLW  01
0A36:  BSF    03.6
0A37:  MOVWF  10
0A38:  BCF    0A.3
0A39:  BCF    03.5
0A3A:  BCF    03.6
0A3B:  CALL   434
0A3C:  BSF    0A.3
....................         //do_adc_current_calcs(VREF, GF_VSCALE, GF_RSENSE, CURRDIVISOR); // Calculate current 
....................         do_adc_voltage_calcs(GF_VSCALE); 
0A3D:  MOVLW  0F
0A3E:  BSF    03.6
0A3F:  MOVWF  35
0A40:  MOVLW  D0
0A41:  MOVWF  34
0A42:  BCF    0A.3
0A43:  BCF    03.6
0A44:  CALL   44C
0A45:  BSF    0A.3
....................         output_bit(PIN_B4, LO);  // Switch GF channel off 
0A46:  BCF    06.4
0A47:  BSF    03.5
0A48:  BCF    06.4
....................  
....................         sprintf(sent_spi_data_slave, "%5.3w",(adc_value_glob/1000));     // Send back the results 
0A49:  BCF    03.5
0A4A:  MOVF   41,W
0A4B:  BSF    03.6
0A4C:  MOVWF  44
0A4D:  BCF    03.6
0A4E:  MOVF   40,W
0A4F:  BSF    03.6
0A50:  MOVWF  43
0A51:  BCF    03.6
0A52:  MOVF   3F,W
0A53:  BSF    03.6
0A54:  MOVWF  42
0A55:  BCF    03.6
0A56:  MOVF   3E,W
0A57:  BSF    03.6
0A58:  MOVWF  41
0A59:  CLRF   48
0A5A:  CLRF   47
0A5B:  MOVLW  03
0A5C:  MOVWF  46
0A5D:  MOVLW  E8
0A5E:  MOVWF  45
0A5F:  BCF    0A.3
0A60:  BCF    03.6
0A61:  CALL   1E4
0A62:  BSF    0A.3
0A63:  MOVF   7A,W
0A64:  BSF    03.6
0A65:  MOVWF  13
0A66:  MOVF   79,W
0A67:  MOVWF  12
0A68:  MOVF   78,W
0A69:  MOVWF  11
0A6A:  MOVF   77,W
0A6B:  MOVWF  10
0A6C:  BCF    03.6
0A6D:  CLRF   6E
0A6E:  MOVLW  D1
0A6F:  MOVWF  6D
0A70:  MOVLW  05
0A71:  MOVWF  04
0A72:  BSF    03.6
0A73:  MOVF   13,W
0A74:  MOVWF  37
0A75:  MOVF   12,W
0A76:  MOVWF  36
0A77:  MOVF   11,W
0A78:  MOVWF  35
0A79:  MOVF   10,W
0A7A:  MOVWF  34
0A7B:  MOVLW  03
0A7C:  MOVWF  38
0A7D:  BCF    0A.3
0A7E:  BCF    03.6
0A7F:  CALL   4C8
0A80:  BSF    0A.3
....................         SPI_strwrite(sent_spi_data_slave); 		 
0A81:  BSF    03.6
0A82:  CLRF   35
0A83:  MOVLW  D1
0A84:  MOVWF  34
0A85:  BCF    0A.3
0A86:  BCF    03.6
0A87:  CALL   541
0A88:  BSF    0A.3
....................     	} 
....................     	// End of Ground Faults 
....................     	 
....................       // Handle Load voltage 
....................       else if( spi_cmd_buff[0] == 50 ) { 
0A89:  GOTO   4E5
0A8A:  BSF    03.5
0A8B:  MOVF   50,W
0A8C:  SUBLW  32
0A8D:  BTFSS  03.2
0A8E:  GOTO   2C2
....................         set_adc_channel(0);	 
0A8F:  MOVLW  00
0A90:  MOVWF  78
0A91:  BCF    03.5
0A92:  MOVF   1F,W
0A93:  ANDLW  C7
0A94:  IORWF  78,W
0A95:  MOVWF  1F
....................         do_adc_voltage_calcs(12); 
0A96:  BSF    03.6
0A97:  CLRF   35
0A98:  MOVLW  0C
0A99:  MOVWF  34
0A9A:  BCF    0A.3
0A9B:  BCF    03.6
0A9C:  CALL   44C
0A9D:  BSF    0A.3
....................  	      sprintf(sent_spi_data_slave, "%5.3w",adc_value_glob);  
0A9E:  CLRF   6E
0A9F:  MOVLW  D1
0AA0:  MOVWF  6D
0AA1:  MOVLW  05
0AA2:  MOVWF  04
0AA3:  MOVF   41,W
0AA4:  BSF    03.6
0AA5:  MOVWF  37
0AA6:  BCF    03.6
0AA7:  MOVF   40,W
0AA8:  BSF    03.6
0AA9:  MOVWF  36
0AAA:  BCF    03.6
0AAB:  MOVF   3F,W
0AAC:  BSF    03.6
0AAD:  MOVWF  35
0AAE:  BCF    03.6
0AAF:  MOVF   3E,W
0AB0:  BSF    03.6
0AB1:  MOVWF  34
0AB2:  MOVLW  03
0AB3:  MOVWF  38
0AB4:  BCF    0A.3
0AB5:  BCF    03.6
0AB6:  CALL   4C8
0AB7:  BSF    0A.3
....................         SPI_strwrite(sent_spi_data_slave);    	 
0AB8:  BSF    03.6
0AB9:  CLRF   35
0ABA:  MOVLW  D1
0ABB:  MOVWF  34
0ABC:  BCF    0A.3
0ABD:  BCF    03.6
0ABE:  CALL   541
0ABF:  BSF    0A.3
....................     	}    	 
....................  
....................     	// Handle Load current 
....................     	else if( spi_cmd_buff[0] == 51 ) { 
0AC0:  GOTO   4E5
0AC1:  BSF    03.5
0AC2:  MOVF   50,W
0AC3:  SUBLW  33
0AC4:  BTFSS  03.2
0AC5:  GOTO   2FF
....................         set_adc_channel(4);	                                     // Set A/D channel 
0AC6:  MOVLW  20
0AC7:  MOVWF  78
0AC8:  BCF    03.5
0AC9:  MOVF   1F,W
0ACA:  ANDLW  C7
0ACB:  IORWF  78,W
0ACC:  MOVWF  1F
....................         do_adc_current_calcs(VREF, VREF, RSENSE, CURRDIVISOR);   // Calculate current. In this case, VREF == VSCALE 
0ACD:  MOVLW  10
0ACE:  BSF    03.6
0ACF:  MOVWF  35
0AD0:  CLRF   34
0AD1:  MOVWF  37
0AD2:  CLRF   36
0AD3:  MOVLW  C8
0AD4:  MOVWF  38
0AD5:  MOVLW  05
0AD6:  MOVWF  39
0AD7:  BCF    0A.3
0AD8:  BCF    03.6
0AD9:  CALL   56C
0ADA:  BSF    0A.3
....................         sprintf(sent_spi_data_slave, "%5.3w",adc_value_glob);      // Send back the results 
0ADB:  CLRF   6E
0ADC:  MOVLW  D1
0ADD:  MOVWF  6D
0ADE:  MOVLW  05
0ADF:  MOVWF  04
0AE0:  MOVF   41,W
0AE1:  BSF    03.6
0AE2:  MOVWF  37
0AE3:  BCF    03.6
0AE4:  MOVF   40,W
0AE5:  BSF    03.6
0AE6:  MOVWF  36
0AE7:  BCF    03.6
0AE8:  MOVF   3F,W
0AE9:  BSF    03.6
0AEA:  MOVWF  35
0AEB:  BCF    03.6
0AEC:  MOVF   3E,W
0AED:  BSF    03.6
0AEE:  MOVWF  34
0AEF:  MOVLW  03
0AF0:  MOVWF  38
0AF1:  BCF    0A.3
0AF2:  BCF    03.6
0AF3:  CALL   4C8
0AF4:  BSF    0A.3
....................         SPI_strwrite(sent_spi_data_slave);  		 
0AF5:  BSF    03.6
0AF6:  CLRF   35
0AF7:  MOVLW  D1
0AF8:  MOVWF  34
0AF9:  BCF    0A.3
0AFA:  BCF    03.6
0AFB:  CALL   541
0AFC:  BSF    0A.3
....................     	} 
....................     	 
....................     	// Set Thresholds 
....................     	// Startup Overcurrent Threshold 
....................     	else if( spi_cmd_buff[0] == 60 ) { 
0AFD:  GOTO   4E5
0AFE:  BSF    03.5
0AFF:  MOVF   50,W
0B00:  SUBLW  3C
0B01:  BTFSS  03.2
0B02:  GOTO   352
....................         SPI_slave_strread(received_spi_data_slave); // Get the parameter 
0B03:  BCF    03.5
0B04:  BSF    03.6
0B05:  CLRF   11
0B06:  MOVLW  DC
0B07:  MOVWF  10
0B08:  BCF    0A.3
0B09:  BCF    03.6
0B0A:  CALL   649
0B0B:  BSF    0A.3
....................         startup_oc_threshold = atoi32(received_spi_data_slave);         
0B0C:  BSF    03.6
0B0D:  CLRF   36
0B0E:  MOVLW  DC
0B0F:  MOVWF  35
0B10:  BCF    0A.3
0B11:  BCF    03.6
0B12:  CALL   66D
0B13:  BSF    0A.3
0B14:  MOVF   78,W
0B15:  MOVWF  30
0B16:  MOVF   77,W
0B17:  MOVWF  2F
....................  
....................         sprintf(sent_spi_data_slave, "%Lu",startup_oc_threshold); // Send back the results 
0B18:  CLRF   6E
0B19:  MOVLW  D1
0B1A:  MOVWF  6D
0B1B:  MOVLW  10
0B1C:  MOVWF  04
0B1D:  MOVF   30,W
0B1E:  BSF    03.6
0B1F:  MOVWF  35
0B20:  BCF    03.6
0B21:  MOVF   2F,W
0B22:  BSF    03.6
0B23:  MOVWF  34
0B24:  BCF    03.6
0B25:  CALL   000
....................         SPI_strwrite(sent_spi_data_slave);  		 
0B26:  BSF    03.6
0B27:  CLRF   35
0B28:  MOVLW  D1
0B29:  MOVWF  34
0B2A:  BCF    0A.3
0B2B:  BCF    03.6
0B2C:  CALL   541
0B2D:  BSF    0A.3
....................         calc_adc_val_startup(); // Calculate the maximum allowed ADC output for current checking 
0B2E:  BCF    0A.3
0B2F:  CALL   2B3
0B30:  BSF    0A.3
....................      
....................         // Save the parameter to flash 
....................         write_eeprom16(EE_startup_oc_threshold, startup_oc_threshold); 
0B31:  BSF    03.6
0B32:  CLRF   34
0B33:  BCF    03.6
0B34:  MOVF   30,W
0B35:  BSF    03.6
0B36:  MOVWF  36
0B37:  BCF    03.6
0B38:  MOVF   2F,W
0B39:  BSF    03.6
0B3A:  MOVWF  35
0B3B:  BCF    0A.3
0B3C:  BCF    03.6
0B3D:  CALL   1A2
0B3E:  BSF    0A.3
....................         // Now read it back just to be sure... 
....................         if( (startup_oc_threshold != read_eeprom16(EE_startup_oc_threshold)) ) {     
0B3F:  BSF    03.6
0B40:  CLRF   34
0B41:  BCF    0A.3
0B42:  BCF    03.6
0B43:  CALL   16F
0B44:  BSF    0A.3
0B45:  MOVF   79,W
0B46:  MOVWF  7A
0B47:  MOVF   78,W
0B48:  SUBWF  2F,W
0B49:  BTFSS  03.2
0B4A:  GOTO   34F
0B4B:  MOVF   7A,W
0B4C:  SUBWF  30,W
0B4D:  BTFSC  03.2
0B4E:  GOTO   350
....................           // There was an error. 
....................           flash_write_err_slave = true; 
0B4F:  BSF    3C.0
....................         }         
....................     	}    	 
....................     	// Overcurrent Threshold Nominal 
....................     	else if( spi_cmd_buff[0] == 61 ) { 
0B50:  GOTO   4E5
0B51:  BSF    03.5
0B52:  MOVF   50,W
0B53:  SUBLW  3D
0B54:  BTFSS  03.2
0B55:  GOTO   3A7
....................         SPI_slave_strread(received_spi_data_slave); // Get the parameter 
0B56:  BCF    03.5
0B57:  BSF    03.6
0B58:  CLRF   11
0B59:  MOVLW  DC
0B5A:  MOVWF  10
0B5B:  BCF    0A.3
0B5C:  BCF    03.6
0B5D:  CALL   649
0B5E:  BSF    0A.3
....................         steady_oc_threshold = atoi32(received_spi_data_slave); 
0B5F:  BSF    03.6
0B60:  CLRF   36
0B61:  MOVLW  DC
0B62:  MOVWF  35
0B63:  BCF    0A.3
0B64:  BCF    03.6
0B65:  CALL   66D
0B66:  BSF    0A.3
0B67:  MOVF   78,W
0B68:  MOVWF  32
0B69:  MOVF   77,W
0B6A:  MOVWF  31
....................          
....................         sprintf(sent_spi_data_slave, "%Lu",steady_oc_threshold); // Send back the results 
0B6B:  CLRF   6E
0B6C:  MOVLW  D1
0B6D:  MOVWF  6D
0B6E:  MOVLW  10
0B6F:  MOVWF  04
0B70:  MOVF   32,W
0B71:  BSF    03.6
0B72:  MOVWF  35
0B73:  BCF    03.6
0B74:  MOVF   31,W
0B75:  BSF    03.6
0B76:  MOVWF  34
0B77:  BCF    03.6
0B78:  CALL   000
....................         SPI_strwrite(sent_spi_data_slave);  	 
0B79:  BSF    03.6
0B7A:  CLRF   35
0B7B:  MOVLW  D1
0B7C:  MOVWF  34
0B7D:  BCF    0A.3
0B7E:  BCF    03.6
0B7F:  CALL   541
0B80:  BSF    0A.3
....................         calc_adc_val_nominal(); // Calculate the maximum allowed ADC output for current checking 
0B81:  BCF    0A.3
0B82:  CALL   228
0B83:  BSF    0A.3
....................  
....................         // Save the parameter to flash 
....................         write_eeprom16(EE_steady_oc_threshold, steady_oc_threshold); 
0B84:  MOVLW  02
0B85:  BSF    03.6
0B86:  MOVWF  34
0B87:  BCF    03.6
0B88:  MOVF   32,W
0B89:  BSF    03.6
0B8A:  MOVWF  36
0B8B:  BCF    03.6
0B8C:  MOVF   31,W
0B8D:  BSF    03.6
0B8E:  MOVWF  35
0B8F:  BCF    0A.3
0B90:  BCF    03.6
0B91:  CALL   1A2
0B92:  BSF    0A.3
....................         // Now read it back just to be sure... 
....................         if( (steady_oc_threshold != read_eeprom16(EE_steady_oc_threshold)) ) {     
0B93:  MOVLW  02
0B94:  BSF    03.6
0B95:  MOVWF  34
0B96:  BCF    0A.3
0B97:  BCF    03.6
0B98:  CALL   16F
0B99:  BSF    0A.3
0B9A:  MOVF   79,W
0B9B:  MOVWF  7A
0B9C:  MOVF   78,W
0B9D:  SUBWF  31,W
0B9E:  BTFSS  03.2
0B9F:  GOTO   3A4
0BA0:  MOVF   7A,W
0BA1:  SUBWF  32,W
0BA2:  BTFSC  03.2
0BA3:  GOTO   3A5
....................           // There was an error. 
....................           flash_write_err_slave = true; 
0BA4:  BSF    3C.0
....................         }         
....................     	}  
....................     	// Startup Overcurrent Time 
....................     	else if( spi_cmd_buff[0] == 62 ) { 
0BA5:  GOTO   4E5
0BA6:  BSF    03.5
0BA7:  MOVF   50,W
0BA8:  SUBLW  3E
0BA9:  BTFSS  03.2
0BAA:  GOTO   3F9
....................         SPI_slave_strread(received_spi_data_slave); // Get the parameter 
0BAB:  BCF    03.5
0BAC:  BSF    03.6
0BAD:  CLRF   11
0BAE:  MOVLW  DC
0BAF:  MOVWF  10
0BB0:  BCF    0A.3
0BB1:  BCF    03.6
0BB2:  CALL   649
0BB3:  BSF    0A.3
....................         startup_oc_time = atoi32(received_spi_data_slave); 
0BB4:  BSF    03.6
0BB5:  CLRF   36
0BB6:  MOVLW  DC
0BB7:  MOVWF  35
0BB8:  BCF    0A.3
0BB9:  BCF    03.6
0BBA:  CALL   66D
0BBB:  BSF    0A.3
0BBC:  MOVF   78,W
0BBD:  MOVWF  34
0BBE:  MOVF   77,W
0BBF:  MOVWF  33
....................          
....................         sprintf(sent_spi_data_slave, "%Lu",startup_oc_time); // Send back the results 
0BC0:  CLRF   6E
0BC1:  MOVLW  D1
0BC2:  MOVWF  6D
0BC3:  MOVLW  10
0BC4:  MOVWF  04
0BC5:  MOVF   34,W
0BC6:  BSF    03.6
0BC7:  MOVWF  35
0BC8:  BCF    03.6
0BC9:  MOVF   33,W
0BCA:  BSF    03.6
0BCB:  MOVWF  34
0BCC:  BCF    03.6
0BCD:  CALL   000
....................         SPI_strwrite(sent_spi_data_slave);  		 
0BCE:  BSF    03.6
0BCF:  CLRF   35
0BD0:  MOVLW  D1
0BD1:  MOVWF  34
0BD2:  BCF    0A.3
0BD3:  BCF    03.6
0BD4:  CALL   541
0BD5:  BSF    0A.3
....................  
....................         // Save the parameter to flash 
....................         write_eeprom16(EE_startup_oc_time, startup_oc_time); 
0BD6:  MOVLW  04
0BD7:  BSF    03.6
0BD8:  MOVWF  34
0BD9:  BCF    03.6
0BDA:  MOVF   34,W
0BDB:  BSF    03.6
0BDC:  MOVWF  36
0BDD:  BCF    03.6
0BDE:  MOVF   33,W
0BDF:  BSF    03.6
0BE0:  MOVWF  35
0BE1:  BCF    0A.3
0BE2:  BCF    03.6
0BE3:  CALL   1A2
0BE4:  BSF    0A.3
....................         // Now read it back just to be sure... 
....................         if( (startup_oc_time != read_eeprom16(EE_startup_oc_time)) ) {     
0BE5:  MOVLW  04
0BE6:  BSF    03.6
0BE7:  MOVWF  34
0BE8:  BCF    0A.3
0BE9:  BCF    03.6
0BEA:  CALL   16F
0BEB:  BSF    0A.3
0BEC:  MOVF   79,W
0BED:  MOVWF  7A
0BEE:  MOVF   78,W
0BEF:  SUBWF  33,W
0BF0:  BTFSS  03.2
0BF1:  GOTO   3F6
0BF2:  MOVF   7A,W
0BF3:  SUBWF  34,W
0BF4:  BTFSC  03.2
0BF5:  GOTO   3F7
....................           // There was an error. 
....................           flash_write_err_slave = true; 
0BF6:  BSF    3C.0
....................         }                
....................     	}  
....................     	// Load Control  
....................     	// Load power off 
....................     	else if( spi_cmd_buff[0] == 70 ) { 
0BF7:  GOTO   4E5
0BF8:  BSF    03.5
0BF9:  MOVF   50,W
0BFA:  SUBLW  46
0BFB:  BTFSS  03.2
0BFC:  GOTO   418
....................         output_bit(PIN_B5, LO); // Turn off load 
0BFD:  BCF    03.5
0BFE:  BCF    06.5
0BFF:  BSF    03.5
0C00:  BCF    06.5
....................         sprintf(sent_spi_data_slave, "%u",spi_cmd_buff[0]); // Send back the results 
0C01:  BCF    03.5
0C02:  CLRF   6E
0C03:  MOVLW  D1
0C04:  MOVWF  6D
0C05:  BSF    03.5
0C06:  MOVF   50,W
0C07:  BCF    03.5
0C08:  BSF    03.6
0C09:  MOVWF  5F
0C0A:  MOVLW  1B
0C0B:  MOVWF  60
0C0C:  BCF    03.6
0C0D:  CALL   069
....................         SPI_strwrite(sent_spi_data_slave);  		 
0C0E:  BSF    03.6
0C0F:  CLRF   35
0C10:  MOVLW  D1
0C11:  MOVWF  34
0C12:  BCF    0A.3
0C13:  BCF    03.6
0C14:  CALL   541
0C15:  BSF    0A.3
....................     	}    	 
....................      	// Load power on 
....................     	else if( spi_cmd_buff[0] == 71 ) { 
0C16:  GOTO   4E5
0C17:  BSF    03.5
0C18:  MOVF   50,W
0C19:  SUBLW  47
0C1A:  BTFSS  03.2
0C1B:  GOTO   437
....................         output_bit(PIN_B5, HI); // Turn on load 
0C1C:  BCF    03.5
0C1D:  BSF    06.5
0C1E:  BSF    03.5
0C1F:  BCF    06.5
....................         sprintf(sent_spi_data_slave, "%u",spi_cmd_buff[0]); // Send back the results 
0C20:  BCF    03.5
0C21:  CLRF   6E
0C22:  MOVLW  D1
0C23:  MOVWF  6D
0C24:  BSF    03.5
0C25:  MOVF   50,W
0C26:  BCF    03.5
0C27:  BSF    03.6
0C28:  MOVWF  5F
0C29:  MOVLW  1B
0C2A:  MOVWF  60
0C2B:  BCF    03.6
0C2C:  CALL   069
....................         SPI_strwrite(sent_spi_data_slave);  		 
0C2D:  BSF    03.6
0C2E:  CLRF   35
0C2F:  MOVLW  D1
0C30:  MOVWF  34
0C31:  BCF    0A.3
0C32:  BCF    03.6
0C33:  CALL   541
0C34:  BSF    0A.3
....................     	} 
....................     	// Error notification 
....................     	// Get Errors 
....................     	else if( spi_cmd_buff[0] == 80 ) { 
0C35:  GOTO   4E5
0C36:  BSF    03.5
0C37:  MOVF   50,W
0C38:  SUBLW  50
0C39:  BTFSS  03.2
0C3A:  GOTO   4C7
....................         //Calculate error bytes 
....................         error_status =( 
....................                       (flash_write_err   << 9) | 
....................                       (ground_fault_err  << 8) | 
....................                       (over_temp_err     << 7) | 
....................                       (over_curr_err     << 6) | 
....................                       (switch_err        << 5) | 
....................                       (invld_cmd_err     << 4) | 
....................                       (invld_param_err   << 3) | 
....................                       (invld_cksum_err   << 2) | 
....................                       (wdt_reset_err     << 1) | 
....................                       (slv_cmd_err       ) 
....................                       ); 
0C3B:  MOVLW  00
0C3C:  BCF    03.5
0C3D:  BTFSC  3C.1
0C3E:  MOVLW  01
0C3F:  BSF    03.6
0C40:  CLRF   11
0C41:  MOVLW  00
0C42:  BCF    03.6
0C43:  BTFSC  3C.2
0C44:  MOVLW  01
0C45:  MOVLW  00
0C46:  BSF    03.6
0C47:  IORWF  11,W
0C48:  MOVWF  13
0C49:  MOVLW  00
0C4A:  BCF    03.6
0C4B:  BTFSC  3C.3
0C4C:  MOVLW  01
0C4D:  MOVWF  77
0C4E:  RRF    77,W
0C4F:  CLRF   77
0C50:  BTFSC  03.0
0C51:  BSF    77.7
0C52:  MOVF   77,W
0C53:  BSF    03.6
0C54:  IORWF  13,W
0C55:  MOVWF  15
0C56:  MOVLW  00
0C57:  BCF    03.6
0C58:  BTFSC  3C.4
0C59:  MOVLW  01
0C5A:  MOVWF  77
0C5B:  SWAPF  77,F
0C5C:  RLF    77,F
0C5D:  RLF    77,F
0C5E:  MOVLW  C0
0C5F:  ANDWF  77,F
0C60:  MOVF   77,W
0C61:  BSF    03.6
0C62:  IORWF  15,W
0C63:  MOVWF  17
0C64:  MOVLW  00
0C65:  BCF    03.6
0C66:  BTFSC  3C.5
0C67:  MOVLW  01
0C68:  MOVWF  77
0C69:  SWAPF  77,F
0C6A:  RLF    77,F
0C6B:  MOVLW  E0
0C6C:  ANDWF  77,F
0C6D:  MOVF   77,W
0C6E:  BSF    03.6
0C6F:  IORWF  17,W
0C70:  MOVWF  19
0C71:  MOVLW  00
0C72:  BCF    03.6
0C73:  BTFSC  3C.6
0C74:  MOVLW  01
0C75:  MOVWF  77
0C76:  SWAPF  77,F
0C77:  MOVLW  F0
0C78:  ANDWF  77,F
0C79:  MOVF   77,W
0C7A:  BSF    03.6
0C7B:  IORWF  19,W
0C7C:  MOVWF  1B
0C7D:  MOVLW  00
0C7E:  BCF    03.6
0C7F:  BTFSC  3C.7
0C80:  MOVLW  01
0C81:  MOVWF  77
0C82:  RLF    77,F
0C83:  RLF    77,F
0C84:  RLF    77,F
0C85:  MOVLW  F8
0C86:  ANDWF  77,F
0C87:  MOVF   77,W
0C88:  BSF    03.6
0C89:  IORWF  1B,W
0C8A:  MOVWF  1D
0C8B:  MOVLW  00
0C8C:  BCF    03.6
0C8D:  BTFSC  3D.0
0C8E:  MOVLW  01
0C8F:  MOVWF  77
0C90:  RLF    77,F
0C91:  RLF    77,F
0C92:  MOVLW  FC
0C93:  ANDWF  77,F
0C94:  MOVF   77,W
0C95:  BSF    03.6
0C96:  IORWF  1D,W
0C97:  MOVWF  1F
0C98:  MOVLW  00
0C99:  BCF    03.6
0C9A:  BTFSC  3D.1
0C9B:  MOVLW  01
0C9C:  MOVWF  77
0C9D:  BCF    03.0
0C9E:  RLF    77,F
0C9F:  MOVF   77,W
0CA0:  BSF    03.6
0CA1:  IORWF  1F,W
0CA2:  MOVWF  21
0CA3:  MOVLW  00
0CA4:  BCF    03.6
0CA5:  BTFSC  3D.2
0CA6:  MOVLW  01
0CA7:  BSF    03.6
0CA8:  IORWF  21,W
0CA9:  BCF    03.6
0CAA:  MOVWF  38
0CAB:  CLRF   39
....................         sprintf(sent_spi_data_slave, "%LX",error_status); // Send back the results 
0CAC:  CLRF   6E
0CAD:  MOVLW  D1
0CAE:  MOVWF  6D
0CAF:  MOVF   39,W
0CB0:  BSF    03.6
0CB1:  MOVWF  61
0CB2:  MOVLW  37
0CB3:  MOVWF  62
0CB4:  BCF    03.6
0CB5:  CALL   0B2
0CB6:  MOVF   38,W
0CB7:  BSF    03.6
0CB8:  MOVWF  61
0CB9:  MOVLW  37
0CBA:  MOVWF  62
0CBB:  BCF    03.6
0CBC:  CALL   0B2
....................         SPI_strwrite(sent_spi_data_slave);          	 
0CBD:  BSF    03.6
0CBE:  CLRF   35
0CBF:  MOVLW  D1
0CC0:  MOVWF  34
0CC1:  BCF    0A.3
0CC2:  BCF    03.6
0CC3:  CALL   541
0CC4:  BSF    0A.3
....................     	}    	 
....................     	// Clear Errors 
....................     	else if( spi_cmd_buff[0] == 81 ) { 
0CC5:  GOTO   4E5
0CC6:  BSF    03.5
0CC7:  MOVF   50,W
0CC8:  SUBLW  51
0CC9:  BTFSS  03.2
0CCA:  GOTO   4E6
....................         clear_errors(true); //Clear all errors including persistent 
0CCB:  MOVLW  01
0CCC:  BCF    03.5
0CCD:  BSF    03.6
0CCE:  MOVWF  5F
0CCF:  BCF    03.6
0CD0:  CALL   0DB
....................          
....................         sprintf(sent_spi_data_slave, "%u",spi_cmd_buff[0]); // Send back the results 
0CD1:  CLRF   6E
0CD2:  MOVLW  D1
0CD3:  MOVWF  6D
0CD4:  BSF    03.5
0CD5:  MOVF   50,W
0CD6:  BCF    03.5
0CD7:  BSF    03.6
0CD8:  MOVWF  5F
0CD9:  MOVLW  1B
0CDA:  MOVWF  60
0CDB:  BCF    03.6
0CDC:  CALL   069
....................         SPI_strwrite(sent_spi_data_slave);  		      	 
0CDD:  BSF    03.6
0CDE:  CLRF   35
0CDF:  MOVLW  D1
0CE0:  MOVWF  34
0CE1:  BCF    0A.3
0CE2:  BCF    03.6
0CE3:  CALL   541
0CE4:  BSF    0A.3
0CE5:  BSF    03.5
....................     	}    	 
....................     	    	 
....................     }	// End spi_data_is_in 
....................  
....................   } // End main "slave" loop 
0CE6:  BCF    03.5
0CE7:  GOTO   0F5
.................... } 
0CE8:  BSF    0A.3
0CE9:  BSF    0A.4
0CEA:  GOTO   6E7 (RETURN)
....................  
....................  
....................  
.................... // 
.................... // Main execution loop. 
.................... // 
.................... #SEPARATE 
.................... main() 
.................... { 
*
1E72:  CLRF   04
1E73:  BCF    03.7
1E74:  MOVLW  1F
1E75:  ANDWF  03,F
1E76:  MOVLW  19
1E77:  BSF    03.5
1E78:  MOVWF  19
1E79:  MOVLW  A6
1E7A:  MOVWF  18
1E7B:  MOVLW  90
1E7C:  BCF    03.5
1E7D:  MOVWF  18
1E7E:  BSF    03.5
1E7F:  BSF    1F.0
1E80:  BSF    1F.1
1E81:  BSF    1F.2
1E82:  BCF    1F.3
1E83:  MOVLW  07
1E84:  MOVWF  1C
....................   // Check for WDT reset and output error if necessary 
....................   switch ( restart_cause() ) 
....................   { 
*
1EBE:  MOVF   03,W
1EBF:  ANDLW  18
1EC0:  MOVWF  77
1EC1:  BSF    03.5
1EC2:  MOVF   0E,W
1EC3:  ANDLW  03
1EC4:  IORWF  77,W
1EC5:  BSF    0E.0
1EC6:  BSF    0E.1
1EC7:  BSF    03.3
1EC8:  BSF    03.4
1EC9:  XORLW  03
1ECA:  BCF    03.5
1ECB:  BTFSC  03.2
1ECC:  GOTO   6D4
1ECD:  XORLW  08
1ECE:  BTFSC  03.2
1ECF:  GOTO   6D4
1ED0:  XORLW  13
1ED1:  BTFSC  03.2
1ED2:  GOTO   6D6
1ED3:  GOTO   6D8
....................   	case WDT_FROM_SLEEP: 
....................     case WDT_TIMEOUT: 
....................     { 
....................       wdt_reset = true; 
1ED4:  BSF    3D.5
....................       break; 
1ED5:  GOTO   6D8
....................     } 
....................     case NORMAL_POWER_UP: 
....................     { 
....................     	wdt_reset = false; 
1ED6:  BCF    3D.5
....................       break; 
1ED7:  GOTO   6D8
....................     } 
....................   }      
....................  
....................   // Run initialization common to both PICs 
....................   initializeLC(); 
1ED8:  BCF    0A.4
1ED9:  BCF    0A.3
1EDA:  GOTO   14D
1EDB:  BSF    0A.4
1EDC:  BSF    0A.3
....................  
....................   // Determine if controller is master or slave 
....................   if(input(PIN_C0) ) {  
1EDD:  BSF    6F.0
1EDE:  MOVF   6F,W
1EDF:  BSF    03.5
1EE0:  MOVWF  07
1EE1:  BCF    03.5
1EE2:  BTFSS  07.0
1EE3:  GOTO   6E9
....................   	master = false; 
1EE4:  BCF    3D.3
....................     mainSlave(); 
1EE5:  BCF    0A.4
1EE6:  GOTO   0EE
1EE7:  BSF    0A.4
....................   } 
....................   else { 
1EE8:  GOTO   6EA
....................   	mainMaster(); 
1EE9:  GOTO   48C
....................   } 
....................  
....................   // 
....................   // If we execute here, there has been a critical failure. Log error and reset the board 
....................   // 
....................    
....................   // log error here 
....................    
....................   software_reset();   
1EEA:  BCF    0A.4
1EEB:  GOTO   7F9
1EEC:  BSF    0A.4
....................  
.................... } 
....................  
....................  
....................  
....................  
....................  
1EED:  GOTO   6ED

Configuration Fuses:
   Word  1: 3731   XT NOWDT PUT DEBUG NOPROTECT NOBROWNOUT NOLVP NOCPD NOWRT
