CCS PCM C Compiler, Version 3.210, 25417               17-Sep-04 06:13

               Filename: freq_gen.LST

               ROM used: 735 words (18%)
                         Largest free fragment is 2048
               RAM used: 25 (13%) at main() level
                         30 (16%) worst case
               Stack:    4 worst case (3 in main + 1 for interrupts)

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   1EE
0003:  NOP
0004:  MOVWF  7F
0005:  SWAPF  03,W
0006:  CLRF   03
0007:  MOVWF  26
0008:  MOVF   7F,W
0009:  MOVWF  25
000A:  MOVF   0A,W
000B:  MOVWF  2D
000C:  CLRF   0A
000D:  SWAPF  25,F
000E:  MOVF   04,W
000F:  MOVWF  27
0010:  MOVF   20,W
0011:  MOVWF  28
0012:  MOVF   21,W
0013:  MOVWF  29
0014:  MOVF   22,W
0015:  MOVWF  2A
0016:  MOVF   23,W
0017:  MOVWF  2B
0018:  MOVF   24,W
0019:  MOVWF  2C
001A:  BCF    03.7
001B:  BCF    03.5
001C:  BTFSS  0B.5
001D:  GOTO   020
001E:  BTFSC  0B.2
001F:  GOTO   033
0020:  MOVF   27,W
0021:  MOVWF  04
0022:  MOVF   28,W
0023:  MOVWF  20
0024:  MOVF   29,W
0025:  MOVWF  21
0026:  MOVF   2A,W
0027:  MOVWF  22
0028:  MOVF   2B,W
0029:  MOVWF  23
002A:  MOVF   2C,W
002B:  MOVWF  24
002C:  MOVF   2D,W
002D:  MOVWF  0A
002E:  SWAPF  26,W
002F:  MOVWF  03
0030:  SWAPF  7F,F
0031:  SWAPF  7F,W
0032:  RETFIE
0033:  BCF    0A.3
0034:  GOTO   0CA
....................  /****************************************************************************/  
.................... /* Copyright 2004 MBARI.                                                    */  
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */  
.................... /* All rights reserved.                                                     */  
.................... /****************************************************************************/  
.................... #if defined(__PCM__)  
.................... #include <16f873.h> 
....................  //////// Standard Header file for the PIC16F873 device ////////////////  
.................... #device PIC16F873  
.................... #list  
....................  
.................... #fuses XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP  
.................... #use delay(clock=3580000)  
013F:  MOVLW  38
0140:  MOVWF  04
0141:  MOVF   00,W
0142:  BTFSC  03.2
0143:  GOTO   153
0144:  MOVLW  01
0145:  MOVWF  21
0146:  CLRF   20
0147:  DECFSZ 20,F
0148:  GOTO   147
0149:  DECFSZ 21,F
014A:  GOTO   146
014B:  MOVLW  27
014C:  MOVWF  20
014D:  DECFSZ 20,F
014E:  GOTO   14D
014F:  NOP
0150:  NOP
0151:  DECFSZ 00,F
0152:  GOTO   144
0153:  RETLW  00
*
01DB:  MOVLW  14
01DC:  SUBWF  39,F
01DD:  BTFSS  03.0
01DE:  GOTO   1ED
01DF:  MOVLW  39
01E0:  MOVWF  04
01E1:  MOVLW  FC
01E2:  ANDWF  00,F
01E3:  BCF    03.0
01E4:  RRF    00,F
01E5:  RRF    00,F
01E6:  MOVF   00,W
01E7:  BTFSC  03.2
01E8:  GOTO   1ED
01E9:  GOTO   1EB
01EA:  NOP
01EB:  DECFSZ 00,F
01EC:  GOTO   1EA
01ED:  RETLW  00
.................... #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)  
*
0173:  BTFSS  0C.5
0174:  GOTO   173
0175:  MOVF   18,W
0176:  MOVWF  2E
0177:  MOVF   1A,W
0178:  MOVWF  21
0179:  BTFSS  2E.1
017A:  GOTO   17D
017B:  BCF    18.4
017C:  BSF    18.4
017D:  NOP
017E:  BCF    0A.3
017F:  GOTO   196 (RETURN)
*
01FD:  CLRF   2E
.................... #use fast_io(C)  
.................... #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: 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);  
....................   
.................... /* 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> 
....................  ///////////////////////////////////////////////////////////////////////////  
.................... ////        (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;  
....................    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;  
01FE:  CLRF   2F
....................   
....................    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);  
.................... }  
....................   
.................... signed int atoi(char *s)  
.................... {  
....................    signed int result;  
....................    int sign, base, index;  
....................    char c;  
....................   
....................    index = 0;  
....................    sign = 0;  
....................    base = 10;  
....................    result = 0;  
....................   
....................    // Omit all preceeding alpha characters  
....................    if(s)  
....................       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)  
....................       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)  
....................       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);  
.................... }  
....................   
.................... 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)  
....................    {  
....................       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 = 1;  
01FF:  MOVLW  01
0200:  MOVWF  30
0201:  CLRF   31
0202:  CLRF   32
0203:  CLRF   33
....................   
.................... 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 <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  
....................  
.................... #include "freq_gen.h" 
....................  /****************************************************************************/  
.................... /* Copyright 2004 MBARI.                                                    */  
.................... /* Monterey Bay Aquarium Research Institute Proprietary Information.        */  
.................... /* All rights reserved.                                                     */  
.................... /****************************************************************************/  
.................... #ifndef FREQ_GEN_H  
.................... #define FREQ_GEN_H  
....................   
.................... #define FREQ_GEN_VERSION 0  
.................... #define FREQ_GEN_SUB_VERSION 1  
....................   
.................... /*  
....................     The ticks per second is based on an 8-bit counter over flowing that  
....................     is driven by a 4 Mhz ocsillator prescaled by 4 and postscaled by 64.  
....................   
....................     TICKS_PER_SEC = (OSC_CLK) / (PRESCALE) / (POSTSCALE) / (8_BIT_OVERFLOW)  
....................                   = 3580000   /     4      /      64     /      256  
....................                   = 54.626  
.................... */  
.................... #define TICKS_PER_SEC           55  
.................... #define FREQ_DURATION           TICKS_PER_SEC  
....................   
.................... #define PORTC_CLEAR_ALL         0x00  
....................   
.................... #define PORTB_LED_ON            0x02  
.................... #define PORTB_LED_OFF           0x00  
....................   
.................... #define PORTC_CURRENT_UP        0x05  
.................... #define PORTC_CURRENT_DN        0x06  
....................   
.................... #define PORTC_1000HZ_FREQ_UP    0x09  
.................... #define PORTC_1000HZ_FREQ_DN    0x0A  
....................   
.................... #define PORTC_316HZ_FREQ_UP     0x29  
.................... #define PORTC_316HZ_FREQ_DN     0x2A  
....................   
.................... #define PORTC_100HZ_FREQ_UP     0x19  
.................... #define PORTC_100HZ_FREQ_DN     0x1A  
....................   
.................... #endif  
....................  
....................   
.................... /********************************** GLOBS ***********************************/  
....................   
.................... long rtccTicks = 0;  
0204:  CLRF   34
0205:  CLRF   35
.................... int freqDuration = 0;  
0206:  CLRF   36
.................... int freqEnabled = FALSE;  
0207:  CLRF   37
.................... #byte portB = 0x06  
.................... #byte portC = 0x07  
....................   
.................... /********************************** GLOBS ***********************************/  
....................   
.................... #INT_RTCC  
.................... rtccIsr()  
.................... {  
....................     if ( !freqEnabled )  
*
00CA:  MOVF   37,F
00CB:  BTFSS  03.2
00CC:  GOTO   0D1
....................     {  
....................         rtccTicks = 0;  
00CD:  CLRF   35
00CE:  CLRF   34
....................         /* stay in process commands */  
....................         freqDuration = 0;  
00CF:  CLRF   36
....................         return;  
00D0:  GOTO   0DE
....................     }  
....................   
....................     rtccTicks++;  
00D1:  INCF   34,F
00D2:  BTFSC  03.2
00D3:  INCF   35,F
....................   
....................     if ( FREQ_DURATION == rtccTicks )  
00D4:  MOVF   34,W
00D5:  SUBLW  37
00D6:  BTFSS  03.2
00D7:  GOTO   0DE
00D8:  MOVF   35,F
00D9:  BTFSS  03.2
00DA:  GOTO   0DE
....................     {  
....................         rtccTicks = 0;  
00DB:  CLRF   35
00DC:  CLRF   34
....................         ++freqDuration;  
00DD:  INCF   36,F
....................     }  
.................... }  
....................   
00DE:  BCF    0B.2
00DF:  BCF    0A.3
00E0:  GOTO   020
.................... void enable()  
.................... {  
....................     freqEnabled = TRUE;  
*
0154:  MOVLW  01
0155:  MOVWF  37
....................     printf("freq gen enabled\r\n");  
0156:  CLRF   3A
0157:  MOVF   3A,W
0158:  CALL   035
0159:  INCF   3A,F
015A:  MOVWF  20
015B:  MOVF   20,W
015C:  BTFSS  0C.4
015D:  GOTO   15C
015E:  MOVWF  19
015F:  MOVLW  12
0160:  SUBWF  3A,W
0161:  BTFSS  03.2
0162:  GOTO   157
....................     /*portB = PORTB_LED_ON;*/  
.................... 	return;  
.................... }  
0163:  RETLW  00
....................   
.................... void disable()  
.................... {  
....................     freqEnabled = FALSE;  
0164:  CLRF   37
....................     printf("freq gen disabled\r\n");  
0165:  CLRF   3A
0166:  MOVF   3A,W
0167:  CALL   04C
0168:  INCF   3A,F
0169:  MOVWF  20
016A:  MOVF   20,W
016B:  BTFSS  0C.4
016C:  GOTO   16B
016D:  MOVWF  19
016E:  MOVLW  13
016F:  SUBWF  3A,W
0170:  BTFSS  03.2
0171:  GOTO   166
....................     /*portB = PORTB_LED_OFF;*/  
....................     return;  
.................... }  
0172:  RETLW  00
....................   
.................... void processCmds()  
.................... {  
....................     int b, c;  
....................   
....................     b = portB & 0x01;  
*
0180:  MOVF   06,W
0181:  ANDLW  01
0182:  MOVWF  38
....................   
....................     if (!b && !freqEnabled)  
0183:  MOVF   38,F
0184:  BTFSS  03.2
0185:  GOTO   18B
0186:  MOVF   37,F
0187:  BTFSS  03.2
0188:  GOTO   18B
....................     {  
.................... 		enable();  
0189:  CALL   154
....................     }  
....................   
....................     else if (b && freqEnabled)  
018A:  GOTO   1DA
018B:  MOVF   38,F
018C:  BTFSC  03.2
018D:  GOTO   193
018E:  MOVF   37,F
018F:  BTFSC  03.2
0190:  GOTO   193
....................     {  
.................... 		disable();  
0191:  CALL   164
....................     }  
....................   
....................     else if ( kbhit() )  
0192:  GOTO   1DA
0193:  BTFSS  0C.5
0194:  GOTO   1DA
....................     {  
....................         c = getc();  
0195:  GOTO   173
0196:  MOVF   21,W
0197:  MOVWF  39
....................   
....................         switch ( toupper(c))  
....................         {  
0198:  MOVF   39,W
0199:  SUBLW  60
019A:  BTFSC  03.0
019B:  GOTO   1A3
019C:  MOVF   39,W
019D:  SUBLW  7A
019E:  BTFSS  03.0
019F:  GOTO   1A3
01A0:  MOVF   39,W
01A1:  ANDLW  DF
01A2:  GOTO   1A4
01A3:  MOVF   39,W
01A4:  XORLW  31
01A5:  BTFSC  03.2
01A6:  GOTO   1AE
01A7:  XORLW  03
01A8:  BTFSC  03.2
01A9:  GOTO   1B0
01AA:  XORLW  0D
01AB:  BTFSC  03.2
01AC:  GOTO   1B2
01AD:  GOTO   1DA
....................             case '1':   enable();  
01AE:  CALL   154
....................                         break;  
01AF:  GOTO   1DA
....................             case '2':   disable();  
01B0:  CALL   164
....................                         break;  
01B1:  GOTO   1DA
....................             case '?:   printf("1 - enable freq gen\r\n");  
01B2:  CLRF   3A
01B3:  MOVF   3A,W
01B4:  CALL   064
01B5:  INCF   3A,F
01B6:  MOVWF  20
01B7:  MOVF   20,W
01B8:  BTFSS  0C.4
01B9:  GOTO   1B8
01BA:  MOVWF  19
01BB:  MOVLW  15
01BC:  SUBWF  3A,W
01BD:  BTFSS  03.2
01BE:  GOTO   1B3
....................                         printf("2 - disable freq gen\r\n");  
01BF:  CLRF   3A
01C0:  MOVF   3A,W
01C1:  CALL   07E
01C2:  INCF   3A,F
01C3:  MOVWF  20
01C4:  MOVF   20,W
01C5:  BTFSS  0C.4
01C6:  GOTO   1C5
01C7:  MOVWF  19
01C8:  MOVLW  16
01C9:  SUBWF  3A,W
01CA:  BTFSS  03.2
01CB:  GOTO   1C0
....................                         printf("?- help menu\r\n");  
01CC:  CLRF   3A
01CD:  MOVF   3A,W
01CE:  CALL   099
01CF:  INCF   3A,F
01D0:  MOVWF  20
01D1:  MOVF   20,W
01D2:  BTFSS  0C.4
01D3:  GOTO   1D2
01D4:  MOVWF  19
01D5:  MOVLW  0F
01D6:  SUBWF  3A,W
01D7:  BTFSS  03.2
01D8:  GOTO   1CD
....................                         break;  
01D9:  GOTO   1DA
....................         }  
....................     }  
....................   
....................     return;  
.................... }  
01DA:  RETLW  00
....................   
.................... main()  
.................... {  
*
01EE:  CLRF   04
01EF:  MOVLW  1F
01F0:  ANDWF  03,F
01F1:  BSF    03.5
01F2:  BSF    1F.0
01F3:  BSF    1F.1
01F4:  BSF    1F.2
01F5:  BCF    1F.3
01F6:  MOVLW  16
01F7:  MOVWF  19
01F8:  MOVLW  26
01F9:  MOVWF  18
01FA:  MOVLW  90
01FB:  BCF    03.5
01FC:  MOVWF  18
....................     /* setup port b bit 0 as input, 1 as output */  
....................     set_tris_b(0x01);  
*
0208:  MOVLW  01
0209:  BSF    03.5
020A:  MOVWF  06
....................   
....................     /* setup port c bits 0-6 as outputs, 7 as input */  
....................     set_tris_c(0x80);  
020B:  MOVLW  80
020C:  MOVWF  07
....................   
....................     /* init freq pins */  
....................     portC = PORTC_CLEAR_ALL;  
020D:  BCF    03.5
020E:  CLRF   07
....................   
....................     /* setup the system clock */  
....................     setup_counters(RTCC_INTERNAL, RTCC_DIV_64);  
020F:  MOVLW  05
0210:  MOVWF  20
0211:  BTFSS  20.3
0212:  GOTO   21B
0213:  MOVLW  07
0214:  CLRF   01
0215:  MOVLW  81
0216:  MOVWF  04
0217:  MOVF   00,W
0218:  ANDLW  C0
0219:  IORLW  0F
021A:  MOVWF  00
021B:  CLRWDT
021C:  MOVLW  81
021D:  MOVWF  04
021E:  MOVF   00,W
021F:  ANDLW  C0
0220:  IORWF  20,W
0221:  MOVWF  00
....................   
....................     /* make sure interrupts are enabled */  
....................     enable_interrupts(INT_RTCC);  
0222:  BSF    0B.5
....................     enable_interrupts(GLOBAL);  
0223:  MOVLW  C0
0224:  IORWF  0B,F
....................   
....................     /* welcome message */  
....................     printf("Freq Gen version %d.%d\r\n",  
....................             FREQ_GEN_VERSION, FREQ_GEN_SUB_VERSION);  
0225:  CLRF   38
0226:  MOVF   38,W
0227:  CALL   0AD
0228:  INCF   38,F
0229:  MOVWF  20
022A:  MOVF   20,W
022B:  BTFSS  0C.4
022C:  GOTO   22B
022D:  MOVWF  19
022E:  MOVLW  11
022F:  SUBWF  38,W
0230:  BTFSS  03.2
0231:  GOTO   226
0232:  CLRF   39
0233:  MOVLW  18
0234:  MOVWF  3A
0235:  CALL   0F6
0236:  MOVLW  2E
0237:  BTFSS  0C.4
0238:  GOTO   237
0239:  MOVWF  19
023A:  MOVLW  01
023B:  MOVWF  39
023C:  MOVLW  18
023D:  MOVWF  3A
023E:  CALL   0F6
023F:  MOVLW  0D
0240:  BTFSS  0C.4
0241:  GOTO   240
0242:  MOVWF  19
0243:  MOVLW  0A
0244:  BTFSS  0C.4
0245:  GOTO   244
0246:  MOVWF  19
....................     /*  
....................     while(freqDuration <=2)  
.................... 	{  
.................... 		portB = PORTB_LED_ON;		  
.................... 		delay_ms(100);  
.................... 		portB = PORTB_LED_OFF;  
.................... 	}*/  
....................   
....................     /* main loop */  
....................     for(;;)  
....................     {  
....................         /* wait for things to settle down */  
....................         delay_ms(50);  
0247:  MOVLW  32
0248:  MOVWF  38
0249:  CALL   13F
....................   
....................         /* process any queued cmds */  
....................         while ( freqDuration <= 5 )  
....................         processCmds();  
024A:  MOVF   36,W
024B:  SUBLW  05
024C:  BTFSS  03.0
024D:  GOTO   250
024E:  CALL   180
024F:  GOTO   24A
....................   
.................... 		/* Magnetic source output */  
....................   
....................         /* 1000 Hz */  
....................         while ( freqDuration == 6 )  
....................         {  
0250:  MOVF   36,W
0251:  SUBLW  06
0252:  BTFSS  03.2
0253:  GOTO   265
....................             /* wave up */  
....................             portC = PORTC_1000HZ_FREQ_UP;  
0254:  MOVLW  09
0255:  MOVWF  07
....................             delay_us(500);  
0256:  MOVLW  94
0257:  MOVWF  20
0258:  DECFSZ 20,F
0259:  GOTO   258
025A:  NOP
025B:  NOP
....................             /* wave down */  
....................             portC = PORTC_1000HZ_FREQ_DN;  
025C:  MOVLW  0A
025D:  MOVWF  07
....................             delay_us(490);  
025E:  MOVLW  91
025F:  MOVWF  20
0260:  DECFSZ 20,F
0261:  GOTO   260
0262:  NOP
0263:  NOP
....................         }  
0264:  GOTO   250
....................   
....................         /* 316 Hz */  
....................         while ( freqDuration == 7 )  
....................         {  
0265:  MOVF   36,W
0266:  SUBLW  07
0267:  BTFSS  03.2
0268:  GOTO   282
....................             /* wave up */  
....................             portC = PORTC_316HZ_FREQ_UP;  
0269:  MOVLW  29
026A:  MOVWF  07
....................             delay_us(1499);  
026B:  MOVLW  01
026C:  MOVWF  38
026D:  CALL   13F
026E:  MOVLW  02
026F:  MOVWF  38
0270:  MOVLW  F6
0271:  MOVWF  39
0272:  CALL   1DB
0273:  DECFSZ 38,F
0274:  GOTO   270
....................             /* wave down */  
....................             portC = PORTC_316HZ_FREQ_DN;  
0275:  MOVLW  2A
0276:  MOVWF  07
....................             delay_us(1491); /* (8 us delay) */  
0277:  MOVLW  01
0278:  MOVWF  38
0279:  CALL   13F
027A:  MOVLW  02
027B:  MOVWF  38
027C:  MOVLW  F2
027D:  MOVWF  39
027E:  CALL   1DB
027F:  DECFSZ 38,F
0280:  GOTO   27C
....................         }  
0281:  GOTO   265
....................   
....................         /* 100 Hz */  
....................         while ( freqDuration == 8 )  
....................         {  
0282:  MOVF   36,W
0283:  SUBLW  08
0284:  BTFSS  03.2
0285:  GOTO   291
....................             /* wave up */  
....................             portC = PORTC_100HZ_FREQ_UP;  
0286:  MOVLW  19
0287:  MOVWF  07
....................             delay_ms(5);  
0288:  MOVLW  05
0289:  MOVWF  38
028A:  CALL   13F
....................             /* wave down */  
....................             portC = PORTC_100HZ_FREQ_DN;  
028B:  MOVLW  1A
028C:  MOVWF  07
....................             delay_ms(5);  
028D:  MOVLW  05
028E:  MOVWF  38
028F:  CALL   13F
....................         }  
0290:  GOTO   282
....................   
....................   
....................         /* clear all the pins */  
....................         portC = PORTC_CLEAR_ALL;  
0291:  CLRF   07
....................   
....................         /* wait for things to settle down */  
....................         delay_ms(50);  
0292:  MOVLW  32
0293:  MOVWF  38
0294:  CALL   13F
....................   
....................         /* process any queued cmds */  
....................         while ( freqDuration <= 14 )  
....................         processCmds();  
0295:  MOVF   36,W
0296:  SUBLW  0E
0297:  BTFSS  03.0
0298:  GOTO   29B
0299:  CALL   180
029A:  GOTO   295
....................   
.................... 		/* Current source output */  
....................   
....................         /* 1000 Hz */  
....................         while ( freqDuration == 15 )  
....................         {  
029B:  MOVF   36,W
029C:  SUBLW  0F
029D:  BTFSS  03.2
029E:  GOTO   2B0
....................             /* wave up */  
....................             portC = PORTC_CURRENT_UP;  
029F:  MOVLW  05
02A0:  MOVWF  07
....................             delay_us(500);  
02A1:  MOVLW  94
02A2:  MOVWF  20
02A3:  DECFSZ 20,F
02A4:  GOTO   2A3
02A5:  NOP
02A6:  NOP
....................             /* wave down */  
....................             portC = PORTC_CURRENT_DN;  
02A7:  MOVLW  06
02A8:  MOVWF  07
....................             delay_us(490);  
02A9:  MOVLW  91
02AA:  MOVWF  20
02AB:  DECFSZ 20,F
02AC:  GOTO   2AB
02AD:  NOP
02AE:  NOP
....................         }  
02AF:  GOTO   29B
....................   
....................         /* 316 Hz */  
....................         while ( freqDuration == 16 )  
....................         {  
02B0:  MOVF   36,W
02B1:  SUBLW  10
02B2:  BTFSS  03.2
02B3:  GOTO   2CD
....................             /* wave up */  
....................             portC = PORTC_CURRENT_UP;  
02B4:  MOVLW  05
02B5:  MOVWF  07
....................             delay_us(1499);  
02B6:  MOVLW  01
02B7:  MOVWF  38
02B8:  CALL   13F
02B9:  MOVLW  02
02BA:  MOVWF  38
02BB:  MOVLW  F6
02BC:  MOVWF  39
02BD:  CALL   1DB
02BE:  DECFSZ 38,F
02BF:  GOTO   2BB
....................             /* wave down */  
....................             portC = PORTC_CURRENT_DN;  
02C0:  MOVLW  06
02C1:  MOVWF  07
....................             delay_us(1491); /* (8 us delay) */  
02C2:  MOVLW  01
02C3:  MOVWF  38
02C4:  CALL   13F
02C5:  MOVLW  02
02C6:  MOVWF  38
02C7:  MOVLW  F2
02C8:  MOVWF  39
02C9:  CALL   1DB
02CA:  DECFSZ 38,F
02CB:  GOTO   2C7
....................         }  
02CC:  GOTO   2B0
....................   
....................         /* 100 Hz */  
....................         while ( freqDuration == 17 )  
....................         {  
02CD:  MOVF   36,W
02CE:  SUBLW  11
02CF:  BTFSS  03.2
02D0:  GOTO   2DB
....................             /* wave up */  
....................             portC = PORTC_CURRENT_UP;  
02D1:  MOVLW  05
02D2:  MOVWF  07
....................             delay_ms(5);  
02D3:  MOVWF  38
02D4:  CALL   13F
....................             /* wave down */  
....................             portC = PORTC_CURRENT_DN;  
02D5:  MOVLW  06
02D6:  MOVWF  07
....................             delay_ms(5);  
02D7:  MOVLW  05
02D8:  MOVWF  38
02D9:  CALL   13F
....................         }  
02DA:  GOTO   2CD
....................   
....................         /* clear all the pins */  
....................         portC = PORTC_CLEAR_ALL;  
02DB:  CLRF   07
....................   
....................         /* do it again ! */  
....................         freqDuration = 0;  
02DC:  CLRF   36
....................     }  
02DD:  GOTO   247
.................... }  
....................  
02DE:  SLEEP

Configuration Fuses:
   Word  1: 3F31   XT NOWDT PUT NOPROTECT NOBROWNOUT NOLVP NOCPD NOWRT NODEBUG
