CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 1

ADDR CODE  LINE SOURCE

           0001 
           0002 ; CC5X Version 3.1J, Copyright (c) B Knudsen Data
           0003 ; C compiler for the PICmicro family
           0004 ; ************  26. Sep 2005  19:49  *************
           0005 
           0006 	processor  16F628
           0007 	radix  DEC
           0008 
     0001  0009 TMR0        EQU   0x01
     0003  0010 STATUS      EQU   0x03
     0005  0011 PORTA       EQU   0x05
     0085  0012 TRISA       EQU   0x85
     0006  0013 PORTB       EQU   0x06
     0086  0014 TRISB       EQU   0x86
     0000  0015 Carry       EQU   0
     0002  0016 Zero_       EQU   2
     0005  0017 RP0         EQU   5
     0006  0018 RP1         EQU   6
     0002  0019 T0IF        EQU   2
     0005  0020 T0IE        EQU   5
     0007  0021 GIE         EQU   7
     0081  0022 OPTION_REG  EQU   0x81
     000C  0023 PIR1        EQU   0x0C
     000E  0024 TMR1L       EQU   0x0E
     000F  0025 TMR1H       EQU   0x0F
     0018  0026 RCSTA       EQU   0x18
     001A  0027 RCREG       EQU   0x1A
     001F  0028 CMCON       EQU   0x1F
     0098  0029 TXSTA       EQU   0x98
     0099  0030 SPBRG       EQU   0x99
     0006  0031 PEIE        EQU   6
     0000  0032 TMR1IF      EQU   0
     0000  0033 TMR1ON      EQU   0
     0001  0034 TMR1CS      EQU   1
     0003  0035 T1OSCEN     EQU   3
     0004  0036 T1CKPS0     EQU   4
     0005  0037 T1CKPS1     EQU   5
     0000  0038 TMR1IE      EQU   0
     0000  0039 turret_tilt_select EQU   0
     0003  0040 turret_pan_select EQU   3
     0023  0041 servo_base  EQU   0x23
     0024  0042 servo_on_mask EQU   0x24
     0025  0043 servo_off_mask EQU   0x25
     0026  0044 servo_pos   EQU   0x26
     0027  0045 int_mode    EQU   0x27
     0028  0046 fire        EQU   0x28
     0029  0047 turret_state EQU   0x29
     002A  0048 motor_state EQU   0x2A
     0070  0049 svrWREG     EQU   0x70
     0020  0050 svrSTATUS   EQU   0x20
     0021  0051 ch          EQU   0x21
     0021  0052 i           EQU   0x21
     0022  0053 j           EQU   0x22
     0021  0054 com         EQU   0x21
           0055 
0000 290A  0056 	GOTO main
           0057 
           0058   ; FILE turret.c
           0059 			;/*
           0060 			;	Serial Motor Controller
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 2

ADDR CODE  LINE SOURCE

           0061 			;
           0062 			;    (C) 2005 Jason Hunt
           0063 			;
           0064 			;    This program is free software; you can redistribute it and/or
           0065 			;    modify it under the terms of the GNU General Public License
           0066 			;    as published by the Free Software Foundation; either version 2
           0067 			;    of the License, or (at your option) any later version.
           0068 			;
           0069 			;    This program is distributed in the hope that it will be useful
           0070 			;    but WITHOUT ANY WARRANTY; without even the implied warranty of
           0071 			;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
           0072 			;    GNU General Public License for more details.
           0073 			;
           0074 			;    You should have received a copy of the GNU General Public License
           0075 			;    along with this program; if not, write to the Free Software
           0076 			;    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
           0077 			;
           0078 			;    Contact: huntjas2@msu.edu
           0079 			;
           0080 			;    FILE: servo.c
           0081 			;
           0082 			;    This file gets position data from the main controller
           0083 			;    and keeps the servos updated and motors
           0084 			;
           0085 			;	nulluser@gmail.com
           0086 			;
           0087 			;	(5 MHZ instruction clock)
           0088 			;*/
           0089 			;
           0090 			;#define START_STRING "Linux robot motorcontroller version 0.4"
           0091 			;
           0092 			;#include <int16cxx.h>
           0093 			;
           0094 			;#pragma  chip PIC16f628
           0095 			;#pragma config |= 0x3FE2 // for ceramic resinator
           0096 			;//#pragma config |= 0x3FF1 // for internal clock
           0097 			;
           0098 			;#pragma bit phase0 @ PORTA.0		// outputs for stepper phase selection
           0099 			;#pragma bit phase1 @ PORTA.1
           0100 			;#pragma bit phase2 @ PORTA.2
           0101 			;#pragma bit phase3 @ PORTA.3
           0102 			;
           0103 			;#pragma bit turret_tilt_select @ PORTB.0		// outputs for stepper motor selection
           0104 			;#pragma bit turret_pan_select @ PORTB.3		   
           0105 			;
           0106 			;#pragma bit led @ PORTB.5 		// output for led
           0107 			;#pragma bit rx	@ PORTB.1 		// data from host          (input)
           0108 			;
           0109 			;unsigned char servo_base;		// Base time offsets
           0110 			;unsigned char servo_on_mask;		// or with this to turn servo[x] on
           0111 			;unsigned char servo_off_mask;	// and with this to turn servo[x] off
           0112 			;unsigned char servo_pos;		   		// positions of servos
           0113 			;
           0114 			;unsigned char int_mode;				// the state of the intrrupt handler
           0115 			;
           0116 			;unsigned char fire;
           0117 			;
           0118 			;
           0119 			;int turret_state;
           0120 			;int motor_state;
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 3

