Rev Author Line No. Line
245 kaklik 1 CCS PCM C Compiler, Version 3.245, 27853 11-V-08 15:47
223 kapl 2  
239 kaklik 3 Filename: D:\MLAB_E\projekty\Ovladani_mobilnim_telefonem\SW\final\main.lst
223 kapl 4  
245 kaklik 5 ROM used: 1315 words (16%)
238 kaklik 6 Largest free fragment is 2048
240 kaklik 7 RAM used: 52 (30%) at main() level
245 kaklik 8 139 (79%) worst case
9 Stack: 2 locations
223 kapl 10  
11 *
12 0000: MOVLW 00
13 0001: MOVWF 0A
245 kaklik 14 0002: GOTO 3D5
223 kapl 15 0003: NOP
16 .................... #include ".\main.h"
238 kaklik 17 .................... #include <16F876A.h>
18 .................... //////// Standard Header file for the PIC16F876A device ////////////////
19 .................... #device PIC16F876A
223 kapl 20 .................... #list
21 ....................
22 .................... #device adc=8
23 ....................
238 kaklik 24 .................... #FUSES NOWDT //Watch Dog Timer
25 .................... #FUSES HS//XT //Crystal osc <= 4mhz
223 kapl 26 .................... #FUSES NOPUT //No Power Up Timer
27 .................... #FUSES NOPROTECT //Code not protected from reading
28 .................... #FUSES NODEBUG //No Debug mode for ICD
29 .................... #FUSES NOBROWNOUT //No brownout reset
30 .................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
31 .................... #FUSES NOCPD //No EE protection
32 .................... #FUSES NOWRT //Program memory not write protected
33 ....................
238 kaklik 34 .................... #use delay(clock=18432000,RESTART_WDT)
245 kaklik 35 *
36 004E: MOVLW 52
37 004F: MOVWF 04
38 0050: MOVF 00,W
39 0051: BTFSC 03.2
40 0052: GOTO 063
41 0053: MOVLW 05
42 0054: MOVWF 78
43 0055: MOVLW BF
44 0056: MOVWF 77
45 0057: CLRWDT
46 0058: DECFSZ 77,F
47 0059: GOTO 057
48 005A: DECFSZ 78,F
49 005B: GOTO 055
50 005C: MOVLW F9
51 005D: MOVWF 77
52 005E: DECFSZ 77,F
53 005F: GOTO 05E
54 0060: CLRWDT
55 0061: DECFSZ 00,F
56 0062: GOTO 053
57 0063: RETLW 00
238 kaklik 58 .................... #use rs232(STREAM=MOBIL,baud=19200,force_sw,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
245 kaklik 59 0064: BCF 20.6
60 0065: MOVF 20,W
61 0066: BSF 03.5
62 0067: MOVWF 07
63 0068: BCF 03.5
64 0069: BCF 07.6
65 006A: MOVLW 08
66 006B: MOVWF 78
67 006C: NOP
68 006D: NOP
69 006E: NOP
70 006F: BSF 78.7
71 0070: GOTO 080
72 0071: BCF 78.7
73 0072: RRF 53,F
74 0073: BTFSC 03.0
75 0074: BSF 07.6
76 0075: BTFSS 03.0
77 0076: BCF 07.6
78 0077: BSF 78.6
79 0078: GOTO 080
80 0079: BCF 78.6
81 007A: DECFSZ 78,F
82 007B: GOTO 072
83 007C: NOP
84 007D: NOP
85 007E: NOP
86 007F: BSF 07.6
87 0080: MOVLW 49
88 0081: MOVWF 04
89 0082: DECFSZ 04,F
90 0083: GOTO 082
91 0084: NOP
92 0085: NOP
93 0086: NOP
94 0087: BTFSC 78.7
95 0088: GOTO 071
96 0089: BTFSC 78.6
97 008A: GOTO 079
98 008B: RETLW 00
99 008C: MOVLW 08
100 008D: MOVWF 77
101 008E: BSF 20.7
102 008F: MOVF 20,W
103 0090: BSF 03.5
104 0091: MOVWF 07
105 0092: BCF 03.5
106 0093: BTFSS 07.7
107 0094: GOTO 097
108 0095: BSF 03.5
109 0096: GOTO 092
110 0097: CLRF 57
111 0098: BSF 77.7
112 0099: GOTO 0A8
113 009A: BCF 77.7
114 009B: GOTO 0A8
115 009C: BCF 03.0
116 009D: BTFSC 07.7
117 009E: BSF 03.0
118 009F: RRF 57,F
119 00A0: BSF 77.6
120 00A1: GOTO 0A8
121 00A2: BCF 77.6
122 00A3: DECFSZ 77,F
123 00A4: GOTO 09C
124 00A5: MOVF 57,W
125 00A6: MOVWF 78
126 00A7: GOTO 0B5
127 00A8: MOVLW 49
128 00A9: BTFSC 77.7
129 00AA: MOVLW 14
130 00AB: MOVWF 78
131 00AC: DECFSZ 78,F
132 00AD: GOTO 0AC
133 00AE: NOP
134 00AF: NOP
135 00B0: BTFSC 77.7
136 00B1: GOTO 09A
137 00B2: BTFSC 77.6
138 00B3: GOTO 0A2
139 00B4: GOTO 09C
140 00B5: RETLW 00
238 kaklik 141 *
245 kaklik 142 03E9: MOVLW FF
143 03EA: BCF 03.5
144 03EB: MOVWF 20
238 kaklik 145 .................... #use rs232(STREAM=VRTULE,baud=600,parity=N,xmit=PIN_B2,rcv=PIN_B4,bits=8)
146 *
245 kaklik 147 01D0: BSF 03.5
148 01D1: BCF 06.2
149 01D2: BCF 03.5
150 01D3: BCF 06.2
151 01D4: MOVLW 08
152 01D5: MOVWF 78
153 01D6: NOP
154 01D7: NOP
155 01D8: NOP
156 01D9: BSF 78.7
157 01DA: GOTO 1EA
158 01DB: BCF 78.7
159 01DC: RRF 52,F
160 01DD: BTFSC 03.0
161 01DE: BSF 06.2
162 01DF: BTFSS 03.0
163 01E0: BCF 06.2
164 01E1: BSF 78.6
165 01E2: GOTO 1EA
166 01E3: BCF 78.6
167 01E4: DECFSZ 78,F
168 01E5: GOTO 1DC
169 01E6: NOP
170 01E7: NOP
171 01E8: NOP
172 01E9: BSF 06.2
173 01EA: MOVLW 09
174 01EB: MOVWF 77
175 01EC: CLRF 04
176 01ED: DECFSZ 04,F
177 01EE: GOTO 1ED
178 01EF: DECFSZ 77,F
179 01F0: GOTO 1EC
180 01F1: MOVLW F0
181 01F2: MOVWF 04
182 01F3: DECFSZ 04,F
183 01F4: GOTO 1F3
184 01F5: NOP
185 01F6: NOP
186 01F7: BTFSC 78.7
187 01F8: GOTO 1DB
188 01F9: BTFSC 78.6
189 01FA: GOTO 1E3
190 01FB: RETLW 00
223 kapl 191 ....................
192 ....................
193 ....................
194 .................... #define LCD_RS PIN_B1 // rizeni registru LCD displeje
195 .................... #define LCD_E PIN_B0 // enable LCD displeje
196 .................... #define LCD_DATA_LSB PIN_C0 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
197 ....................
240 kaklik 198 ....................
238 kaklik 199 .................... #bit SPEN=0x18.7
200 .................... #bit RCIF=0x0C.5
201 ....................
240 kaklik 202 .................... #include <stdio.h>
203 .................... ///////////////////////////////////////////////////////////////////////////
204 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
205 .................... //// This source code may only be used by licensed users of the CCS C ////
206 .................... //// compiler. This source code may only be distributed to other ////
207 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
208 .................... //// or distribution is permitted without written permission. ////
209 .................... //// Derivative programs created using this software in object code ////
210 .................... //// form are not restricted in any way. ////
211 .................... ///////////////////////////////////////////////////////////////////////////
223 kapl 212 ....................
240 kaklik 213 .................... #ifndef _STDIO
214 .................... #define _STDIO
215 .................... #include <string.h>
216 .................... ////////////////////////////////////////////////////////////////////////////
217 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
218 .................... //// This source code may only be used by licensed users of the CCS C ////
219 .................... //// compiler. This source code may only be distributed to other ////
220 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
221 .................... //// or distribution is permitted without written permission. ////
222 .................... //// Derivative programs created using this software in object code ////
223 .................... //// form are not restricted in any way. ////
224 .................... ////////////////////////////////////////////////////////////////////////////
223 kapl 225 ....................
240 kaklik 226 .................... #ifndef _STRING
227 .................... #define _STRING
228 .................... #include <stddef.h>
229 .................... ///////////////////////////////////////////////////////////////////////////
230 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
231 .................... //// This source code may only be used by licensed users of the CCS C ////
232 .................... //// compiler. This source code may only be distributed to other ////
233 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
234 .................... //// or distribution is permitted without written permission. ////
235 .................... //// Derivative programs created using this software in object code ////
236 .................... //// form are not restricted in any way. ////
237 .................... ///////////////////////////////////////////////////////////////////////////
223 kapl 238 ....................
240 kaklik 239 .................... #ifndef _STDDEF
223 kapl 240 ....................
240 kaklik 241 .................... #define _STDDEF
223 kapl 242 ....................
240 kaklik 243 .................... #if sizeof(int *)==1
244 .................... #define ptrdiff_t int
245 .................... #else
246 .................... #define ptrdiff_t long
247 .................... #endif
223 kapl 248 ....................
240 kaklik 249 .................... #define size_t int
250 .................... #define wchar_t char
251 .................... #define NULL 0
223 kapl 252 ....................
240 kaklik 253 .................... #define offsetof(s,f) (offsetofbit(s,f)/8)
223 kapl 254 ....................
240 kaklik 255 .................... #endif
223 kapl 256 ....................
240 kaklik 257 .................... #include <ctype.h>
258 .................... ////////////////////////////////////////////////////////////////////////////
259 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
260 .................... //// This source code may only be used by licensed users of the CCS C ////
261 .................... //// compiler. This source code may only be distributed to other ////
262 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
263 .................... //// or distribution is permitted without written permission. ////
264 .................... //// Derivative programs created using this software in object code ////
265 .................... //// form are not restricted in any way. ////
266 .................... ////////////////////////////////////////////////////////////////////////////
223 kapl 267 ....................
240 kaklik 268 .................... #ifndef _CTYPE
269 .................... #define _CTYPE
223 kapl 270 ....................
240 kaklik 271 .................... #define islower(x) isamong(x,"abcdefghijklmnopqrstuvwxyz")
272 .................... #define isupper(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
273 .................... #define isalnum(x) isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
274 .................... #define isalpha(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
275 .................... #define isdigit(x) isamong(x,"0123456789")
276 .................... #define isspace(x) (x==' ')
277 .................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef")
278 .................... #define iscntrl(x) (x<' ')
279 .................... #define isprint(x) (x>=' ')
280 .................... #define isgraph(x) (x>' ')
281 .................... #define ispunct(x) ((x>' ')&&!isalnum(x))
223 kapl 282 ....................
240 kaklik 283 .................... #endif
284 ....................
285 ....................
286 ....................
287 ....................
288 ....................
289 .................... //////////////////////////////////////////////
290 .................... //// Uncomment the following define to ////
291 .................... //// allow some functions to use a ////
292 .................... //// quicker algorithm, but use more ROM ////
293 .................... //// ////
294 .................... //// #define FASTER_BUT_MORE_ROM ////
295 .................... //////////////////////////////////////////////
296 ....................
297 ....................
298 ....................
299 .................... /*Copying functions*/
300 .................... /* standard template:
301 .................... void *memmove(void *s1, void *s2, size_t n).
302 .................... Copies max of n characters safely (not following ending '\0')
303 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
304 ....................
305 .................... char *memmove(void *s1,char *s2,size_t n)
223 kapl 306 .................... {
240 kaklik 307 .................... char *sc1;
308 .................... char *sc2;
309 .................... sc1=s1;
310 .................... sc2=s2;
311 .................... if(sc2<sc1 && sc1 <sc2 +n)
312 .................... for(sc1+=n,sc2+=n;0<n;--n)
313 .................... *--sc1=*--sc2;
314 .................... else
315 .................... for(;0<n;--n)
316 .................... *sc1++=*sc2++;
317 .................... return s1;
318 .................... }
223 kapl 319 ....................
240 kaklik 320 .................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved?
321 .................... Standard template: char *strcpy(char *s1, const char *s2)
322 .................... copies the string s2 including the null character to s1*/
223 kapl 323 ....................
240 kaklik 324 .................... char *strcopy(char *s1, char *s2)
223 kapl 325 .................... {
240 kaklik 326 .................... char *s;
327 ....................
328 .................... for (s = s1; *s2 != 0; s++, s2++) {
329 .................... *s = *s2;
330 .................... }
331 .................... *s = *s2;
332 .................... return(s1);
223 kapl 333 .................... }
334 ....................
240 kaklik 335 .................... /* standard template:
336 .................... char *strncpy(char *s1, const char *s2, size_t n).
337 .................... Copies max of n characters (not following ending '\0')
338 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
223 kapl 339 ....................
240 kaklik 340 .................... char *strncpy(char *s1, char *s2, size_t n)
223 kapl 341 .................... {
240 kaklik 342 .................... char *s;
343 ....................
344 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
345 .................... *s++ = *s2++;
346 .................... for (; n > 0; n--)
347 .................... *s++ = '\0';
348 ....................
349 .................... return(s1);
350 .................... }
351 .................... /***********************************************************/
352 ....................
353 .................... /*concatenation functions*/
354 .................... /* standard template: char *strcat(char *s1, const char *s2)
355 .................... appends s2 to s1*/
356 ....................
357 .................... char *strcat(char *s1, char *s2)
358 .................... {
359 .................... char *s;
360 ....................
361 .................... for (s = s1; *s != '\0'; ++s);
362 .................... while(*s2 != '\0')
363 .................... {
364 .................... *s = *s2;
365 .................... ++s;
366 .................... ++s2;
367 .................... }
368 ....................
369 .................... *s = '\0';
370 .................... return(s1);
371 .................... }
372 .................... /* standard template: char *strncat(char *s1, char *s2,size_t n)
373 .................... appends not more than n characters from s2 to s1*/
374 ....................
375 .................... char *strncat(char *s1, char *s2, size_t n)
376 .................... {
377 .................... char *s;
378 ....................
379 .................... for (s = s1; *s != '\0'; ++s);
380 .................... while(*s2 != '\0' && 0<n)
381 .................... {
382 .................... *s = *s2;
383 .................... ++s;
384 .................... ++s2;
385 .................... --n;
386 .................... }
387 ....................
388 .................... *s = '\0';
389 .................... return(s1);
390 .................... }
391 ....................
392 .................... /***********************************************************/
393 ....................
394 ....................
395 .................... /*comparison functions*/
396 .................... /* standard template: signed int memcmp(void *s1, void *s2).
397 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
398 ....................
399 .................... signed int memcmp(void * s1,char *s2,size_t n)
400 .................... {
401 .................... char *su1, *su2;
402 .................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n)
403 .................... {
404 .................... if(*su1!=*su2)
405 .................... return ((*su1<*su2)?-1:+1);
406 .................... }
407 .................... return 0;
408 .................... }
409 ....................
410 .................... /* standard template: int strcmp(const char *s1, const char *s2).
411 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
412 ....................
413 .................... signed int strcmp(char *s1, char *s2)
414 .................... {
415 .................... for (; *s1 == *s2; s1++, s2++)
416 .................... if (*s1 == '\0')
417 .................... return(0);
418 .................... return((*s1 < *s2) ? -1: 1);
419 .................... }
420 .................... /* standard template: int strcoll(const char *s1, const char *s2).
421 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
422 ....................
423 .................... signed int strcoll(char *s1, char *s2)
424 .................... {
425 .................... for (; *s1 == *s2; s1++, s2++)
426 .................... if (*s1 == '\0')
427 .................... return(0);
428 .................... return((*s1 < *s2) ? -1: 1);
429 .................... }
430 ....................
431 .................... /* standard template:
432 .................... int strncmp(const char *s1, const char *s2, size_t n).
433 .................... Compares max of n characters (not following 0) from s1 to s2;
434 .................... returns same as strcmp */
435 ....................
436 .................... signed int strncmp(char *s1, char *s2, size_t n)
437 .................... {
438 .................... for (; n > 0; s1++, s2++, n--)
439 .................... if (*s1 != *s2)
440 .................... return((*s1 <*s2) ? -1: 1);
441 .................... else if (*s1 == '\0')
442 .................... return(0);
443 .................... return(0);
444 .................... }
445 .................... /* standard template:
446 .................... int strxfrm(const char *s1, const char *s2, size_t n).
447 .................... transforms maximum of n characters from s2 and places them into s1*/
448 .................... size_t strxfrm(char *s1, char *s2, size_t n)
449 .................... {
450 .................... char *s;
451 .................... int n1;
452 .................... n1=n;
453 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
454 .................... *s++ = *s2++;
455 .................... for (; n > 0; n--)
456 .................... *s++ = '\0';
457 ....................
458 .................... return(n1);
459 .................... }
460 ....................
461 ....................
462 ....................
463 ....................
464 ....................
465 .................... /***********************************************************/
466 .................... /*Search functions*/
467 .................... /* standard template: void *memchr(const char *s, int c).
468 .................... Finds first occurrence of c in n characters of s */
469 ....................
470 .................... char *memchr(void *s,int c,size_t n)
471 .................... {
472 .................... char uc;
473 .................... char *su;
474 .................... uc=c;
245 kaklik 475 *
476 021D: BSF 03.5
477 021E: MOVF 47,W
478 021F: MOVWF 49
240 kaklik 479 .................... for(su=s;0<n;++su,--n)
245 kaklik 480 0220: MOVF 46,W
481 0221: MOVWF 4A
482 0222: MOVF 48,W
483 0223: SUBLW 00
484 0224: BTFSC 03.0
485 0225: GOTO 232
240 kaklik 486 .................... if(*su==uc)
245 kaklik 487 0226: MOVF 4A,W
488 0227: MOVWF 04
489 0228: MOVF 49,W
490 0229: SUBWF 00,W
491 022A: BTFSS 03.2
492 022B: GOTO 22F
240 kaklik 493 .................... return su;
245 kaklik 494 022C: MOVF 4A,W
495 022D: MOVWF 78
496 022E: GOTO 234
497 022F: INCF 4A,F
498 0230: DECF 48,F
499 0231: GOTO 222
240 kaklik 500 .................... return NULL;
245 kaklik 501 0232: MOVLW 00
502 0233: MOVWF 78
240 kaklik 503 .................... }
245 kaklik 504 0234: BCF 03.5
505 0235: RETLW 00
240 kaklik 506 ....................
507 .................... /* standard template: char *strchr(const char *s, int c).
508 .................... Finds first occurrence of c in s */
509 ....................
510 .................... char *strchr(char *s, int c)
511 .................... {
512 .................... for (; *s != c; s++)
513 .................... if (*s == '\0')
514 .................... return(0);
515 .................... return(s);
516 .................... }
517 .................... /* standard template:
518 .................... size_t strcspn(const char *s1, const char *s2).
519 .................... Computes length of max initial segment of s1 that
520 .................... consists entirely of characters NOT from s2*/
521 ....................
522 .................... int *strcspn(char *s1, char *s2)
523 .................... {
524 .................... char *sc1, *sc2;
525 ....................
526 .................... for (sc1 = s1; *sc1 != 0; sc1++)
527 .................... for (sc2 = s2; *sc2 != 0; sc2++)
528 .................... if (*sc1 == *sc2)
529 .................... return(sc1 - s1);
530 .................... return(sc1 - s1);
531 .................... }
532 .................... /* standard template:
533 .................... char *strpbrk(const char *s1, const char *s2).
534 .................... Locates first occurence of any character from s2 in s1;
535 .................... returns s1 if s2 is empty string */
536 ....................
537 .................... char *strpbrk(char *s1, char *s2)
538 .................... {
539 .................... char *sc1, *sc2;
540 ....................
541 .................... for (sc1 = s1; *sc1 != 0; sc1++)
542 .................... for (sc2 = s2; *sc2 != 0; sc2++)
543 .................... if (*sc1 == *sc2)
544 .................... return(sc1);
545 .................... return(0);
546 .................... }
547 ....................
548 ....................
549 .................... /* standard template: char *strrchr(const char *s, int c).
550 .................... Finds last occurrence of c in s */
551 ....................
552 .................... char *strrchr(char *s, int c)
553 .................... {
554 .................... char *p;
555 ....................
556 .................... for (p = 0; ; s++)
557 .................... {
558 .................... if (*s == c)
559 .................... p = s;
560 .................... if (*s == '\0')
561 .................... return(p);
562 .................... }
563 .................... }
564 .................... /* computes length of max initial segment of s1 consisting
565 .................... entirely of characters from s2 */
566 ....................
567 .................... int *strspn(char *s1, char *s2)
568 .................... {
569 .................... char *sc1, *sc2;
570 ....................
571 .................... for (sc1 = s1; *sc1 != 0; sc1++)
572 .................... for (sc2 = s2; ; sc2++)
573 .................... if (*sc2 == '\0')
574 .................... return(sc1 - s1);
575 .................... else if (*sc1 == *sc2)
576 .................... break;
577 .................... return(sc1 - s1);
578 .................... }
579 .................... /* standard template:
580 .................... char *strstr(const char *s1, const char *s2);
581 .................... Locates first occurence of character sequence s2 in s1;
582 .................... returns 0 if s2 is empty string
583 ....................
584 .................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
585 .................... file to use the faster algorithm */
586 .................... char *strstr(char *s1, char *s2)
587 .................... {
588 .................... char *s, *t;
589 ....................
590 .................... #ifdef FASTER_BUT_MORE_ROM
591 .................... if (*s2 == '\0')
592 .................... return(s1);
593 .................... #endif
594 ....................
595 .................... while (*s1)
596 .................... {
597 .................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t);
598 ....................
599 .................... if (*t == '\0')
600 .................... return s1;
601 .................... ++s1;
602 .................... #ifdef FASTER_BUT_MORE_ROM
603 .................... while(*s1 != '\0' && *s1 != *s2)
604 .................... ++s1;
605 .................... #endif
606 .................... }
607 .................... return 0;
608 .................... }
609 ....................
610 .................... /* standard template: char *strtok(char *s1, const char *s2).
611 ....................
612 .................... Finds next token in s1 delimited by a character from separator
613 .................... string s2 (which can be different from call to call). First call
614 .................... starts at beginning of s1 searching for first character NOT
615 .................... contained in s2; returns 0 if none is found.
616 .................... If one is found, it is the start of first token (return value).
617 .................... Function then searches from there for a character contained in s2.
618 .................... If none is found, current token extends to end of s1, and subsequent
619 .................... searches for a token will return 0. If one is found, it is
620 .................... overwritten by '\0', which terminates current token. Function saves
621 .................... pointer to following character from which next search will start.
622 .................... Each subsequent call, with 0 as first argument, starts searching
623 .................... from saved pointer */
624 ....................
625 .................... char *strtok(char *s1, char *s2)
626 .................... {
627 .................... char *beg, *end;
628 .................... static char *save;
239 kaklik 629 *
245 kaklik 630 03EC: CLRF 21
240 kaklik 631 ....................
632 .................... beg = (s1)? s1: save;
633 .................... beg += strspn(beg, s2);
634 .................... if (*beg == '\0')
635 .................... {
636 .................... *save = ' ';
637 .................... return(0);
638 .................... }
639 .................... end = strpbrk(beg, s2);
640 .................... if (*end != '\0')
641 .................... {
642 .................... *end = '\0';
643 .................... end++;
644 .................... }
645 .................... save = end;
646 .................... return(beg);
223 kapl 647 .................... }
648 ....................
240 kaklik 649 .................... /*****************************************************************/
650 .................... /*Miscellaneous functions*/
651 .................... /* standard template
652 .................... maps error number in errnum to an error message string
653 .................... Returns: Pointer to string
654 .................... */
655 .................... #ifdef _ERRNO
656 .................... char * strerror(int errnum)
657 .................... {
658 .................... char s[15];
659 .................... switch( errnum)
660 .................... {
661 .................... case 0:
662 .................... strcpy(s,"no errors");
663 .................... return s;
664 .................... case EDOM :
665 .................... strcpy(s,"domain error");
666 .................... return s;
667 .................... case ERANGE:
668 .................... strcpy(s,"range error");
669 .................... return s;
670 .................... }
671 .................... }
672 .................... #ENDIF
673 .................... /* standard template: size_t strlen(const char *s).
674 .................... Computes length of s1 (preceding terminating 0) */
223 kapl 675 ....................
240 kaklik 676 .................... int *strlen(char *s)
223 kapl 677 .................... {
240 kaklik 678 .................... char *sc;
223 kapl 679 ....................
240 kaklik 680 .................... for (sc = s; *sc != 0; sc++);
681 .................... return(sc - s);
682 .................... }
223 kapl 683 ....................
240 kaklik 684 .................... /* standard template: size_t stricmp(const char *s1, const char *s2).
685 .................... Compares s1 to s2 ignoring case (upper vs. lower) */
223 kapl 686 ....................
240 kaklik 687 .................... signed int stricmp(char *s1, char *s2)
688 .................... {
689 .................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
690 .................... s1++, s2++)
691 .................... if (*s1 == '\0')
692 .................... return(0);
693 .................... return((*s1 < *s2) ? -1: 1);
694 .................... }
223 kapl 695 ....................
696 ....................
240 kaklik 697 .................... /* standard template: char *strlwr(char *s).
698 .................... Replaces uppercase letters by lowercase;
699 .................... returns pointer to new string s */
700 ....................
701 .................... char *strlwr(char *s)
702 .................... {
703 .................... char *p;
704 ....................
705 .................... for (p = s; *p != '\0'; p++)
706 .................... if (*p >= 'A' && *p <='Z')
707 .................... *p += 'a' - 'A';
708 .................... return(s);
709 .................... }
710 ....................
711 ....................
712 .................... /************************************************************/
713 ....................
714 ....................
715 .................... #endif
716 ....................
717 .................... #ifndef getc
718 .................... #define getc getch
719 .................... #define getchar getch
720 .................... #define puts(s) {printf(s); putchar(13); putchar(10);}
721 .................... #define putc putchar
722 .................... #endif
723 .................... /* maps error number to an error message. Writes a sequence of characters to
724 .................... stderr stream thus: if s is not null then string pointed to by s follwed by
725 .................... a colon (:) and a space and the appropriate error message returned by strerror
726 .................... function with argument errno
727 ....................
728 .................... Returns: no value
729 .................... */
730 ....................
731 .................... #ifdef _ERRNO
732 .................... void perror(char *s)
733 .................... {
734 .................... if(s)
735 .................... fprintf(STDERR,"%s: ",s);
736 .................... fprintf(STDERR,"%s\r\n",strerror(errno));
737 .................... }
738 .................... #endif
739 .................... #endif
740 ....................
741 .................... #include <string.h>
742 .................... ////////////////////////////////////////////////////////////////////////////
743 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
744 .................... //// This source code may only be used by licensed users of the CCS C ////
745 .................... //// compiler. This source code may only be distributed to other ////
746 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
747 .................... //// or distribution is permitted without written permission. ////
748 .................... //// Derivative programs created using this software in object code ////
749 .................... //// form are not restricted in any way. ////
750 .................... ////////////////////////////////////////////////////////////////////////////
751 ....................
752 .................... #ifndef _STRING
753 .................... #define _STRING
754 .................... #include <stddef.h>
755 .................... #include <ctype.h>
756 ....................
757 ....................
758 ....................
759 .................... //////////////////////////////////////////////
760 .................... //// Uncomment the following define to ////
761 .................... //// allow some functions to use a ////
762 .................... //// quicker algorithm, but use more ROM ////
763 .................... //// ////
764 .................... //// #define FASTER_BUT_MORE_ROM ////
765 .................... //////////////////////////////////////////////
766 ....................
767 ....................
768 ....................
769 .................... /*Copying functions*/
770 .................... /* standard template:
771 .................... void *memmove(void *s1, void *s2, size_t n).
772 .................... Copies max of n characters safely (not following ending '\0')
773 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
774 ....................
775 .................... char *memmove(void *s1,char *s2,size_t n)
776 .................... {
777 .................... char *sc1;
778 .................... char *sc2;
779 .................... sc1=s1;
780 .................... sc2=s2;
781 .................... if(sc2<sc1 && sc1 <sc2 +n)
782 .................... for(sc1+=n,sc2+=n;0<n;--n)
783 .................... *--sc1=*--sc2;
784 .................... else
785 .................... for(;0<n;--n)
786 .................... *sc1++=*sc2++;
787 .................... return s1;
788 .................... }
789 ....................
790 .................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved?
791 .................... Standard template: char *strcpy(char *s1, const char *s2)
792 .................... copies the string s2 including the null character to s1*/
793 ....................
794 .................... char *strcopy(char *s1, char *s2)
795 .................... {
796 .................... char *s;
797 ....................
798 .................... for (s = s1; *s2 != 0; s++, s2++) {
799 .................... *s = *s2;
800 .................... }
801 .................... *s = *s2;
802 .................... return(s1);
803 .................... }
804 ....................
805 .................... /* standard template:
806 .................... char *strncpy(char *s1, const char *s2, size_t n).
807 .................... Copies max of n characters (not following ending '\0')
808 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
809 ....................
810 .................... char *strncpy(char *s1, char *s2, size_t n)
811 .................... {
812 .................... char *s;
813 ....................
814 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
815 .................... *s++ = *s2++;
816 .................... for (; n > 0; n--)
817 .................... *s++ = '\0';
818 ....................
819 .................... return(s1);
820 .................... }
821 .................... /***********************************************************/
822 ....................
823 .................... /*concatenation functions*/
824 .................... /* standard template: char *strcat(char *s1, const char *s2)
825 .................... appends s2 to s1*/
826 ....................
827 .................... char *strcat(char *s1, char *s2)
828 .................... {
829 .................... char *s;
830 ....................
831 .................... for (s = s1; *s != '\0'; ++s);
832 .................... while(*s2 != '\0')
223 kapl 833 .................... {
240 kaklik 834 .................... *s = *s2;
835 .................... ++s;
836 .................... ++s2;
223 kapl 837 .................... }
838 ....................
240 kaklik 839 .................... *s = '\0';
840 .................... return(s1);
841 .................... }
842 .................... /* standard template: char *strncat(char *s1, char *s2,size_t n)
843 .................... appends not more than n characters from s2 to s1*/
223 kapl 844 ....................
240 kaklik 845 .................... char *strncat(char *s1, char *s2, size_t n)
846 .................... {
847 .................... char *s;
848 ....................
849 .................... for (s = s1; *s != '\0'; ++s);
850 .................... while(*s2 != '\0' && 0<n)
223 kapl 851 .................... {
240 kaklik 852 .................... *s = *s2;
853 .................... ++s;
854 .................... ++s2;
855 .................... --n;
223 kapl 856 .................... }
240 kaklik 857 ....................
858 .................... *s = '\0';
859 .................... return(s1);
223 kapl 860 .................... }
861 ....................
240 kaklik 862 .................... /***********************************************************/
223 kapl 863 ....................
240 kaklik 864 ....................
865 .................... /*comparison functions*/
866 .................... /* standard template: signed int memcmp(void *s1, void *s2).
867 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
868 ....................
869 .................... signed int memcmp(void * s1,char *s2,size_t n)
223 kapl 870 .................... {
240 kaklik 871 .................... char *su1, *su2;
872 .................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n)
873 .................... {
874 .................... if(*su1!=*su2)
875 .................... return ((*su1<*su2)?-1:+1);
876 .................... }
877 .................... return 0;
878 .................... }
223 kapl 879 ....................
240 kaklik 880 .................... /* standard template: int strcmp(const char *s1, const char *s2).
881 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
223 kapl 882 ....................
240 kaklik 883 .................... signed int strcmp(char *s1, char *s2)
884 .................... {
885 .................... for (; *s1 == *s2; s1++, s2++)
886 .................... if (*s1 == '\0')
887 .................... return(0);
888 .................... return((*s1 < *s2) ? -1: 1);
889 .................... }
890 .................... /* standard template: int strcoll(const char *s1, const char *s2).
891 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
892 ....................
893 .................... signed int strcoll(char *s1, char *s2)
894 .................... {
895 .................... for (; *s1 == *s2; s1++, s2++)
896 .................... if (*s1 == '\0')
897 .................... return(0);
898 .................... return((*s1 < *s2) ? -1: 1);
899 .................... }
900 ....................
901 .................... /* standard template:
902 .................... int strncmp(const char *s1, const char *s2, size_t n).
903 .................... Compares max of n characters (not following 0) from s1 to s2;
904 .................... returns same as strcmp */
905 ....................
906 .................... signed int strncmp(char *s1, char *s2, size_t n)
907 .................... {
908 .................... for (; n > 0; s1++, s2++, n--)
909 .................... if (*s1 != *s2)
910 .................... return((*s1 <*s2) ? -1: 1);
911 .................... else if (*s1 == '\0')
912 .................... return(0);
913 .................... return(0);
914 .................... }
915 .................... /* standard template:
916 .................... int strxfrm(const char *s1, const char *s2, size_t n).
917 .................... transforms maximum of n characters from s2 and places them into s1*/
918 .................... size_t strxfrm(char *s1, char *s2, size_t n)
919 .................... {
920 .................... char *s;
921 .................... int n1;
922 .................... n1=n;
923 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
924 .................... *s++ = *s2++;
925 .................... for (; n > 0; n--)
926 .................... *s++ = '\0';
927 ....................
928 .................... return(n1);
929 .................... }
930 ....................
931 ....................
932 ....................
933 ....................
934 ....................
935 .................... /***********************************************************/
936 .................... /*Search functions*/
937 .................... /* standard template: void *memchr(const char *s, int c).
938 .................... Finds first occurrence of c in n characters of s */
939 ....................
940 .................... char *memchr(void *s,int c,size_t n)
941 .................... {
942 .................... char uc;
943 .................... char *su;
944 .................... uc=c;
945 .................... for(su=s;0<n;++su,--n)
946 .................... if(*su==uc)
947 .................... return su;
948 .................... return NULL;
949 .................... }
950 ....................
951 .................... /* standard template: char *strchr(const char *s, int c).
952 .................... Finds first occurrence of c in s */
953 ....................
954 .................... char *strchr(char *s, int c)
955 .................... {
956 .................... for (; *s != c; s++)
957 .................... if (*s == '\0')
958 .................... return(0);
959 .................... return(s);
960 .................... }
961 .................... /* standard template:
962 .................... size_t strcspn(const char *s1, const char *s2).
963 .................... Computes length of max initial segment of s1 that
964 .................... consists entirely of characters NOT from s2*/
965 ....................
966 .................... int *strcspn(char *s1, char *s2)
967 .................... {
968 .................... char *sc1, *sc2;
969 ....................
970 .................... for (sc1 = s1; *sc1 != 0; sc1++)
971 .................... for (sc2 = s2; *sc2 != 0; sc2++)
972 .................... if (*sc1 == *sc2)
973 .................... return(sc1 - s1);
974 .................... return(sc1 - s1);
975 .................... }
976 .................... /* standard template:
977 .................... char *strpbrk(const char *s1, const char *s2).
978 .................... Locates first occurence of any character from s2 in s1;
979 .................... returns s1 if s2 is empty string */
980 ....................
981 .................... char *strpbrk(char *s1, char *s2)
982 .................... {
983 .................... char *sc1, *sc2;
984 ....................
985 .................... for (sc1 = s1; *sc1 != 0; sc1++)
986 .................... for (sc2 = s2; *sc2 != 0; sc2++)
987 .................... if (*sc1 == *sc2)
988 .................... return(sc1);
989 .................... return(0);
990 .................... }
991 ....................
992 ....................
993 .................... /* standard template: char *strrchr(const char *s, int c).
994 .................... Finds last occurrence of c in s */
995 ....................
996 .................... char *strrchr(char *s, int c)
997 .................... {
998 .................... char *p;
999 ....................
1000 .................... for (p = 0; ; s++)
223 kapl 1001 .................... {
240 kaklik 1002 .................... if (*s == c)
1003 .................... p = s;
1004 .................... if (*s == '\0')
1005 .................... return(p);
223 kapl 1006 .................... }
240 kaklik 1007 .................... }
1008 .................... /* computes length of max initial segment of s1 consisting
1009 .................... entirely of characters from s2 */
223 kapl 1010 ....................
240 kaklik 1011 .................... int *strspn(char *s1, char *s2)
1012 .................... {
1013 .................... char *sc1, *sc2;
1014 ....................
1015 .................... for (sc1 = s1; *sc1 != 0; sc1++)
1016 .................... for (sc2 = s2; ; sc2++)
1017 .................... if (*sc2 == '\0')
1018 .................... return(sc1 - s1);
1019 .................... else if (*sc1 == *sc2)
1020 .................... break;
1021 .................... return(sc1 - s1);
223 kapl 1022 .................... }
240 kaklik 1023 .................... /* standard template:
1024 .................... char *strstr(const char *s1, const char *s2);
1025 .................... Locates first occurence of character sequence s2 in s1;
1026 .................... returns 0 if s2 is empty string
223 kapl 1027 ....................
240 kaklik 1028 .................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
1029 .................... file to use the faster algorithm */
1030 .................... char *strstr(char *s1, char *s2)
1031 .................... {
1032 .................... char *s, *t;
223 kapl 1033 ....................
240 kaklik 1034 .................... #ifdef FASTER_BUT_MORE_ROM
1035 .................... if (*s2 == '\0')
1036 .................... return(s1);
1037 .................... #endif
1038 ....................
1039 .................... while (*s1)
1040 .................... {
1041 .................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t);
1042 ....................
1043 .................... if (*t == '\0')
1044 .................... return s1;
1045 .................... ++s1;
1046 .................... #ifdef FASTER_BUT_MORE_ROM
1047 .................... while(*s1 != '\0' && *s1 != *s2)
1048 .................... ++s1;
1049 .................... #endif
1050 .................... }
1051 .................... return 0;
1052 .................... }
1053 ....................
1054 .................... /* standard template: char *strtok(char *s1, const char *s2).
1055 ....................
1056 .................... Finds next token in s1 delimited by a character from separator
1057 .................... string s2 (which can be different from call to call). First call
1058 .................... starts at beginning of s1 searching for first character NOT
1059 .................... contained in s2; returns 0 if none is found.
1060 .................... If one is found, it is the start of first token (return value).
1061 .................... Function then searches from there for a character contained in s2.
1062 .................... If none is found, current token extends to end of s1, and subsequent
1063 .................... searches for a token will return 0. If one is found, it is
1064 .................... overwritten by '\0', which terminates current token. Function saves
1065 .................... pointer to following character from which next search will start.
1066 .................... Each subsequent call, with 0 as first argument, starts searching
1067 .................... from saved pointer */
1068 ....................
1069 .................... char *strtok(char *s1, char *s2)
223 kapl 1070 .................... {
240 kaklik 1071 .................... char *beg, *end;
1072 .................... static char *save;
223 kapl 1073 ....................
240 kaklik 1074 .................... beg = (s1)? s1: save;
1075 .................... beg += strspn(beg, s2);
1076 .................... if (*beg == '\0')
223 kapl 1077 .................... {
240 kaklik 1078 .................... *save = ' ';
1079 .................... return(0);
223 kapl 1080 .................... }
240 kaklik 1081 .................... end = strpbrk(beg, s2);
1082 .................... if (*end != '\0')
1083 .................... {
1084 .................... *end = '\0';
1085 .................... end++;
1086 .................... }
1087 .................... save = end;
1088 .................... return(beg);
223 kapl 1089 .................... }
1090 ....................
240 kaklik 1091 .................... /*****************************************************************/
1092 .................... /*Miscellaneous functions*/
1093 .................... /* standard template
1094 .................... maps error number in errnum to an error message string
1095 .................... Returns: Pointer to string
1096 .................... */
1097 .................... #ifdef _ERRNO
1098 .................... char * strerror(int errnum)
1099 .................... {
1100 .................... char s[15];
1101 .................... switch( errnum)
1102 .................... {
1103 .................... case 0:
1104 .................... strcpy(s,"no errors");
1105 .................... return s;
1106 .................... case EDOM :
1107 .................... strcpy(s,"domain error");
1108 .................... return s;
1109 .................... case ERANGE:
1110 .................... strcpy(s,"range error");
1111 .................... return s;
1112 .................... }
1113 .................... }
1114 .................... #ENDIF
1115 .................... /* standard template: size_t strlen(const char *s).
1116 .................... Computes length of s1 (preceding terminating 0) */
223 kapl 1117 ....................
240 kaklik 1118 .................... int *strlen(char *s)
223 kapl 1119 .................... {
240 kaklik 1120 .................... char *sc;
1121 ....................
1122 .................... for (sc = s; *sc != 0; sc++);
1123 .................... return(sc - s);
223 kapl 1124 .................... }
1125 ....................
240 kaklik 1126 .................... /* standard template: size_t stricmp(const char *s1, const char *s2).
1127 .................... Compares s1 to s2 ignoring case (upper vs. lower) */
223 kapl 1128 ....................
240 kaklik 1129 .................... signed int stricmp(char *s1, char *s2)
223 kapl 1130 .................... {
240 kaklik 1131 .................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
1132 .................... s1++, s2++)
1133 .................... if (*s1 == '\0')
1134 .................... return(0);
1135 .................... return((*s1 < *s2) ? -1: 1);
223 kapl 1136 .................... }
1137 ....................
1138 ....................
240 kaklik 1139 .................... /* standard template: char *strlwr(char *s).
1140 .................... Replaces uppercase letters by lowercase;
1141 .................... returns pointer to new string s */
223 kapl 1142 ....................
240 kaklik 1143 .................... char *strlwr(char *s)
1144 .................... {
1145 .................... char *p;
223 kapl 1146 ....................
240 kaklik 1147 .................... for (p = s; *p != '\0'; p++)
1148 .................... if (*p >= 'A' && *p <='Z')
1149 .................... *p += 'a' - 'A';
1150 .................... return(s);
1151 .................... }
1152 ....................
1153 ....................
1154 .................... /************************************************************/
1155 ....................
1156 ....................
1157 .................... #endif
1158 ....................
1159 .................... #include <stdlib.h>
1160 .................... ///////////////////////////////////////////////////////////////////////////
1161 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
1162 .................... //// This source code may only be used by licensed users of the CCS C ////
1163 .................... //// compiler. This source code may only be distributed to other ////
1164 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
1165 .................... //// or distribution is permitted without written permission. ////
1166 .................... //// Derivative programs created using this software in object code ////
1167 .................... //// form are not restricted in any way. ////
1168 .................... ///////////////////////////////////////////////////////////////////////////
1169 ....................
1170 .................... #ifndef _STDLIB
1171 .................... #define _STDLIB
1172 ....................
1173 .................... //---------------------------------------------------------------------------
1174 .................... // Definitions and types
1175 .................... //---------------------------------------------------------------------------
1176 ....................
1177 .................... #ifndef RAND_MAX
1178 .................... #define RAND_MAX 32767 // The value of which is the maximum value
1179 .................... // ... returned by the rand function
1180 .................... #endif
1181 ....................
1182 .................... typedef struct {
1183 .................... signed int quot;
1184 .................... signed int rem;
1185 .................... } div_t;
1186 ....................
1187 .................... typedef struct {
1188 .................... signed long quot;
1189 .................... signed long rem;
1190 .................... } ldiv_t;
1191 ....................
1192 .................... #include <stddef.h>
1193 .................... ///////////////////////////////////////////////////////////////////////////
1194 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
1195 .................... //// This source code may only be used by licensed users of the CCS C ////
1196 .................... //// compiler. This source code may only be distributed to other ////
1197 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
1198 .................... //// or distribution is permitted without written permission. ////
1199 .................... //// Derivative programs created using this software in object code ////
1200 .................... //// form are not restricted in any way. ////
1201 .................... ///////////////////////////////////////////////////////////////////////////
1202 ....................
1203 .................... #ifndef _STDDEF
1204 ....................
1205 .................... #define _STDDEF
1206 ....................
1207 .................... #if sizeof(int *)==1
1208 .................... #define ptrdiff_t int
1209 .................... #else
1210 .................... #define ptrdiff_t long
1211 .................... #endif
1212 ....................
1213 .................... #define size_t int
1214 .................... #define wchar_t char
1215 .................... #define NULL 0
1216 ....................
1217 .................... #define offsetof(s,f) (offsetofbit(s,f)/8)
1218 ....................
1219 .................... #endif
1220 ....................
1221 ....................
1222 .................... //---------------------------------------------------------------------------
1223 .................... // String conversion functions
1224 .................... //---------------------------------------------------------------------------
1225 ....................
1226 .................... /* Standard template: float atof(char * s)
1227 .................... * converts the initial portion of the string s to a float.
1228 .................... * returns the converted value if any, 0 otherwise
1229 .................... */
1230 .................... float atof(char * s);
1231 ....................
1232 .................... /* Standard template: float atoe(char * s)
1233 .................... * converts the initial portion of the string s to a float.
1234 .................... * returns the converted value if any, 0 otherwise
1235 .................... * also handles E format numbers
1236 .................... */
1237 .................... float atoe(char * s);
1238 ....................
1239 .................... /* Standard template: signed int atoi(char * s)
1240 .................... * converts the initial portion of the string s to a signed int
1241 .................... * returns the converted value if any, 0 otherwise
1242 .................... */
1243 .................... signed int atoi(char *s);
1244 ....................
1245 .................... /* Syntax: signed int32 atoi32(char * s)
1246 .................... converts the initial portion of the string s to a signed int32
1247 .................... returns the converted value if any, 0 otherwise*/
1248 .................... signed int32 atoi32(char *s);
1249 ....................
1250 .................... /* Syntax: char * itoa(signed int32 num, int8 base, char * s)
1251 .................... converts the signed int32 to a string and
1252 .................... returns the converted value if any, 0 otherwise*/
1253 .................... char * itoa(signed int32 num, int8 base, char * s);
1254 ....................
1255 .................... /* Standard template: signed long atol(char * s)
1256 .................... * converts the initial portion of the string s to a signed long
1257 .................... * returns the converted value if any, 0 otherwise
1258 .................... */
1259 .................... signed long atol(char *s);
1260 ....................
1261 .................... /* Standard template: float strtol(char * s,char *endptr)
1262 .................... * converts the initial portion of the string s to a float
1263 .................... * returns the converted value if any, 0 otherwise
1264 .................... * the final string is returned in the endptr, if endptr is not null
1265 .................... */
1266 .................... float strtod(char *s,char *endptr);
1267 ....................
1268 .................... /* Standard template: long strtoul(char * s,char *endptr,signed int base)
1269 .................... * converts the initial portion of the string s, represented as an
1270 .................... * integral value of radix base to a signed long.
1271 .................... * Returns the converted value if any, 0 otherwise
1272 .................... * the final string is returned in the endptr, if endptr is not null
1273 .................... */
1274 .................... signed long strtol(char *s,char *endptr,signed int base);
1275 ....................
1276 .................... /* Standard template: long strtoul(char * s,char *endptr,signed int base)
1277 .................... * converts the initial portion of the string s, represented as an
1278 .................... * integral value of radix base to a unsigned long.
1279 .................... * returns the converted value if any, 0 otherwise
1280 .................... * the final string is returned in the endptr, if endptr is not null
1281 .................... */
1282 .................... long strtoul(char *s,char *endptr,signed int base);
1283 ....................
1284 .................... //---------------------------------------------------------------------------
1285 .................... // Pseudo-random sequence generation functions
1286 .................... //---------------------------------------------------------------------------
1287 ....................
1288 .................... /* The rand function computes a sequence of pseudo-random integers in
1289 .................... * the range 0 to RAND_MAX
1290 .................... *
1291 .................... * Parameters:
1292 .................... * (none)
1293 .................... *
1294 .................... * Returns:
1295 .................... * The pseudo-random integer
1296 .................... */
1297 .................... long rand(void);
1298 ....................
1299 .................... /* The srand function uses the argument as a seed for a new sequence of
1300 .................... * pseudo-random numbers to be returned by subsequent calls to rand.
1301 .................... *
1302 .................... * Parameters:
1303 .................... * [in] seed: The seed value to start from. You might need to pass
1304 .................... *
1305 .................... * Returns:
1306 .................... * (none)
1307 .................... *
1308 .................... * Remarks
1309 .................... * The srand function sets the starting point for generating
1310 .................... * a series of pseudorandom integers. To reinitialize the
1311 .................... * generator, use 1 as the seed argument. Any other value for
1312 .................... * seed sets the generator to a random starting point. rand
1313 .................... * retrieves the pseudorandom numbers that are generated.
1314 .................... * Calling rand before any call to srand generates the same
1315 .................... * sequence as calling srand with seed passed as 1.
1316 .................... * Usually, you need to pass a time here from outer source
1317 .................... * so that the numbers will be different every time you run.
1318 .................... */
1319 .................... void srand(unsigned int32 seed);
1320 ....................
1321 .................... //---------------------------------------------------------------------------
1322 .................... // Memory management functions
1323 .................... //---------------------------------------------------------------------------
1324 ....................
1325 .................... // Comming soon
1326 ....................
1327 .................... //---------------------------------------------------------------------------
1328 .................... // Communication with the environment
1329 .................... //---------------------------------------------------------------------------
1330 ....................
1331 .................... /* The function returns 0 always
1332 .................... */
1333 .................... signed int system(char *string);
1334 ....................
1335 .................... //---------------------------------------------------------------------------
1336 .................... // Searching and sorting utilities
1337 .................... //---------------------------------------------------------------------------
1338 ....................
1339 .................... /* Performs a binary search of a sorted array..
1340 .................... *
1341 .................... * Parameters:
1342 .................... * [in] key: Object to search for
1343 .................... * [in] base: Pointer to base of search data
1344 .................... * [in] num: Number of elements
1345 .................... * [in] width: Width of elements
1346 .................... * [in] compare: Function that compares two elements
1347 .................... *
1348 .................... * Returns:
1349 .................... * bsearch returns a pointer to an occurrence of key in the array pointed
1350 .................... * to by base. If key is not found, the function returns NULL. If the
1351 .................... * array is not in order or contains duplicate records with identical keys,
1352 .................... * the result is unpredictable.
1353 .................... */
1354 .................... //void *bsearch(const void *key, const void *base, size_t num, size_t width,
1355 .................... // int (*compare)(const void *, const void *));
1356 ....................
1357 .................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents
1358 .................... * of the array are sorted into ascending order according to a comparison
1359 .................... * function pointed to by compar.
1360 .................... *
1361 .................... * Parameters:
1362 .................... * [in] base: Pointer to base of search data
1363 .................... * [in] num: Number of elements
1364 .................... * [in] width: Width of elements
1365 .................... * [in] compare: Function that compares two elements
1366 .................... *
1367 .................... * Returns:
1368 .................... * (none)
1369 .................... */
1370 .................... //void *qsort(const void *base, size_t num, size_t width,
1371 .................... // int (*compare)(const void *, const void *));
1372 ....................
1373 .................... //---------------------------------------------------------------------------
1374 .................... // Integer arithmetic functions
1375 .................... //---------------------------------------------------------------------------
1376 ....................
1377 .................... #define labs abs
1378 ....................
1379 .................... div_t div(signed int numer,signed int denom);
1380 .................... ldiv_t ldiv(signed long numer,signed long denom);
1381 ....................
1382 .................... //---------------------------------------------------------------------------
1383 .................... // Multibyte character functions
1384 .................... //---------------------------------------------------------------------------
1385 ....................
1386 .................... // Not supported
1387 ....................
1388 .................... //---------------------------------------------------------------------------
1389 .................... // Multibyte string functions
1390 .................... //---------------------------------------------------------------------------
1391 ....................
1392 .................... // Not supported
1393 ....................
1394 ....................
1395 .................... //---------------------------------------------------------------------------
1396 .................... // Internal implementation
1397 .................... //---------------------------------------------------------------------------
1398 ....................
1399 .................... #include <stddef.h>
1400 .................... ///////////////////////////////////////////////////////////////////////////
1401 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
1402 .................... //// This source code may only be used by licensed users of the CCS C ////
1403 .................... //// compiler. This source code may only be distributed to other ////
1404 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
1405 .................... //// or distribution is permitted without written permission. ////
1406 .................... //// Derivative programs created using this software in object code ////
1407 .................... //// form are not restricted in any way. ////
1408 .................... ///////////////////////////////////////////////////////////////////////////
1409 ....................
1410 .................... #ifndef _STDDEF
1411 ....................
1412 .................... #define _STDDEF
1413 ....................
1414 .................... #if sizeof(int *)==1
1415 .................... #define ptrdiff_t int
1416 .................... #else
1417 .................... #define ptrdiff_t long
1418 .................... #endif
1419 ....................
1420 .................... #define size_t int
1421 .................... #define wchar_t char
1422 .................... #define NULL 0
1423 ....................
1424 .................... #define offsetof(s,f) (offsetofbit(s,f)/8)
1425 ....................
1426 .................... #endif
1427 ....................
1428 .................... #include <string.h>
1429 .................... ////////////////////////////////////////////////////////////////////////////
1430 .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
1431 .................... //// This source code may only be used by licensed users of the CCS C ////
1432 .................... //// compiler. This source code may only be distributed to other ////
1433 .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
1434 .................... //// or distribution is permitted without written permission. ////
1435 .................... //// Derivative programs created using this software in object code ////
1436 .................... //// form are not restricted in any way. ////
1437 .................... ////////////////////////////////////////////////////////////////////////////
1438 ....................
1439 .................... #ifndef _STRING
1440 .................... #define _STRING
1441 .................... #include <stddef.h>
1442 .................... #include <ctype.h>
1443 ....................
1444 ....................
1445 ....................
1446 .................... //////////////////////////////////////////////
1447 .................... //// Uncomment the following define to ////
1448 .................... //// allow some functions to use a ////
1449 .................... //// quicker algorithm, but use more ROM ////
1450 .................... //// ////
1451 .................... //// #define FASTER_BUT_MORE_ROM ////
1452 .................... //////////////////////////////////////////////
1453 ....................
1454 ....................
1455 ....................
1456 .................... /*Copying functions*/
1457 .................... /* standard template:
1458 .................... void *memmove(void *s1, void *s2, size_t n).
1459 .................... Copies max of n characters safely (not following ending '\0')
1460 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
1461 ....................
1462 .................... char *memmove(void *s1,char *s2,size_t n)
223 kapl 1463 .................... {
240 kaklik 1464 .................... char *sc1;
1465 .................... char *sc2;
1466 .................... sc1=s1;
1467 .................... sc2=s2;
1468 .................... if(sc2<sc1 && sc1 <sc2 +n)
1469 .................... for(sc1+=n,sc2+=n;0<n;--n)
1470 .................... *--sc1=*--sc2;
1471 .................... else
1472 .................... for(;0<n;--n)
1473 .................... *sc1++=*sc2++;
1474 .................... return s1;
1475 .................... }
1476 ....................
1477 .................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved?
1478 .................... Standard template: char *strcpy(char *s1, const char *s2)
1479 .................... copies the string s2 including the null character to s1*/
1480 ....................
1481 .................... char *strcopy(char *s1, char *s2)
1482 .................... {
1483 .................... char *s;
1484 ....................
1485 .................... for (s = s1; *s2 != 0; s++, s2++) {
1486 .................... *s = *s2;
1487 .................... }
1488 .................... *s = *s2;
1489 .................... return(s1);
223 kapl 1490 .................... }
1491 ....................
240 kaklik 1492 .................... /* standard template:
1493 .................... char *strncpy(char *s1, const char *s2, size_t n).
1494 .................... Copies max of n characters (not following ending '\0')
1495 .................... from s2 in s1; if s2 has less than n characters, appends 0 */
223 kapl 1496 ....................
240 kaklik 1497 .................... char *strncpy(char *s1, char *s2, size_t n)
1498 .................... {
1499 .................... char *s;
223 kapl 1500 ....................
240 kaklik 1501 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
1502 .................... *s++ = *s2++;
1503 .................... for (; n > 0; n--)
1504 .................... *s++ = '\0';
223 kapl 1505 ....................
240 kaklik 1506 .................... return(s1);
1507 .................... }
1508 .................... /***********************************************************/
223 kapl 1509 ....................
240 kaklik 1510 .................... /*concatenation functions*/
1511 .................... /* standard template: char *strcat(char *s1, const char *s2)
1512 .................... appends s2 to s1*/
223 kapl 1513 ....................
240 kaklik 1514 .................... char *strcat(char *s1, char *s2)
1515 .................... {
1516 .................... char *s;
223 kapl 1517 ....................
240 kaklik 1518 .................... for (s = s1; *s != '\0'; ++s);
1519 .................... while(*s2 != '\0')
1520 .................... {
1521 .................... *s = *s2;
1522 .................... ++s;
1523 .................... ++s2;
1524 .................... }
223 kapl 1525 ....................
240 kaklik 1526 .................... *s = '\0';
1527 .................... return(s1);
1528 .................... }
1529 .................... /* standard template: char *strncat(char *s1, char *s2,size_t n)
1530 .................... appends not more than n characters from s2 to s1*/
223 kapl 1531 ....................
240 kaklik 1532 .................... char *strncat(char *s1, char *s2, size_t n)
1533 .................... {
1534 .................... char *s;
223 kapl 1535 ....................
240 kaklik 1536 .................... for (s = s1; *s != '\0'; ++s);
1537 .................... while(*s2 != '\0' && 0<n)
1538 .................... {
1539 .................... *s = *s2;
1540 .................... ++s;
1541 .................... ++s2;
1542 .................... --n;
1543 .................... }
1544 ....................
1545 .................... *s = '\0';
1546 .................... return(s1);
1547 .................... }
1548 ....................
1549 .................... /***********************************************************/
1550 ....................
1551 ....................
1552 .................... /*comparison functions*/
1553 .................... /* standard template: signed int memcmp(void *s1, void *s2).
1554 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
1555 ....................
1556 .................... signed int memcmp(void * s1,char *s2,size_t n)
223 kapl 1557 .................... {
240 kaklik 1558 .................... char *su1, *su2;
1559 .................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n)
1560 .................... {
1561 .................... if(*su1!=*su2)
1562 .................... return ((*su1<*su2)?-1:+1);
1563 .................... }
1564 .................... return 0;
1565 .................... }
223 kapl 1566 ....................
240 kaklik 1567 .................... /* standard template: int strcmp(const char *s1, const char *s2).
1568 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
239 kaklik 1569 ....................
240 kaklik 1570 .................... signed int strcmp(char *s1, char *s2)
1571 .................... {
1572 .................... for (; *s1 == *s2; s1++, s2++)
1573 .................... if (*s1 == '\0')
1574 .................... return(0);
1575 .................... return((*s1 < *s2) ? -1: 1);
1576 .................... }
1577 .................... /* standard template: int strcoll(const char *s1, const char *s2).
1578 .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
1579 ....................
1580 .................... signed int strcoll(char *s1, char *s2)
1581 .................... {
1582 .................... for (; *s1 == *s2; s1++, s2++)
1583 .................... if (*s1 == '\0')
1584 .................... return(0);
1585 .................... return((*s1 < *s2) ? -1: 1);
1586 .................... }
1587 ....................
1588 .................... /* standard template:
1589 .................... int strncmp(const char *s1, const char *s2, size_t n).
1590 .................... Compares max of n characters (not following 0) from s1 to s2;
1591 .................... returns same as strcmp */
1592 ....................
1593 .................... signed int strncmp(char *s1, char *s2, size_t n)
1594 .................... {
1595 .................... for (; n > 0; s1++, s2++, n--)
1596 .................... if (*s1 != *s2)
1597 .................... return((*s1 <*s2) ? -1: 1);
1598 .................... else if (*s1 == '\0')
1599 .................... return(0);
1600 .................... return(0);
1601 .................... }
1602 .................... /* standard template:
1603 .................... int strxfrm(const char *s1, const char *s2, size_t n).
1604 .................... transforms maximum of n characters from s2 and places them into s1*/
1605 .................... size_t strxfrm(char *s1, char *s2, size_t n)
1606 .................... {
1607 .................... char *s;
1608 .................... int n1;
1609 .................... n1=n;
1610 .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
1611 .................... *s++ = *s2++;
1612 .................... for (; n > 0; n--)
1613 .................... *s++ = '\0';
1614 ....................
1615 .................... return(n1);
1616 .................... }
1617 ....................
1618 ....................
1619 ....................
1620 ....................
1621 ....................
1622 .................... /***********************************************************/
1623 .................... /*Search functions*/
1624 .................... /* standard template: void *memchr(const char *s, int c).
1625 .................... Finds first occurrence of c in n characters of s */
1626 ....................
1627 .................... char *memchr(void *s,int c,size_t n)
1628 .................... {
1629 .................... char uc;
1630 .................... char *su;
1631 .................... uc=c;
1632 .................... for(su=s;0<n;++su,--n)
1633 .................... if(*su==uc)
1634 .................... return su;
1635 .................... return NULL;
1636 .................... }
1637 ....................
1638 .................... /* standard template: char *strchr(const char *s, int c).
1639 .................... Finds first occurrence of c in s */
1640 ....................
1641 .................... char *strchr(char *s, int c)
1642 .................... {
1643 .................... for (; *s != c; s++)
1644 .................... if (*s == '\0')
1645 .................... return(0);
1646 .................... return(s);
1647 .................... }
1648 .................... /* standard template:
1649 .................... size_t strcspn(const char *s1, const char *s2).
1650 .................... Computes length of max initial segment of s1 that
1651 .................... consists entirely of characters NOT from s2*/
1652 ....................
1653 .................... int *strcspn(char *s1, char *s2)
1654 .................... {
1655 .................... char *sc1, *sc2;
1656 ....................
1657 .................... for (sc1 = s1; *sc1 != 0; sc1++)
1658 .................... for (sc2 = s2; *sc2 != 0; sc2++)
1659 .................... if (*sc1 == *sc2)
1660 .................... return(sc1 - s1);
1661 .................... return(sc1 - s1);
1662 .................... }
1663 .................... /* standard template:
1664 .................... char *strpbrk(const char *s1, const char *s2).
1665 .................... Locates first occurence of any character from s2 in s1;
1666 .................... returns s1 if s2 is empty string */
1667 ....................
1668 .................... char *strpbrk(char *s1, char *s2)
1669 .................... {
1670 .................... char *sc1, *sc2;
1671 ....................
1672 .................... for (sc1 = s1; *sc1 != 0; sc1++)
1673 .................... for (sc2 = s2; *sc2 != 0; sc2++)
1674 .................... if (*sc1 == *sc2)
1675 .................... return(sc1);
1676 .................... return(0);
1677 .................... }
1678 ....................
1679 ....................
1680 .................... /* standard template: char *strrchr(const char *s, int c).
1681 .................... Finds last occurrence of c in s */
1682 ....................
1683 .................... char *strrchr(char *s, int c)
1684 .................... {
1685 .................... char *p;
1686 ....................
1687 .................... for (p = 0; ; s++)
223 kapl 1688 .................... {
240 kaklik 1689 .................... if (*s == c)
1690 .................... p = s;
1691 .................... if (*s == '\0')
1692 .................... return(p);
1693 .................... }
1694 .................... }
1695 .................... /* computes length of max initial segment of s1 consisting
1696 .................... entirely of characters from s2 */
239 kaklik 1697 ....................
240 kaklik 1698 .................... int *strspn(char *s1, char *s2)
1699 .................... {
1700 .................... char *sc1, *sc2;
239 kaklik 1701 ....................
240 kaklik 1702 .................... for (sc1 = s1; *sc1 != 0; sc1++)
1703 .................... for (sc2 = s2; ; sc2++)
1704 .................... if (*sc2 == '\0')
1705 .................... return(sc1 - s1);
1706 .................... else if (*sc1 == *sc2)
1707 .................... break;
1708 .................... return(sc1 - s1);
1709 .................... }
1710 .................... /* standard template:
1711 .................... char *strstr(const char *s1, const char *s2);
1712 .................... Locates first occurence of character sequence s2 in s1;
1713 .................... returns 0 if s2 is empty string
238 kaklik 1714 ....................
240 kaklik 1715 .................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
1716 .................... file to use the faster algorithm */
1717 .................... char *strstr(char *s1, char *s2)
1718 .................... {
1719 .................... char *s, *t;
238 kaklik 1720 ....................
240 kaklik 1721 .................... #ifdef FASTER_BUT_MORE_ROM
1722 .................... if (*s2 == '\0')
1723 .................... return(s1);
1724 .................... #endif
238 kaklik 1725 ....................
240 kaklik 1726 .................... while (*s1)
1727 .................... {
1728 .................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t);
1729 ....................
1730 .................... if (*t == '\0')
1731 .................... return s1;
1732 .................... ++s1;
1733 .................... #ifdef FASTER_BUT_MORE_ROM
1734 .................... while(*s1 != '\0' && *s1 != *s2)
1735 .................... ++s1;
1736 .................... #endif
1737 .................... }
1738 .................... return 0;
1739 .................... }
1740 ....................
1741 .................... /* standard template: char *strtok(char *s1, const char *s2).
1742 ....................
1743 .................... Finds next token in s1 delimited by a character from separator
1744 .................... string s2 (which can be different from call to call). First call
1745 .................... starts at beginning of s1 searching for first character NOT
1746 .................... contained in s2; returns 0 if none is found.
1747 .................... If one is found, it is the start of first token (return value).
1748 .................... Function then searches from there for a character contained in s2.
1749 .................... If none is found, current token extends to end of s1, and subsequent
1750 .................... searches for a token will return 0. If one is found, it is
1751 .................... overwritten by '\0', which terminates current token. Function saves
1752 .................... pointer to following character from which next search will start.
1753 .................... Each subsequent call, with 0 as first argument, starts searching
1754 .................... from saved pointer */
1755 ....................
1756 .................... char *strtok(char *s1, char *s2)
1757 .................... {
1758 .................... char *beg, *end;
1759 .................... static char *save;
1760 ....................
1761 .................... beg = (s1)? s1: save;
1762 .................... beg += strspn(beg, s2);
1763 .................... if (*beg == '\0')
1764 .................... {
1765 .................... *save = ' ';
1766 .................... return(0);
1767 .................... }
1768 .................... end = strpbrk(beg, s2);
1769 .................... if (*end != '\0')
1770 .................... {
1771 .................... *end = '\0';
1772 .................... end++;
1773 .................... }
1774 .................... save = end;
1775 .................... return(beg);
1776 .................... }
1777 ....................
1778 .................... /*****************************************************************/
1779 .................... /*Miscellaneous functions*/
1780 .................... /* standard template
1781 .................... maps error number in errnum to an error message string
1782 .................... Returns: Pointer to string
238 kaklik 1783 .................... */
240 kaklik 1784 .................... #ifdef _ERRNO
1785 .................... char * strerror(int errnum)
1786 .................... {
1787 .................... char s[15];
1788 .................... switch( errnum)
1789 .................... {
1790 .................... case 0:
1791 .................... strcpy(s,"no errors");
1792 .................... return s;
1793 .................... case EDOM :
1794 .................... strcpy(s,"domain error");
1795 .................... return s;
1796 .................... case ERANGE:
1797 .................... strcpy(s,"range error");
1798 .................... return s;
1799 .................... }
1800 .................... }
1801 .................... #ENDIF
1802 .................... /* standard template: size_t strlen(const char *s).
1803 .................... Computes length of s1 (preceding terminating 0) */
239 kaklik 1804 ....................
240 kaklik 1805 .................... int *strlen(char *s)
1806 .................... {
1807 .................... char *sc;
239 kaklik 1808 ....................
240 kaklik 1809 .................... for (sc = s; *sc != 0; sc++);
1810 .................... return(sc - s);
1811 .................... }
238 kaklik 1812 ....................
240 kaklik 1813 .................... /* standard template: size_t stricmp(const char *s1, const char *s2).
1814 .................... Compares s1 to s2 ignoring case (upper vs. lower) */
238 kaklik 1815 ....................
240 kaklik 1816 .................... signed int stricmp(char *s1, char *s2)
1817 .................... {
1818 .................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
1819 .................... s1++, s2++)
1820 .................... if (*s1 == '\0')
1821 .................... return(0);
1822 .................... return((*s1 < *s2) ? -1: 1);
1823 .................... }
238 kaklik 1824 ....................
1825 ....................
240 kaklik 1826 .................... /* standard template: char *strlwr(char *s).
1827 .................... Replaces uppercase letters by lowercase;
1828 .................... returns pointer to new string s */
1829 ....................
1830 .................... char *strlwr(char *s)
1831 .................... {
1832 .................... char *p;
1833 ....................
1834 .................... for (p = s; *p != '\0'; p++)
1835 .................... if (*p >= 'A' && *p <='Z')
1836 .................... *p += 'a' - 'A';
1837 .................... return(s);
1838 .................... }
1839 ....................
1840 ....................
1841 .................... /************************************************************/
1842 ....................
1843 ....................
1844 .................... #endif
1845 ....................
1846 ....................
1847 .................... div_t div(signed int numer,signed int denom)
1848 .................... {
1849 .................... div_t val;
1850 .................... val.quot = numer / denom;
1851 .................... val.rem = numer - (denom * val.quot);
1852 .................... return (val);
1853 .................... }
1854 ....................
1855 .................... ldiv_t ldiv(signed long numer,signed long denom)
1856 .................... {
1857 .................... ldiv_t val;
1858 .................... val.quot = numer / denom;
1859 .................... val.rem = numer - (denom * val.quot);
1860 .................... return (val);
1861 .................... }
1862 ....................
1863 .................... float atof(char * s)
1864 .................... {
1865 .................... float pow10 = 1.0;
1866 .................... float result = 0.0;
1867 .................... int sign = 0;
1868 .................... char c;
1869 .................... int ptr = 0;
1870 ....................
1871 .................... c = s[ptr++];
1872 ....................
1873 .................... if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') {
1874 .................... if(c == '-') {
1875 .................... sign = 1;
1876 .................... c = s[ptr++];
1877 .................... }
1878 .................... if(c == '+')
1879 .................... c = s[ptr++];
1880 ....................
1881 .................... while((c >= '0' && c <= '9')) {
1882 .................... result = 10*result + c - '0';
1883 .................... c = s[ptr++];
1884 .................... }
1885 ....................
1886 .................... if (c == '.') {
1887 .................... c = s[ptr++];
1888 .................... while((c >= '0' && c <= '9')) {
1889 .................... pow10 = pow10*10;
1890 .................... result += (c - '0')/pow10;
1891 .................... c = s[ptr++];
1892 .................... }
1893 .................... }
1894 ....................
1895 .................... }
1896 ....................
1897 .................... if (sign == 1)
1898 .................... result = -1*result;
1899 .................... return(result);
1900 .................... }
1901 ....................
1902 .................... float atoe(char * s)
1903 .................... {
1904 .................... float pow10 = 1.0;
1905 .................... float result = 0.0;
1906 .................... int sign = 0;
1907 .................... int expsign = 0;
1908 .................... char c;
1909 .................... int ptr = 0;
1910 .................... int i;
1911 .................... float exp = 1.0;
1912 .................... int expcnt = 0;
1913 ....................
1914 .................... c = s[ptr++];
1915 ....................
1916 .................... if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') {
1917 .................... if(c == '-') {
1918 .................... sign = 1;
1919 .................... c = s[ptr++];
1920 .................... }
1921 .................... if(c == '+')
1922 .................... c = s[ptr++];
1923 ....................
1924 .................... while((c >= '0' && c <= '9')) {
1925 .................... result = 10*result + c - '0';
1926 .................... c = s[ptr++];
1927 .................... }
1928 ....................
1929 .................... if (c == '.') {
1930 .................... c = s[ptr++];
1931 .................... while((c >= '0' && c <= '9')) {
1932 .................... pow10 = pow10*10;
1933 .................... result += (c - '0')/pow10;
1934 .................... c = s[ptr++];
1935 .................... }
1936 .................... }
1937 ....................
1938 .................... // Handling the exponent
1939 .................... if (c=='e' || c=='E') {
1940 .................... c = s[ptr++];
1941 ....................
1942 .................... if(c == '-') {
1943 .................... expsign = 1;
1944 .................... c = s[ptr++];
1945 .................... }
1946 .................... if(c == '+')
1947 .................... c = s[ptr++];
1948 ....................
1949 .................... while((c >= '0' && c <= '9')) {
1950 .................... expcnt = 10*expcnt + c - '0';
1951 .................... c = s[ptr++];
1952 .................... }
1953 ....................
1954 .................... for(i=0;i<expcnt;i++)
1955 .................... exp*=10;
1956 ....................
1957 .................... if(expsign==1)
1958 .................... result/=exp;
1959 .................... else
1960 .................... result*=exp;
1961 .................... }
1962 .................... }
1963 ....................
1964 .................... if (sign == 1)
1965 .................... result = -1*result;
1966 .................... return(result);
1967 .................... }
1968 ....................
1969 .................... signed int atoi(char *s)
1970 .................... {
1971 .................... signed int result;
1972 .................... int sign, base, index;
1973 .................... char c;
1974 ....................
1975 .................... index = 0;
1976 .................... sign = 0;
1977 .................... base = 10;
1978 .................... result = 0;
1979 ....................
1980 .................... if (!s)
1981 .................... return 0;
1982 .................... // Omit all preceeding alpha characters
1983 .................... c = s[index++];
1984 ....................
1985 .................... // increase index if either positive or negative sign is detected
1986 .................... if (c == '-')
223 kapl 1987 .................... {
240 kaklik 1988 .................... sign = 1; // Set the sign to negative
1989 .................... c = s[index++];
239 kaklik 1990 .................... }
240 kaklik 1991 .................... else if (c == '+')
1992 .................... {
1993 .................... c = s[index++];
1994 .................... }
1995 ....................
1996 .................... if (c >= '0' && c <= '9')
1997 .................... {
1998 ....................
1999 .................... // Check for hexa number
2000 .................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
2001 .................... {
2002 .................... base = 16;
2003 .................... index++;
2004 .................... c = s[index++];
2005 .................... }
2006 ....................
2007 .................... // The number is a decimal number
2008 .................... if (base == 10)
2009 .................... {
2010 .................... while (c >= '0' && c <= '9')
2011 .................... {
2012 .................... result = 10*result + (c - '0');
2013 .................... c = s[index++];
2014 .................... }
2015 .................... }
2016 .................... else if (base == 16) // The number is a hexa number
2017 .................... {
2018 .................... c = toupper(c);
2019 .................... while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F'))
2020 .................... {
2021 .................... if (c >= '0' && c <= '9')
2022 .................... result = (result << 4) + (c - '0');
2023 .................... else
2024 .................... result = (result << 4) + (c - 'A' + 10);
2025 ....................
2026 .................... c = s[index++];
2027 .................... c = toupper(c);
2028 .................... }
2029 .................... }
2030 .................... }
2031 ....................
2032 .................... if (sign == 1 && base == 10)
2033 .................... result = -result;
2034 ....................
2035 .................... return(result);
2036 .................... }
2037 ....................
2038 .................... signed long atol(char *s)
2039 .................... {
2040 .................... signed long result;
2041 .................... int sign, base, index;
2042 .................... char c;
2043 ....................
2044 .................... index = 0;
2045 .................... sign = 0;
2046 .................... base = 10;
2047 .................... result = 0;
2048 ....................
2049 .................... if (!s)
2050 .................... return 0;
2051 .................... c = s[index++];
2052 ....................
2053 .................... // increase index if either positive or negative sign is detected
2054 .................... if (c == '-')
2055 .................... {
2056 .................... sign = 1; // Set the sign to negative
2057 .................... c = s[index++];
2058 .................... }
2059 .................... else if (c == '+')
2060 .................... {
2061 .................... c = s[index++];
2062 .................... }
2063 ....................
2064 .................... if (c >= '0' && c <= '9')
2065 .................... {
2066 .................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
2067 .................... {
2068 .................... base = 16;
2069 .................... index++;
2070 .................... c = s[index++];
2071 .................... }
2072 ....................
2073 .................... // The number is a decimal number
2074 .................... if (base == 10)
2075 .................... {
2076 .................... while (c >= '0' && c <= '9')
2077 .................... {
2078 .................... result = 10*result + (c - '0');
2079 .................... c = s[index++];
2080 .................... }
2081 .................... }
2082 .................... else if (base == 16) // The number is a hexa number
2083 .................... {
2084 .................... c = toupper(c);
2085 .................... while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F'))
2086 .................... {
2087 .................... if (c >= '0' && c <= '9')
2088 .................... result = (result << 4) + (c - '0');
2089 .................... else
2090 .................... result = (result << 4) + (c - 'A' + 10);
2091 ....................
2092 .................... c = s[index++];c = toupper(c);
2093 .................... }
2094 .................... }
2095 .................... }
2096 ....................
2097 .................... if (base == 10 && sign == 1)
2098 .................... result = -result;
2099 ....................
2100 .................... return(result);
2101 .................... }
2102 ....................
2103 .................... /* A fast routine to multiply by 10
2104 .................... */
2105 .................... signed int32 mult_with10(int32 num)
2106 .................... {
2107 .................... return ( (num << 1) + (num << 3) );
2108 .................... }
2109 ....................
2110 .................... signed int32 atoi32(char *s)
2111 .................... {
2112 .................... signed int32 result;
2113 .................... int sign, base, index;
2114 .................... char c;
2115 ....................
2116 .................... index = 0;
2117 .................... sign = 0;
2118 .................... base = 10;
2119 .................... result = 0;
2120 ....................
2121 .................... if (!s)
2122 .................... return 0;
2123 .................... c = s[index++];
2124 ....................
2125 .................... // increase index if either positive or negative sign is detected
2126 .................... if (c == '-')
2127 .................... {
2128 .................... sign = 1; // Set the sign to negative
2129 .................... c = s[index++];
2130 .................... }
2131 .................... else if (c == '+')
2132 .................... {
2133 .................... c = s[index++];
2134 .................... }
2135 ....................
2136 .................... if (c >= '0' && c <= '9')
2137 .................... {
2138 .................... if (c == '0' && (s[index] == 'x' || s[index] == 'X'))
2139 .................... {
2140 .................... base = 16;
2141 .................... index++;
2142 .................... c = s[index++];
2143 .................... }
2144 ....................
2145 .................... // The number is a decimal number
2146 .................... if (base == 10)
2147 .................... {
2148 .................... while (c >= '0' && c <= '9') {
2149 .................... result = (result << 1) + (result << 3); // result *= 10;
2150 .................... result += (c - '0');
2151 .................... c = s[index++];
2152 .................... }
2153 .................... }
2154 .................... else if (base == 16) // The number is a hexa number
2155 .................... {
2156 .................... c = toupper(c);
2157 .................... while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F'))
2158 .................... {
2159 .................... if (c >= '0' && c <= '9')
2160 .................... result = (result << 4) + (c - '0');
2161 .................... else
2162 .................... result = (result << 4) + (c - 'A' + 10);
2163 ....................
2164 .................... c = s[index++];c = toupper(c);
2165 .................... }
2166 .................... }
2167 .................... }
2168 ....................
2169 .................... if (base == 10 && sign == 1)
2170 .................... result = -result;
2171 ....................
2172 .................... return(result);
2173 .................... }
2174 ....................
2175 .................... char * itoa(signed int32 num, int8 base, char *s)
2176 .................... {
2177 .................... int32 temp=1;
2178 .................... int8 i,sign=0,cnt=0;
2179 .................... char c;
2180 ....................
2181 .................... if(num<0) {
2182 .................... sign=1; // Check for negative number
2183 .................... num*=-1;
2184 .................... }
2185 ....................
2186 .................... while(temp>0) {
2187 .................... temp=(num/base);
2188 .................... s[cnt]=(num%base)+'0'; // Conversion
2189 ....................
2190 .................... if(s[cnt]>0x39)
2191 .................... s[cnt]+=0x7;
2192 ....................
2193 .................... cnt++;
2194 .................... num=temp;
2195 .................... }
2196 ....................
2197 .................... if(sign==1) {
2198 .................... s[cnt]=0x2D; // Negative sign
2199 .................... cnt++;
2200 .................... }
2201 ....................
2202 .................... for(i = 0;i<(int8)(cnt/2);i++) {
2203 ....................
2204 .................... c=s[i];
2205 .................... s[i]=s[cnt-i-1]; // Reverse the number
2206 .................... s[cnt-i-1]=c;
2207 .................... }
2208 .................... s[cnt]='\0'; // End the string
2209 .................... return s;
2210 .................... }
2211 ....................
2212 .................... float strtod(char *s,char *endptr) {
2213 .................... float pow10 = 1.0;
2214 .................... float result = 0.0;
2215 .................... int sign = 0, point = 0;
2216 .................... char c;
2217 .................... int ptr = 0;
2218 ....................
2219 .................... if (!s)
2220 .................... return 0;
2221 .................... c=s[ptr++];
2222 ....................
2223 ....................
2224 .................... while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') {
2225 .................... if(c == '-') {
2226 .................... sign = 1;
2227 .................... c = s[ptr++];
2228 .................... }
2229 ....................
2230 .................... while((c >= '0' && c <= '9') && point == 0) {
2231 .................... result = 10*result + c - '0';
2232 .................... c = s[ptr++];
2233 .................... }
2234 ....................
2235 .................... if (c == '.') {
2236 .................... point = 1;
2237 .................... c = s[ptr++];
2238 .................... }
2239 ....................
2240 .................... while((c >= '0' && c <= '9') && point == 1) {
2241 .................... pow10 = pow10*10;
2242 .................... result += (c - '0')/pow10;
2243 .................... c = s[ptr++];
2244 .................... }
2245 ....................
2246 .................... if (c == '+') {
2247 .................... c = s[ptr++];
2248 .................... }
2249 .................... }
2250 ....................
2251 .................... if (sign == 1)
2252 .................... result = -1*result;
2253 .................... if(endptr)
2254 .................... {
2255 .................... if (ptr) {
2256 .................... ptr--;
2257 .................... *((char *)endptr)=s+ptr;
2258 .................... }
2259 .................... else
2260 .................... *((char *)endptr)=s;
2261 .................... }
2262 ....................
2263 .................... return(result);
2264 .................... }
2265 ....................
2266 .................... long strtoul(char *s,char *endptr,signed int base)
2267 .................... {
2268 .................... char *sc,*s1,*sd;
2269 .................... unsigned long x=0;
245 kaklik 2270 *
2271 024F: CLRF 57
2272 0250: CLRF 58
240 kaklik 2273 .................... char sign;
2274 .................... char digits[]="0123456789abcdefghijklmnopqstuvwxyz";
245 kaklik 2275 0251: MOVLW 30
2276 0252: BSF 03.5
2277 0253: MOVWF 20
2278 0254: MOVLW 31
2279 0255: MOVWF 21
2280 0256: MOVLW 32
2281 0257: MOVWF 22
2282 0258: MOVLW 33
2283 0259: MOVWF 23
2284 025A: MOVLW 34
2285 025B: MOVWF 24
2286 025C: MOVLW 35
2287 025D: MOVWF 25
2288 025E: MOVLW 36
2289 025F: MOVWF 26
2290 0260: MOVLW 37
2291 0261: MOVWF 27
2292 0262: MOVLW 38
2293 0263: MOVWF 28
2294 0264: MOVLW 39
2295 0265: MOVWF 29
2296 0266: MOVLW 61
2297 0267: MOVWF 2A
2298 0268: MOVLW 62
2299 0269: MOVWF 2B
2300 026A: MOVLW 63
2301 026B: MOVWF 2C
2302 026C: MOVLW 64
2303 026D: MOVWF 2D
2304 026E: MOVLW 65
2305 026F: MOVWF 2E
2306 0270: MOVLW 66
2307 0271: MOVWF 2F
2308 0272: MOVLW 67
2309 0273: MOVWF 30
2310 0274: MOVLW 68
2311 0275: MOVWF 31
2312 0276: MOVLW 69
2313 0277: MOVWF 32
2314 0278: MOVLW 6A
2315 0279: MOVWF 33
2316 027A: MOVLW 6B
2317 027B: MOVWF 34
2318 027C: MOVLW 6C
2319 027D: MOVWF 35
2320 027E: MOVLW 6D
2321 027F: MOVWF 36
2322 0280: MOVLW 6E
2323 0281: MOVWF 37
2324 0282: MOVLW 6F
2325 0283: MOVWF 38
2326 0284: MOVLW 70
2327 0285: MOVWF 39
2328 0286: MOVLW 71
2329 0287: MOVWF 3A
2330 0288: MOVLW 73
2331 0289: MOVWF 3B
2332 028A: MOVLW 74
2333 028B: MOVWF 3C
2334 028C: MOVLW 75
2335 028D: MOVWF 3D
2336 028E: MOVLW 76
2337 028F: MOVWF 3E
2338 0290: MOVLW 77
2339 0291: MOVWF 3F
2340 0292: MOVLW 78
2341 0293: MOVWF 40
2342 0294: MOVLW 79
2343 0295: MOVWF 41
2344 0296: MOVLW 7A
2345 0297: MOVWF 42
2346 0298: CLRF 43
240 kaklik 2347 .................... for(sc=s;isspace(*sc);++sc);
245 kaklik 2348 0299: BCF 03.5
2349 029A: MOVF 51,W
2350 029B: MOVWF 54
2351 029C: MOVF 54,W
2352 029D: MOVWF 04
2353 029E: MOVF 00,W
2354 029F: SUBLW 20
2355 02A0: BTFSS 03.2
2356 02A1: GOTO 2A4
2357 02A2: INCF 54,F
2358 02A3: GOTO 29C
240 kaklik 2359 .................... sign=*sc=='-'||*sc=='+'?*sc++:'+';
245 kaklik 2360 02A4: MOVF 54,W
2361 02A5: MOVWF 04
2362 02A6: MOVF 00,W
2363 02A7: SUBLW 2D
2364 02A8: BTFSC 03.2
2365 02A9: GOTO 2B0
2366 02AA: MOVF 54,W
2367 02AB: MOVWF 04
2368 02AC: MOVF 00,W
2369 02AD: SUBLW 2B
2370 02AE: BTFSS 03.2
2371 02AF: GOTO 2B5
2372 02B0: MOVF 54,W
2373 02B1: INCF 54,F
2374 02B2: MOVWF 04
2375 02B3: MOVF 00,W
2376 02B4: GOTO 2B6
2377 02B5: MOVLW 2B
2378 02B6: MOVWF 59
240 kaklik 2379 .................... if(sign=='-')
245 kaklik 2380 02B7: MOVF 59,W
2381 02B8: SUBLW 2D
2382 02B9: BTFSS 03.2
2383 02BA: GOTO 2C6
240 kaklik 2384 .................... {
2385 .................... if (endptr)
245 kaklik 2386 02BB: MOVF 52,F
2387 02BC: BTFSC 03.2
2388 02BD: GOTO 2C2
240 kaklik 2389 .................... {
2390 .................... *((char *)endptr)=s;
245 kaklik 2391 02BE: MOVF 52,W
2392 02BF: MOVWF 04
2393 02C0: MOVF 51,W
2394 02C1: MOVWF 00
240 kaklik 2395 .................... }
2396 .................... return 0;
245 kaklik 2397 02C2: MOVLW 00
2398 02C3: MOVWF 78
2399 02C4: MOVWF 79
2400 02C5: GOTO 3D2
240 kaklik 2401 .................... }
2402 ....................
2403 .................... if (base <0 || base ==1|| base >36) // invalid base
245 kaklik 2404 02C6: BTFSC 53.7
2405 02C7: GOTO 2D1
2406 02C8: DECFSZ 53,W
2407 02C9: GOTO 2CB
2408 02CA: GOTO 2D1
2409 02CB: BTFSC 53.7
2410 02CC: GOTO 2DD
2411 02CD: MOVF 53,W
2412 02CE: SUBLW 24
2413 02CF: BTFSC 03.0
2414 02D0: GOTO 2DD
240 kaklik 2415 .................... {
2416 .................... if (endptr)
245 kaklik 2417 02D1: MOVF 52,F
2418 02D2: BTFSC 03.2
2419 02D3: GOTO 2D8
240 kaklik 2420 .................... {
2421 .................... *((char *)endptr)=s;
245 kaklik 2422 02D4: MOVF 52,W
2423 02D5: MOVWF 04
2424 02D6: MOVF 51,W
2425 02D7: MOVWF 00
240 kaklik 2426 .................... }
2427 .................... return 0;
245 kaklik 2428 02D8: MOVLW 00
2429 02D9: MOVWF 78
2430 02DA: MOVWF 79
2431 02DB: GOTO 3D2
240 kaklik 2432 .................... }
2433 .................... else if (base)
245 kaklik 2434 02DC: GOTO 343
2435 02DD: MOVF 53,F
2436 02DE: BTFSC 03.2
2437 02DF: GOTO 31A
240 kaklik 2438 .................... {
2439 .................... if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X'))
245 kaklik 2440 02E0: MOVF 53,W
2441 02E1: SUBLW 10
2442 02E2: BTFSS 03.2
2443 02E3: GOTO 2FA
2444 02E4: MOVF 54,W
2445 02E5: MOVWF 04
2446 02E6: MOVF 00,W
2447 02E7: SUBLW 30
2448 02E8: BTFSS 03.2
2449 02E9: GOTO 2FA
2450 02EA: MOVLW 01
2451 02EB: ADDWF 54,W
2452 02EC: MOVWF 04
2453 02ED: MOVF 00,W
2454 02EE: SUBLW 78
2455 02EF: BTFSC 03.2
2456 02F0: GOTO 2F8
2457 02F1: MOVLW 01
2458 02F2: ADDWF 54,W
2459 02F3: MOVWF 04
2460 02F4: MOVF 00,W
2461 02F5: SUBLW 58
2462 02F6: BTFSS 03.2
2463 02F7: GOTO 2FA
240 kaklik 2464 .................... sc+=2;
245 kaklik 2465 02F8: MOVLW 02
2466 02F9: ADDWF 54,F
240 kaklik 2467 .................... if(base==8 && *sc =='0')
245 kaklik 2468 02FA: MOVF 53,W
2469 02FB: SUBLW 08
2470 02FC: BTFSS 03.2
2471 02FD: GOTO 306
2472 02FE: MOVF 54,W
2473 02FF: MOVWF 04
2474 0300: MOVF 00,W
2475 0301: SUBLW 30
2476 0302: BTFSS 03.2
2477 0303: GOTO 306
240 kaklik 2478 .................... sc+=1;
245 kaklik 2479 0304: MOVLW 01
2480 0305: ADDWF 54,F
240 kaklik 2481 .................... if(base==2 && *sc =='0'&&sc[1]=='b')
245 kaklik 2482 0306: MOVF 53,W
2483 0307: SUBLW 02
2484 0308: BTFSS 03.2
2485 0309: GOTO 319
2486 030A: MOVF 54,W
2487 030B: MOVWF 04
2488 030C: MOVF 00,W
2489 030D: SUBLW 30
2490 030E: BTFSS 03.2
2491 030F: GOTO 319
2492 0310: MOVLW 01
2493 0311: ADDWF 54,W
2494 0312: MOVWF 04
2495 0313: MOVF 00,W
2496 0314: SUBLW 62
2497 0315: BTFSS 03.2
2498 0316: GOTO 319
240 kaklik 2499 .................... sc+=2;
245 kaklik 2500 0317: MOVLW 02
2501 0318: ADDWF 54,F
240 kaklik 2502 ....................
2503 .................... }
2504 .................... else if(*sc!='0') // base is 0, find base
245 kaklik 2505 0319: GOTO 343
2506 031A: MOVF 54,W
2507 031B: MOVWF 04
2508 031C: MOVF 00,W
2509 031D: SUBLW 30
2510 031E: BTFSC 03.2
2511 031F: GOTO 323
240 kaklik 2512 .................... base=10;
245 kaklik 2513 0320: MOVLW 0A
2514 0321: MOVWF 53
240 kaklik 2515 .................... else if (sc[1]=='x' || sc[1]=='X')
245 kaklik 2516 0322: GOTO 343
2517 0323: MOVLW 01
2518 0324: ADDWF 54,W
2519 0325: MOVWF 04
2520 0326: MOVF 00,W
2521 0327: SUBLW 78
2522 0328: BTFSC 03.2
2523 0329: GOTO 331
2524 032A: MOVLW 01
2525 032B: ADDWF 54,W
2526 032C: MOVWF 04
2527 032D: MOVF 00,W
2528 032E: SUBLW 58
2529 032F: BTFSS 03.2
2530 0330: GOTO 336
240 kaklik 2531 .................... base =16,sc+=2;
245 kaklik 2532 0331: MOVLW 10
2533 0332: MOVWF 53
2534 0333: MOVLW 02
2535 0334: ADDWF 54,F
240 kaklik 2536 .................... else if(sc[1]=='b')
245 kaklik 2537 0335: GOTO 343
2538 0336: MOVLW 01
2539 0337: ADDWF 54,W
2540 0338: MOVWF 04
2541 0339: MOVF 00,W
2542 033A: SUBLW 62
2543 033B: BTFSS 03.2
2544 033C: GOTO 341
240 kaklik 2545 .................... base=2,sc+=2;
245 kaklik 2546 033D: MOVLW 02
2547 033E: MOVWF 53
2548 033F: ADDWF 54,F
239 kaklik 2549 .................... else
245 kaklik 2550 0340: GOTO 343
240 kaklik 2551 .................... base=8;
245 kaklik 2552 0341: MOVLW 08
2553 0342: MOVWF 53
240 kaklik 2554 .................... for (s1=sc;*sc=='0';++sc);// skip leading zeroes
245 kaklik 2555 0343: MOVF 54,W
2556 0344: MOVWF 55
2557 0345: MOVF 54,W
2558 0346: MOVWF 04
2559 0347: MOVF 00,W
2560 0348: SUBLW 30
2561 0349: BTFSS 03.2
2562 034A: GOTO 34D
2563 034B: INCF 54,F
2564 034C: GOTO 345
240 kaklik 2565 .................... sd=memchr(digits,tolower(*sc),base);
245 kaklik 2566 034D: MOVF 54,W
2567 034E: MOVWF 04
2568 034F: MOVF 00,W
2569 0350: MOVWF 5A
2570 0351: SUBLW 40
2571 0352: BTFSC 03.0
2572 0353: GOTO 35B
2573 0354: MOVF 5A,W
2574 0355: SUBLW 5A
2575 0356: BTFSS 03.0
2576 0357: GOTO 35B
2577 0358: MOVF 5A,W
2578 0359: IORLW 20
2579 035A: GOTO 35C
2580 035B: MOVF 5A,W
2581 035C: MOVWF 5B
2582 035D: MOVLW A0
2583 035E: BSF 03.5
2584 035F: MOVWF 46
2585 0360: BCF 03.5
2586 0361: MOVF 5A,W
2587 0362: BSF 03.5
2588 0363: MOVWF 47
2589 0364: BCF 03.5
2590 0365: MOVF 53,W
2591 0366: BSF 03.5
2592 0367: MOVWF 48
2593 0368: BCF 03.5
2594 0369: CALL 21D
2595 036A: MOVF 78,W
2596 036B: MOVWF 56
240 kaklik 2597 .................... for(; sd!=0; )
245 kaklik 2598 036C: MOVF 56,F
2599 036D: BTFSC 03.2
2600 036E: GOTO 3B8
223 kapl 2601 .................... {
240 kaklik 2602 .................... x=x*base+(int16)(sd-digits);
245 kaklik 2603 036F: CLRF 7A
2604 0370: MOVF 53,W
2605 0371: MOVWF 77
2606 0372: BTFSC 53.7
2607 0373: DECF 7A,F
2608 0374: MOVWF 5A
2609 0375: MOVF 7A,W
2610 0376: MOVWF 5B
2611 0377: MOVF 58,W
2612 0378: BSF 03.5
2613 0379: MOVWF 47
2614 037A: BCF 03.5
2615 037B: MOVF 57,W
2616 037C: BSF 03.5
2617 037D: MOVWF 46
2618 037E: BCF 03.5
2619 037F: MOVF 7A,W
2620 0380: BSF 03.5
2621 0381: MOVWF 49
2622 0382: BCF 03.5
2623 0383: MOVF 5A,W
2624 0384: BSF 03.5
2625 0385: MOVWF 48
2626 0386: BCF 03.5
2627 0387: GOTO 236
2628 0388: MOVF 78,W
2629 0389: MOVWF 5B
2630 038A: MOVLW A0
2631 038B: SUBWF 56,W
2632 038C: CLRF 7A
2633 038D: ADDWF 78,W
2634 038E: MOVWF 78
2635 038F: BTFSC 03.0
2636 0390: INCF 7A,F
2637 0391: MOVF 79,W
2638 0392: ADDWF 7A,F
2639 0393: MOVF 78,W
2640 0394: MOVWF 57
2641 0395: MOVF 7A,W
2642 0396: MOVWF 58
240 kaklik 2643 .................... ++sc;
245 kaklik 2644 0397: INCF 54,F
240 kaklik 2645 .................... sd=memchr(digits,tolower(*sc),base);
245 kaklik 2646 0398: MOVF 54,W
2647 0399: MOVWF 04
2648 039A: MOVF 00,W
2649 039B: MOVWF 5A
2650 039C: SUBLW 40
2651 039D: BTFSC 03.0
2652 039E: GOTO 3A6
2653 039F: MOVF 5A,W
2654 03A0: SUBLW 5A
2655 03A1: BTFSS 03.0
2656 03A2: GOTO 3A6
2657 03A3: MOVF 5A,W
2658 03A4: IORLW 20
2659 03A5: GOTO 3A7
2660 03A6: MOVF 5A,W
2661 03A7: MOVWF 5B
2662 03A8: MOVLW A0
2663 03A9: BSF 03.5
2664 03AA: MOVWF 46
2665 03AB: BCF 03.5
2666 03AC: MOVF 5A,W
2667 03AD: BSF 03.5
2668 03AE: MOVWF 47
2669 03AF: BCF 03.5
2670 03B0: MOVF 53,W
2671 03B1: BSF 03.5
2672 03B2: MOVWF 48
2673 03B3: BCF 03.5
2674 03B4: CALL 21D
2675 03B5: MOVF 78,W
2676 03B6: MOVWF 56
240 kaklik 2677 .................... }
245 kaklik 2678 03B7: GOTO 36C
240 kaklik 2679 .................... if(s1==sc)
245 kaklik 2680 03B8: MOVF 54,W
2681 03B9: SUBWF 55,W
2682 03BA: BTFSS 03.2
2683 03BB: GOTO 3C7
240 kaklik 2684 .................... {
2685 .................... if (endptr)
245 kaklik 2686 03BC: MOVF 52,F
2687 03BD: BTFSC 03.2
2688 03BE: GOTO 3C3
240 kaklik 2689 .................... {
2690 .................... *((char *)endptr)=s;
245 kaklik 2691 03BF: MOVF 52,W
2692 03C0: MOVWF 04
2693 03C1: MOVF 51,W
2694 03C2: MOVWF 00
240 kaklik 2695 .................... }
2696 .................... return 0;
245 kaklik 2697 03C3: MOVLW 00
2698 03C4: MOVWF 78
2699 03C5: MOVWF 79
2700 03C6: GOTO 3D2
240 kaklik 2701 .................... }
2702 .................... if (endptr)
245 kaklik 2703 03C7: MOVF 52,F
2704 03C8: BTFSC 03.2
2705 03C9: GOTO 3CE
240 kaklik 2706 .................... *((char *)endptr)=sc;
245 kaklik 2707 03CA: MOVF 52,W
2708 03CB: MOVWF 04
2709 03CC: MOVF 54,W
2710 03CD: MOVWF 00
240 kaklik 2711 .................... return x;
245 kaklik 2712 03CE: MOVF 57,W
2713 03CF: MOVWF 78
2714 03D0: MOVF 58,W
2715 03D1: MOVWF 79
240 kaklik 2716 .................... }
245 kaklik 2717 03D2: BCF 0A.3
2718 03D3: BCF 0A.4
2719 03D4: GOTO 4FF (RETURN)
240 kaklik 2720 ....................
2721 ....................
2722 .................... signed long strtol(char *s,char *endptr,signed int base)
2723 .................... {
2724 .................... char *sc,*s1,*sd;
2725 .................... signed long x=0;
2726 .................... char sign;
2727 .................... char digits[]="0123456789abcdefghijklmnopqstuvwxyz";
2728 .................... for(sc=s;isspace(*sc);++sc);
2729 .................... sign=*sc=='-'||*sc=='+'?*sc++:'+';
2730 .................... if (base <0 || base ==1|| base >36) // invalid base
2731 .................... {
2732 .................... if (endptr)
2733 .................... {
2734 .................... *((char *)endptr)=s;
2735 .................... }
2736 .................... return 0;
2737 .................... }
2738 .................... else if (base)
2739 .................... {
2740 .................... if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X'))
2741 .................... sc+=2;
2742 .................... if(base==8 && *sc =='0')
2743 .................... sc+=1;
2744 .................... if(base==2 && *sc =='0'&&sc[1]=='b')
2745 .................... sc+=2;
2746 ....................
2747 .................... }
2748 .................... else if(*sc!='0') // base is 0, find base
2749 .................... base=10;
2750 .................... else if (sc[1]=='x' || sc[1]=='X')
2751 .................... base =16,sc+=2;
2752 .................... else if(sc[1]=='b')
2753 .................... base=2,sc+=2;
2754 .................... else
2755 .................... base=8;
2756 .................... for (s1=sc;*sc=='0';++sc);// skip leading zeroes
2757 ....................
2758 .................... sd=memchr(digits,tolower(*sc),base);
2759 .................... for(;sd!=0;)
2760 .................... {
2761 .................... x=x*base+(int16)(sd-digits);
2762 .................... ++sc;
2763 .................... sd=memchr(digits,tolower(*sc),base);
2764 .................... }
2765 .................... if(s1==sc)
2766 .................... {
2767 .................... if (endptr)
2768 .................... {
2769 .................... *((char *)endptr)=s;
2770 .................... }
2771 .................... return 0;
2772 .................... }
2773 .................... if(sign=='-')
2774 .................... x =-x;
2775 .................... if (endptr)
2776 .................... *((char *)endptr)=sc;
2777 .................... return x;
2778 .................... }
2779 ....................
2780 .................... signed int system(char *string)
2781 .................... {
2782 .................... return 0;
2783 .................... }
2784 ....................
2785 .................... int mblen(char *s,size_t n)
2786 .................... {
2787 .................... return strlen(s);
2788 .................... }
2789 ....................
2790 .................... int mbtowc(wchar_t *pwc,char *s,size_t n)
2791 .................... {
2792 .................... *pwc=*s;
2793 .................... return 1;
2794 .................... }
2795 ....................
2796 .................... int wctomb(char *s,wchar_t wchar)
2797 .................... {
2798 .................... *s=wchar;
2799 .................... return 1;
2800 .................... }
2801 ....................
2802 .................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n)
2803 .................... {
2804 .................... strncpy(pwcs,s,n);
2805 .................... return strlen(pwcs);
2806 .................... }
2807 ....................
2808 .................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n)
2809 .................... {
2810 .................... strncpy(s,pwcs,n);
2811 .................... return strlen(s);
2812 .................... }
2813 ....................
2814 .................... //---------------------------------------------------------------------------
2815 .................... // The random number implementation
2816 .................... //---------------------------------------------------------------------------
2817 ....................
2818 .................... unsigned int32 _Randseed = 1;
245 kaklik 2819 *
2820 03ED: MOVLW 01
2821 03EE: MOVWF 22
2822 03EF: CLRF 23
2823 03F0: CLRF 24
2824 03F1: CLRF 25
240 kaklik 2825 ....................
2826 .................... long rand(void)
2827 .................... {
2828 .................... _Randseed = _Randseed * 1103515245 + 12345;
2829 .................... return ((unsigned long)(_Randseed >> 16) % RAND_MAX);
2830 .................... }
2831 ....................
2832 .................... void srand(unsigned int32 seed)
2833 .................... {
2834 .................... _Randseed = seed;
2835 .................... }
2836 ....................
2837 .................... //---------------------------------------------------------------------------
2838 .................... // Searching and sorting utilities implementation
2839 .................... //---------------------------------------------------------------------------
2840 ....................
2841 .................... typedef signed int (*_Cmpfun)(char * p1,char * p2);
2842 ....................
2843 .................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) {
2844 .................... int m,j,i,l;
2845 .................... short done;
2846 .................... BYTE t[16];
2847 ....................
2848 .................... m = qitems/2;
2849 .................... while( m > 0 ) {
2850 .................... for(j=0; j<(qitems-m); ++j) {
2851 .................... i = j;
2852 .................... do
2853 .................... {
2854 .................... done=TRUE;
2855 .................... l = i+m;
2856 .................... if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) {
2857 .................... memcpy(t, qdata+i*qsize, qsize);
2858 .................... memcpy(qdata+i*qsize, qdata+l*qsize, qsize);
2859 .................... memcpy(qdata+l*qsize, t, qsize);
2860 .................... if(m <= i)
2861 .................... i -= m;
2862 .................... done = FALSE;
2863 .................... }
2864 .................... } while(!done);
2865 .................... }
2866 .................... m = m/2;
2867 .................... }
2868 .................... }
2869 ....................
2870 ....................
2871 .................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp)
2872 .................... {
2873 .................... char *p, *q;
2874 .................... size_t n;
2875 .................... size_t pivot;
2876 .................... signed int val;
2877 ....................
2878 .................... p = base;
2879 .................... n = num;
2880 ....................
2881 .................... while (n > 0)
2882 .................... {
2883 .................... pivot = n >> 1;
2884 .................... q = p + width * pivot;
2885 ....................
2886 .................... val = (*cmp)(key, q);
2887 ....................
2888 .................... if (val < 0)
2889 .................... n = pivot;
2890 .................... else if (val == 0)
2891 .................... return ((char *)q);
2892 .................... else {
2893 .................... p = q + width;
2894 .................... n -= pivot + 1;
2895 .................... }
2896 .................... }
2897 ....................
2898 .................... return NULL; // There's no match
2899 .................... }
2900 ....................
2901 ....................
2902 .................... #endif
2903 ....................
2904 ....................
2905 .................... #define DELKA 40
2906 ....................
2907 .................... char odp[DELKA];
2908 ....................
2909 .................... int1 check_new_sms()
2910 .................... {
2911 .................... fprintf(MOBIL,"AT+CMGL=1\r"); //vycti prijate SMS (0=nove;1=vsechny)
245 kaklik 2912 *
2913 00B6: CLRF 51
2914 00B7: MOVF 51,W
2915 00B8: CALL 004
2916 00B9: IORLW 00
2917 00BA: BTFSC 03.2
2918 00BB: GOTO 0C0
2919 00BC: INCF 51,F
2920 00BD: MOVWF 53
2921 00BE: CALL 064
2922 00BF: GOTO 0B7
240 kaklik 2923 .................... while(fgetc(MOBIL)!=0x0A); // predkoc prvni radek odpovedi
245 kaklik 2924 00C0: CALL 08C
2925 00C1: MOVF 78,W
2926 00C2: SUBLW 0A
2927 00C3: BTFSS 03.2
2928 00C4: GOTO 0C0
240 kaklik 2929 .................... odp[0]=fgetc(MOBIL); // Nacti prvni dva znaky druheho radku odpovedi
245 kaklik 2930 00C5: CALL 08C
2931 00C6: MOVF 78,W
2932 00C7: MOVWF 26
240 kaklik 2933 .................... odp[1]=fgetc(MOBIL);
245 kaklik 2934 00C8: CALL 08C
2935 00C9: MOVF 78,W
2936 00CA: MOVWF 27
240 kaklik 2937 .................... while(fgetc(MOBIL)!=0x0A); // Preskoc zbytek radku
245 kaklik 2938 00CB: CALL 08C
2939 00CC: MOVF 78,W
2940 00CD: SUBLW 0A
2941 00CE: BTFSS 03.2
2942 00CF: GOTO 0CB
240 kaklik 2943 ....................
2944 .................... if(odp[0] == 'O' && odp[1] == 'K') return 1;
245 kaklik 2945 00D0: MOVF 26,W
2946 00D1: SUBLW 4F
2947 00D2: BTFSS 03.2
2948 00D3: GOTO 0DC
2949 00D4: MOVF 27,W
2950 00D5: SUBLW 4B
2951 00D6: BTFSS 03.2
2952 00D7: GOTO 0DC
2953 00D8: MOVLW 01
2954 00D9: MOVWF 78
2955 00DA: GOTO 0DF
240 kaklik 2956 .................... else return 0;
245 kaklik 2957 00DB: GOTO 0DF
2958 00DC: MOVLW 00
2959 00DD: MOVWF 78
2960 00DE: GOTO 0DF
240 kaklik 2961 .................... }
245 kaklik 2962 00DF: BCF 0A.3
2963 00E0: BCF 0A.4
2964 00E1: GOTO 46E (RETURN)
240 kaklik 2965 ....................
2966 .................... read_sms()
2967 .................... {
2968 .................... int pom,pom2,pom3,odkl,odkl2,maskovadlo;
238 kaklik 2969 .................... for(pom=0;pom<54;pom++) //preskoc nedulezite informace
245 kaklik 2970 00E2: CLRF 51
2971 00E3: MOVF 51,W
2972 00E4: SUBLW 35
2973 00E5: BTFSS 03.0
2974 00E6: GOTO 0EA
223 kapl 2975 .................... {
238 kaklik 2976 .................... fgetc(MOBIL);
245 kaklik 2977 00E7: CALL 08C
239 kaklik 2978 .................... }
245 kaklik 2979 00E8: INCF 51,F
2980 00E9: GOTO 0E3
239 kaklik 2981 ....................
223 kapl 2982 .................... //gets(odp); //uloz zakodovany text SMS
239 kaklik 2983 ....................
238 kaklik 2984 .................... odp[0]=fgetc(MOBIL);
245 kaklik 2985 00EA: CALL 08C
2986 00EB: MOVF 78,W
2987 00EC: MOVWF 26
238 kaklik 2988 .................... odp[1]=fgetc(MOBIL);
245 kaklik 2989 00ED: CALL 08C
2990 00EE: MOVF 78,W
2991 00EF: MOVWF 27
238 kaklik 2992 .................... odp[2]=fgetc(MOBIL);
245 kaklik 2993 00F0: CALL 08C
2994 00F1: MOVF 78,W
2995 00F2: MOVWF 28
238 kaklik 2996 .................... odp[3]=fgetc(MOBIL);
245 kaklik 2997 00F3: CALL 08C
2998 00F4: MOVF 78,W
2999 00F5: MOVWF 29
238 kaklik 3000 .................... odp[4]=fgetc(MOBIL);
245 kaklik 3001 00F6: CALL 08C
3002 00F7: MOVF 78,W
3003 00F8: MOVWF 2A
238 kaklik 3004 .................... odp[5]=fgetc(MOBIL);
245 kaklik 3005 00F9: CALL 08C
3006 00FA: MOVF 78,W
3007 00FB: MOVWF 2B
238 kaklik 3008 .................... odp[6]=fgetc(MOBIL);
245 kaklik 3009 00FC: CALL 08C
3010 00FD: MOVF 78,W
3011 00FE: MOVWF 2C
238 kaklik 3012 .................... odp[7]=fgetc(MOBIL);
245 kaklik 3013 00FF: CALL 08C
3014 0100: MOVF 78,W
3015 0101: MOVWF 2D
238 kaklik 3016 ....................
223 kapl 3017 .................... /*lcd_gotoxy(1,1);
3018 .................... printf(lcd_putc,"\f%s\n",odp);*/
239 kaklik 3019 ....................
3020 .................... if(odp[0]==0) odp[1]='0'; // Prevod z ASCII do BIN
245 kaklik 3021 0102: MOVF 26,F
3022 0103: BTFSS 03.2
3023 0104: GOTO 107
3024 0105: MOVLW 30
3025 0106: MOVWF 27
223 kapl 3026 .................... odp[0]=odp[0] - '0';
245 kaklik 3027 0107: MOVLW 30
3028 0108: SUBWF 26,F
223 kapl 3029 .................... odp[1]=odp[1] - '0';
245 kaklik 3030 0109: SUBWF 27,F
223 kapl 3031 .................... if(odp[0]>9) odp[0]=odp[0]-7;
245 kaklik 3032 010A: MOVF 26,W
3033 010B: SUBLW 09
3034 010C: BTFSC 03.0
3035 010D: GOTO 110
3036 010E: MOVLW 07
3037 010F: SUBWF 26,F
223 kapl 3038 .................... if(odp[1]>9) odp[1]=odp[1]-7;
245 kaklik 3039 0110: MOVF 27,W
3040 0111: SUBLW 09
3041 0112: BTFSC 03.0
3042 0113: GOTO 116
3043 0114: MOVLW 07
3044 0115: SUBWF 27,F
223 kapl 3045 .................... odp[0]=odp[0] << 4;
245 kaklik 3046 0116: SWAPF 26,F
3047 0117: MOVLW F0
3048 0118: ANDWF 26,F
223 kapl 3049 .................... odp[0] |= odp[1];
245 kaklik 3050 0119: MOVF 27,W
3051 011A: IORWF 26,F
239 kaklik 3052 ....................
223 kapl 3053 .................... if(odp[2]==0) odp[3]='0';
245 kaklik 3054 011B: MOVF 28,F
3055 011C: BTFSS 03.2
3056 011D: GOTO 120
3057 011E: MOVLW 30
3058 011F: MOVWF 29
223 kapl 3059 .................... odp[2]=odp[2] - '0';
245 kaklik 3060 0120: MOVLW 30
3061 0121: SUBWF 28,F
223 kapl 3062 .................... odp[3]=odp[3] - '0';
245 kaklik 3063 0122: SUBWF 29,F
223 kapl 3064 .................... if(odp[2]>9) odp[2]=odp[2]-7;
245 kaklik 3065 0123: MOVF 28,W
3066 0124: SUBLW 09
3067 0125: BTFSC 03.0
3068 0126: GOTO 129
3069 0127: MOVLW 07
3070 0128: SUBWF 28,F
223 kapl 3071 .................... if(odp[3]>9) odp[3]=odp[3]-7;
245 kaklik 3072 0129: MOVF 29,W
3073 012A: SUBLW 09
3074 012B: BTFSC 03.0
3075 012C: GOTO 12F
3076 012D: MOVLW 07
3077 012E: SUBWF 29,F
223 kapl 3078 .................... odp[2]=odp[2] << 4;
245 kaklik 3079 012F: SWAPF 28,F
3080 0130: MOVLW F0
3081 0131: ANDWF 28,F
223 kapl 3082 .................... odp[2] |= odp[3];
245 kaklik 3083 0132: MOVF 29,W
3084 0133: IORWF 28,F
239 kaklik 3085 ....................
223 kapl 3086 .................... if(odp[4]==0) odp[5]='0';
245 kaklik 3087 0134: MOVF 2A,F
3088 0135: BTFSS 03.2
3089 0136: GOTO 139
3090 0137: MOVLW 30
3091 0138: MOVWF 2B
223 kapl 3092 .................... odp[4]=odp[4] - '0';
245 kaklik 3093 0139: MOVLW 30
3094 013A: SUBWF 2A,F
223 kapl 3095 .................... odp[5]=odp[5] - '0';
245 kaklik 3096 013B: SUBWF 2B,F
223 kapl 3097 .................... if(odp[4]>9) odp[4]=odp[4]-7;
245 kaklik 3098 013C: MOVF 2A,W
3099 013D: SUBLW 09
3100 013E: BTFSC 03.0
3101 013F: GOTO 142
3102 0140: MOVLW 07
3103 0141: SUBWF 2A,F
223 kapl 3104 .................... if(odp[5]>9) odp[5]=odp[5]-7;
245 kaklik 3105 0142: MOVF 2B,W
3106 0143: SUBLW 09
3107 0144: BTFSC 03.0
3108 0145: GOTO 148
3109 0146: MOVLW 07
3110 0147: SUBWF 2B,F
223 kapl 3111 .................... odp[4]=odp[4] << 4;
245 kaklik 3112 0148: SWAPF 2A,F
3113 0149: MOVLW F0
3114 014A: ANDWF 2A,F
223 kapl 3115 .................... odp[4] |= odp[5];
245 kaklik 3116 014B: MOVF 2B,W
3117 014C: IORWF 2A,F
239 kaklik 3118 ....................
223 kapl 3119 .................... if(odp[6]==0) odp[7]='0';
245 kaklik 3120 014D: MOVF 2C,F
3121 014E: BTFSS 03.2
3122 014F: GOTO 152
3123 0150: MOVLW 30
3124 0151: MOVWF 2D
223 kapl 3125 .................... odp[6]=odp[6] - '0';
245 kaklik 3126 0152: MOVLW 30
3127 0153: SUBWF 2C,F
223 kapl 3128 .................... odp[7]=odp[7] - '0';
245 kaklik 3129 0154: SUBWF 2D,F
223 kapl 3130 .................... if(odp[6]>9) odp[6]=odp[6]-7;
245 kaklik 3131 0155: MOVF 2C,W
3132 0156: SUBLW 09
3133 0157: BTFSC 03.0
3134 0158: GOTO 15B
3135 0159: MOVLW 07
3136 015A: SUBWF 2C,F
223 kapl 3137 .................... if(odp[7]>9) odp[7]=odp[7]-7;
245 kaklik 3138 015B: MOVF 2D,W
3139 015C: SUBLW 09
3140 015D: BTFSC 03.0
3141 015E: GOTO 161
3142 015F: MOVLW 07
3143 0160: SUBWF 2D,F
223 kapl 3144 .................... odp[6]=odp[6] << 4;
245 kaklik 3145 0161: SWAPF 2C,F
3146 0162: MOVLW F0
3147 0163: ANDWF 2C,F
223 kapl 3148 .................... odp[6] |= odp[7];
245 kaklik 3149 0164: MOVF 2D,W
3150 0165: IORWF 2C,F
223 kapl 3151 ....................
3152 .................... odp[1]=odp[2];
245 kaklik 3153 0166: MOVF 28,W
3154 0167: MOVWF 27
223 kapl 3155 .................... odp[2]=odp[4];
245 kaklik 3156 0168: MOVF 2A,W
3157 0169: MOVWF 28
223 kapl 3158 .................... odp[3]=odp[6];
245 kaklik 3159 016A: MOVF 2C,W
3160 016B: MOVWF 29
239 kaklik 3161 .................... odp[4]=odp[5]=odp[6]=0;
245 kaklik 3162 016C: CLRF 2C
3163 016D: MOVF 2C,W
3164 016E: MOVWF 2B
3165 016F: MOVWF 2A
239 kaklik 3166 ....................
3167 .................... /*lcd_gotoxy(1,2);
223 kapl 3168 .................... printf(lcd_putc,"%u %u %u %u",odp[0],odp[1],odp[2]odp[3]); */
239 kaklik 3169 ....................
223 kapl 3170 .................... pom3=0;
245 kaklik 3171 0170: CLRF 53
239 kaklik 3172 .................... for (pom = 0; pom < 4;pom++)
245 kaklik 3173 0171: CLRF 51
3174 0172: MOVF 51,W
3175 0173: SUBLW 03
3176 0174: BTFSS 03.0
3177 0175: GOTO 1C9
223 kapl 3178 .................... {
3179 .................... maskovadlo = maskovadlo >> 1; //rotace promene urcene pro maskovani
245 kaklik 3180 0176: BCF 03.0
3181 0177: RRF 56,F
223 kapl 3182 .................... maskovadlo = maskovadlo | 0x80;
245 kaklik 3183 0178: BSF 56.7
223 kapl 3184 .................... odkl = odp[pom] & maskovadlo; //odlozeni "prenosu" do odkl pomoci maskovadla
245 kaklik 3185 0179: MOVLW 26
3186 017A: ADDWF 51,W
3187 017B: MOVWF 04
3188 017C: MOVF 00,W
3189 017D: ANDWF 56,W
3190 017E: MOVWF 54
223 kapl 3191 .................... odp[pom] = odp[pom] << pom3; //rotace znaku
245 kaklik 3192 017F: MOVLW 26
3193 0180: ADDWF 51,W
3194 0181: MOVWF 57
3195 0182: MOVLW 26
3196 0183: ADDWF 51,W
3197 0184: MOVWF 04
3198 0185: MOVF 00,W
3199 0186: MOVWF 77
3200 0187: MOVF 53,W
3201 0188: MOVWF 78
3202 0189: BTFSC 03.2
3203 018A: GOTO 18F
3204 018B: BCF 03.0
3205 018C: RLF 77,F
3206 018D: DECFSZ 78,F
3207 018E: GOTO 18B
3208 018F: MOVF 57,W
3209 0190: MOVWF 04
3210 0191: MOVF 77,W
3211 0192: MOVWF 00
223 kapl 3212 .................... for (pom2 = 0; pom2 < (8-pom3);pom2++) //rotace odkl2
245 kaklik 3213 0193: CLRF 52
3214 0194: MOVF 53,W
3215 0195: SUBLW 08
3216 0196: SUBWF 52,W
3217 0197: BTFSC 03.0
3218 0198: GOTO 19E
223 kapl 3219 .................... {
3220 .................... odkl2 = odkl2 >> 1;
245 kaklik 3221 0199: BCF 03.0
3222 019A: RRF 55,F
239 kaklik 3223 .................... odkl2 = odkl2 & 127;
245 kaklik 3224 019B: BCF 55.7
223 kapl 3225 .................... }
245 kaklik 3226 019C: INCF 52,F
3227 019D: GOTO 194
223 kapl 3228 .................... odp[pom] = odp[pom] | odkl2; //pridani odkl2 ke znaku
245 kaklik 3229 019E: MOVLW 26
3230 019F: ADDWF 51,W
3231 01A0: MOVWF 57
3232 01A1: MOVLW 26
3233 01A2: ADDWF 51,W
3234 01A3: MOVWF 04
3235 01A4: MOVF 00,W
3236 01A5: IORWF 55,W
3237 01A6: MOVWF 59
3238 01A7: MOVF 57,W
3239 01A8: MOVWF 04
3240 01A9: MOVF 59,W
3241 01AA: MOVWF 00
223 kapl 3242 .................... odp[pom] = odp[pom] & 127; //smazani nejvysiho bitu
245 kaklik 3243 01AB: MOVLW 26
3244 01AC: ADDWF 51,W
3245 01AD: MOVWF 57
3246 01AE: MOVLW 26
3247 01AF: ADDWF 51,W
3248 01B0: MOVWF 04
3249 01B1: MOVF 00,W
3250 01B2: ANDLW 7F
3251 01B3: MOVWF 59
3252 01B4: MOVF 57,W
3253 01B5: MOVWF 04
3254 01B6: MOVF 59,W
3255 01B7: MOVWF 00
223 kapl 3256 .................... odkl2 = odkl; //ulozeni odlk na dalsi pruchod
245 kaklik 3257 01B8: MOVF 54,W
3258 01B9: MOVWF 55
223 kapl 3259 .................... pom3++; //inkrementace citace rotace
245 kaklik 3260 01BA: INCF 53,F
223 kapl 3261 .................... if (pom3 == 8) //kazdy 8my znak
245 kaklik 3262 01BB: MOVF 53,W
3263 01BC: SUBLW 08
3264 01BD: BTFSS 03.2
3265 01BE: GOTO 1C7
223 kapl 3266 .................... {
3267 .................... pom3 = 0; //smaz citac
245 kaklik 3268 01BF: CLRF 53
223 kapl 3269 .................... odp[pom+1] = odkl2; //uloz 8my znak vznikly z "prenosu"
245 kaklik 3270 01C0: MOVLW 01
3271 01C1: ADDWF 51,W
3272 01C2: ADDLW 26
3273 01C3: MOVWF 04
3274 01C4: MOVF 55,W
3275 01C5: MOVWF 00
223 kapl 3276 .................... maskovadlo = 0; //smaz maskovadlo
245 kaklik 3277 01C6: CLRF 56
223 kapl 3278 .................... }
3279 .................... }
245 kaklik 3280 01C7: INCF 51,F
3281 01C8: GOTO 172
239 kaklik 3282 .................... odp[pom]='\0';
245 kaklik 3283 01C9: MOVLW 26
3284 01CA: ADDWF 51,W
3285 01CB: MOVWF 04
3286 01CC: CLRF 00
240 kaklik 3287 .................... }
245 kaklik 3288 01CD: BCF 0A.3
3289 01CE: BCF 0A.4
3290 01CF: GOTO 47A (RETURN)
239 kaklik 3291 ....................
240 kaklik 3292 .................... void read_time()
3293 .................... {
3294 .................... unsigned int8 n;
238 kaklik 3295 ....................
239 kaklik 3296 ....................
240 kaklik 3297 .................... fprintf(MOBIL,"AT+CCLK?\r");
245 kaklik 3298 *
3299 01FC: CLRF 52
3300 01FD: MOVF 52,W
3301 01FE: CALL 013
3302 01FF: IORLW 00
3303 0200: BTFSC 03.2
3304 0201: GOTO 206
3305 0202: INCF 52,F
3306 0203: MOVWF 53
3307 0204: CALL 064
3308 0205: GOTO 1FD
240 kaklik 3309 .................... while(fgetc(MOBIL)!='"');
245 kaklik 3310 0206: CALL 08C
3311 0207: MOVF 78,W
3312 0208: SUBLW 22
3313 0209: BTFSS 03.2
3314 020A: GOTO 206
240 kaklik 3315 .................... for(n=0;n<12;n++) //preskoc nedulezite informace
245 kaklik 3316 020B: CLRF 51
3317 020C: MOVF 51,W
3318 020D: SUBLW 0B
3319 020E: BTFSS 03.0
3320 020F: GOTO 213
240 kaklik 3321 .................... {
3322 .................... fgetc(MOBIL);
245 kaklik 3323 0210: CALL 08C
240 kaklik 3324 .................... }
245 kaklik 3325 0211: INCF 51,F
3326 0212: GOTO 20C
240 kaklik 3327 .................... odp[0]=fgetc(MOBIL);
245 kaklik 3328 0213: CALL 08C
3329 0214: MOVF 78,W
3330 0215: MOVWF 26
240 kaklik 3331 .................... odp[1]=fgetc(MOBIL);
245 kaklik 3332 0216: CALL 08C
3333 0217: MOVF 78,W
3334 0218: MOVWF 27
240 kaklik 3335 .................... odp[2]=0;
245 kaklik 3336 0219: CLRF 28
240 kaklik 3337 .................... }
245 kaklik 3338 021A: BCF 0A.3
3339 021B: BCF 0A.4
3340 021C: GOTO 4F8 (RETURN)
239 kaklik 3341 ....................
240 kaklik 3342 .................... void del_sms()
3343 .................... {
3344 .................... fprintf(MOBIL,"AT+CMGD=1\r"); //smaz prijatou SMSku
3345 .................... }
239 kaklik 3346 ....................
240 kaklik 3347 .................... void main()
3348 .................... {
3349 *
245 kaklik 3350 03D5: CLRF 04
3351 03D6: MOVLW 1F
3352 03D7: ANDWF 03,F
3353 03D8: BCF 20.6
3354 03D9: MOVF 20,W
3355 03DA: BSF 03.5
3356 03DB: MOVWF 07
3357 03DC: BCF 03.5
3358 03DD: BSF 07.6
3359 03DE: BSF 03.5
3360 03DF: BCF 06.2
3361 03E0: BCF 03.5
3362 03E1: BSF 06.2
3363 03E2: BSF 03.5
3364 03E3: BSF 1F.0
3365 03E4: BSF 1F.1
3366 03E5: BSF 1F.2
3367 03E6: BCF 1F.3
3368 03E7: MOVLW 07
3369 03E8: MOVWF 1C
240 kaklik 3370 .................... setup_adc_ports(NO_ANALOGS);
3371 *
245 kaklik 3372 03F2: BSF 03.5
3373 03F3: BSF 1F.0
3374 03F4: BSF 1F.1
3375 03F5: BSF 1F.2
3376 03F6: BCF 1F.3
240 kaklik 3377 .................... setup_adc(ADC_OFF);
245 kaklik 3378 03F7: BCF 03.5
3379 03F8: BCF 1F.0
240 kaklik 3380 .................... setup_spi(SPI_SS_DISABLED);
245 kaklik 3381 03F9: BCF 14.5
3382 03FA: BCF 20.5
3383 03FB: MOVF 20,W
3384 03FC: BSF 03.5
3385 03FD: MOVWF 07
3386 03FE: BCF 03.5
3387 03FF: BSF 20.4
3388 0400: MOVF 20,W
3389 0401: BSF 03.5
3390 0402: MOVWF 07
3391 0403: BCF 03.5
3392 0404: BCF 20.3
3393 0405: MOVF 20,W
3394 0406: BSF 03.5
3395 0407: MOVWF 07
3396 0408: MOVLW 01
3397 0409: BCF 03.5
3398 040A: MOVWF 14
3399 040B: MOVLW 00
3400 040C: BSF 03.5
3401 040D: MOVWF 14
240 kaklik 3402 .................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
245 kaklik 3403 040E: MOVF 01,W
3404 040F: ANDLW C7
3405 0410: IORLW 08
3406 0411: MOVWF 01
240 kaklik 3407 .................... setup_timer_1(T1_DISABLED);
245 kaklik 3408 0412: BCF 03.5
3409 0413: CLRF 10
240 kaklik 3410 .................... setup_timer_2(T2_DIV_BY_4,255,1);
245 kaklik 3411 0414: MOVLW 00
3412 0415: MOVWF 78
3413 0416: IORLW 05
3414 0417: MOVWF 12
3415 0418: MOVLW FF
3416 0419: BSF 03.5
3417 041A: MOVWF 12
240 kaklik 3418 .................... setup_ccp1(CCP_PWM);
245 kaklik 3419 041B: BCF 03.5
3420 041C: BCF 20.2
3421 041D: MOVF 20,W
3422 041E: BSF 03.5
3423 041F: MOVWF 07
3424 0420: BCF 03.5
3425 0421: BCF 07.2
3426 0422: MOVLW 0C
3427 0423: MOVWF 17
240 kaklik 3428 .................... setup_ccp2(CCP_PWM);
245 kaklik 3429 0424: BCF 20.1
3430 0425: MOVF 20,W
3431 0426: BSF 03.5
3432 0427: MOVWF 07
3433 0428: BCF 03.5
3434 0429: BCF 07.1
3435 042A: MOVLW 0C
3436 042B: MOVWF 1D
240 kaklik 3437 .................... setup_comparator(NC_NC_NC_NC);
245 kaklik 3438 042C: MOVLW 07
3439 042D: BSF 03.5
3440 042E: MOVWF 1C
3441 042F: MOVF 05,W
3442 0430: CLRWDT
3443 0431: MOVLW 0E
3444 0432: MOVWF 77
3445 0433: DECFSZ 77,F
3446 0434: GOTO 433
3447 0435: NOP
3448 0436: NOP
3449 0437: MOVF 1C,W
3450 0438: BCF 03.5
3451 0439: BCF 0D.6
240 kaklik 3452 .................... setup_vref(FALSE);
245 kaklik 3453 043A: BSF 03.5
3454 043B: CLRF 1D
240 kaklik 3455 .................... setup_wdt(WDT_2304MS);
245 kaklik 3456 043C: MOVLW 0F
3457 043D: MOVWF 77
3458 043E: MOVLW 07
3459 043F: BCF 03.5
3460 0440: CLRF 01
3461 0441: MOVLW 81
3462 0442: MOVWF 04
3463 0443: MOVF 00,W
3464 0444: ANDLW F0
3465 0445: IORLW 07
3466 0446: MOVWF 00
3467 0447: CLRWDT
3468 0448: MOVF 00,W
3469 0449: ANDLW F7
3470 044A: BTFSC 77.3
3471 044B: ANDLW F0
3472 044C: IORWF 77,W
3473 044D: MOVWF 00
239 kaklik 3474 ....................
240 kaklik 3475 .................... set_pwm1_duty(0);
245 kaklik 3476 044E: CLRF 15
240 kaklik 3477 .................... set_pwm2_duty(0);
245 kaklik 3478 044F: CLRF 1B
239 kaklik 3479 ....................
240 kaklik 3480 .................... while(TRUE)
3481 .................... {
3482 .................... int status;
3483 .................... char *ptr;
3484 .................... int time;
238 kaklik 3485 ....................
240 kaklik 3486 .................... restart_wdt();
245 kaklik 3487 0450: CLRWDT
239 kaklik 3488 ....................
240 kaklik 3489 .................... output_low(PIN_A4) ;
245 kaklik 3490 0451: BSF 03.5
3491 0452: BCF 05.4
3492 0453: BCF 03.5
3493 0454: BCF 05.4
240 kaklik 3494 .................... delay_ms(150);
245 kaklik 3495 0455: MOVLW 96
3496 0456: MOVWF 52
3497 0457: CALL 04E
240 kaklik 3498 .................... output_high(PIN_A4);
245 kaklik 3499 0458: BSF 03.5
3500 0459: BCF 05.4
3501 045A: BCF 03.5
3502 045B: BSF 05.4
240 kaklik 3503 .................... delay_ms(150);
245 kaklik 3504 045C: MOVLW 96
3505 045D: MOVWF 52
3506 045E: CALL 04E
240 kaklik 3507 .................... output_low(PIN_A4) ;
245 kaklik 3508 045F: BSF 03.5
3509 0460: BCF 05.4
3510 0461: BCF 03.5
3511 0462: BCF 05.4
240 kaklik 3512 .................... delay_ms(150);
245 kaklik 3513 0463: MOVLW 96
3514 0464: MOVWF 52
3515 0465: CALL 04E
240 kaklik 3516 .................... output_high(PIN_A4);
245 kaklik 3517 0466: BSF 03.5
3518 0467: BCF 05.4
3519 0468: BCF 03.5
3520 0469: BSF 05.4
240 kaklik 3521 .................... delay_ms(150);
245 kaklik 3522 046A: MOVLW 96
3523 046B: MOVWF 52
3524 046C: CALL 04E
238 kaklik 3525 ....................
3526 ....................
245 kaklik 3527 .................... if(check_new_sms()) // Je odpoved "OK"?
3528 046D: GOTO 0B6
3529 046E: MOVF 78,F
3530 046F: BTFSC 03.2
3531 0470: GOTO 479
240 kaklik 3532 .................... {
3533 .................... // printf(lcd_putc,"736 655 250");
3534 .................... delay_ms(1000);
245 kaklik 3535 0471: MOVLW 04
3536 0472: MOVWF 51
3537 0473: MOVLW FA
3538 0474: MOVWF 52
3539 0475: CALL 04E
3540 0476: DECFSZ 51,F
3541 0477: GOTO 473
240 kaklik 3542 .................... }
3543 .................... else
245 kaklik 3544 0478: GOTO 4F7
240 kaklik 3545 .................... {
3546 .................... read_sms();
245 kaklik 3547 0479: GOTO 0E2
240 kaklik 3548 ....................
245 kaklik 3549 .................... /* if (odp[0] == 'A' || odp[0] == 'a')
240 kaklik 3550 .................... {
3551 .................... set_pwm1_duty(500);
3552 .................... set_pwm2_duty(500);
245 kaklik 3553 .................... Delay_ms(10000);
3554 .................... fprintf(VRTULE,"JACK[BARmk"); // "JACK BAR :)"
3555 .................... Delay_ms(2000);
3556 .................... fprintf(VRTULE,"JACK[BARmk"); // "JACK BAR :)"
240 kaklik 3557 .................... Delay_ms(5000);
3558 .................... set_pwm1_duty(0);
3559 .................... set_pwm2_duty(0);
245 kaklik 3560 .................... }*/
240 kaklik 3561 ....................
245 kaklik 3562 .................... /* if (odp[1] == 'h')
3563 .................... {
3564 .................... set_pwm1_duty(500);
3565 .................... set_pwm2_duty(500);
3566 .................... Delay_ms(10000);
3567 .................... fprintf(VRTULE,"[ERROR[d[["); // " ERROR 3 "
3568 .................... Delay_ms(2000);
3569 .................... fprintf(VRTULE,"[ERROR[d[["); // " ERROR 3 "
3570 .................... Delay_ms(2000);
3571 .................... fprintf(VRTULE,"[OVERFLOW["); // " OVERFLOW "
3572 .................... Delay_ms(2000);
3573 .................... fprintf(VRTULE,"[OVERFLOW[");
3574 .................... Delay_ms(5000);
3575 .................... set_pwm1_duty(0);
3576 .................... set_pwm2_duty(0);
3577 .................... }*/
239 kaklik 3578 ....................
245 kaklik 3579 .................... if (odp[2] == 'o')
3580 047A: MOVF 28,W
3581 047B: SUBLW 6F
3582 047C: BTFSS 03.2
3583 047D: GOTO 4F7
3584 .................... {
3585 .................... set_pwm1_duty(500);
3586 047E: MOVLW 7D
3587 047F: MOVWF 15
3588 0480: MOVF 17,W
3589 0481: ANDLW CF
3590 0482: MOVWF 17
3591 .................... set_pwm2_duty(500);
3592 0483: MOVLW 7D
3593 0484: MOVWF 1B
3594 0485: MOVF 1D,W
3595 0486: ANDLW CF
3596 0487: MOVWF 1D
3597 .................... Delay_ms(10000);
3598 0488: MOVLW 28
3599 0489: MOVWF 51
3600 048A: MOVLW FA
3601 048B: MOVWF 52
3602 048C: CALL 04E
3603 048D: DECFSZ 51,F
3604 048E: GOTO 48A
3605 .................... fprintf(VRTULE,"[ERROR[e[["); // " ERROR 4 "
3606 048F: CLRF 51
3607 0490: MOVF 51,W
3608 0491: CALL 021
3609 0492: IORLW 00
3610 0493: BTFSC 03.2
3611 0494: GOTO 499
3612 0495: INCF 51,F
3613 0496: MOVWF 52
3614 0497: CALL 1D0
3615 0498: GOTO 490
3616 .................... Delay_ms(2000);
3617 0499: MOVLW 08
3618 049A: MOVWF 51
3619 049B: MOVLW FA
3620 049C: MOVWF 52
3621 049D: CALL 04E
3622 049E: DECFSZ 51,F
3623 049F: GOTO 49B
3624 .................... fprintf(VRTULE,"[ERROR[e[["); // " ERROR 4 "
3625 04A0: CLRF 51
3626 04A1: MOVF 51,W
3627 04A2: CALL 021
3628 04A3: IORLW 00
3629 04A4: BTFSC 03.2
3630 04A5: GOTO 4AA
3631 04A6: INCF 51,F
3632 04A7: MOVWF 52
3633 04A8: CALL 1D0
3634 04A9: GOTO 4A1
3635 .................... Delay_ms(2000);
3636 04AA: MOVLW 08
3637 04AB: MOVWF 51
3638 04AC: MOVLW FA
3639 04AD: MOVWF 52
3640 04AE: CALL 04E
3641 04AF: DECFSZ 51,F
3642 04B0: GOTO 4AC
3643 .................... fprintf(VRTULE,"[OPAKUJTE["); // " OPAKUJTE "
3644 04B1: CLRF 51
3645 04B2: MOVF 51,W
3646 04B3: CALL 030
3647 04B4: IORLW 00
3648 04B5: BTFSC 03.2
3649 04B6: GOTO 4BB
3650 04B7: INCF 51,F
3651 04B8: MOVWF 52
3652 04B9: CALL 1D0
3653 04BA: GOTO 4B2
3654 .................... Delay_ms(2000);
3655 04BB: MOVLW 08
3656 04BC: MOVWF 51
3657 04BD: MOVLW FA
3658 04BE: MOVWF 52
3659 04BF: CALL 04E
3660 04C0: DECFSZ 51,F
3661 04C1: GOTO 4BD
3662 .................... fprintf(VRTULE,"[OPAKUJTE[");
3663 04C2: CLRF 51
3664 04C3: MOVF 51,W
3665 04C4: CALL 030
3666 04C5: IORLW 00
3667 04C6: BTFSC 03.2
3668 04C7: GOTO 4CC
3669 04C8: INCF 51,F
3670 04C9: MOVWF 52
3671 04CA: CALL 1D0
3672 04CB: GOTO 4C3
3673 .................... Delay_ms(2000);
3674 04CC: MOVLW 08
3675 04CD: MOVWF 51
3676 04CE: MOVLW FA
3677 04CF: MOVWF 52
3678 04D0: CALL 04E
3679 04D1: DECFSZ 51,F
3680 04D2: GOTO 4CE
3681 .................... fprintf(VRTULE,"[[VOLBU[[["); // " VOLBU "
3682 04D3: CLRF 51
3683 04D4: MOVF 51,W
3684 04D5: CALL 03F
3685 04D6: IORLW 00
3686 04D7: BTFSC 03.2
3687 04D8: GOTO 4DD
3688 04D9: INCF 51,F
3689 04DA: MOVWF 52
3690 04DB: CALL 1D0
3691 04DC: GOTO 4D4
3692 .................... Delay_ms(2000);
3693 04DD: MOVLW 08
3694 04DE: MOVWF 51
3695 04DF: MOVLW FA
3696 04E0: MOVWF 52
3697 04E1: CALL 04E
3698 04E2: DECFSZ 51,F
3699 04E3: GOTO 4DF
3700 .................... fprintf(VRTULE,"[[VOLBU[[[");
3701 04E4: CLRF 51
3702 04E5: MOVF 51,W
3703 04E6: CALL 03F
3704 04E7: IORLW 00
3705 04E8: BTFSC 03.2
3706 04E9: GOTO 4EE
3707 04EA: INCF 51,F
3708 04EB: MOVWF 52
3709 04EC: CALL 1D0
3710 04ED: GOTO 4E5
3711 .................... Delay_ms(3000);
3712 04EE: MOVLW 0C
3713 04EF: MOVWF 51
3714 04F0: MOVLW FA
3715 04F1: MOVWF 52
3716 04F2: CALL 04E
3717 04F3: DECFSZ 51,F
3718 04F4: GOTO 4F0
3719 .................... set_pwm1_duty(0);
3720 04F5: CLRF 15
3721 .................... set_pwm2_duty(0);
3722 04F6: CLRF 1B
3723 .................... }
240 kaklik 3724 .................... }
245 kaklik 3725 .................... read_time();
3726 04F7: GOTO 1FC
240 kaklik 3727 .................... time=strtoul(odp,&ptr,10);
245 kaklik 3728 04F8: MOVLW 26
3729 04F9: MOVWF 51
3730 04FA: MOVLW 4F
3731 04FB: MOVWF 52
3732 04FC: MOVLW 0A
3733 04FD: MOVWF 53
3734 04FE: GOTO 24F
3735 04FF: MOVF 78,W
3736 0500: MOVWF 50
240 kaklik 3737 .................... if((time >= 30 && time <= 35) || (time >= 0 && time <= 5))
245 kaklik 3738 0501: MOVF 50,W
3739 0502: SUBLW 1D
3740 0503: BTFSC 03.0
3741 0504: GOTO 509
3742 0505: MOVF 50,W
3743 0506: SUBLW 23
3744 0507: BTFSC 03.0
3745 0508: GOTO 50D
3746 0509: MOVF 50,W
3747 050A: SUBLW 05
3748 050B: BTFSS 03.0
3749 050C: GOTO 518
238 kaklik 3750 .................... {
240 kaklik 3751 .................... set_pwm1_duty(500);
245 kaklik 3752 050D: MOVLW 7D
3753 050E: MOVWF 15
3754 050F: MOVF 17,W
3755 0510: ANDLW CF
3756 0511: MOVWF 17
240 kaklik 3757 .................... set_pwm2_duty(500);
245 kaklik 3758 0512: MOVLW 7D
3759 0513: MOVWF 1B
3760 0514: MOVF 1D,W
3761 0515: ANDLW CF
3762 0516: MOVWF 1D
240 kaklik 3763 .................... }
3764 .................... else
245 kaklik 3765 0517: GOTO 51A
240 kaklik 3766 .................... {
3767 .................... set_pwm1_duty(0);
245 kaklik 3768 0518: CLRF 15
240 kaklik 3769 .................... set_pwm2_duty(0);
245 kaklik 3770 0519: CLRF 1B
3771 .................... }
223 kapl 3772 ....................
238 kaklik 3773 .................... delay_ms(1000);
245 kaklik 3774 051A: MOVLW 04
3775 051B: MOVWF 51
3776 051C: MOVLW FA
3777 051D: MOVWF 52
3778 051E: CALL 04E
3779 051F: DECFSZ 51,F
3780 0520: GOTO 51C
223 kapl 3781 .................... }
245 kaklik 3782 0521: GOTO 450
223 kapl 3783 .................... }
245 kaklik 3784 0522: SLEEP
223 kapl 3785  
3786 Configuration Fuses:
238 kaklik 3787 Word 1: 3F3A HS NOWDT NOPUT NODEBUG NOPROTECT NOBROWNOUT NOLVP NOCPD NOWRT