CCS PCM C Compiler, Version 3.245, 27853 11-V-08 15:47
Filename: D:\MLAB_E\projekty\Ovladani_mobilnim_telefonem\SW\final\main.lst
ROM used: 1315 words (16%)
Largest free fragment is 2048
RAM used: 52 (30%) at main() level
139 (79%) worst case
Stack: 2 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 3D5
0003: NOP
.................... #include ".\main.h"
.................... #include <16F876A.h>
.................... //////// Standard Header file for the PIC16F876A device ////////////////
.................... #device PIC16F876A
.................... #list
....................
.................... #device adc=8
....................
.................... #FUSES NOWDT //Watch Dog Timer
.................... #FUSES HS//XT //Crystal osc <= 4mhz
.................... #FUSES NOPUT //No Power Up Timer
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES NODEBUG //No Debug mode for ICD
.................... #FUSES NOBROWNOUT //No brownout reset
.................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
.................... #FUSES NOCPD //No EE protection
.................... #FUSES NOWRT //Program memory not write protected
....................
.................... #use delay(clock=18432000,RESTART_WDT)
*
004E: MOVLW 52
004F: MOVWF 04
0050: MOVF 00,W
0051: BTFSC 03.2
0052: GOTO 063
0053: MOVLW 05
0054: MOVWF 78
0055: MOVLW BF
0056: MOVWF 77
0057: CLRWDT
0058: DECFSZ 77,F
0059: GOTO 057
005A: DECFSZ 78,F
005B: GOTO 055
005C: MOVLW F9
005D: MOVWF 77
005E: DECFSZ 77,F
005F: GOTO 05E
0060: CLRWDT
0061: DECFSZ 00,F
0062: GOTO 053
0063: RETLW 00
.................... #use rs232(STREAM=MOBIL,baud=19200,force_sw,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
0064: BCF 20.6
0065: MOVF 20,W
0066: BSF 03.5
0067: MOVWF 07
0068: BCF 03.5
0069: BCF 07.6
006A: MOVLW 08
006B: MOVWF 78
006C: NOP
006D: NOP
006E: NOP
006F: BSF 78.7
0070: GOTO 080
0071: BCF 78.7
0072: RRF 53,F
0073: BTFSC 03.0
0074: BSF 07.6
0075: BTFSS 03.0
0076: BCF 07.6
0077: BSF 78.6
0078: GOTO 080
0079: BCF 78.6
007A: DECFSZ 78,F
007B: GOTO 072
007C: NOP
007D: NOP
007E: NOP
007F: BSF 07.6
0080: MOVLW 49
0081: MOVWF 04
0082: DECFSZ 04,F
0083: GOTO 082
0084: NOP
0085: NOP
0086: NOP
0087: BTFSC 78.7
0088: GOTO 071
0089: BTFSC 78.6
008A: GOTO 079
008B: RETLW 00
008C: MOVLW 08
008D: MOVWF 77
008E: BSF 20.7
008F: MOVF 20,W
0090: BSF 03.5
0091: MOVWF 07
0092: BCF 03.5
0093: BTFSS 07.7
0094: GOTO 097
0095: BSF 03.5
0096: GOTO 092
0097: CLRF 57
0098: BSF 77.7
0099: GOTO 0A8
009A: BCF 77.7
009B: GOTO 0A8
009C: BCF 03.0
009D: BTFSC 07.7
009E: BSF 03.0
009F: RRF 57,F
00A0: BSF 77.6
00A1: GOTO 0A8
00A2: BCF 77.6
00A3: DECFSZ 77,F
00A4: GOTO 09C
00A5: MOVF 57,W
00A6: MOVWF 78
00A7: GOTO 0B5
00A8: MOVLW 49
00A9: BTFSC 77.7
00AA: MOVLW 14
00AB: MOVWF 78
00AC: DECFSZ 78,F
00AD: GOTO 0AC
00AE: NOP
00AF: NOP
00B0: BTFSC 77.7
00B1: GOTO 09A
00B2: BTFSC 77.6
00B3: GOTO 0A2
00B4: GOTO 09C
00B5: RETLW 00
*
03E9: MOVLW FF
03EA: BCF 03.5
03EB: MOVWF 20
.................... #use rs232(STREAM=VRTULE,baud=600,parity=N,xmit=PIN_B2,rcv=PIN_B4,bits=8)
*
01D0: BSF 03.5
01D1: BCF 06.2
01D2: BCF 03.5
01D3: BCF 06.2
01D4: MOVLW 08
01D5: MOVWF 78
01D6: NOP
01D7: NOP
01D8: NOP
01D9: BSF 78.7
01DA: GOTO 1EA
01DB: BCF 78.7
01DC: RRF 52,F
01DD: BTFSC 03.0
01DE: BSF 06.2
01DF: BTFSS 03.0
01E0: BCF 06.2
01E1: BSF 78.6
01E2: GOTO 1EA
01E3: BCF 78.6
01E4: DECFSZ 78,F
01E5: GOTO 1DC
01E6: NOP
01E7: NOP
01E8: NOP
01E9: BSF 06.2
01EA: MOVLW 09
01EB: MOVWF 77
01EC: CLRF 04
01ED: DECFSZ 04,F
01EE: GOTO 1ED
01EF: DECFSZ 77,F
01F0: GOTO 1EC
01F1: MOVLW F0
01F2: MOVWF 04
01F3: DECFSZ 04,F
01F4: GOTO 1F3
01F5: NOP
01F6: NOP
01F7: BTFSC 78.7
01F8: GOTO 1DB
01F9: BTFSC 78.6
01FA: GOTO 1E3
01FB: RETLW 00
....................
....................
....................
.................... #define LCD_RS PIN_B1 // rizeni registru LCD displeje
.................... #define LCD_E PIN_B0 // enable LCD displeje
.................... #define LCD_DATA_LSB PIN_C0 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
....................
....................
.................... #bit SPEN=0x18.7
.................... #bit RCIF=0x0C.5
....................
.................... #include <stdio.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2003 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef _STDIO
.................... #define _STDIO
.................... #include <string.h>
.................... ////////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2003 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ////////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef _STRING
.................... #define _STRING
.................... #include <stddef.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (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;
*
021D: BSF 03.5
021E: MOVF 47,W
021F: MOVWF 49
.................... for(su=s;0<n;++su,--n)
0220: MOVF 46,W
0221: MOVWF 4A
0222: MOVF 48,W
0223: SUBLW 00
0224: BTFSC 03.0
0225: GOTO 232
.................... if(*su==uc)
0226: MOVF 4A,W
0227: MOVWF 04
0228: MOVF 49,W
0229: SUBWF 00,W
022A: BTFSS 03.2
022B: GOTO 22F
.................... return su;
022C: MOVF 4A,W
022D: MOVWF 78
022E: GOTO 234
022F: INCF 4A,F
0230: DECF 48,F
0231: GOTO 222
.................... return NULL;
0232: MOVLW 00
0233: MOVWF 78
.................... }
0234: BCF 03.5
0235: RETLW 00
....................
.................... /* standard template: char *strchr(const char *s, int c).
.................... Finds first occurrence of c in s */
....................
.................... char *strchr(char *s, int c)
.................... {
.................... for (; *s != c; s++)
.................... if (*s == '\0')
.................... return(0);
.................... return(s);
.................... }
.................... /* standard template:
.................... size_t strcspn(const char *s1, const char *s2).
.................... Computes length of max initial segment of s1 that
.................... consists entirely of characters NOT from s2*/
....................
.................... int *strcspn(char *s1, char *s2)
.................... {
.................... char *sc1, *sc2;
....................
.................... for (sc1 = s1; *sc1 != 0; sc1++)
.................... for (sc2 = s2; *sc2 != 0; sc2++)
.................... if (*sc1 == *sc2)
.................... return(sc1 - s1);
.................... return(sc1 - s1);
.................... }
.................... /* standard template:
.................... char *strpbrk(const char *s1, const char *s2).
.................... Locates first occurence of any character from s2 in s1;
.................... returns s1 if s2 is empty string */
....................
.................... char *strpbrk(char *s1, char *s2)
.................... {
.................... char *sc1, *sc2;
....................
.................... for (sc1 = s1; *sc1 != 0; sc1++)
.................... for (sc2 = s2; *sc2 != 0; sc2++)
.................... if (*sc1 == *sc2)
.................... return(sc1);
.................... return(0);
.................... }
....................
....................
.................... /* standard template: char *strrchr(const char *s, int c).
.................... Finds last occurrence of c in s */
....................
.................... char *strrchr(char *s, int c)
.................... {
.................... char *p;
....................
.................... for (p = 0; ; s++)
.................... {
.................... if (*s == c)
.................... p = s;
.................... if (*s == '\0')
.................... return(p);
.................... }
.................... }
.................... /* computes length of max initial segment of s1 consisting
.................... entirely of characters from s2 */
....................
.................... int *strspn(char *s1, char *s2)
.................... {
.................... char *sc1, *sc2;
....................
.................... for (sc1 = s1; *sc1 != 0; sc1++)
.................... for (sc2 = s2; ; sc2++)
.................... if (*sc2 == '\0')
.................... return(sc1 - s1);
.................... else if (*sc1 == *sc2)
.................... break;
.................... return(sc1 - s1);
.................... }
.................... /* standard template:
.................... char *strstr(const char *s1, const char *s2);
.................... Locates first occurence of character sequence s2 in s1;
.................... returns 0 if s2 is empty string
....................
.................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
.................... file to use the faster algorithm */
.................... char *strstr(char *s1, char *s2)
.................... {
.................... char *s, *t;
....................
.................... #ifdef FASTER_BUT_MORE_ROM
.................... if (*s2 == '\0')
.................... return(s1);
.................... #endif
....................
.................... while (*s1)
.................... {
.................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t);
....................
.................... if (*t == '\0')
.................... return s1;
.................... ++s1;
.................... #ifdef FASTER_BUT_MORE_ROM
.................... while(*s1 != '\0' && *s1 != *s2)
.................... ++s1;
.................... #endif
.................... }
.................... return 0;
.................... }
....................
.................... /* standard template: char *strtok(char *s1, const char *s2).
....................
.................... Finds next token in s1 delimited by a character from separator
.................... string s2 (which can be different from call to call). First call
.................... starts at beginning of s1 searching for first character NOT
.................... contained in s2; returns 0 if none is found.
.................... If one is found, it is the start of first token (return value).
.................... Function then searches from there for a character contained in s2.
.................... If none is found, current token extends to end of s1, and subsequent
.................... searches for a token will return 0. If one is found, it is
.................... overwritten by '\0', which terminates current token. Function saves
.................... pointer to following character from which next search will start.
.................... Each subsequent call, with 0 as first argument, starts searching
.................... from saved pointer */
....................
.................... char *strtok(char *s1, char *s2)
.................... {
.................... char *beg, *end;
.................... static char *save;
*
03EC: CLRF 21
....................
.................... beg = (s1)? s1: save;
.................... beg += strspn(beg, s2);
.................... if (*beg == '\0')
.................... {
.................... *save = ' ';
.................... return(0);
.................... }
.................... end = strpbrk(beg, s2);
.................... if (*end != '\0')
.................... {
.................... *end = '\0';
.................... end++;
.................... }
.................... save = end;
.................... return(beg);
.................... }
....................
.................... /*****************************************************************/
.................... /*Miscellaneous functions*/
.................... /* standard template
.................... maps error number in errnum to an error message string
.................... Returns: Pointer to string
.................... */
.................... #ifdef _ERRNO
.................... char * strerror(int errnum)
.................... {
.................... char s[15];
.................... switch( errnum)
.................... {
.................... case 0:
.................... strcpy(s,"no errors");
.................... return s;
.................... case EDOM :
.................... strcpy(s,"domain error");
.................... return s;
.................... case ERANGE:
.................... strcpy(s,"range error");
.................... return s;
.................... }
.................... }
.................... #ENDIF
.................... /* standard template: size_t strlen(const char *s).
.................... Computes length of s1 (preceding terminating 0) */
....................
.................... int *strlen(char *s)
.................... {
.................... char *sc;
....................
.................... for (sc = s; *sc != 0; sc++);
.................... return(sc - s);
.................... }
....................
.................... /* standard template: size_t stricmp(const char *s1, const char *s2).
.................... Compares s1 to s2 ignoring case (upper vs. lower) */
....................
.................... signed int stricmp(char *s1, char *s2)
.................... {
.................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
.................... s1++, s2++)
.................... if (*s1 == '\0')
.................... return(0);
.................... return((*s1 < *s2) ? -1: 1);
.................... }
....................
....................
.................... /* standard template: char *strlwr(char *s).
.................... Replaces uppercase letters by lowercase;
.................... returns pointer to new string s */
....................
.................... char *strlwr(char *s)
.................... {
.................... char *p;
....................
.................... for (p = s; *p != '\0'; p++)
.................... if (*p >= 'A' && *p <='Z')
.................... *p += 'a' - 'A';
.................... return(s);
.................... }
....................
....................
.................... /************************************************************/
....................
....................
.................... #endif
....................
.................... #ifndef getc
.................... #define getc getch
.................... #define getchar getch
.................... #define puts(s) {printf(s); putchar(13); putchar(10);}
.................... #define putc putchar
.................... #endif
.................... /* maps error number to an error message. Writes a sequence of characters to
.................... stderr stream thus: if s is not null then string pointed to by s follwed by
.................... a colon (:) and a space and the appropriate error message returned by strerror
.................... function with argument errno
....................
.................... Returns: no value
.................... */
....................
.................... #ifdef _ERRNO
.................... void perror(char *s)
.................... {
.................... if(s)
.................... fprintf(STDERR,"%s: ",s);
.................... fprintf(STDERR,"%s\r\n",strerror(errno));
.................... }
.................... #endif
.................... #endif
....................
.................... #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 <stdlib.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2003 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef _STDLIB
.................... #define _STDLIB
....................
.................... //---------------------------------------------------------------------------
.................... // Definitions and types
.................... //---------------------------------------------------------------------------
....................
.................... #ifndef RAND_MAX
.................... #define RAND_MAX 32767 // The value of which is the maximum value
.................... // ... returned by the rand function
.................... #endif
....................
.................... typedef struct {
.................... signed int quot;
.................... signed int rem;
.................... } div_t;
....................
.................... typedef struct {
.................... signed long quot;
.................... signed long rem;
.................... } ldiv_t;
....................
.................... #include <stddef.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2003 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef _STDDEF
....................
.................... #define _STDDEF
....................
.................... #if sizeof(int *)==1
.................... #define ptrdiff_t int
.................... #else
.................... #define ptrdiff_t long
.................... #endif
....................
.................... #define size_t int
.................... #define wchar_t char
.................... #define NULL 0
....................
.................... #define offsetof(s,f) (offsetofbit(s,f)/8)
....................
.................... #endif
....................
....................
.................... //---------------------------------------------------------------------------
.................... // String conversion functions
.................... //---------------------------------------------------------------------------
....................
.................... /* Standard template: float atof(char * s)
.................... * converts the initial portion of the string s to a float.
.................... * returns the converted value if any, 0 otherwise
.................... */
.................... float atof(char * s);
....................
.................... /* Standard template: float atoe(char * s)
.................... * converts the initial portion of the string s to a float.
.................... * returns the converted value if any, 0 otherwise
.................... * also handles E format numbers
.................... */
.................... float atoe(char * s);
....................
.................... /* Standard template: signed int atoi(char * s)
.................... * converts the initial portion of the string s to a signed int
.................... * returns the converted value if any, 0 otherwise
.................... */
.................... signed int atoi(char *s);
....................
.................... /* Syntax: signed int32 atoi32(char * s)
.................... converts the initial portion of the string s to a signed int32
.................... returns the converted value if any, 0 otherwise*/
.................... signed int32 atoi32(char *s);
....................
.................... /* Syntax: char * itoa(signed int32 num, int8 base, char * s)
.................... converts the signed int32 to a string and
.................... returns the converted value if any, 0 otherwise*/
.................... char * itoa(signed int32 num, int8 base, char * s);
....................
.................... /* Standard template: signed long atol(char * s)
.................... * converts the initial portion of the string s to a signed long
.................... * returns the converted value if any, 0 otherwise
.................... */
.................... signed long atol(char *s);
....................
.................... /* Standard template: float strtol(char * s,char *endptr)
.................... * converts the initial portion of the string s to a float
.................... * returns the converted value if any, 0 otherwise
.................... * the final string is returned in the endptr, if endptr is not null
.................... */
.................... float strtod(char *s,char *endptr);
....................
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base)
.................... * converts the initial portion of the string s, represented as an
.................... * integral value of radix base to a signed long.
.................... * Returns the converted value if any, 0 otherwise
.................... * the final string is returned in the endptr, if endptr is not null
.................... */
.................... signed long strtol(char *s,char *endptr,signed int base);
....................
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base)
.................... * converts the initial portion of the string s, represented as an
.................... * integral value of radix base to a unsigned long.
.................... * returns the converted value if any, 0 otherwise
.................... * the final string is returned in the endptr, if endptr is not null
.................... */
.................... long strtoul(char *s,char *endptr,signed int base);
....................
.................... //---------------------------------------------------------------------------
.................... // Pseudo-random sequence generation functions
.................... //---------------------------------------------------------------------------
....................
.................... /* The rand function computes a sequence of pseudo-random integers in
.................... * the range 0 to RAND_MAX
.................... *
.................... * Parameters:
.................... * (none)
.................... *
.................... * Returns:
.................... * The pseudo-random integer
.................... */
.................... long rand(void);
....................
.................... /* The srand function uses the argument as a seed for a new sequence of
.................... * pseudo-random numbers to be returned by subsequent calls to rand.
.................... *
.................... * Parameters:
.................... * [in] seed: The seed value to start from. You might need to pass
.................... *
.................... * Returns:
.................... * (none)
.................... *
.................... * Remarks
.................... * The srand function sets the starting point for generating
.................... * a series of pseudorandom integers. To reinitialize the
.................... * generator, use 1 as the seed argument. Any other value for
.................... * seed sets the generator to a random starting point. rand
.................... * retrieves the pseudorandom numbers that are generated.
.................... * Calling rand before any call to srand generates the same
.................... * sequence as calling srand with seed passed as 1.
.................... * Usually, you need to pass a time here from outer source
.................... * so that the numbers will be different every time you run.
.................... */
.................... void srand(unsigned int32 seed);
....................
.................... //---------------------------------------------------------------------------
.................... // Memory management functions
.................... //---------------------------------------------------------------------------
....................
.................... // Comming soon
....................
.................... //---------------------------------------------------------------------------
.................... // Communication with the environment
.................... //---------------------------------------------------------------------------
....................
.................... /* The function returns 0 always
.................... */
.................... signed int system(char *string);
....................
.................... //---------------------------------------------------------------------------
.................... // Searching and sorting utilities
.................... //---------------------------------------------------------------------------
....................
.................... /* Performs a binary search of a sorted array..
.................... *
.................... * Parameters:
.................... * [in] key: Object to search for
.................... * [in] base: Pointer to base of search data
.................... * [in] num: Number of elements
.................... * [in] width: Width of elements
.................... * [in] compare: Function that compares two elements
.................... *
.................... * Returns:
.................... * bsearch returns a pointer to an occurrence of key in the array pointed
.................... * to by base. If key is not found, the function returns NULL. If the
.................... * array is not in order or contains duplicate records with identical keys,
.................... * the result is unpredictable.
.................... */
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width,
.................... // int (*compare)(const void *, const void *));
....................
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents
.................... * of the array are sorted into ascending order according to a comparison
.................... * function pointed to by compar.
.................... *
.................... * Parameters:
.................... * [in] base: Pointer to base of search data
.................... * [in] num: Number of elements
.................... * [in] width: Width of elements
.................... * [in] compare: Function that compares two elements
.................... *
.................... * Returns:
.................... * (none)
.................... */
.................... //void *qsort(const void *base, size_t num, size_t width,
.................... // int (*compare)(const void *, const void *));
....................
.................... //---------------------------------------------------------------------------
.................... // Integer arithmetic functions
.................... //---------------------------------------------------------------------------
....................
.................... #define labs abs
....................
.................... div_t div(signed int numer,signed int denom);
.................... ldiv_t ldiv(signed long numer,signed long denom);
....................
.................... //---------------------------------------------------------------------------
.................... // Multibyte character functions
.................... //---------------------------------------------------------------------------
....................
.................... // Not supported
....................
.................... //---------------------------------------------------------------------------
.................... // Multibyte string functions
.................... //---------------------------------------------------------------------------
....................
.................... // Not supported
....................
....................
.................... //---------------------------------------------------------------------------
.................... // Internal implementation
.................... //---------------------------------------------------------------------------
....................
.................... #include <stddef.h>
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2003 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef _STDDEF
....................
.................... #define _STDDEF
....................
.................... #if sizeof(int *)==1
.................... #define ptrdiff_t int
.................... #else
.................... #define ptrdiff_t long
.................... #endif
....................
.................... #define size_t int
.................... #define wchar_t char
.................... #define NULL 0
....................
.................... #define offsetof(s,f) (offsetofbit(s,f)/8)
....................
.................... #endif
....................
.................... #include <string.h>
.................... ////////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996,2003 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ////////////////////////////////////////////////////////////////////////////
....................
.................... #ifndef _STRING
.................... #define _STRING
.................... #include <stddef.h>
.................... #include <ctype.h>
....................
....................
....................
.................... //////////////////////////////////////////////
.................... //// Uncomment the following define to ////
.................... //// allow some functions to use a ////
.................... //// quicker algorithm, but use more ROM ////
.................... //// ////
.................... //// #define FASTER_BUT_MORE_ROM ////
.................... //////////////////////////////////////////////
....................
....................
....................
.................... /*Copying functions*/
.................... /* standard template:
.................... void *memmove(void *s1, void *s2, size_t n).
.................... Copies max of n characters safely (not following ending '\0')
.................... from s2 in s1; if s2 has less than n characters, appends 0 */
....................
.................... char *memmove(void *s1,char *s2,size_t n)
.................... {
.................... char *sc1;
.................... char *sc2;
.................... sc1=s1;
.................... sc2=s2;
.................... if(sc2<sc1 && sc1 <sc2 +n)
.................... for(sc1+=n,sc2+=n;0<n;--n)
.................... *--sc1=*--sc2;
.................... else
.................... for(;0<n;--n)
.................... *sc1++=*sc2++;
.................... return s1;
.................... }
....................
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved?
.................... Standard template: char *strcpy(char *s1, const char *s2)
.................... copies the string s2 including the null character to s1*/
....................
.................... char *strcopy(char *s1, char *s2)
.................... {
.................... char *s;
....................
.................... for (s = s1; *s2 != 0; s++, s2++) {
.................... *s = *s2;
.................... }
.................... *s = *s2;
.................... return(s1);
.................... }
....................
.................... /* standard template:
.................... char *strncpy(char *s1, const char *s2, size_t n).
.................... Copies max of n characters (not following ending '\0')
.................... from s2 in s1; if s2 has less than n characters, appends 0 */
....................
.................... char *strncpy(char *s1, char *s2, size_t n)
.................... {
.................... char *s;
....................
.................... for (s = s1; n > 0 && *s2 != '\0'; n--)
.................... *s++ = *s2++;
.................... for (; n > 0; n--)
.................... *s++ = '\0';
....................
.................... return(s1);
.................... }
.................... /***********************************************************/
....................
.................... /*concatenation functions*/
.................... /* standard template: char *strcat(char *s1, const char *s2)
.................... appends s2 to s1*/
....................
.................... char *strcat(char *s1, char *s2)
.................... {
.................... char *s;
....................
.................... for (s = s1; *s != '\0'; ++s);
.................... while(*s2 != '\0')
.................... {
.................... *s = *s2;
.................... ++s;
.................... ++s2;
.................... }
....................
.................... *s = '\0';
.................... return(s1);
.................... }
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n)
.................... appends not more than n characters from s2 to s1*/
....................
.................... char *strncat(char *s1, char *s2, size_t n)
.................... {
.................... char *s;
....................
.................... for (s = s1; *s != '\0'; ++s);
.................... while(*s2 != '\0' && 0<n)
.................... {
.................... *s = *s2;
.................... ++s;
.................... ++s2;
.................... --n;
.................... }
....................
.................... *s = '\0';
.................... return(s1);
.................... }
....................
.................... /***********************************************************/
....................
....................
.................... /*comparison functions*/
.................... /* standard template: signed int memcmp(void *s1, void *s2).
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
....................
.................... signed int memcmp(void * s1,char *s2,size_t n)
.................... {
.................... char *su1, *su2;
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n)
.................... {
.................... if(*su1!=*su2)
.................... return ((*su1<*su2)?-1:+1);
.................... }
.................... return 0;
.................... }
....................
.................... /* standard template: int strcmp(const char *s1, const char *s2).
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
....................
.................... signed int strcmp(char *s1, char *s2)
.................... {
.................... for (; *s1 == *s2; s1++, s2++)
.................... if (*s1 == '\0')
.................... return(0);
.................... return((*s1 < *s2) ? -1: 1);
.................... }
.................... /* standard template: int strcoll(const char *s1, const char *s2).
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
....................
.................... signed int strcoll(char *s1, char *s2)
.................... {
.................... for (; *s1 == *s2; s1++, s2++)
.................... if (*s1 == '\0')
.................... return(0);
.................... return((*s1 < *s2) ? -1: 1);
.................... }
....................
.................... /* standard template:
.................... int strncmp(const char *s1, const char *s2, size_t n).
.................... Compares max of n characters (not following 0) from s1 to s2;
.................... returns same as strcmp */
....................
.................... signed int strncmp(char *s1, char *s2, size_t n)
.................... {
.................... for (; n > 0; s1++, s2++, n--)
.................... if (*s1 != *s2)
.................... return((*s1 <*s2) ? -1: 1);
.................... else if (*s1 == '\0')
.................... return(0);
.................... return(0);
.................... }
.................... /* standard template:
.................... int strxfrm(const char *s1, const char *s2, size_t n).
.................... transforms maximum of n characters from s2 and places them into s1*/
.................... size_t strxfrm(char *s1, char *s2, size_t n)
.................... {
.................... char *s;
.................... int n1;
.................... n1=n;
.................... for (s = s1; n > 0 && *s2 != '\0'; n--)
.................... *s++ = *s2++;
.................... for (; n > 0; n--)
.................... *s++ = '\0';
....................
.................... return(n1);
.................... }
....................
....................
....................
....................
....................
.................... /***********************************************************/
.................... /*Search functions*/
.................... /* standard template: void *memchr(const char *s, int c).
.................... Finds first occurrence of c in n characters of s */
....................
.................... char *memchr(void *s,int c,size_t n)
.................... {
.................... char uc;
.................... char *su;
.................... uc=c;
.................... for(su=s;0<n;++su,--n)
.................... if(*su==uc)
.................... return su;
.................... return NULL;
.................... }
....................
.................... /* standard template: char *strchr(const char *s, int c).
.................... Finds first occurrence of c in s */
....................
.................... char *strchr(char *s, int c)
.................... {
.................... for (; *s != c; s++)
.................... if (*s == '\0')
.................... return(0);
.................... return(s);
.................... }
.................... /* standard template:
.................... size_t strcspn(const char *s1, const char *s2).
.................... Computes length of max initial segment of s1 that
.................... consists entirely of characters NOT from s2*/
....................
.................... int *strcspn(char *s1, char *s2)
.................... {
.................... char *sc1, *sc2;
....................
.................... for (sc1 = s1; *sc1 != 0; sc1++)
.................... for (sc2 = s2; *sc2 != 0; sc2++)
.................... if (*sc1 == *sc2)
.................... return(sc1 - s1);
.................... return(sc1 - s1);
.................... }
.................... /* standard template:
.................... char *strpbrk(const char *s1, const char *s2).
.................... Locates first occurence of any character from s2 in s1;
.................... returns s1 if s2 is empty string */
....................
.................... char *strpbrk(char *s1, char *s2)
.................... {
.................... char *sc1, *sc2;
....................
.................... for (sc1 = s1; *sc1 != 0; sc1++)
.................... for (sc2 = s2; *sc2 != 0; sc2++)
.................... if (*sc1 == *sc2)
.................... return(sc1);
.................... return(0);
.................... }
....................
....................
.................... /* standard template: char *strrchr(const char *s, int c).
.................... Finds last occurrence of c in s */
....................
.................... char *strrchr(char *s, int c)
.................... {
.................... char *p;
....................
.................... for (p = 0; ; s++)
.................... {
.................... if (*s == c)
.................... p = s;
.................... if (*s == '\0')
.................... return(p);
.................... }
.................... }
.................... /* computes length of max initial segment of s1 consisting
.................... entirely of characters from s2 */
....................
.................... int *strspn(char *s1, char *s2)
.................... {
.................... char *sc1, *sc2;
....................
.................... for (sc1 = s1; *sc1 != 0; sc1++)
.................... for (sc2 = s2; ; sc2++)
.................... if (*sc2 == '\0')
.................... return(sc1 - s1);
.................... else if (*sc1 == *sc2)
.................... break;
.................... return(sc1 - s1);
.................... }
.................... /* standard template:
.................... char *strstr(const char *s1, const char *s2);
.................... Locates first occurence of character sequence s2 in s1;
.................... returns 0 if s2 is empty string
....................
.................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
.................... file to use the faster algorithm */
.................... char *strstr(char *s1, char *s2)
.................... {
.................... char *s, *t;
....................
.................... #ifdef FASTER_BUT_MORE_ROM
.................... if (*s2 == '\0')
.................... return(s1);
.................... #endif
....................
.................... while (*s1)
.................... {
.................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t);
....................
.................... if (*t == '\0')
.................... return s1;
.................... ++s1;
.................... #ifdef FASTER_BUT_MORE_ROM
.................... while(*s1 != '\0' && *s1 != *s2)
.................... ++s1;
.................... #endif
.................... }
.................... return 0;
.................... }
....................
.................... /* standard template: char *strtok(char *s1, const char *s2).
....................
.................... Finds next token in s1 delimited by a character from separator
.................... string s2 (which can be different from call to call). First call
.................... starts at beginning of s1 searching for first character NOT
.................... contained in s2; returns 0 if none is found.
.................... If one is found, it is the start of first token (return value).
.................... Function then searches from there for a character contained in s2.
.................... If none is found, current token extends to end of s1, and subsequent
.................... searches for a token will return 0. If one is found, it is
.................... overwritten by '\0', which terminates current token. Function saves
.................... pointer to following character from which next search will start.
.................... Each subsequent call, with 0 as first argument, starts searching
.................... from saved pointer */
....................
.................... char *strtok(char *s1, char *s2)
.................... {
.................... char *beg, *end;
.................... static char *save;
....................
.................... beg = (s1)? s1: save;
.................... beg += strspn(beg, s2);
.................... if (*beg == '\0')
.................... {
.................... *save = ' ';
.................... return(0);
.................... }
.................... end = strpbrk(beg, s2);
.................... if (*end != '\0')
.................... {
.................... *end = '\0';
.................... end++;
.................... }
.................... save = end;
.................... return(beg);
.................... }
....................
.................... /*****************************************************************/
.................... /*Miscellaneous functions*/
.................... /* standard template
.................... maps error number in errnum to an error message string
.................... Returns: Pointer to string
.................... */
.................... #ifdef _ERRNO
.................... char * strerror(int errnum)
.................... {
.................... char s[15];
.................... switch( errnum)
.................... {
.................... case 0:
.................... strcpy(s,"no errors");
.................... return s;
.................... case EDOM :
.................... strcpy(s,"domain error");
.................... return s;
.................... case ERANGE:
.................... strcpy(s,"range error");
.................... return s;
.................... }
.................... }
.................... #ENDIF
.................... /* standard template: size_t strlen(const char *s).
.................... Computes length of s1 (preceding terminating 0) */
....................
.................... int *strlen(char *s)
.................... {
.................... char *sc;
....................
.................... for (sc = s; *sc != 0; sc++);
.................... return(sc - s);
.................... }
....................
.................... /* standard template: size_t stricmp(const char *s1, const char *s2).
.................... Compares s1 to s2 ignoring case (upper vs. lower) */
....................
.................... signed int stricmp(char *s1, char *s2)
.................... {
.................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
.................... s1++, s2++)
.................... if (*s1 == '\0')
.................... return(0);
.................... return((*s1 < *s2) ? -1: 1);
.................... }
....................
....................
.................... /* standard template: char *strlwr(char *s).
.................... Replaces uppercase letters by lowercase;
.................... returns pointer to new string s */
....................
.................... char *strlwr(char *s)
.................... {
.................... char *p;
....................
.................... for (p = s; *p != '\0'; p++)
.................... if (*p >= 'A' && *p <='Z')
.................... *p += 'a' - 'A';
.................... return(s);
.................... }
....................
....................
.................... /************************************************************/
....................
....................
.................... #endif
....................
....................
.................... div_t div(signed int numer,signed int denom)
.................... {
.................... div_t val;
.................... val.quot = numer / denom;
.................... val.rem = numer - (denom * val.quot);
.................... return (val);
.................... }
....................
.................... ldiv_t ldiv(signed long numer,signed long denom)
.................... {
.................... ldiv_t val;
.................... val.quot = numer / denom;
.................... val.rem = numer - (denom * val.quot);
.................... return (val);
.................... }
....................
.................... float atof(char * s)
.................... {
.................... float pow10 = 1.0;
.................... float result = 0.0;
.................... int sign = 0;
.................... char c;
.................... int ptr = 0;
....................
.................... c = s[ptr++];
....................
.................... if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') {
.................... if(c == '-') {
.................... sign = 1;
.................... c = s[ptr++];
.................... }
.................... if(c == '+')
.................... c = s[ptr++];
....................
.................... while((c >= '0' && c <= '9')) {
.................... result = 10*result + c - '0';
.................... c = s[ptr++];
.................... }
....................
.................... if (c == '.') {
.................... c = s[ptr++];
.................... while((c >= '0' && c <= '9')) {
.................... pow10 = pow10*10;
.................... result += (c - '0')/pow10;
.................... c = s[ptr++];
.................... }
.................... }
....................
.................... }
....................
.................... if (sign == 1)
.................... result = -1*result;
.................... return(result);
.................... }
....................
.................... float atoe(char * s)
.................... {
.................... float pow10 = 1.0;
.................... float result = 0.0;
.................... int sign = 0;
.................... int expsign = 0;
.................... char c;
.................... int ptr = 0;
.................... int i;
.................... float exp = 1.0;
.................... int expcnt = 0;
....................
.................... c = s[ptr++];
....................
.................... if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') {
.................... if(c == '-') {
.................... sign = 1;
.................... c = s[ptr++];
.................... }
.................... if(c == '+')
.................... c = s[ptr++];
....................
.................... while((c >= '0' && c <= '9')) {
.................... result = 10*result + c - '0';
.................... c = s[ptr++];
.................... }
....................
.................... if (c == '.') {
.................... c = s[ptr++];
.................... while((c >= '0' && c <= '9')) {
.................... pow10 = pow10*10;
.................... result += (c - '0')/pow10;
.................... c = s[ptr++];
.................... }
.................... }
....................
.................... // Handling the exponent
.................... if (c=='e' || c=='E') {
.................... c = s[ptr++];
....................
.................... if(c == '-') {
.................... expsign = 1;
.................... c = s[ptr++];
.................... }
.................... if(c == '+')
.................... c = s[ptr++];
....................
.................... while((c >= '0' && c <= '9')) {
.................... expcnt = 10*expcnt + c - '0';
.................... c = s[ptr++];
.................... }
....................
.................... for(i=0;i<expcnt;i++)
.................... exp*=10;
....................
.................... if(expsign==1)
.................... result/=exp;
.................... else
.................... result*=exp;
.................... }
.................... }
....................
.................... if (sign == 1)
.................... result = -1*result;
.................... return(result);
.................... }
....................
.................... signed int atoi(char *s)
.................... {
.................... signed int result;
.................... int sign, base, index;
.................... char c;
....................
.................... index = 0;
.................... sign = 0;
.................... base = 10;
.................... result = 0;
....................
.................... if (!s)
.................... return 0;
.................... // Omit all preceeding alpha characters
.................... c = s[index++];
....................
.................... // increase index if either positive or negative sign is detected
.................... if (c == '-')
.................... {
.................... sign = 1; // Set the sign to negative
.................... c = s[index++];
.................... }
.................... else if (c == '+')
.................... {
.................... c = s[index++];
.................... }
....................
.................... if (c >= '0' && c <= '9')
.................... {
....................
.................... // Check for hexa number
.................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
.................... {
.................... base = 16;
.................... index++;
.................... c = s[index++];
.................... }
....................
.................... // The number is a decimal number
.................... if (base == 10)
.................... {
.................... while (c >= '0' && c <= '9')
.................... {
.................... result = 10*result + (c - '0');
.................... c = s[index++];
.................... }
.................... }
.................... else if (base == 16) // The number is a hexa number
.................... {
.................... c = toupper(c);
.................... while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F'))
.................... {
.................... if (c >= '0' && c <= '9')
.................... result = (result << 4) + (c - '0');
.................... else
.................... result = (result << 4) + (c - 'A' + 10);
....................
.................... c = s[index++];
.................... c = toupper(c);
.................... }
.................... }
.................... }
....................
.................... if (sign == 1 && base == 10)
.................... result = -result;
....................
.................... return(result);
.................... }
....................
.................... signed long atol(char *s)
.................... {
.................... signed long result;
.................... int sign, base, index;
.................... char c;
....................
.................... index = 0;
.................... sign = 0;
.................... base = 10;
.................... result = 0;
....................
.................... if (!s)
.................... return 0;
.................... c = s[index++];
....................
.................... // increase index if either positive or negative sign is detected
.................... if (c == '-')
.................... {
.................... sign = 1; // Set the sign to negative
.................... c = s[index++];
.................... }
.................... else if (c == '+')
.................... {
.................... c = s[index++];
.................... }
....................
.................... if (c >= '0' && c <= '9')
.................... {
.................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
.................... {
.................... base = 16;
.................... index++;
.................... c = s[index++];
.................... }
....................
.................... // The number is a decimal number
.................... if (base == 10)
.................... {
.................... while (c >= '0' && c <= '9')
.................... {
.................... result = 10*result + (c - '0');
.................... c = s[index++];
.................... }
.................... }
.................... else if (base == 16) // The number is a hexa number
.................... {
.................... c = toupper(c);
.................... while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F'))
.................... {
.................... if (c >= '0' && c <= '9')
.................... result = (result << 4) + (c - '0');
.................... else
.................... result = (result << 4) + (c - 'A' + 10);
....................
.................... c = s[index++];c = toupper(c);
.................... }
.................... }
.................... }
....................
.................... if (base == 10 && sign == 1)
.................... result = -result;
....................
.................... return(result);
.................... }
....................
.................... /* A fast routine to multiply by 10
.................... */
.................... signed int32 mult_with10(int32 num)
.................... {
.................... return ( (num << 1) + (num << 3) );
.................... }
....................
.................... signed int32 atoi32(char *s)
.................... {
.................... signed int32 result;
.................... int sign, base, index;
.................... char c;
....................
.................... index = 0;
.................... sign = 0;
.................... base = 10;
.................... result = 0;
....................
.................... if (!s)
.................... return 0;
.................... c = s[index++];
....................
.................... // increase index if either positive or negative sign is detected
.................... if (c == '-')
.................... {
.................... sign = 1; // Set the sign to negative
.................... c = s[index++];
.................... }
.................... else if (c == '+')
.................... {
.................... c = s[index++];
.................... }
....................
.................... if (c >= '0' && c <= '9')
.................... {
.................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
.................... {
.................... base = 16;
.................... index++;
.................... c = s[index++];
.................... }
....................
.................... // The number is a decimal number
.................... if (base == 10)
.................... {
.................... while (c >= '0' && c <= '9') {
.................... result = (result << 1) + (result << 3); // result *= 10;
.................... result += (c - '0');
.................... c = s[index++];
.................... }
.................... }
.................... else if (base == 16) // The number is a hexa number
.................... {
.................... c = toupper(c);
.................... while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F'))
.................... {
.................... if (c >= '0' && c <= '9')
.................... result = (result << 4) + (c - '0');
.................... else
.................... result = (result << 4) + (c - 'A' + 10);
....................
.................... c = s[index++];c = toupper(c);
.................... }
.................... }
.................... }
....................
.................... if (base == 10 && sign == 1)
.................... result = -result;
....................
.................... return(result);
.................... }
....................
.................... char * itoa(signed int32 num, int8 base, char *s)
.................... {
.................... int32 temp=1;
.................... int8 i,sign=0,cnt=0;
.................... char c;
....................
.................... if(num<0) {
.................... sign=1; // Check for negative number
.................... num*=-1;
.................... }
....................
.................... while(temp>0) {
.................... temp=(num/base);
.................... s[cnt]=(num%base)+'0'; // Conversion
....................
.................... if(s[cnt]>0x39)
.................... s[cnt]+=0x7;
....................
.................... cnt++;
.................... num=temp;
.................... }
....................
.................... if(sign==1) {
.................... s[cnt]=0x2D; // Negative sign
.................... cnt++;
.................... }
....................
.................... for(i = 0;i<(int8)(cnt/2);i++) {
....................
.................... c=s[i];
.................... s[i]=s[cnt-i-1]; // Reverse the number
.................... s[cnt-i-1]=c;
.................... }
.................... s[cnt]='\0'; // End the string
.................... return s;
.................... }
....................
.................... float strtod(char *s,char *endptr) {
.................... float pow10 = 1.0;
.................... float result = 0.0;
.................... int sign = 0, point = 0;
.................... char c;
.................... int ptr = 0;
....................
.................... if (!s)
.................... return 0;
.................... c=s[ptr++];
....................
....................
.................... while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') {
.................... if(c == '-') {
.................... sign = 1;
.................... c = s[ptr++];
.................... }
....................
.................... while((c >= '0' && c <= '9') && point == 0) {
.................... result = 10*result + c - '0';
.................... c = s[ptr++];
.................... }
....................
.................... if (c == '.') {
.................... point = 1;
.................... c = s[ptr++];
.................... }
....................
.................... while((c >= '0' && c <= '9') && point == 1) {
.................... pow10 = pow10*10;
.................... result += (c - '0')/pow10;
.................... c = s[ptr++];
.................... }
....................
.................... if (c == '+') {
.................... c = s[ptr++];
.................... }
.................... }
....................
.................... if (sign == 1)
.................... result = -1*result;
.................... if(endptr)
.................... {
.................... if (ptr) {
.................... ptr--;
.................... *((char *)endptr)=s+ptr;
.................... }
.................... else
.................... *((char *)endptr)=s;
.................... }
....................
.................... return(result);
.................... }
....................
.................... long strtoul(char *s,char *endptr,signed int base)
.................... {
.................... char *sc,*s1,*sd;
.................... unsigned long x=0;
*
024F: CLRF 57
0250: CLRF 58
.................... char sign;
.................... char digits[]="0123456789abcdefghijklmnopqstuvwxyz";
0251: MOVLW 30
0252: BSF 03.5
0253: MOVWF 20
0254: MOVLW 31
0255: MOVWF 21
0256: MOVLW 32
0257: MOVWF 22
0258: MOVLW 33
0259: MOVWF 23
025A: MOVLW 34
025B: MOVWF 24
025C: MOVLW 35
025D: MOVWF 25
025E: MOVLW 36
025F: MOVWF 26
0260: MOVLW 37
0261: MOVWF 27
0262: MOVLW 38
0263: MOVWF 28
0264: MOVLW 39
0265: MOVWF 29
0266: MOVLW 61
0267: MOVWF 2A
0268: MOVLW 62
0269: MOVWF 2B
026A: MOVLW 63
026B: MOVWF 2C
026C: MOVLW 64
026D: MOVWF 2D
026E: MOVLW 65
026F: MOVWF 2E
0270: MOVLW 66
0271: MOVWF 2F
0272: MOVLW 67
0273: MOVWF 30
0274: MOVLW 68
0275: MOVWF 31
0276: MOVLW 69
0277: MOVWF 32
0278: MOVLW 6A
0279: MOVWF 33
027A: MOVLW 6B
027B: MOVWF 34
027C: MOVLW 6C
027D: MOVWF 35
027E: MOVLW 6D
027F: MOVWF 36
0280: MOVLW 6E
0281: MOVWF 37
0282: MOVLW 6F
0283: MOVWF 38
0284: MOVLW 70
0285: MOVWF 39
0286: MOVLW 71
0287: MOVWF 3A
0288: MOVLW 73
0289: MOVWF 3B
028A: MOVLW 74
028B: MOVWF 3C
028C: MOVLW 75
028D: MOVWF 3D
028E: MOVLW 76
028F: MOVWF 3E
0290: MOVLW 77
0291: MOVWF 3F
0292: MOVLW 78
0293: MOVWF 40
0294: MOVLW 79
0295: MOVWF 41
0296: MOVLW 7A
0297: MOVWF 42
0298: CLRF 43
.................... for(sc=s;isspace(*sc);++sc);
0299: BCF 03.5
029A: MOVF 51,W
029B: MOVWF 54
029C: MOVF 54,W
029D: MOVWF 04
029E: MOVF 00,W
029F: SUBLW 20
02A0: BTFSS 03.2
02A1: GOTO 2A4
02A2: INCF 54,F
02A3: GOTO 29C
.................... sign=*sc=='-'||*sc=='+'?*sc++:'+';
02A4: MOVF 54,W
02A5: MOVWF 04
02A6: MOVF 00,W
02A7: SUBLW 2D
02A8: BTFSC 03.2
02A9: GOTO 2B0
02AA: MOVF 54,W
02AB: MOVWF 04
02AC: MOVF 00,W
02AD: SUBLW 2B
02AE: BTFSS 03.2
02AF: GOTO 2B5
02B0: MOVF 54,W
02B1: INCF 54,F
02B2: MOVWF 04
02B3: MOVF 00,W
02B4: GOTO 2B6
02B5: MOVLW 2B
02B6: MOVWF 59
.................... if(sign=='-')
02B7: MOVF 59,W
02B8: SUBLW 2D
02B9: BTFSS 03.2
02BA: GOTO 2C6
.................... {
.................... if (endptr)
02BB: MOVF 52,F
02BC: BTFSC 03.2
02BD: GOTO 2C2
.................... {
.................... *((char *)endptr)=s;
02BE: MOVF 52,W
02BF: MOVWF 04
02C0: MOVF 51,W
02C1: MOVWF 00
.................... }
.................... return 0;
02C2: MOVLW 00
02C3: MOVWF 78
02C4: MOVWF 79
02C5: GOTO 3D2
.................... }
....................
.................... if (base <0 || base ==1|| base >36) // invalid base
02C6: BTFSC 53.7
02C7: GOTO 2D1
02C8: DECFSZ 53,W
02C9: GOTO 2CB
02CA: GOTO 2D1
02CB: BTFSC 53.7
02CC: GOTO 2DD
02CD: MOVF 53,W
02CE: SUBLW 24
02CF: BTFSC 03.0
02D0: GOTO 2DD
.................... {
.................... if (endptr)
02D1: MOVF 52,F
02D2: BTFSC 03.2
02D3: GOTO 2D8
.................... {
.................... *((char *)endptr)=s;
02D4: MOVF 52,W
02D5: MOVWF 04
02D6: MOVF 51,W
02D7: MOVWF 00
.................... }
.................... return 0;
02D8: MOVLW 00
02D9: MOVWF 78
02DA: MOVWF 79
02DB: GOTO 3D2
.................... }
.................... else if (base)
02DC: GOTO 343
02DD: MOVF 53,F
02DE: BTFSC 03.2
02DF: GOTO 31A
.................... {
.................... if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X'))
02E0: MOVF 53,W
02E1: SUBLW 10
02E2: BTFSS 03.2
02E3: GOTO 2FA
02E4: MOVF 54,W
02E5: MOVWF 04
02E6: MOVF 00,W
02E7: SUBLW 30
02E8: BTFSS 03.2
02E9: GOTO 2FA
02EA: MOVLW 01
02EB: ADDWF 54,W
02EC: MOVWF 04
02ED: MOVF 00,W
02EE: SUBLW 78
02EF: BTFSC 03.2
02F0: GOTO 2F8
02F1: MOVLW 01
02F2: ADDWF 54,W
02F3: MOVWF 04
02F4: MOVF 00,W
02F5: SUBLW 58
02F6: BTFSS 03.2
02F7: GOTO 2FA
.................... sc+=2;
02F8: MOVLW 02
02F9: ADDWF 54,F
.................... if(base==8 && *sc =='0')
02FA: MOVF 53,W
02FB: SUBLW 08
02FC: BTFSS 03.2
02FD: GOTO 306
02FE: MOVF 54,W
02FF: MOVWF 04
0300: MOVF 00,W
0301: SUBLW 30
0302: BTFSS 03.2
0303: GOTO 306
.................... sc+=1;
0304: MOVLW 01
0305: ADDWF 54,F
.................... if(base==2 && *sc =='0'&&sc[1]=='b')
0306: MOVF 53,W
0307: SUBLW 02
0308: BTFSS 03.2
0309: GOTO 319
030A: MOVF 54,W
030B: MOVWF 04
030C: MOVF 00,W
030D: SUBLW 30
030E: BTFSS 03.2
030F: GOTO 319
0310: MOVLW 01
0311: ADDWF 54,W
0312: MOVWF 04
0313: MOVF 00,W
0314: SUBLW 62
0315: BTFSS 03.2
0316: GOTO 319
.................... sc+=2;
0317: MOVLW 02
0318: ADDWF 54,F
....................
.................... }
.................... else if(*sc!='0') // base is 0, find base
0319: GOTO 343
031A: MOVF 54,W
031B: MOVWF 04
031C: MOVF 00,W
031D: SUBLW 30
031E: BTFSC 03.2
031F: GOTO 323
.................... base=10;
0320: MOVLW 0A
0321: MOVWF 53
.................... else if (sc[1]=='x' || sc[1]=='X')
0322: GOTO 343
0323: MOVLW 01
0324: ADDWF 54,W
0325: MOVWF 04
0326: MOVF 00,W
0327: SUBLW 78
0328: BTFSC 03.2
0329: GOTO 331
032A: MOVLW 01
032B: ADDWF 54,W
032C: MOVWF 04
032D: MOVF 00,W
032E: SUBLW 58
032F: BTFSS 03.2
0330: GOTO 336
.................... base =16,sc+=2;
0331: MOVLW 10
0332: MOVWF 53
0333: MOVLW 02
0334: ADDWF 54,F
.................... else if(sc[1]=='b')
0335: GOTO 343
0336: MOVLW 01
0337: ADDWF 54,W
0338: MOVWF 04
0339: MOVF 00,W
033A: SUBLW 62
033B: BTFSS 03.2
033C: GOTO 341
.................... base=2,sc+=2;
033D: MOVLW 02
033E: MOVWF 53
033F: ADDWF 54,F
.................... else
0340: GOTO 343
.................... base=8;
0341: MOVLW 08
0342: MOVWF 53
.................... for (s1=sc;*sc=='0';++sc);// skip leading zeroes
0343: MOVF 54,W
0344: MOVWF 55
0345: MOVF 54,W
0346: MOVWF 04
0347: MOVF 00,W
0348: SUBLW 30
0349: BTFSS 03.2
034A: GOTO 34D
034B: INCF 54,F
034C: GOTO 345
.................... sd=memchr(digits,tolower(*sc),base);
034D: MOVF 54,W
034E: MOVWF 04
034F: MOVF 00,W
0350: MOVWF 5A
0351: SUBLW 40
0352: BTFSC 03.0
0353: GOTO 35B
0354: MOVF 5A,W
0355: SUBLW 5A
0356: BTFSS 03.0
0357: GOTO 35B
0358: MOVF 5A,W
0359: IORLW 20
035A: GOTO 35C
035B: MOVF 5A,W
035C: MOVWF 5B
035D: MOVLW A0
035E: BSF 03.5
035F: MOVWF 46
0360: BCF 03.5
0361: MOVF 5A,W
0362: BSF 03.5
0363: MOVWF 47
0364: BCF 03.5
0365: MOVF 53,W
0366: BSF 03.5
0367: MOVWF 48
0368: BCF 03.5
0369: CALL 21D
036A: MOVF 78,W
036B: MOVWF 56
.................... for(; sd!=0; )
036C: MOVF 56,F
036D: BTFSC 03.2
036E: GOTO 3B8
.................... {
.................... x=x*base+(int16)(sd-digits);
036F: CLRF 7A
0370: MOVF 53,W
0371: MOVWF 77
0372: BTFSC 53.7
0373: DECF 7A,F
0374: MOVWF 5A
0375: MOVF 7A,W
0376: MOVWF 5B
0377: MOVF 58,W
0378: BSF 03.5
0379: MOVWF 47
037A: BCF 03.5
037B: MOVF 57,W
037C: BSF 03.5
037D: MOVWF 46
037E: BCF 03.5
037F: MOVF 7A,W
0380: BSF 03.5
0381: MOVWF 49
0382: BCF 03.5
0383: MOVF 5A,W
0384: BSF 03.5
0385: MOVWF 48
0386: BCF 03.5
0387: GOTO 236
0388: MOVF 78,W
0389: MOVWF 5B
038A: MOVLW A0
038B: SUBWF 56,W
038C: CLRF 7A
038D: ADDWF 78,W
038E: MOVWF 78
038F: BTFSC 03.0
0390: INCF 7A,F
0391: MOVF 79,W
0392: ADDWF 7A,F
0393: MOVF 78,W
0394: MOVWF 57
0395: MOVF 7A,W
0396: MOVWF 58
.................... ++sc;
0397: INCF 54,F
.................... sd=memchr(digits,tolower(*sc),base);
0398: MOVF 54,W
0399: MOVWF 04
039A: MOVF 00,W
039B: MOVWF 5A
039C: SUBLW 40
039D: BTFSC 03.0
039E: GOTO 3A6
039F: MOVF 5A,W
03A0: SUBLW 5A
03A1: BTFSS 03.0
03A2: GOTO 3A6
03A3: MOVF 5A,W
03A4: IORLW 20
03A5: GOTO 3A7
03A6: MOVF 5A,W
03A7: MOVWF 5B
03A8: MOVLW A0
03A9: BSF 03.5
03AA: MOVWF 46
03AB: BCF 03.5
03AC: MOVF 5A,W
03AD: BSF 03.5
03AE: MOVWF 47
03AF: BCF 03.5
03B0: MOVF 53,W
03B1: BSF 03.5
03B2: MOVWF 48
03B3: BCF 03.5
03B4: CALL 21D
03B5: MOVF 78,W
03B6: MOVWF 56
.................... }
03B7: GOTO 36C
.................... if(s1==sc)
03B8: MOVF 54,W
03B9: SUBWF 55,W
03BA: BTFSS 03.2
03BB: GOTO 3C7
.................... {
.................... if (endptr)
03BC: MOVF 52,F
03BD: BTFSC 03.2
03BE: GOTO 3C3
.................... {
.................... *((char *)endptr)=s;
03BF: MOVF 52,W
03C0: MOVWF 04
03C1: MOVF 51,W
03C2: MOVWF 00
.................... }
.................... return 0;
03C3: MOVLW 00
03C4: MOVWF 78
03C5: MOVWF 79
03C6: GOTO 3D2
.................... }
.................... if (endptr)
03C7: MOVF 52,F
03C8: BTFSC 03.2
03C9: GOTO 3CE
.................... *((char *)endptr)=sc;
03CA: MOVF 52,W
03CB: MOVWF 04
03CC: MOVF 54,W
03CD: MOVWF 00
.................... return x;
03CE: MOVF 57,W
03CF: MOVWF 78
03D0: MOVF 58,W
03D1: MOVWF 79
.................... }
03D2: BCF 0A.3
03D3: BCF 0A.4
03D4: GOTO 4FF (RETURN)
....................
....................
.................... 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;
*
03ED: MOVLW 01
03EE: MOVWF 22
03EF: CLRF 23
03F0: CLRF 24
03F1: CLRF 25
....................
.................... 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
....................
....................
.................... #define DELKA 40
....................
.................... char odp[DELKA];
....................
.................... int1 check_new_sms()
.................... {
.................... fprintf(MOBIL,"AT+CMGL=1\r"); //vycti prijate SMS (0=nove;1=vsechny)
*
00B6: CLRF 51
00B7: MOVF 51,W
00B8: CALL 004
00B9: IORLW 00
00BA: BTFSC 03.2
00BB: GOTO 0C0
00BC: INCF 51,F
00BD: MOVWF 53
00BE: CALL 064
00BF: GOTO 0B7
.................... while(fgetc(MOBIL)!=0x0A); // predkoc prvni radek odpovedi
00C0: CALL 08C
00C1: MOVF 78,W
00C2: SUBLW 0A
00C3: BTFSS 03.2
00C4: GOTO 0C0
.................... odp[0]=fgetc(MOBIL); // Nacti prvni dva znaky druheho radku odpovedi
00C5: CALL 08C
00C6: MOVF 78,W
00C7: MOVWF 26
.................... odp[1]=fgetc(MOBIL);
00C8: CALL 08C
00C9: MOVF 78,W
00CA: MOVWF 27
.................... while(fgetc(MOBIL)!=0x0A); // Preskoc zbytek radku
00CB: CALL 08C
00CC: MOVF 78,W
00CD: SUBLW 0A
00CE: BTFSS 03.2
00CF: GOTO 0CB
....................
.................... if(odp[0] == 'O' && odp[1] == 'K') return 1;
00D0: MOVF 26,W
00D1: SUBLW 4F
00D2: BTFSS 03.2
00D3: GOTO 0DC
00D4: MOVF 27,W
00D5: SUBLW 4B
00D6: BTFSS 03.2
00D7: GOTO 0DC
00D8: MOVLW 01
00D9: MOVWF 78
00DA: GOTO 0DF
.................... else return 0;
00DB: GOTO 0DF
00DC: MOVLW 00
00DD: MOVWF 78
00DE: GOTO 0DF
.................... }
00DF: BCF 0A.3
00E0: BCF 0A.4
00E1: GOTO 46E (RETURN)
....................
.................... read_sms()
.................... {
.................... int pom,pom2,pom3,odkl,odkl2,maskovadlo;
.................... for(pom=0;pom<54;pom++) //preskoc nedulezite informace
00E2: CLRF 51
00E3: MOVF 51,W
00E4: SUBLW 35
00E5: BTFSS 03.0
00E6: GOTO 0EA
.................... {
.................... fgetc(MOBIL);
00E7: CALL 08C
.................... }
00E8: INCF 51,F
00E9: GOTO 0E3
....................
.................... //gets(odp); //uloz zakodovany text SMS
....................
.................... odp[0]=fgetc(MOBIL);
00EA: CALL 08C
00EB: MOVF 78,W
00EC: MOVWF 26
.................... odp[1]=fgetc(MOBIL);
00ED: CALL 08C
00EE: MOVF 78,W
00EF: MOVWF 27
.................... odp[2]=fgetc(MOBIL);
00F0: CALL 08C
00F1: MOVF 78,W
00F2: MOVWF 28
.................... odp[3]=fgetc(MOBIL);
00F3: CALL 08C
00F4: MOVF 78,W
00F5: MOVWF 29
.................... odp[4]=fgetc(MOBIL);
00F6: CALL 08C
00F7: MOVF 78,W
00F8: MOVWF 2A
.................... odp[5]=fgetc(MOBIL);
00F9: CALL 08C
00FA: MOVF 78,W
00FB: MOVWF 2B
.................... odp[6]=fgetc(MOBIL);
00FC: CALL 08C
00FD: MOVF 78,W
00FE: MOVWF 2C
.................... odp[7]=fgetc(MOBIL);
00FF: CALL 08C
0100: MOVF 78,W
0101: MOVWF 2D
....................
.................... /*lcd_gotoxy(1,1);
.................... printf(lcd_putc,"\f%s\n",odp);*/
....................
.................... if(odp[0]==0) odp[1]='0'; // Prevod z ASCII do BIN
0102: MOVF 26,F
0103: BTFSS 03.2
0104: GOTO 107
0105: MOVLW 30
0106: MOVWF 27
.................... odp[0]=odp[0] - '0';
0107: MOVLW 30
0108: SUBWF 26,F
.................... odp[1]=odp[1] - '0';
0109: SUBWF 27,F
.................... if(odp[0]>9) odp[0]=odp[0]-7;
010A: MOVF 26,W
010B: SUBLW 09
010C: BTFSC 03.0
010D: GOTO 110
010E: MOVLW 07
010F: SUBWF 26,F
.................... if(odp[1]>9) odp[1]=odp[1]-7;
0110: MOVF 27,W
0111: SUBLW 09
0112: BTFSC 03.0
0113: GOTO 116
0114: MOVLW 07
0115: SUBWF 27,F
.................... odp[0]=odp[0] << 4;
0116: SWAPF 26,F
0117: MOVLW F0
0118: ANDWF 26,F
.................... odp[0] |= odp[1];
0119: MOVF 27,W
011A: IORWF 26,F
....................
.................... if(odp[2]==0) odp[3]='0';
011B: MOVF 28,F
011C: BTFSS 03.2
011D: GOTO 120
011E: MOVLW 30
011F: MOVWF 29
.................... odp[2]=odp[2] - '0';
0120: MOVLW 30
0121: SUBWF 28,F
.................... odp[3]=odp[3] - '0';
0122: SUBWF 29,F
.................... if(odp[2]>9) odp[2]=odp[2]-7;
0123: MOVF 28,W
0124: SUBLW 09
0125: BTFSC 03.0
0126: GOTO 129
0127: MOVLW 07
0128: SUBWF 28,F
.................... if(odp[3]>9) odp[3]=odp[3]-7;
0129: MOVF 29,W
012A: SUBLW 09
012B: BTFSC 03.0
012C: GOTO 12F
012D: MOVLW 07
012E: SUBWF 29,F
.................... odp[2]=odp[2] << 4;
012F: SWAPF 28,F
0130: MOVLW F0
0131: ANDWF 28,F
.................... odp[2] |= odp[3];
0132: MOVF 29,W
0133: IORWF 28,F
....................
.................... if(odp[4]==0) odp[5]='0';
0134: MOVF 2A,F
0135: BTFSS 03.2
0136: GOTO 139
0137: MOVLW 30
0138: MOVWF 2B
.................... odp[4]=odp[4] - '0';
0139: MOVLW 30
013A: SUBWF 2A,F
.................... odp[5]=odp[5] - '0';
013B: SUBWF 2B,F
.................... if(odp[4]>9) odp[4]=odp[4]-7;
013C: MOVF 2A,W
013D: SUBLW 09
013E: BTFSC 03.0
013F: GOTO 142
0140: MOVLW 07
0141: SUBWF 2A,F
.................... if(odp[5]>9) odp[5]=odp[5]-7;
0142: MOVF 2B,W
0143: SUBLW 09
0144: BTFSC 03.0
0145: GOTO 148
0146: MOVLW 07
0147: SUBWF 2B,F
.................... odp[4]=odp[4] << 4;
0148: SWAPF 2A,F
0149: MOVLW F0
014A: ANDWF 2A,F
.................... odp[4] |= odp[5];
014B: MOVF 2B,W
014C: IORWF 2A,F
....................
.................... if(odp[6]==0) odp[7]='0';
014D: MOVF 2C,F
014E: BTFSS 03.2
014F: GOTO 152
0150: MOVLW 30
0151: MOVWF 2D
.................... odp[6]=odp[6] - '0';
0152: MOVLW 30
0153: SUBWF 2C,F
.................... odp[7]=odp[7] - '0';
0154: SUBWF 2D,F
.................... if(odp[6]>9) odp[6]=odp[6]-7;
0155: MOVF 2C,W
0156: SUBLW 09
0157: BTFSC 03.0
0158: GOTO 15B
0159: MOVLW 07
015A: SUBWF 2C,F
.................... if(odp[7]>9) odp[7]=odp[7]-7;
015B: MOVF 2D,W
015C: SUBLW 09
015D: BTFSC 03.0
015E: GOTO 161
015F: MOVLW 07
0160: SUBWF 2D,F
.................... odp[6]=odp[6] << 4;
0161: SWAPF 2C,F
0162: MOVLW F0
0163: ANDWF 2C,F
.................... odp[6] |= odp[7];
0164: MOVF 2D,W
0165: IORWF 2C,F
....................
.................... odp[1]=odp[2];
0166: MOVF 28,W
0167: MOVWF 27
.................... odp[2]=odp[4];
0168: MOVF 2A,W
0169: MOVWF 28
.................... odp[3]=odp[6];
016A: MOVF 2C,W
016B: MOVWF 29
.................... odp[4]=odp[5]=odp[6]=0;
016C: CLRF 2C
016D: MOVF 2C,W
016E: MOVWF 2B
016F: MOVWF 2A
....................
.................... /*lcd_gotoxy(1,2);
.................... printf(lcd_putc,"%u %u %u %u",odp[0],odp[1],odp[2]odp[3]); */
....................
.................... pom3=0;
0170: CLRF 53
.................... for (pom = 0; pom < 4;pom++)
0171: CLRF 51
0172: MOVF 51,W
0173: SUBLW 03
0174: BTFSS 03.0
0175: GOTO 1C9
.................... {
.................... maskovadlo = maskovadlo >> 1; //rotace promene urcene pro maskovani
0176: BCF 03.0
0177: RRF 56,F
.................... maskovadlo = maskovadlo | 0x80;
0178: BSF 56.7
.................... odkl = odp[pom] & maskovadlo; //odlozeni "prenosu" do odkl pomoci maskovadla
0179: MOVLW 26
017A: ADDWF 51,W
017B: MOVWF 04
017C: MOVF 00,W
017D: ANDWF 56,W
017E: MOVWF 54
.................... odp[pom] = odp[pom] << pom3; //rotace znaku
017F: MOVLW 26
0180: ADDWF 51,W
0181: MOVWF 57
0182: MOVLW 26
0183: ADDWF 51,W
0184: MOVWF 04
0185: MOVF 00,W
0186: MOVWF 77
0187: MOVF 53,W
0188: MOVWF 78
0189: BTFSC 03.2
018A: GOTO 18F
018B: BCF 03.0
018C: RLF 77,F
018D: DECFSZ 78,F
018E: GOTO 18B
018F: MOVF 57,W
0190: MOVWF 04
0191: MOVF 77,W
0192: MOVWF 00
.................... for (pom2 = 0; pom2 < (8-pom3);pom2++) //rotace odkl2
0193: CLRF 52
0194: MOVF 53,W
0195: SUBLW 08
0196: SUBWF 52,W
0197: BTFSC 03.0
0198: GOTO 19E
.................... {
.................... odkl2 = odkl2 >> 1;
0199: BCF 03.0
019A: RRF 55,F
.................... odkl2 = odkl2 & 127;
019B: BCF 55.7
.................... }
019C: INCF 52,F
019D: GOTO 194
.................... odp[pom] = odp[pom] | odkl2; //pridani odkl2 ke znaku
019E: MOVLW 26
019F: ADDWF 51,W
01A0: MOVWF 57
01A1: MOVLW 26
01A2: ADDWF 51,W
01A3: MOVWF 04
01A4: MOVF 00,W
01A5: IORWF 55,W
01A6: MOVWF 59
01A7: MOVF 57,W
01A8: MOVWF 04
01A9: MOVF 59,W
01AA: MOVWF 00
.................... odp[pom] = odp[pom] & 127; //smazani nejvysiho bitu
01AB: MOVLW 26
01AC: ADDWF 51,W
01AD: MOVWF 57
01AE: MOVLW 26
01AF: ADDWF 51,W
01B0: MOVWF 04
01B1: MOVF 00,W
01B2: ANDLW 7F
01B3: MOVWF 59
01B4: MOVF 57,W
01B5: MOVWF 04
01B6: MOVF 59,W
01B7: MOVWF 00
.................... odkl2 = odkl; //ulozeni odlk na dalsi pruchod
01B8: MOVF 54,W
01B9: MOVWF 55
.................... pom3++; //inkrementace citace rotace
01BA: INCF 53,F
.................... if (pom3 == 8) //kazdy 8my znak
01BB: MOVF 53,W
01BC: SUBLW 08
01BD: BTFSS 03.2
01BE: GOTO 1C7
.................... {
.................... pom3 = 0; //smaz citac
01BF: CLRF 53
.................... odp[pom+1] = odkl2; //uloz 8my znak vznikly z "prenosu"
01C0: MOVLW 01
01C1: ADDWF 51,W
01C2: ADDLW 26
01C3: MOVWF 04
01C4: MOVF 55,W
01C5: MOVWF 00
.................... maskovadlo = 0; //smaz maskovadlo
01C6: CLRF 56
.................... }
.................... }
01C7: INCF 51,F
01C8: GOTO 172
.................... odp[pom]='\0';
01C9: MOVLW 26
01CA: ADDWF 51,W
01CB: MOVWF 04
01CC: CLRF 00
.................... }
01CD: BCF 0A.3
01CE: BCF 0A.4
01CF: GOTO 47A (RETURN)
....................
.................... void read_time()
.................... {
.................... unsigned int8 n;
....................
....................
.................... fprintf(MOBIL,"AT+CCLK?\r");
*
01FC: CLRF 52
01FD: MOVF 52,W
01FE: CALL 013
01FF: IORLW 00
0200: BTFSC 03.2
0201: GOTO 206
0202: INCF 52,F
0203: MOVWF 53
0204: CALL 064
0205: GOTO 1FD
.................... while(fgetc(MOBIL)!='"');
0206: CALL 08C
0207: MOVF 78,W
0208: SUBLW 22
0209: BTFSS 03.2
020A: GOTO 206
.................... for(n=0;n<12;n++) //preskoc nedulezite informace
020B: CLRF 51
020C: MOVF 51,W
020D: SUBLW 0B
020E: BTFSS 03.0
020F: GOTO 213
.................... {
.................... fgetc(MOBIL);
0210: CALL 08C
.................... }
0211: INCF 51,F
0212: GOTO 20C
.................... odp[0]=fgetc(MOBIL);
0213: CALL 08C
0214: MOVF 78,W
0215: MOVWF 26
.................... odp[1]=fgetc(MOBIL);
0216: CALL 08C
0217: MOVF 78,W
0218: MOVWF 27
.................... odp[2]=0;
0219: CLRF 28
.................... }
021A: BCF 0A.3
021B: BCF 0A.4
021C: GOTO 4F8 (RETURN)
....................
.................... void del_sms()
.................... {
.................... fprintf(MOBIL,"AT+CMGD=1\r"); //smaz prijatou SMSku
.................... }
....................
.................... void main()
.................... {
*
03D5: CLRF 04
03D6: MOVLW 1F
03D7: ANDWF 03,F
03D8: BCF 20.6
03D9: MOVF 20,W
03DA: BSF 03.5
03DB: MOVWF 07
03DC: BCF 03.5
03DD: BSF 07.6
03DE: BSF 03.5
03DF: BCF 06.2
03E0: BCF 03.5
03E1: BSF 06.2
03E2: BSF 03.5
03E3: BSF 1F.0
03E4: BSF 1F.1
03E5: BSF 1F.2
03E6: BCF 1F.3
03E7: MOVLW 07
03E8: MOVWF 1C
.................... setup_adc_ports(NO_ANALOGS);
*
03F2: BSF 03.5
03F3: BSF 1F.0
03F4: BSF 1F.1
03F5: BSF 1F.2
03F6: BCF 1F.3
.................... setup_adc(ADC_OFF);
03F7: BCF 03.5
03F8: BCF 1F.0
.................... setup_spi(SPI_SS_DISABLED);
03F9: BCF 14.5
03FA: BCF 20.5
03FB: MOVF 20,W
03FC: BSF 03.5
03FD: MOVWF 07
03FE: BCF 03.5
03FF: BSF 20.4
0400: MOVF 20,W
0401: BSF 03.5
0402: MOVWF 07
0403: BCF 03.5
0404: BCF 20.3
0405: MOVF 20,W
0406: BSF 03.5
0407: MOVWF 07
0408: MOVLW 01
0409: BCF 03.5
040A: MOVWF 14
040B: MOVLW 00
040C: BSF 03.5
040D: MOVWF 14
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
040E: MOVF 01,W
040F: ANDLW C7
0410: IORLW 08
0411: MOVWF 01
.................... setup_timer_1(T1_DISABLED);
0412: BCF 03.5
0413: CLRF 10
.................... setup_timer_2(T2_DIV_BY_4,255,1);
0414: MOVLW 00
0415: MOVWF 78
0416: IORLW 05
0417: MOVWF 12
0418: MOVLW FF
0419: BSF 03.5
041A: MOVWF 12
.................... setup_ccp1(CCP_PWM);
041B: BCF 03.5
041C: BCF 20.2
041D: MOVF 20,W
041E: BSF 03.5
041F: MOVWF 07
0420: BCF 03.5
0421: BCF 07.2
0422: MOVLW 0C
0423: MOVWF 17
.................... setup_ccp2(CCP_PWM);
0424: BCF 20.1
0425: MOVF 20,W
0426: BSF 03.5
0427: MOVWF 07
0428: BCF 03.5
0429: BCF 07.1
042A: MOVLW 0C
042B: MOVWF 1D
.................... setup_comparator(NC_NC_NC_NC);
042C: MOVLW 07
042D: BSF 03.5
042E: MOVWF 1C
042F: MOVF 05,W
0430: CLRWDT
0431: MOVLW 0E
0432: MOVWF 77
0433: DECFSZ 77,F
0434: GOTO 433
0435: NOP
0436: NOP
0437: MOVF 1C,W
0438: BCF 03.5
0439: BCF 0D.6
.................... setup_vref(FALSE);
043A: BSF 03.5
043B: CLRF 1D
.................... setup_wdt(WDT_2304MS);
043C: MOVLW 0F
043D: MOVWF 77
043E: MOVLW 07
043F: BCF 03.5
0440: CLRF 01
0441: MOVLW 81
0442: MOVWF 04
0443: MOVF 00,W
0444: ANDLW F0
0445: IORLW 07
0446: MOVWF 00
0447: CLRWDT
0448: MOVF 00,W
0449: ANDLW F7
044A: BTFSC 77.3
044B: ANDLW F0
044C: IORWF 77,W
044D: MOVWF 00
....................
.................... set_pwm1_duty(0);
044E: CLRF 15
.................... set_pwm2_duty(0);
044F: CLRF 1B
....................
.................... while(TRUE)
.................... {
.................... int status;
.................... char *ptr;
.................... int time;
....................
.................... restart_wdt();
0450: CLRWDT
....................
.................... output_low(PIN_A4) ;
0451: BSF 03.5
0452: BCF 05.4
0453: BCF 03.5
0454: BCF 05.4
.................... delay_ms(150);
0455: MOVLW 96
0456: MOVWF 52
0457: CALL 04E
.................... output_high(PIN_A4);
0458: BSF 03.5
0459: BCF 05.4
045A: BCF 03.5
045B: BSF 05.4
.................... delay_ms(150);
045C: MOVLW 96
045D: MOVWF 52
045E: CALL 04E
.................... output_low(PIN_A4) ;
045F: BSF 03.5
0460: BCF 05.4
0461: BCF 03.5
0462: BCF 05.4
.................... delay_ms(150);
0463: MOVLW 96
0464: MOVWF 52
0465: CALL 04E
.................... output_high(PIN_A4);
0466: BSF 03.5
0467: BCF 05.4
0468: BCF 03.5
0469: BSF 05.4
.................... delay_ms(150);
046A: MOVLW 96
046B: MOVWF 52
046C: CALL 04E
....................
....................
.................... if(check_new_sms()) // Je odpoved "OK"?
046D: GOTO 0B6
046E: MOVF 78,F
046F: BTFSC 03.2
0470: GOTO 479
.................... {
.................... // printf(lcd_putc,"736 655 250");
.................... delay_ms(1000);
0471: MOVLW 04
0472: MOVWF 51
0473: MOVLW FA
0474: MOVWF 52
0475: CALL 04E
0476: DECFSZ 51,F
0477: GOTO 473
.................... }
.................... else
0478: GOTO 4F7
.................... {
.................... read_sms();
0479: GOTO 0E2
....................
.................... /* if (odp[0] == 'A' || odp[0] == 'a')
.................... {
.................... set_pwm1_duty(500);
.................... set_pwm2_duty(500);
.................... Delay_ms(10000);
.................... fprintf(VRTULE,"JACK[BARmk"); // "JACK BAR :)"
.................... Delay_ms(2000);
.................... fprintf(VRTULE,"JACK[BARmk"); // "JACK BAR :)"
.................... Delay_ms(5000);
.................... set_pwm1_duty(0);
.................... set_pwm2_duty(0);
.................... }*/
....................
.................... /* if (odp[1] == 'h')
.................... {
.................... set_pwm1_duty(500);
.................... set_pwm2_duty(500);
.................... Delay_ms(10000);
.................... fprintf(VRTULE,"[ERROR[d[["); // " ERROR 3 "
.................... Delay_ms(2000);
.................... fprintf(VRTULE,"[ERROR[d[["); // " ERROR 3 "
.................... Delay_ms(2000);
.................... fprintf(VRTULE,"[OVERFLOW["); // " OVERFLOW "
.................... Delay_ms(2000);
.................... fprintf(VRTULE,"[OVERFLOW[");
.................... Delay_ms(5000);
.................... set_pwm1_duty(0);
.................... set_pwm2_duty(0);
.................... }*/
....................
.................... if (odp[2] == 'o')
047A: MOVF 28,W
047B: SUBLW 6F
047C: BTFSS 03.2
047D: GOTO 4F7
.................... {
.................... set_pwm1_duty(500);
047E: MOVLW 7D
047F: MOVWF 15
0480: MOVF 17,W
0481: ANDLW CF
0482: MOVWF 17
.................... set_pwm2_duty(500);
0483: MOVLW 7D
0484: MOVWF 1B
0485: MOVF 1D,W
0486: ANDLW CF
0487: MOVWF 1D
.................... Delay_ms(10000);
0488: MOVLW 28
0489: MOVWF 51
048A: MOVLW FA
048B: MOVWF 52
048C: CALL 04E
048D: DECFSZ 51,F
048E: GOTO 48A
.................... fprintf(VRTULE,"[ERROR[e[["); // " ERROR 4 "
048F: CLRF 51
0490: MOVF 51,W
0491: CALL 021
0492: IORLW 00
0493: BTFSC 03.2
0494: GOTO 499
0495: INCF 51,F
0496: MOVWF 52
0497: CALL 1D0
0498: GOTO 490
.................... Delay_ms(2000);
0499: MOVLW 08
049A: MOVWF 51
049B: MOVLW FA
049C: MOVWF 52
049D: CALL 04E
049E: DECFSZ 51,F
049F: GOTO 49B
.................... fprintf(VRTULE,"[ERROR[e[["); // " ERROR 4 "
04A0: CLRF 51
04A1: MOVF 51,W
04A2: CALL 021
04A3: IORLW 00
04A4: BTFSC 03.2
04A5: GOTO 4AA
04A6: INCF 51,F
04A7: MOVWF 52
04A8: CALL 1D0
04A9: GOTO 4A1
.................... Delay_ms(2000);
04AA: MOVLW 08
04AB: MOVWF 51
04AC: MOVLW FA
04AD: MOVWF 52
04AE: CALL 04E
04AF: DECFSZ 51,F
04B0: GOTO 4AC
.................... fprintf(VRTULE,"[OPAKUJTE["); // " OPAKUJTE "
04B1: CLRF 51
04B2: MOVF 51,W
04B3: CALL 030
04B4: IORLW 00
04B5: BTFSC 03.2
04B6: GOTO 4BB
04B7: INCF 51,F
04B8: MOVWF 52
04B9: CALL 1D0
04BA: GOTO 4B2
.................... Delay_ms(2000);
04BB: MOVLW 08
04BC: MOVWF 51
04BD: MOVLW FA
04BE: MOVWF 52
04BF: CALL 04E
04C0: DECFSZ 51,F
04C1: GOTO 4BD
.................... fprintf(VRTULE,"[OPAKUJTE[");
04C2: CLRF 51
04C3: MOVF 51,W
04C4: CALL 030
04C5: IORLW 00
04C6: BTFSC 03.2
04C7: GOTO 4CC
04C8: INCF 51,F
04C9: MOVWF 52
04CA: CALL 1D0
04CB: GOTO 4C3
.................... Delay_ms(2000);
04CC: MOVLW 08
04CD: MOVWF 51
04CE: MOVLW FA
04CF: MOVWF 52
04D0: CALL 04E
04D1: DECFSZ 51,F
04D2: GOTO 4CE
.................... fprintf(VRTULE,"[[VOLBU[[["); // " VOLBU "
04D3: CLRF 51
04D4: MOVF 51,W
04D5: CALL 03F
04D6: IORLW 00
04D7: BTFSC 03.2
04D8: GOTO 4DD
04D9: INCF 51,F
04DA: MOVWF 52
04DB: CALL 1D0
04DC: GOTO 4D4
.................... Delay_ms(2000);
04DD: MOVLW 08
04DE: MOVWF 51
04DF: MOVLW FA
04E0: MOVWF 52
04E1: CALL 04E
04E2: DECFSZ 51,F
04E3: GOTO 4DF
.................... fprintf(VRTULE,"[[VOLBU[[[");
04E4: CLRF 51
04E5: MOVF 51,W
04E6: CALL 03F
04E7: IORLW 00
04E8: BTFSC 03.2
04E9: GOTO 4EE
04EA: INCF 51,F
04EB: MOVWF 52
04EC: CALL 1D0
04ED: GOTO 4E5
.................... Delay_ms(3000);
04EE: MOVLW 0C
04EF: MOVWF 51
04F0: MOVLW FA
04F1: MOVWF 52
04F2: CALL 04E
04F3: DECFSZ 51,F
04F4: GOTO 4F0
.................... set_pwm1_duty(0);
04F5: CLRF 15
.................... set_pwm2_duty(0);
04F6: CLRF 1B
.................... }
.................... }
.................... read_time();
04F7: GOTO 1FC
.................... time=strtoul(odp,&ptr,10);
04F8: MOVLW 26
04F9: MOVWF 51
04FA: MOVLW 4F
04FB: MOVWF 52
04FC: MOVLW 0A
04FD: MOVWF 53
04FE: GOTO 24F
04FF: MOVF 78,W
0500: MOVWF 50
.................... if((time >= 30 && time <= 35) || (time >= 0 && time <= 5))
0501: MOVF 50,W
0502: SUBLW 1D
0503: BTFSC 03.0
0504: GOTO 509
0505: MOVF 50,W
0506: SUBLW 23
0507: BTFSC 03.0
0508: GOTO 50D
0509: MOVF 50,W
050A: SUBLW 05
050B: BTFSS 03.0
050C: GOTO 518
.................... {
.................... set_pwm1_duty(500);
050D: MOVLW 7D
050E: MOVWF 15
050F: MOVF 17,W
0510: ANDLW CF
0511: MOVWF 17
.................... set_pwm2_duty(500);
0512: MOVLW 7D
0513: MOVWF 1B
0514: MOVF 1D,W
0515: ANDLW CF
0516: MOVWF 1D
.................... }
.................... else
0517: GOTO 51A
.................... {
.................... set_pwm1_duty(0);
0518: CLRF 15
.................... set_pwm2_duty(0);
0519: CLRF 1B
.................... }
....................
.................... delay_ms(1000);
051A: MOVLW 04
051B: MOVWF 51
051C: MOVLW FA
051D: MOVWF 52
051E: CALL 04E
051F: DECFSZ 51,F
0520: GOTO 51C
.................... }
0521: GOTO 450
.................... }
0522: SLEEP
Configuration Fuses:
Word 1: 3F3A HS NOWDT NOPUT NODEBUG NOPROTECT NOBROWNOUT NOLVP NOCPD NOWRT