ADDR CODE  LINE SOURCE

           0121 			;
           0122 			;
           0123 			;#define turret_stop       0
           0124 			;#define turret_tilt_up    1
           0125 			;#define turret_tilt_down  2
           0126 			;#define turret_pan_left   3
           0127 			;#define turret_pan_right  4
           0128 			;
           0129 			;
           0130 			;
           0131 			;/* the ISR to update the servos */
           0132 			;#pragma interruptSaveCheck  n
           0133 			;#pragma origin 4
     0000  0134 	ORG 0x0004
           0135 			;
           0136 			;interrupt ISR(void)
           0137 			;{
           0138 ISR
           0139 			;    int_save_registers
0004 00F0  0140 	MOVWF svrWREG
0005 0E03  0141 	SWAPF STATUS,W
0006 1283  0142 	BCF   0x03,RP0
0007 1303  0143 	BCF   0x03,RP1
0008 00A0  0144 	MOVWF svrSTATUS
           0145 			;
           0146 			;	// check for timer zero interrupt
           0147 			;	if (T0IF)
0009 1D0B  0148 	BTFSS 0x0B,T0IF
000A 2833  0149 	GOTO  m004
           0150 			;	{
           0151 			;		if (int_mode == 0) // setupup for base pos wait
000B 08A7  0152 	MOVF  int_mode,1
000C 1D03  0153 	BTFSS 0x03,Zero_
000D 2819  0154 	GOTO  m001
           0155 			;		{
           0156 			;			int_mode = 1; 					   // next trigger we will setup for base delay
000E 3001  0157 	MOVLW .1
000F 00A7  0158 	MOVWF int_mode
           0159 			;			OPTION = 4;   					   // reset back into 1:16 prescaled mode
0010 3004  0160 	MOVLW .4
0011 1683  0161 	BSF   0x03,RP0
0012 0081  0162 	MOVWF OPTION_REG
           0163 			;			TMR0 = servo_base;      // set base time delay		
0013 1283  0164 	BCF   0x03,RP0
0014 0823  0165 	MOVF  servo_base,W
0015 0081  0166 	MOVWF TMR0
           0167 			;	   		PORTA |= servo_on_mask; // turn this one on
0016 0824  0168 	MOVF  servo_on_mask,W
0017 0485  0169 	IORWF PORTA,1
           0170 			;		} else
0018 2831  0171 	GOTO  m003
           0172 			;		if (int_mode == 1) 
0019 1283  0173 m001	BCF   0x03,RP0
001A 1303  0174 	BCF   0x03,RP1
001B 0B27  0175 	DECFSZ int_mode,W
001C 2822  0176 	GOTO  m002
           0177 			;		{
           0178 			;			int_mode = 2;					// next mode will turn off and check for long delay
001D 3002  0179 	MOVLW .2
001E 00A7  0180 	MOVWF int_mode
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 4

ADDR CODE  LINE SOURCE

           0181 			;			TMR0 = servo_pos;	// reset the timer to the pos
001F 0826  0182 	MOVF  servo_pos,W
0020 0081  0183 	MOVWF TMR0
           0184 			;	
           0185 			;		} else
0021 2831  0186 	GOTO  m003
           0187 			;		if (int_mode == 2)
0022 1283  0188 m002	BCF   0x03,RP0
0023 1303  0189 	BCF   0x03,RP1
0024 0827  0190 	MOVF  int_mode,W
0025 3A02  0191 	XORLW .2
0026 1D03  0192 	BTFSS 0x03,Zero_
0027 2831  0193 	GOTO  m003
           0194 			;		{
           0195 			;			int_mode = 0;						// reset back to base mode
0028 01A7  0196 	CLRF  int_mode
           0197 			;
           0198 			;	  	    PORTA &= servo_off_mask; // turn the current servo off
0029 0825  0199 	MOVF  servo_off_mask,W
002A 0585  0200 	ANDWF PORTA,1
           0201 			;	
           0202 			;    		OPTION = 7;		// ser the prescale for a longer delay time
002B 3007  0203 	MOVLW .7
002C 1683  0204 	BSF   0x03,RP0
002D 0081  0205 	MOVWF OPTION_REG
           0206 			;			TMR0 = 30;		// set the value for the longer delay
002E 301E  0207 	MOVLW .30
002F 1283  0208 	BCF   0x03,RP0
0030 0081  0209 	MOVWF TMR0
           0210 			;		}
           0211 			;
           0212 			;	    T0IF = 0; // clear timer zero interrupt
0031 110B  0213 m003	BCF   0x0B,T0IF
           0214 			;	} else
0032 28A5  0215 	GOTO  m018
           0216 			;	if (TMR1IF)	// timer1 interrupt
0033 1283  0217 m004	BCF   0x03,RP0
0034 1303  0218 	BCF   0x03,RP1
0035 1C0C  0219 	BTFSS 0x0C,TMR1IF
0036 28A5  0220 	GOTO  m018
           0221 			;	{
           0222 			;		TMR1L = 0x80;				// reset to roll over in 128 cycles
0037 3080  0223 	MOVLW .128
0038 008E  0224 	MOVWF TMR1L
           0225 			;		TMR1H = 0xea;
0039 30EA  0226 	MOVLW .234
003A 008F  0227 	MOVWF TMR1H
           0228 			;
           0229 			;		if (fire)
003B 08A8  0230 	MOVF  fire,1
003C 1903  0231 	BTFSC 0x03,Zero_
003D 2840  0232 	GOTO  m005
           0233 			;			fire--;
003E 03A8  0234 	DECF  fire,1
           0235 			;		else
003F 2844  0236 	GOTO  m006
           0237 			;			servo_pos = 200;
0040 30C8  0238 m005	MOVLW .200
0041 1283  0239 	BCF   0x03,RP0
0042 1303  0240 	BCF   0x03,RP1
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 5

ADDR CODE  LINE SOURCE

0043 00A6  0241 	MOVWF servo_pos
           0242 			;		
           0243 			;		led=!led;
0044 3020  0244 m006	MOVLW .32
0045 1283  0245 	BCF   0x03,RP0
0046 1303  0246 	BCF   0x03,RP1
0047 0686  0247 	XORWF PORTB,1
           0248 			;
           0249 			;		if (turret_state != turret_stop)
0048 08A9  0250 	MOVF  turret_state,1
0049 1903  0251 	BTFSC 0x03,Zero_
004A 289E  0252 	GOTO  m016
           0253 			;		{
           0254 			;			if (turret_state == turret_tilt_up)   motor_state--; else
004B 0B29  0255 	DECFSZ turret_state,W
004C 284F  0256 	GOTO  m007
004D 03AA  0257 	DECF  motor_state,1
004E 2865  0258 	GOTO  m010
           0259 			;			if (turret_state == turret_tilt_down) motor_state++; else
004F 1283  0260 m007	BCF   0x03,RP0
0050 1303  0261 	BCF   0x03,RP1
0051 0829  0262 	MOVF  turret_state,W
0052 3A02  0263 	XORLW .2
0053 1D03  0264 	BTFSS 0x03,Zero_
0054 2857  0265 	GOTO  m008
0055 0AAA  0266 	INCF  motor_state,1
0056 2865  0267 	GOTO  m010
           0268 			;			if (turret_state == turret_pan_left)  motor_state++; else
0057 1283  0269 m008	BCF   0x03,RP0
0058 1303  0270 	BCF   0x03,RP1
0059 0829  0271 	MOVF  turret_state,W
005A 3A03  0272 	XORLW .3
005B 1D03  0273 	BTFSS 0x03,Zero_
005C 285F  0274 	GOTO  m009
005D 0AAA  0275 	INCF  motor_state,1
005E 2865  0276 	GOTO  m010
           0277 			;    		if (turret_state == turret_pan_right) motor_state--; 
005F 1283  0278 m009	BCF   0x03,RP0
0060 1303  0279 	BCF   0x03,RP1
0061 0829  0280 	MOVF  turret_state,W
0062 3A04  0281 	XORLW .4
0063 1903  0282 	BTFSC 0x03,Zero_
0064 03AA  0283 	DECF  motor_state,1
           0284 			;
           0285 			;			if (motor_state > 3) motor_state = 0; else
0065 1283  0286 m010	BCF   0x03,RP0
0066 1303  0287 	BCF   0x03,RP1
0067 1BAA  0288 	BTFSC motor_state,7
0068 286F  0289 	GOTO  m011
0069 3004  0290 	MOVLW .4
006A 022A  0291 	SUBWF motor_state,W
006B 1C03  0292 	BTFSS 0x03,Carry
006C 286F  0293 	GOTO  m011
006D 01AA  0294 	CLRF  motor_state
006E 2875  0295 	GOTO  m012
           0296 			;			if (motor_state < 0) motor_state = 3;
006F 1283  0297 m011	BCF   0x03,RP0
0070 1303  0298 	BCF   0x03,RP1
0071 1FAA  0299 	BTFSS motor_state,7
0072 2875  0300 	GOTO  m012
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 6

ADDR CODE  LINE SOURCE

0073 3003  0301 	MOVLW .3
0074 00AA  0302 	MOVWF motor_state
           0303 			;
           0304 			;			if (motor_state == 0) PORTA = (PORTA & 0xf0) | 0x01; else
0075 1283  0305 m012	BCF   0x03,RP0
0076 1303  0306 	BCF   0x03,RP1
0077 08AA  0307 	MOVF  motor_state,1
0078 1D03  0308 	BTFSS 0x03,Zero_
0079 287F  0309 	GOTO  m013
007A 30F0  0310 	MOVLW .240
007B 0505  0311 	ANDWF PORTA,W
007C 3801  0312 	IORLW .1
007D 0085  0313 	MOVWF PORTA
007E 28A2  0314 	GOTO  m017
           0315 			;			if (motor_state == 1) PORTA = (PORTA & 0xf0) | 0x04; else
007F 1283  0316 m013	BCF   0x03,RP0
0080 1303  0317 	BCF   0x03,RP1
0081 0B2A  0318 	DECFSZ motor_state,W
0082 2888  0319 	GOTO  m014
0083 30F0  0320 	MOVLW .240
0084 0505  0321 	ANDWF PORTA,W
0085 3804  0322 	IORLW .4
0086 0085  0323 	MOVWF PORTA
0087 28A2  0324 	GOTO  m017
           0325 			;			if (motor_state == 2) PORTA = (PORTA & 0xf0) | 0x02; else
0088 1283  0326 m014	BCF   0x03,RP0
0089 1303  0327 	BCF   0x03,RP1
008A 082A  0328 	MOVF  motor_state,W
008B 3A02  0329 	XORLW .2
008C 1D03  0330 	BTFSS 0x03,Zero_
008D 2893  0331 	GOTO  m015
008E 30F0  0332 	MOVLW .240
008F 0505  0333 	ANDWF PORTA,W
0090 3802  0334 	IORLW .2
0091 0085  0335 	MOVWF PORTA
0092 28A2  0336 	GOTO  m017
           0337 			;			if (motor_state == 3) PORTA = (PORTA & 0xf0) | 0x08; 
0093 1283  0338 m015	BCF   0x03,RP0
0094 1303  0339 	BCF   0x03,RP1
0095 082A  0340 	MOVF  motor_state,W
0096 3A03  0341 	XORLW .3
0097 1D03  0342 	BTFSS 0x03,Zero_
0098 28A2  0343 	GOTO  m017
0099 30F0  0344 	MOVLW .240
009A 0505  0345 	ANDWF PORTA,W
009B 3808  0346 	IORLW .8
009C 0085  0347 	MOVWF PORTA
           0348 			;		} else
009D 28A2  0349 	GOTO  m017
           0350 			;		{
           0351 			;			PORTA &= 0xf0;	// clear phase select lines
009E 30F0  0352 m016	MOVLW .240
009F 1283  0353 	BCF   0x03,RP0
00A0 1303  0354 	BCF   0x03,RP1
00A1 0585  0355 	ANDWF PORTA,1
           0356 			;		}
           0357 			;
           0358 			;		TMR1IF = 0; // clear flag
00A2 1283  0359 m017	BCF   0x03,RP0
00A3 1303  0360 	BCF   0x03,RP1
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 7

ADDR CODE  LINE SOURCE

00A4 100C  0361 	BCF   0x0C,TMR1IF
           0362 			;	}
           0363 			;
           0364 			;    int_restore_registers
00A5 1283  0365 m018	BCF   0x03,RP0
00A6 1303  0366 	BCF   0x03,RP1
00A7 0E20  0367 	SWAPF svrSTATUS,W
00A8 0083  0368 	MOVWF STATUS
00A9 0EF0  0369 	SWAPF svrWREG,1
00AA 0E70  0370 	SWAPF svrWREG,W
           0371 			;}
