2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 Changes between V1.2.4 and V1.2.5
\r
68 + Introduced portGLOBAL_INTERRUPT_FLAG definition to test the global
\r
69 interrupt flag setting. Using the two bits defined within
\r
70 portINITAL_INTERRUPT_STATE was causing the w register to get clobbered
\r
71 before the test was performed.
\r
75 + Set the interrupt vector address to 0x08. Previously it was at the
\r
76 incorrect address for compatibility mode of 0x18.
\r
80 + PCLATU and PCLATH are now saved as part of the context. This allows
\r
81 function pointers to be used within tasks. Thanks to Javier Espeche
\r
82 for the enhancement.
\r
86 + TABLAT is now saved as part of the task context.
\r
90 + TBLPTRU is now initialised to zero as the MPLAB compiler expects this
\r
91 value and does not write to the register.
\r
94 /* Scheduler include files. */
\r
95 #include "FreeRTOS.h"
\r
98 /* MPLAB library include file. */
\r
101 /*-----------------------------------------------------------
\r
102 * Implementation of functions defined in portable.h for the PIC port.
\r
103 *----------------------------------------------------------*/
\r
105 /* Hardware setup for tick. */
\r
106 #define portTIMER_FOSC_SCALE ( ( unsigned long ) 4 )
\r
108 /* Initial interrupt enable state for newly created tasks. This value is
\r
109 copied into INTCON when a task switches in for the first time. */
\r
110 #define portINITAL_INTERRUPT_STATE 0xc0
\r
112 /* Just the bit within INTCON for the global interrupt flag. */
\r
113 #define portGLOBAL_INTERRUPT_FLAG 0x80
\r
115 /* Constant used for context switch macro when we require the interrupt
\r
116 enable state to be unchanged when the interrupted task is switched back in. */
\r
117 #define portINTERRUPTS_UNCHANGED 0x00
\r
119 /* Some memory areas get saved as part of the task context. These memory
\r
120 area's get used by the compiler for temporary storage, especially when
\r
121 performing mathematical operations, or when using 32bit data types. This
\r
122 constant defines the size of memory area which must be saved. */
\r
123 #define portCOMPILER_MANAGED_MEMORY_SIZE ( ( unsigned char ) 0x13 )
\r
125 /* We require the address of the pxCurrentTCB variable, but don't want to know
\r
126 any details of its type. */
\r
127 typedef void tskTCB;
\r
128 extern volatile tskTCB * volatile pxCurrentTCB;
\r
130 /* IO port constants. */
\r
131 #define portBIT_SET ( ( unsigned char ) 1 )
\r
132 #define portBIT_CLEAR ( ( unsigned char ) 0 )
\r
135 * The serial port ISR's are defined in serial.c, but are called from portable
\r
136 * as they use the same vector as the tick ISR.
\r
138 void vSerialTxISR( void );
\r
139 void vSerialRxISR( void );
\r
142 * Perform hardware setup to enable ticks.
\r
144 static void prvSetupTimerInterrupt( void );
\r
147 * ISR to maintain the tick, and perform tick context switches if the
\r
148 * preemptive scheduler is being used.
\r
150 static void prvTickISR( void );
\r
153 * ISR placed on the low priority vector. This calls the appropriate ISR for
\r
154 * the actual interrupt.
\r
156 static void prvLowInterrupt( void );
\r
159 * Macro that pushes all the registers that make up the context of a task onto
\r
160 * the stack, then saves the new top of stack into the TCB.
\r
162 * If this is called from an ISR then the interrupt enable bits must have been
\r
163 * set for the ISR to ever get called. Therefore we want to save the INTCON
\r
164 * register with the enable bits forced to be set - and ucForcedInterruptFlags
\r
165 * must contain these bit settings. This means the interrupts will again be
\r
166 * enabled when the interrupted task is switched back in.
\r
168 * If this is called from a manual context switch (i.e. from a call to yield),
\r
169 * then we want to save the INTCON so it is restored with its current state,
\r
170 * and ucForcedInterruptFlags must be 0. This allows a yield from within
\r
171 * a critical section.
\r
173 * The compiler uses some locations at the bottom of the memory for temporary
\r
174 * storage during math and other computations. This is especially true if
\r
175 * 32bit data types are utilised (as they are by the scheduler). The .tmpdata
\r
176 * and MATH_DATA sections have to be stored in there entirety as part of a task
\r
177 * context. This macro stores from data address 0x00 to
\r
178 * portCOMPILER_MANAGED_MEMORY_SIZE. This is sufficient for the demo
\r
179 * applications but you should check the map file for your project to ensure
\r
180 * this is sufficient for your needs. It is not clear whether this size is
\r
181 * fixed for all compilations or has the potential to be program specific.
\r
183 #define portSAVE_CONTEXT( ucForcedInterruptFlags ) \
\r
186 /* Save the status and WREG registers first, as these will get modified \
\r
187 by the operations below. */ \
\r
188 MOVFF WREG, PREINC1 \
\r
189 MOVFF STATUS, PREINC1 \
\r
190 /* Save the INTCON register with the appropriate bits forced if \
\r
191 necessary - as described above. */ \
\r
192 MOVFF INTCON, WREG \
\r
193 IORLW ucForcedInterruptFlags \
\r
194 MOVFF WREG, PREINC1 \
\r
197 portDISABLE_INTERRUPTS(); \
\r
200 /* Store the necessary registers to the stack. */ \
\r
201 MOVFF BSR, PREINC1 \
\r
202 MOVFF FSR2L, PREINC1 \
\r
203 MOVFF FSR2H, PREINC1 \
\r
204 MOVFF FSR0L, PREINC1 \
\r
205 MOVFF FSR0H, PREINC1 \
\r
206 MOVFF TABLAT, PREINC1 \
\r
207 MOVFF TBLPTRU, PREINC1 \
\r
208 MOVFF TBLPTRH, PREINC1 \
\r
209 MOVFF TBLPTRL, PREINC1 \
\r
210 MOVFF PRODH, PREINC1 \
\r
211 MOVFF PRODL, PREINC1 \
\r
212 MOVFF PCLATU, PREINC1 \
\r
213 MOVFF PCLATH, PREINC1 \
\r
214 /* Store the .tempdata and MATH_DATA areas as described above. */ \
\r
217 MOVFF POSTINC0, PREINC1 \
\r
218 MOVFF POSTINC0, PREINC1 \
\r
219 MOVFF POSTINC0, PREINC1 \
\r
220 MOVFF POSTINC0, PREINC1 \
\r
221 MOVFF POSTINC0, PREINC1 \
\r
222 MOVFF POSTINC0, PREINC1 \
\r
223 MOVFF POSTINC0, PREINC1 \
\r
224 MOVFF POSTINC0, PREINC1 \
\r
225 MOVFF POSTINC0, PREINC1 \
\r
226 MOVFF POSTINC0, PREINC1 \
\r
227 MOVFF POSTINC0, PREINC1 \
\r
228 MOVFF POSTINC0, PREINC1 \
\r
229 MOVFF POSTINC0, PREINC1 \
\r
230 MOVFF POSTINC0, PREINC1 \
\r
231 MOVFF POSTINC0, PREINC1 \
\r
232 MOVFF POSTINC0, PREINC1 \
\r
233 MOVFF POSTINC0, PREINC1 \
\r
234 MOVFF POSTINC0, PREINC1 \
\r
235 MOVFF POSTINC0, PREINC1 \
\r
236 MOVFF INDF0, PREINC1 \
\r
237 MOVFF FSR0L, PREINC1 \
\r
238 MOVFF FSR0H, PREINC1 \
\r
239 /* Store the hardware stack pointer in a temp register before we \
\r
241 MOVFF STKPTR, FSR0L \
\r
244 /* Store each address from the hardware stack. */ \
\r
245 while( STKPTR > ( unsigned char ) 0 ) \
\r
248 MOVFF TOSL, PREINC1 \
\r
249 MOVFF TOSH, PREINC1 \
\r
250 MOVFF TOSU, PREINC1 \
\r
256 /* Store the number of addresses on the hardware stack (from the \
\r
257 temporary register). */ \
\r
258 MOVFF FSR0L, PREINC1 \
\r
259 MOVF PREINC1, 1, 0 \
\r
262 /* Save the new top of the software stack in the TCB. */ \
\r
264 MOVFF pxCurrentTCB, FSR0L \
\r
265 MOVFF pxCurrentTCB + 1, FSR0H \
\r
266 MOVFF FSR1L, POSTINC0 \
\r
267 MOVFF FSR1H, POSTINC0 \
\r
270 /*-----------------------------------------------------------*/
\r
273 * This is the reverse of portSAVE_CONTEXT. See portSAVE_CONTEXT for more
\r
276 #define portRESTORE_CONTEXT() \
\r
279 /* Set FSR0 to point to pxCurrentTCB->pxTopOfStack. */ \
\r
280 MOVFF pxCurrentTCB, FSR0L \
\r
281 MOVFF pxCurrentTCB + 1, FSR0H \
\r
283 /* De-reference FSR0 to set the address it holds into FSR1. \
\r
284 (i.e. *( pxCurrentTCB->pxTopOfStack ) ). */ \
\r
285 MOVFF POSTINC0, FSR1L \
\r
286 MOVFF POSTINC0, FSR1H \
\r
288 /* How many return addresses are there on the hardware stack? Discard \
\r
289 the first byte as we are pointing to the next free space. */ \
\r
290 MOVFF POSTDEC1, FSR0L \
\r
291 MOVFF POSTDEC1, FSR0L \
\r
294 /* Fill the hardware stack from our software stack. */ \
\r
297 while( STKPTR < FSR0L ) \
\r
301 MOVF POSTDEC1, 0, 0 \
\r
303 MOVF POSTDEC1, 0, 0 \
\r
305 MOVF POSTDEC1, 0, 0 \
\r
311 /* Restore the .tmpdata and MATH_DATA memory. */ \
\r
312 MOVFF POSTDEC1, FSR0H \
\r
313 MOVFF POSTDEC1, FSR0L \
\r
314 MOVFF POSTDEC1, POSTDEC0 \
\r
315 MOVFF POSTDEC1, POSTDEC0 \
\r
316 MOVFF POSTDEC1, POSTDEC0 \
\r
317 MOVFF POSTDEC1, POSTDEC0 \
\r
318 MOVFF POSTDEC1, POSTDEC0 \
\r
319 MOVFF POSTDEC1, POSTDEC0 \
\r
320 MOVFF POSTDEC1, POSTDEC0 \
\r
321 MOVFF POSTDEC1, POSTDEC0 \
\r
322 MOVFF POSTDEC1, POSTDEC0 \
\r
323 MOVFF POSTDEC1, POSTDEC0 \
\r
324 MOVFF POSTDEC1, POSTDEC0 \
\r
325 MOVFF POSTDEC1, POSTDEC0 \
\r
326 MOVFF POSTDEC1, POSTDEC0 \
\r
327 MOVFF POSTDEC1, POSTDEC0 \
\r
328 MOVFF POSTDEC1, POSTDEC0 \
\r
329 MOVFF POSTDEC1, POSTDEC0 \
\r
330 MOVFF POSTDEC1, POSTDEC0 \
\r
331 MOVFF POSTDEC1, POSTDEC0 \
\r
332 MOVFF POSTDEC1, POSTDEC0 \
\r
333 MOVFF POSTDEC1, INDF0 \
\r
334 /* Restore the other registers forming the tasks context. */ \
\r
335 MOVFF POSTDEC1, PCLATH \
\r
336 MOVFF POSTDEC1, PCLATU \
\r
337 MOVFF POSTDEC1, PRODL \
\r
338 MOVFF POSTDEC1, PRODH \
\r
339 MOVFF POSTDEC1, TBLPTRL \
\r
340 MOVFF POSTDEC1, TBLPTRH \
\r
341 MOVFF POSTDEC1, TBLPTRU \
\r
342 MOVFF POSTDEC1, TABLAT \
\r
343 MOVFF POSTDEC1, FSR0H \
\r
344 MOVFF POSTDEC1, FSR0L \
\r
345 MOVFF POSTDEC1, FSR2H \
\r
346 MOVFF POSTDEC1, FSR2L \
\r
347 MOVFF POSTDEC1, BSR \
\r
348 /* The next byte is the INTCON register. Read this into WREG as some \
\r
349 manipulation is required. */ \
\r
350 MOVFF POSTDEC1, WREG \
\r
353 /* From the INTCON register, only the interrupt enable bits form part \
\r
354 of the tasks context. It is perfectly legitimate for another task to \
\r
355 have modified any other bits. We therefore only restore the top two bits. \
\r
357 if( WREG & portGLOBAL_INTERRUPT_FLAG ) \
\r
360 MOVFF POSTDEC1, STATUS \
\r
361 MOVFF POSTDEC1, WREG \
\r
362 /* Return enabling interrupts. */ \
\r
369 MOVFF POSTDEC1, STATUS \
\r
370 MOVFF POSTDEC1, WREG \
\r
371 /* Return without effecting interrupts. The context may have \
\r
372 been saved from a critical region. */ \
\r
377 /*-----------------------------------------------------------*/
\r
380 * See header file for description.
\r
382 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
384 unsigned long ulAddress;
\r
385 unsigned char ucBlock;
\r
387 /* Place a few bytes of known values on the bottom of the stack.
\r
388 This is just useful for debugging. */
\r
390 *pxTopOfStack = 0x11;
\r
392 *pxTopOfStack = 0x22;
\r
394 *pxTopOfStack = 0x33;
\r
398 /* Simulate how the stack would look after a call to vPortYield() generated
\r
401 First store the function parameters. This is where the task will expect to
\r
402 find them when it starts running. */
\r
403 ulAddress = ( unsigned long ) pvParameters;
\r
404 *pxTopOfStack = ( portSTACK_TYPE ) ( ulAddress & ( unsigned long ) 0x00ff );
\r
408 *pxTopOfStack = ( portSTACK_TYPE ) ( ulAddress & ( unsigned long ) 0x00ff );
\r
411 /* Next we just leave a space. When a context is saved the stack pointer
\r
412 is incremented before it is used so as not to corrupt whatever the stack
\r
413 pointer is actually pointing to. This is especially necessary during
\r
414 function epilogue code generated by the compiler. */
\r
415 *pxTopOfStack = 0x44;
\r
418 /* Next are all the registers that form part of the task context. */
\r
420 *pxTopOfStack = ( portSTACK_TYPE ) 0x66; /* WREG. */
\r
423 *pxTopOfStack = ( portSTACK_TYPE ) 0xcc; /* Status. */
\r
426 /* INTCON is saved with interrupts enabled. */
\r
427 *pxTopOfStack = ( portSTACK_TYPE ) portINITAL_INTERRUPT_STATE; /* INTCON */
\r
430 *pxTopOfStack = ( portSTACK_TYPE ) 0x11; /* BSR. */
\r
433 *pxTopOfStack = ( portSTACK_TYPE ) 0x22; /* FSR2L. */
\r
436 *pxTopOfStack = ( portSTACK_TYPE ) 0x33; /* FSR2H. */
\r
439 *pxTopOfStack = ( portSTACK_TYPE ) 0x44; /* FSR0L. */
\r
442 *pxTopOfStack = ( portSTACK_TYPE ) 0x55; /* FSR0H. */
\r
445 *pxTopOfStack = ( portSTACK_TYPE ) 0x66; /* TABLAT. */
\r
448 *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* TBLPTRU. */
\r
451 *pxTopOfStack = ( portSTACK_TYPE ) 0x88; /* TBLPTRUH. */
\r
454 *pxTopOfStack = ( portSTACK_TYPE ) 0x99; /* TBLPTRUL. */
\r
457 *pxTopOfStack = ( portSTACK_TYPE ) 0xaa; /* PRODH. */
\r
460 *pxTopOfStack = ( portSTACK_TYPE ) 0xbb; /* PRODL. */
\r
463 *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* PCLATU. */
\r
466 *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* PCLATH. */
\r
469 /* Next the .tmpdata and MATH_DATA sections. */
\r
470 for( ucBlock = 0; ucBlock <= portCOMPILER_MANAGED_MEMORY_SIZE; ucBlock++ )
\r
472 *pxTopOfStack = ( portSTACK_TYPE ) ucBlock;
\r
476 /* Store the top of the global data section. */
\r
477 *pxTopOfStack = ( portSTACK_TYPE ) portCOMPILER_MANAGED_MEMORY_SIZE; /* Low. */
\r
480 *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* High. */
\r
483 /* The only function return address so far is the address of the
\r
485 ulAddress = ( unsigned long ) pxCode;
\r
488 *pxTopOfStack = ( portSTACK_TYPE ) ( ulAddress & ( unsigned long ) 0x00ff );
\r
493 *pxTopOfStack = ( portSTACK_TYPE ) ( ulAddress & ( unsigned long ) 0x00ff );
\r
497 /* TOS even higher. */
\r
498 *pxTopOfStack = ( portSTACK_TYPE ) ( ulAddress & ( unsigned long ) 0x00ff );
\r
501 /* Store the number of return addresses on the hardware stack - so far only
\r
502 the address of the task entry point. */
\r
503 *pxTopOfStack = ( portSTACK_TYPE ) 1;
\r
506 return pxTopOfStack;
\r
508 /*-----------------------------------------------------------*/
\r
510 portBASE_TYPE xPortStartScheduler( void )
\r
512 /* Setup a timer for the tick ISR is using the preemptive scheduler. */
\r
513 prvSetupTimerInterrupt();
\r
515 /* Restore the context of the first task to run. */
\r
516 portRESTORE_CONTEXT();
\r
518 /* Should not get here. Use the function name to stop compiler warnings. */
\r
519 ( void ) prvLowInterrupt;
\r
520 ( void ) prvTickISR;
\r
524 /*-----------------------------------------------------------*/
\r
526 void vPortEndScheduler( void )
\r
528 /* It is unlikely that the scheduler for the PIC port will get stopped
\r
529 once running. If required disable the tick interrupt here, then return
\r
530 to xPortStartScheduler(). */
\r
532 /*-----------------------------------------------------------*/
\r
535 * Manual context switch. This is similar to the tick context switch,
\r
536 * but does not increment the tick count. It must be identical to the
\r
537 * tick context switch in how it stores the stack of a task.
\r
539 void vPortYield( void )
\r
541 /* This can get called with interrupts either enabled or disabled. We
\r
542 will save the INTCON register with the interrupt enable bits unmodified. */
\r
543 portSAVE_CONTEXT( portINTERRUPTS_UNCHANGED );
\r
545 /* Switch to the highest priority task that is ready to run. */
\r
546 vTaskSwitchContext();
\r
548 /* Start executing the task we have just switched to. */
\r
549 portRESTORE_CONTEXT();
\r
551 /*-----------------------------------------------------------*/
\r
554 * Vector for ISR. Nothing here must alter any registers!
\r
556 #pragma code high_vector=0x08
\r
557 static void prvLowInterrupt( void )
\r
559 /* Was the interrupt the tick? */
\r
560 if( PIR1bits.CCP1IF )
\r
567 /* Was the interrupt a byte being received? */
\r
568 if( PIR1bits.RCIF )
\r
575 /* Was the interrupt the Tx register becoming empty? */
\r
576 if( PIR1bits.TXIF )
\r
578 if( PIE1bits.TXIE )
\r
588 /*-----------------------------------------------------------*/
\r
591 * ISR for the tick.
\r
592 * This increments the tick count and, if using the preemptive scheduler,
\r
593 * performs a context switch. This must be identical to the manual
\r
594 * context switch in how it stores the context of a task.
\r
596 static void prvTickISR( void )
\r
598 /* Interrupts must have been enabled for the ISR to fire, so we have to
\r
599 save the context with interrupts enabled. */
\r
600 portSAVE_CONTEXT( portGLOBAL_INTERRUPT_FLAG );
\r
601 PIR1bits.CCP1IF = 0;
\r
603 /* Maintain the tick count. */
\r
604 if( xTaskIncrementTick() != pdFALSE )
\r
606 /* Switch to the highest priority task that is ready to run. */
\r
607 vTaskSwitchContext();
\r
610 portRESTORE_CONTEXT();
\r
612 /*-----------------------------------------------------------*/
\r
615 * Setup a timer for a regular tick.
\r
617 static void prvSetupTimerInterrupt( void )
\r
619 const unsigned long ulConstCompareValue = ( ( configCPU_CLOCK_HZ / portTIMER_FOSC_SCALE ) / configTICK_RATE_HZ );
\r
620 unsigned long ulCompareValue;
\r
621 unsigned char ucByte;
\r
623 /* Interrupts are disabled when this function is called.
\r
625 Setup CCP1 to provide the tick interrupt using a compare match on timer
\r
628 Clear the time count then setup timer. */
\r
629 TMR1H = ( unsigned char ) 0x00;
\r
630 TMR1L = ( unsigned char ) 0x00;
\r
632 /* Set the compare match value. */
\r
633 ulCompareValue = ulConstCompareValue;
\r
634 CCPR1L = ( unsigned char ) ( ulCompareValue & ( unsigned long ) 0xff );
\r
635 ulCompareValue >>= ( unsigned long ) 8;
\r
636 CCPR1H = ( unsigned char ) ( ulCompareValue & ( unsigned long ) 0xff );
\r
638 CCP1CONbits.CCP1M0 = portBIT_SET; /*< Compare match mode. */
\r
639 CCP1CONbits.CCP1M1 = portBIT_SET; /*< Compare match mode. */
\r
640 CCP1CONbits.CCP1M2 = portBIT_CLEAR; /*< Compare match mode. */
\r
641 CCP1CONbits.CCP1M3 = portBIT_SET; /*< Compare match mode. */
\r
642 PIE1bits.CCP1IE = portBIT_SET; /*< Interrupt enable. */
\r
644 /* We are only going to use the global interrupt bit, so set the peripheral
\r
646 INTCONbits.GIEL = portBIT_SET;
\r
648 /* Provided library function for setting up the timer that will produce the
\r
650 OpenTimer1( T1_16BIT_RW & T1_SOURCE_INT & T1_PS_1_1 & T1_CCP1_T3_CCP2 );
\r