00AB 0009  0372 	RETFIE
           0373 			;/* end of interrupt service routine */
           0374 			;
           0375 			;
           0376 			;
           0377 			;/* Set the serial port to  9600 8N1 */
           0378 			;void setup_serial(void)
           0379 			;{
           0380 setup_serial
           0381 			;	SPBRG = 129;   // divisor for 9600 baud
00AC 3081  0382 	MOVLW .129
00AD 1683  0383 	BSF   0x03,RP0
00AE 1303  0384 	BCF   0x03,RP1
00AF 0099  0385 	MOVWF SPBRG
           0386 			;//    TXSTA = 0x24; // transmitt enable, high speed
           0387 			;    TXSTA = 0x04; // transmitt enable, high speed
00B0 3004  0388 	MOVLW .4
00B1 0098  0389 	MOVWF TXSTA
           0390 			;
           0391 			;	RCSTA = 0x90; // serial enabled
00B2 3090  0392 	MOVLW .144
00B3 1283  0393 	BCF   0x03,RP0
00B4 0098  0394 	MOVWF RCSTA
           0395 			;
           0396 			;
           0397 			;
           0398 			;	char ch = RCREG;  // flush buffer
00B5 081A  0399 	MOVF  RCREG,W
00B6 00A1  0400 	MOVWF ch
           0401 			;	ch = RCREG;
00B7 081A  0402 	MOVF  RCREG,W
00B8 00A1  0403 	MOVWF ch
           0404 			;	ch = RCREG;
00B9 081A  0405 	MOVF  RCREG,W
00BA 00A1  0406 	MOVWF ch
           0407 			;}
00BB 0008  0408 	RETURN
           0409 			;/* end of setup serial */
           0410 			;
           0411 			;
           0412 			;/* sends a byte to the serial port */
           0413 			;/*void send_serial(unsigned char byte)
           0414 			;{
           0415 			;	while ((TXSTA & 0x02) == 0);	// wait until buffer is empty
           0416 			;	TXREG  = byte;					// set the transmit byte
           0417 			;}*/
           0418 			;/* end of send byte */
           0419 			;
           0420 			;
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 8

ADDR CODE  LINE SOURCE

           0421 			;/* sends a byte to the serial port */
           0422 			;unsigned char get_serial(void)
           0423 			;{
           0424 get_serial
           0425 			;	while ((PIR1 & 0x20) == 0);
00BC 1283  0426 m019	BCF   0x03,RP0
00BD 1303  0427 	BCF   0x03,RP1
00BE 1E8C  0428 	BTFSS PIR1,5
00BF 28BC  0429 	GOTO  m019
           0430 			;	return(RCREG);
00C0 1283  0431 	BCF   0x03,RP0
00C1 1303  0432 	BCF   0x03,RP1
00C2 081A  0433 	MOVF  RCREG,W
00C3 0008  0434 	RETURN
           0435 			;}
           0436 			;/* end of send byte */
           0437 			;
           0438 			;
           0439 			;/* called only once during startup */
           0440 			;void start_setup( void )
           0441 			;{
           0442 start_setup
           0443 			;	// setup io ports
           0444 			;	PORTA = 0;				// clear the ports
00C4 1283  0445 	BCF   0x03,RP0
00C5 1303  0446 	BCF   0x03,RP1
00C6 0185  0447 	CLRF  PORTA
           0448 			;	PORTB = 0;
00C7 0186  0449 	CLRF  PORTB
           0450 			;
           0451 			;	CMCON = 0x07;			// switch comparators off
00C8 3007  0452 	MOVLW .7
00C9 009F  0453 	MOVWF CMCON
           0454 			;
           0455 			;	TRISA = 0x00;			// all output
00CA 1683  0456 	BSF   0x03,RP0
00CB 0185  0457 	CLRF  TRISA
           0458 			;	TRISB = 0x02;			// bit 0 (bump) and 1 (rx) are inputs
00CC 3002  0459 	MOVLW .2
00CD 0086  0460 	MOVWF TRISB
           0461 			;
           0462 			;    GIE = 1;				// interrupts allowed 
00CE 178B  0463 	BSF   0x0B,GIE
           0464 			;	PEIE = 1;				// enable periphial interrupt
00CF 170B  0465 	BSF   0x0B,PEIE
           0466 			;
           0467 			;	// setup timer 0
           0468 			;    OPTION = 4;			// prescaler divide by 16
00D0 3004  0469 	MOVLW .4
00D1 0081  0470 	MOVWF OPTION_REG
           0471 			;    TMR0 = 0;				// clear the timer
00D2 1283  0472 	BCF   0x03,RP0
00D3 0181  0473 	CLRF  TMR0
           0474 			;    T0IE = 1;				// enable interrupt 
00D4 168B  0475 	BSF   0x0B,T0IE
           0476 			;
           0477 			;
           0478 			;	// setup timer 1
           0479 			;	TMR1L = 0x80;			// reset timer
00D5 3080  0480 	MOVLW .128
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 9

ADDR CODE  LINE SOURCE

00D6 008E  0481 	MOVWF TMR1L
           0482 			;	TMR1H = 0xe0;
00D7 30E0  0483 	MOVLW .224
00D8 008F  0484 	MOVWF TMR1H
           0485 			;
           0486 			;	TMR1ON = 0; 			// shut off timer to modify values
00D9 1010  0487 	BCF   0x10,TMR1ON
           0488 			;	T1CKPS1 = 1;			// setup prescaler
00DA 1690  0489 	BSF   0x10,T1CKPS1
           0490 			;	T1CKPS0 = 1;
00DB 1610  0491 	BSF   0x10,T1CKPS0
           0492 			;	T1OSCEN = 0;			// shut off oscillator
00DC 1190  0493 	BCF   0x10,T1OSCEN
           0494 			;	TMR1CS = 0;				// internal clock
00DD 1090  0495 	BCF   0x10,TMR1CS
           0496 			;	TMR1IE = 1;				// enable interrupt
00DE 1683  0497 	BSF   0x03,RP0
00DF 140C  0498 	BSF   0x8C,TMR1IE
           0499 			;	TMR1ON = 1; 			// turn timer on
00E0 1283  0500 	BCF   0x03,RP0
00E1 1410  0501 	BSF   0x10,TMR1ON
           0502 			;	TMR1IF = 0;				// clear interrupt flag*/
00E2 100C  0503 	BCF   0x0C,TMR1IF
           0504 			;
           0505 			;}
00E3 0008  0506 	RETURN
           0507 			;/* end of start_setup */
           0508 			;
           0509 			;
           0510 			;/* small delay to let everything settle */
           0511 			;void start_delay( void )
           0512 			;{
           0513 start_delay
           0514 			;	unsigned int i, j;
           0515 			;
           0516 			;	for (i = 0; i < 200; i++)
00E4 1283  0517 	BCF   0x03,RP0
00E5 1303  0518 	BCF   0x03,RP1
00E6 01A1  0519 	CLRF  i
00E7 30C8  0520 m020	MOVLW .200
00E8 1283  0521 	BCF   0x03,RP0
00E9 1303  0522 	BCF   0x03,RP1
00EA 0221  0523 	SUBWF i,W
00EB 1803  0524 	BTFSC 0x03,Carry
00EC 28FA  0525 	GOTO  m023
           0526 			;		for (j = 0; j < 50; j++);
00ED 01A2  0527 	CLRF  j
00EE 3032  0528 m021	MOVLW .50
00EF 1283  0529 	BCF   0x03,RP0
00F0 1303  0530 	BCF   0x03,RP1
00F1 0222  0531 	SUBWF j,W
00F2 1803  0532 	BTFSC 0x03,Carry
00F3 28F6  0533 	GOTO  m022
00F4 0AA2  0534 	INCF  j,1
00F5 28EE  0535 	GOTO  m021
00F6 1283  0536 m022	BCF   0x03,RP0
00F7 1303  0537 	BCF   0x03,RP1
00F8 0AA1  0538 	INCF  i,1
00F9 28E7  0539 	GOTO  m020
           0540 			;}
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 10

ADDR CODE  LINE SOURCE

00FA 0008  0541 m023	RETURN
           0542 			;/* end of start delay */
           0543 			;
           0544 			;
           0545 			;/* end of start delay */
           0546 			;
           0547 			;
           0548 			;/* reset all servoes to middle positions */
           0549 			;void home_controls( void )
           0550 			;{
           0551 home_controls
           0552 			;	int_mode = 0;
00FB 1283  0553 	BCF   0x03,RP0
00FC 1303  0554 	BCF   0x03,RP1
00FD 01A7  0555 	CLRF  int_mode
           0556 			;	fire = 0;
00FE 01A8  0557 	CLRF  fire
           0558 			;
           0559 			;	motor_state = 0;
00FF 01AA  0560 	CLRF  motor_state
           0561 			;
           0562 			;	turret_state = turret_stop;
0100 01A9  0563 	CLRF  turret_state
           0564 			;
           0565 			;	// home the servos
           0566 			;    servo_pos = 200;
0101 30C8  0567 	MOVLW .200
0102 00A6  0568 	MOVWF servo_pos
           0569 			;	servo_on_mask = 0x10;
0103 3010  0570 	MOVLW .16
0104 00A4  0571 	MOVWF servo_on_mask
           0572 			;	servo_off_mask = 0xff - 0x10;  
0105 30EF  0573 	MOVLW .239
0106 00A5  0574 	MOVWF servo_off_mask
           0575 			;	servo_base = 134;
0107 3086  0576 	MOVLW .134
0108 00A3  0577 	MOVWF servo_base
           0578 			;}
0109 0008  0579 	RETURN
           0580 			;/* end of home_servos */
           0581 			;
           0582 			;
           0583 			;
           0584 			;/* main function */
           0585 			;void main(void)
           0586 			;{
           0587 main
           0588 			;	start_setup();
010A 20C4  0589 	CALL  start_setup
           0590 			;
           0591 			;	home_controls();
010B 20FB  0592 	CALL  home_controls
           0593 			;
           0594 			;	setup_serial();
010C 20AC  0595 	CALL  setup_serial
           0596 			;
           0597 			;	start_delay();
010D 20E4  0598 	CALL  start_delay
           0599 			;
           0600 			;	while(1)
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 11

ADDR CODE  LINE SOURCE

           0601 			;	{
           0602 			;		char com = get_serial();	// get command
010E 20BC  0603 m024	CALL  get_serial
010F 1283  0604 	BCF   0x03,RP0
0110 1303  0605 	BCF   0x03,RP1
0111 00A1  0606 	MOVWF com
           0607 			;
           0608 			;		if (com == 0x60 && fire == 0) 
0112 0821  0609 	MOVF  com,W
0113 3A60  0610 	XORLW .96
0114 1D03  0611 	BTFSS 0x03,Zero_
0115 291E  0612 	GOTO  m025
0116 08A8  0613 	MOVF  fire,1
0117 1D03  0614 	BTFSS 0x03,Zero_
0118 291E  0615 	GOTO  m025
           0616 			;		{ 
           0617 			;			servo_pos = 100; 
0119 3064  0618 	MOVLW .100
011A 00A6  0619 	MOVWF servo_pos
           0620 			;			fire = 60; 
011B 303C  0621 	MOVLW .60
011C 00A8  0622 	MOVWF fire
           0623 			;		} else
011D 290E  0624 	GOTO  m024
           0625 			;		if (com == 0x10) 
011E 1283  0626 m025	BCF   0x03,RP0
011F 1303  0627 	BCF   0x03,RP1
0120 0821  0628 	MOVF  com,W
0121 3A10  0629 	XORLW .16
0122 1D03  0630 	BTFSS 0x03,Zero_
0123 2929  0631 	GOTO  m026
           0632 			;		{ 
           0633 			;			turret_state = turret_tilt_up;
0124 3001  0634 	MOVLW .1
0125 00A9  0635 	MOVWF turret_state
           0636 			;			turret_tilt_select = 1; 
0126 1406  0637 	BSF   0x06,turret_tilt_select
           0638 			;			turret_pan_select = 0;
0127 1186  0639 	BCF   0x06,turret_pan_select
           0640 			;		} else
0128 290E  0641 	GOTO  m024
           0642 			;		if (com == 0x20) 
0129 1283  0643 m026	BCF   0x03,RP0
012A 1303  0644 	BCF   0x03,RP1
012B 0821  0645 	MOVF  com,W
012C 3A20  0646 	XORLW .32
012D 1D03  0647 	BTFSS 0x03,Zero_
012E 2934  0648 	GOTO  m027
           0649 			;		{ 
           0650 			;			turret_state = turret_tilt_down;
012F 3002  0651 	MOVLW .2
0130 00A9  0652 	MOVWF turret_state
           0653 			;			turret_tilt_select = 1; 
0131 1406  0654 	BSF   0x06,turret_tilt_select
           0655 			;			turret_pan_select = 0;
0132 1186  0656 	BCF   0x06,turret_pan_select
           0657 			;		} else
0133 290E  0658 	GOTO  m024
           0659 			;		if (com == 0x30) 
0134 1283  0660 m027	BCF   0x03,RP0
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 12

ADDR CODE  LINE SOURCE

0135 1303  0661 	BCF   0x03,RP1
0136 0821  0662 	MOVF  com,W
0137 3A30  0663 	XORLW .48
0138 1D03  0664 	BTFSS 0x03,Zero_
0139 293F  0665 	GOTO  m028
           0666 			;		{ 
           0667 			;			turret_state = turret_pan_left;
013A 3003  0668 	MOVLW .3
013B 00A9  0669 	MOVWF turret_state
           0670 			;			turret_pan_select = 1; 
013C 1586  0671 	BSF   0x06,turret_pan_select
           0672 			;			turret_tilt_select = 0;
013D 1006  0673 	BCF   0x06,turret_tilt_select
           0674 			;		}  else
013E 290E  0675 	GOTO  m024
           0676 			;		if (com == 0x40) 
013F 1283  0677 m028	BCF   0x03,RP0
0140 1303  0678 	BCF   0x03,RP1
0141 0821  0679 	MOVF  com,W
0142 3A40  0680 	XORLW .64
0143 1D03  0681 	BTFSS 0x03,Zero_
0144 294A  0682 	GOTO  m029
           0683 			;		{ 
           0684 			;			turret_state = turret_pan_right;
0145 3004  0685 	MOVLW .4
0146 00A9  0686 	MOVWF turret_state
           0687 			;			turret_pan_select = 1; 
0147 1586  0688 	BSF   0x06,turret_pan_select
           0689 			;			turret_tilt_select = 0;
0148 1006  0690 	BCF   0x06,turret_tilt_select
           0691 			;		}  else
0149 290E  0692 	GOTO  m024
           0693 			;		if (com == 0x50) 
014A 1283  0694 m029	BCF   0x03,RP0
014B 1303  0695 	BCF   0x03,RP1
014C 0821  0696 	MOVF  com,W
014D 3A50  0697 	XORLW .80
014E 1D03  0698 	BTFSS 0x03,Zero_
014F 290E  0699 	GOTO  m024
           0700 			;		{ 
           0701 			;			turret_state = turret_stop;
0150 01A9  0702 	CLRF  turret_state
           0703 			;			turret_tilt_select = 0;
0151 1006  0704 	BCF   0x06,turret_tilt_select
           0705 			;			turret_pan_select = 0;
0152 1186  0706 	BCF   0x06,turret_pan_select
           0707 			;		} 
           0708 			;	}
0153 290E  0709 	GOTO  m024
           0710 
     0000  0711 	ORG 0x2007
2007 3FE2  0712 	DATA 3FE2H
     0000  0713 	END
     0000  0714 
     0000  0715 
     0000  0716 ; *** KEY INFO ***
     0000  0717 
     0000  0718 ; 0x0004  168 word(s)  8 % : ISR
     0000  0719 ; 0x00AC   16 word(s)  0 % : setup_serial
     0000  0720 ; 0x00BC    8 word(s)  0 % : get_serial
CC5X Version 3.1J,   File: turret.c            26. Sep 2005  19:49   Page 13

ADDR CODE  LINE SOURCE

     0000  0721 ; 0x00C4   32 word(s)  1 % : start_setup
     0000  0722 ; 0x00E4   23 word(s)  1 % : start_delay
     0000  0723 ; 0x00FB   15 word(s)  0 % : home_controls
     0000  0724 ; 0x010A   74 word(s)  3 % : main
     0000  0725 
     0000  0726 ; RAM usage: 12 bytes (4 local), 212 bytes free
     0000  0727 ; Maximum call level: 1 (+1 for interrupt)
     0000  0728 ; Total of 337 code words (16 %)
