T:\My Documents\Robot_Codedemo.lst - generated by MGTEK Assembler ASM11 V1.22 Build 137 for WIN32 (x86) - Fri Mar 17 12:13:24 2006

    1:                                 ;**************************************************************************
    2:                                 ;Name:          Robot Library
    3:                                 ;Version:       0.1b
    4:                                 ;Author:        Dan Kohn
    5:                                 ; Comments By:  Dan Kohn & Adrian Austin
    6:                                 ;Date of Mod):  March, 15, 2006
    7:                                 ;
    8:                                 ;IO Table:
    9:                                 ;
   10:                                 ;PortA          PA7     Output / Sonar Init
   11:                                 ;               PA6     OC2 / RIGHT Motor (PWM for servo)
   12:                                 ;               PA5     OC3 / LEFT Motor (PWM for servo)
   13:                                 ;               PA4     OC4 / Multiplexed Servo Output ;mike code gripper motor
   14:                                 ;               PA3     OC5 / USED FOR TRACE - BUFFALO
   15:                                 ;               PA2     IC1 / Gripper
   16:                                 ;               PA1     IC2 / Sonar Echo 
   17:                                 ;               PA0     IC3/Clock for barcode
   18:                                 ;
   19:                                 ;PortE          PE7     Data for barcode
   20:                                 ;               PE6
   21:                                 ;               PE5
   22:                                 ;               PE4
   23:                                 ;               PE3     ADR4/Line Track 3       left   \
   24:                                 ;               PE2     ADR3/Line Track 2       center  - looking from the back of robot
   25:                                 ;               PE1     ADR2/Line Track 1       Right  /
   26:                                 ;               PE0
   27:                                 ;
   28:                                 ;               
   29:                                 ;PortD          PD5     
   30:                                 ;               PD4
   31:                                 
   32:                                 ;               PD3     
   33:                                 ;               PD2     
   34:                                 ;
   35:                                 ;               OUTPUT Circuit
   36:                                 ;$B580          BIT0    LSB Servo Multiplexer 
   37:                                 ;               BIT1    |
   38:                                 ;               BIT2    MSB Servo Multiplexer
   39:                                 ;               BIT3
   40:                                 ;               BIT4
   41:                                 ;               BIT5
   42:                                 ;               BIT6
   43:                                 ;               BIT7
   44:                                 ;
   45:                                 ;               Input Circuit // not currently in use
   46:                                 ;$B590          BIT0     
   47:                                 ;               BIT1
   48:                                 ;               BIT2
   49:                                 ;               BIT3
   50:                                 ;               BIT4
   51:                                 ;               BIT5
   52:                                 ;               BIT6
   53:                                 ;               BIT7
   54:                                 ;
   55:                                 ;               Input Circuit // not currently in use
   56:                                 ;$B5A0          BIT0
   57:                                 ;               BIT1
   58:                                 ;               BIT2
   59:                                 ;               BIT3
   60:                                 ;               BIT4
   61:                                 ;               BIT5
   62:                                 ;               BIT6
   63:                                 ;               BIT7
   64:                                 ;**************************************************************************
   65:                                 
   66:                                 
   67:          =00002000                              ORG $2000
   68:                                                 
   69:                                                 include Hc11.inc        ;definds all HC11 Registers
    1:                                 * Define Register Locations for ASM Portion of Code
    2:                                 
    3:          =00001000              REG_BASE        equ     $1000
    4:                                 
    5:          =00001000              PORTA           equ     REG_BASE+$0000
    6:          =00001002              PIOC            equ     REG_BASE+$0002
    7:          =00001003              PORTC           equ     REG_BASE+$0003
    8:          =00001004              PORTB           equ     REG_BASE+$0004
    9:          =00001005              PORTCL          equ     REG_BASE+$0005
   10:          =00001007              DDRC            equ     REG_BASE+$0007
   11:          =00001008              PORTD           equ     REG_BASE+$0008
   12:          =00001009              DDRD            equ     REG_BASE+$0009
   13:          =0000100A              PORTE           equ     REG_BASE+$000A
   14:          =0000100B              CFORC           equ     REG_BASE+$000B
   15:          =0000100C              OC1M            equ     REG_BASE+$000C
   16:          =0000100D              OC1D            equ     REG_BASE+$000D
   17:          =0000100E              TCNT            equ     REG_BASE+$000E
   18:          =00001010              TIC1            equ     REG_BASE+$0010
   19:          =00001012              TIC2            equ     REG_BASE+$0012
   20:          =00001014              TIC3            equ     REG_BASE+$0014
   21:          =00001016              TOC1            equ     REG_BASE+$0016
   22:          =00001018              TOC2            equ     REG_BASE+$0018
   23:          =0000101A              TOC3            equ     REG_BASE+$001A
   24:          =0000101C              TOC4            equ     REG_BASE+$001C
   25:          =0000101E              TOC5            equ     REG_BASE+$001E
   26:          =00001020              TCTL1           equ     REG_BASE+$0020
   27:          =00001021              TCTL2           equ     REG_BASE+$0021
   28:          =00001022              TMSK1           equ     REG_BASE+$0022
   29:          =00001023              TFLG1           equ     REG_BASE+$0023
   30:          =00001024              TMSK2           equ     REG_BASE+$0024
   31:          =00001025              TFLG2           equ     REG_BASE+$0025
   32:          =00001026              PACTL           equ     REG_BASE+$0026
   33:          =00001027              PACNT           equ     REG_BASE+$0027
   34:          =00001028              SPCR            equ     REG_BASE+$0028
   35:          =00001029              SPSR            equ     REG_BASE+$0029
   36:          =0000102A              SPDR            equ     REG_BASE+$002A
   37:          =0000102B              BAUD            equ     REG_BASE+$002B
   38:          =0000102C              SCCR1           equ     REG_BASE+$002C
   39:          =0000102D              SCCR2           equ     REG_BASE+$002D
   40:          =0000102E              SCSR            equ     REG_BASE+$002E
   41:          =0000102F              SCDR            equ     REG_BASE+$002F
   42:          =00001030              ADCTL           equ     REG_BASE+$0030
   43:          =00001031              ADR1            equ     REG_BASE+$0031
   44:          =00001032              ADR2            equ     REG_BASE+$0032
   45:          =00001033              ADR3            equ     REG_BASE+$0033
   46:          =00001034              ADR4            equ     REG_BASE+$0034
   47:          =00001039              OPTION          equ     REG_BASE+$0039
   48:          =0000103A              COPRST          equ     REG_BASE+$003A
   49:          =0000103B              PPROG           equ     REG_BASE+$003B
   50:          =0000103C              HPRIO           equ     REG_BASE+$003C
   51:          =0000103D              INIT            equ     REG_BASE+$003D
   52:          =0000103E              TEST1           equ     REG_BASE+$003E
   53:          =0000103F              CONFIG          equ     REG_BASE+$003F
   70:                                 
   71:     2000 7E 202F                                JMP MAIN
   72:                                 ;Barcode Equates
   73:          =000000E2              IC3IV           EQU $00E2
   74:     2003 +0005                  Barcode         RMB 5
   75:     2008 +0001                  BC_count        RMB 1
   76:     2009 +0001                  Boxcode         RMB 1
   77:          =0000FFB8              outa            equ $ffb8
   78:                                 
   79:                                 ;Buffalo Equates
   80:          =0000FFC1              out2bsp         equ $ffc1               ; prints what is pointed to by x to the screen
   81:          =0000FFC4              outcrlf         equ $ffc4               ; outputs a carrage return and line feed
   82:          =0000FFBE              out1bsp         equ $ffbe               ; prints what is pointed to by x to the screen
   83:                                 
   84:                                 ;Gipper Motor Variables and Equates                     ;mike code
   85:          =000000D6              TOC4IV          EQU $00D6
   86:     200A +0002                  On_cnts_G       RMB 2
   87:     200C +0002                  Off_cnts_G      RMB 2
   88:                                 
   89:                                 ;Left Motor Variables and Equates
   90:          =000000D9              TOC3IV          EQU $00D9
   91:     200E +0002                  On_cnts_L       RMB 2
   92:     2010 +0002                  Off_cnts_L      RMB 2
   93:                                 
   94:                                 ;Line Track Control Byte
   95:     2012 +0001                  LTCB            rmb 1
   96:                                 
   97:                                 ;Line Track Level
   98:          =00000094              LTL             equ $94         ; comparison number for more black and less is white? 
   99:                                 
  100:                                 ;multiplexer values
  101:          =0000B580              cs0             equ $B580
  102:     2013 +0002                  On_cnts_A       RMB 2
  103:     2015 +0002                  Off_cnts_A      RMB 2
  104:     2017 +0002                  On_cnts_B       RMB 2
  105:     2019 +0002                  Off_cnts_B      RMB 2
  106:                                 
  107:                                 ;Sonar variables
  108:     201B +0002                  Sonar_start     rmb 2
  109:     201D +0002                  Sonar_end       rmb 2
  110:     201F +0002                  Sonar_ans       rmb 2
  111:                                 
  112:                                 ;Right Motor Variables and Equates
  113:          =000000DC              TOC2IV          EQU $00DC               
  114:     2021 +0002                  On_cnts_R       RMB 2
  115:     2023 +0002                  Off_cnts_R      RMB 2
  116:                                 
  117:                                 
  118:                                 ;Timer Overflow Counter
  119:          =000000D0              TOFIV           EQU $00D0
  120:     2025 +0001                  Sec_Temp        rmb 1           ;counter 32.77mSec [0-15]
  121:     2026 +0001                  Sec_count       rmb 1           ;counter 0.1Sec [0-255]
  122:     2027 +0002                  plane_temp      rmb 2           ;counter 32.77ms [0-30]
  123:     2029 +0002                  plane1_cd       rmb 2           ;countdown timer - plane 1 [180 -> 0 Sec]
  124:     202B +0002                  plane2_cd       rmb 2           ;countdown timer - plane 2 [240 -> 0 Sec]
  125:     202D +0002                  plane3_cd       rmb 2           ;countdown timer - plane 3 [300 -> 0 Sec]
  126:                                 
  127:     202F                        MAIN            
  128:                                 
  129:     202F BD 22A5                                jsr go_stop             ;Set up On/Off times for stop
  130:     2032 BD 2539                                jsr TOC4_init           ;init gripper motor
  131:     2035 BD 24E9                                jsr TOC3_init           ;init left motor
  132:     2038 BD 2499                                jsr TOC2_init           ;init right motor
  133:     203B BD 23F5                                jsr TOF_init            ;init Timer Overflow (for 0.5 sec Timer)
  134:     203E BD 2301                                jsr A2D                 ;init A/D PE0..PE3
  135:     2041 86 96                                  ldaa #150               ; pause robot for placement at beginning
  136:     2043 BD 23CC                                jsr pause
  137:                                                 
  138:     2046 BD 206A                                jsr Start               ;leave the block
  139:     2049 BD 2080                                jsr LeaveShoot          ; moves robot from shoot to the plane 1 intersection            
  140:                                                                         ; spot to check if need to go to 1st plane
  141:     204C BD 20A7                                jsr Plane1              ; moves the plane to plane one and dumps and returns
  142:                                                                         ; to the 1st t intersection
  143:     204F BD 210D                                jsr Shoot2              ; this moves the robot back to the shoot
  144:     2052 BD 2080                                jsr LeaveShoot          ; moves from the shoot back to the 1st t intersection
  145:     2055 BD 2139                                jsr Plane2              ; moves from t intersection an back to t intersection
  146:     2058 BD 210D                                jsr Shoot2              ; moves back to the shoot
  147:     205B BD 2080                                jsr LeaveShoot          ; moves back to t intersection
  148:     205E BD 21A7                                jsr Plane3              ; moves from the t intersection and back from the 3rd plane
  149:     2061 BD 210D                                jsr Shoot2              ; moves back to the shoot
  150:     2064 BD 22A5                                jsr go_stop
  151:     2067 7E E000                                jmp $e000
  152:                                 ;**************************************************************************
  153:                                 ; this section moves the robot to the block shoot
  154:                                 ;**************************************************************************
  155:     206A 36                     Start:          psha
  156:                                 
  157:     206B BD 22B7                                jsr go_forward          ;Leaving Block
  158:     206E 86 0A                                  ldaa #10
  159:     2070 BD 23CC                                jsr pause
  160:     2073 BD 2207                                jsr LineTrack           ; this line moves forward until the 1st plus intersection
  161:                                                 
  162:                                                 
  163:     2076 BD 22B7                                jsr go_forward          ; moves forward so line tracking will work 
  164:     2079 86 05                                  ldaa #5
  165:     207B BD 23CC                                jsr pause
  166:                                                 
  167:                                                 ;jsr Linetrack          ; moves forward to the 1st plus intersection
  168:                                 ;
  169:                                 ;               jsr go_Close            ;call sub that close the gripper hand
  170:                                 ;               ldaa #20
  171:                                 ;;              jsr pause
  172:                                 ;               
  173:                                 ;               jsr go_stop             ;call stop for the gripper
  174:                                 ;               ldaa #10
  175:                                 ;               jsr pause
  176:                                 
  177:     207E 32                                     pula
  178:     207F 39                                     rts
  179:                                 ;**************************************************************************
  180:                                 ; this section moves the robot away from the shoot to the intersection for
  181:                                 ; turning to plane 1
  182:                                 ;**************************************************************************
  183:                                                 
  184:     2080 36                     LeaveShoot:     psha
  185:                                         
  186:                                 
  187:     2081 BD 227B                                jsr clockw              ;180 Right Turn to leave the Package shoot
  188:     2084 BD 2207                                jsr LineTrack           ; line track back to the 1st plus
  189:     2087 BD 22B7                                jsr go_forward          ; this section makes the first turn
  190:     208A 86 05                                  ldaa #5
  191:                                                                         ; *
  192:     208C BD 23CC                                jsr pause               ; *
  193:     208F BD 22A5                                jsr go_stop
  194:     2092 86 05                                  ldaa #5
  195:     2094 BD 23CC                                jsr pause               ; *
  196:     2097 BD 2290                                jsr counterclck         ; *
  197:     209A BD 22A5                                jsr go_stop             ; *
  198:     209D 86 05                                  ldaa #5                 ; *
  199:     209F BD 23CC                                jsr pause               ; *
  200:                                 
  201:     20A2 BD 2207                                jsr LineTrack           ; moves robot to the 1st t intersection
  202:                                                                         ; ends this section
  203:     20A5 32                                     pula
  204:     20A6 39                                     rts
  205:                                 ;**************************************************************************
  206:                                 ; this section moves the robot to the first plane and then moves it back to the 1st t intersection
  207:                                 ;**************************************************************************
  208:     20A7 36                     Plane1:         psha
  209:                                 
  210:     20A8 BD 22B7                                jsr go_forward          ; moves forward so turn will work properly
  211:     20AB 86 0A                                  ldaa #10
  212:     20AD BD 23CC                                jsr pause
  213:     20B0 BD 22A5                                jsr go_stop
  214:     20B3 86 05                                  ldaa #5
  215:     20B5 BD 23CC                                jsr pause
  216:     20B8 BD 227B                                jsr clockw              ;turns right until hits white line for the first plane
  217:                                 
  218:     20BB BD 22A5                                jsr go_stop             
  219:     20BE 86 14                                  ldaa #20
  220:     20C0 BD 23CC                                jsr pause
  221:     20C3 BD 2207                                jsr Linetrack           ;Stops at 2nd plus by Loading Zone 1
  222:     20C6 BD 22B7                                jsr go_forward          
  223:     20C9 86 03                                  ldaa #3
  224:     20CB BD 23CC                                jsr pause
  225:     20CE BD 2207                                jsr Linetrack
  226:     20D1 BD 23DF                                jsr Left90              ; turns to the airplane
  227:     20D4 BD 22A5                                jsr go_stop             ; right her is where droping will occur         
  228:     20D7 86 19                                  ldaa #25        
  229:     20D9 BD 23CC                                jsr pause
  230:                                 
  231:                                                         
  232:     20DC BD 231A                                jsr go_Open             ; for the simple robot must remove
  233:     20DF 86 0A                                  ldaa #10                        ; and replace with carrage dump section
  234:     20E1 BD 23CC                                jsr pause               ;*
  235:                                                 
  236:     20E4 BD 2290                                jsr counterclck
  237:                                 
  238:                                 
  239:     20E7 BD 2207                                jsr linetrack           ; moves the robot forward to the 2nd plus
  240:     20EA BD 22B7                                jsr go_forward          ; this section moves the robot back to the 
  241:     20ED 86 05                                  ldaa #5         
  242:     20EF BD 23CC                                jsr pause
  243:     20F2 BD 2207                                jsr linetrack
  244:                                 
  245:     20F5 BD 22B7                                jsr go_forward
  246:     20F8 86 07                                  ldaa #7
  247:     20FA BD 23CC                                jsr pause
  248:                                                 
  249:                                                 
  250:     20FD BD 2290                                jsr counterclck
  251:     2100 BD 22A5                                jsr go_stop
  252:     2103 86 05                                  ldaa #5         
  253:                                 
  254:     2105 BD 2207                                jsr Linetrack   ;       
  255:     2108 BD 23CC                                jsr pause               ;
  256:                                 
  257:                                                 
  258:                                 
  259:     210B 32                                     pula
  260:                                 
  261:     210C 39                                     rts
  262:                                 ;**************************************************************************
  263:                                 ; this section goes back to the shoot from the t intersection
  264:                                 ;
  265:                                 ;
  266:                                 ;**************************************************************************
  267:     210D 36                     Shoot2:         psha
  268:                                                 
  269:     210E BD 2207                                jsr Linetrack
  270:     2111 BD 22B7                                jsr go_forward
  271:     2114 86 08                                  ldaa #8
  272:     2116 BD 23CC                                jsr pause
  273:                                                 
  274:                                                 ;jsr Linetrack
  275:                                 
  276:     2119 BD 227B                                jsr clockw              ;Goes back to Shoot
  277:     211C BD 22A5                                jsr go_stop             ;
  278:     211F 86 08                                  ldaa #8
  279:     2121 BD 23CC                                jsr pause
  280:                                                 
  281:     2124 BD 2207                                jsr Linetrack
  282:     2127 BD 22A5                                jsr go_stop
  283:     212A 86 0A                                  ldaa #10
  284:     212C BD 23CC                                jsr pause
  285:                                 
  286:     212F BD 2320                                jsr go_close
  287:     2132 86 14                                  ldaa #20
  288:     2134 BD 23CC                                jsr pause
  289:                                                 
  290:     2137 32                                     pula
  291:     2138 39                                     rts
  292:                                 ;
  293:                                 ;**************************************************************************
  294:                                 ; this section moves from the t intersection
  295:                                 ; to the second plane and back to the 1st t intersection
  296:                                 ;**************************************************************************
  297:     2139 36                     Plane2:         psha
  298:                                                 
  299:     213A BD 22B7                                jsr go_forward
  300:     213D 86 05                                  ldaa #5
  301:     213F BD 23CC                                jsr pause
  302:                                                 
  303:     2142 BD 2207                                jsr Linetrack           ; moves the robot forward until you get to the 3rd plus
  304:                                                                         ; intersection
  305:     2145 BD 22B7                                jsr go_forward          
  306:     2148 86 05                                  ldaa #5
  307:     214A BD 23CC                                jsr pause
  308:     214D BD 227B                                jsr clockw              ;will trun right until hits the white line agian
  309:                                                 
  310:     2150 BD 22A5                                jsr go_stop
  311:     2153 86 05                                  ldaa #5
  312:     2155 BD 23CC                                jsr pause
  313:     2158 BD 2207                                jsr Linetrack           ;Stops at 4th plus by Loading Zone 1
  314:     215B BD 22B7                                jsr go_forward
  315:     215E 86 0A                                  ldaa #10
  316:     2160 BD 23CC                                jsr pause
  317:     2163 BD 2207                                jsr Linetrack           ; moves forward until side of board
  318:     2166 86 05                                  ldaa #5
  319:     2168 BD 23CC                                jsr pause
  320:     216B BD 23DF                                jsr Left90              ; turn left to go towards the plane
  321:     216E BD 22A5                                jsr go_stop
  322:     2171 86 05                                  ldaa #5
  323:     2173 BD 23CC                                jsr pause
  324:     2176 BD 231A                                jsr go_Open             ; this section for the simple robot 
  325:     2179 86 0A                                  ldaa #10                ; this is where the carrage drop occurs
  326:     217B BD 23CC                                jsr pause
  327:                                 
  328:     217E BD 2290                                jsr counterclck         ; 
  329:     2181 BD 2207                                jsr linetrack           ; move to the 4rd plus intersection
  330:     2184 BD 22B7                                jsr go_forward                          
  331:     2187 86 05                                  ldaa #5 
  332:     2189 BD 23CC                                jsr pause
  333:     218C BD 2207                                jsr linetrack           ; here stops at the 3rd plus intersection
  334:                                 
  335:     218F BD 22B7                                jsr go_forward          ; moves the robot forward to get line track off the plus
  336:     2192 86 09                                  ldaa #9
  337:     2194 BD 23CC                                jsr pause
  338:                                 
  339:     2197 BD 2290                                jsr counterclck         ; turns the robot to the left until hits the white line
  340:                                                                         ; back towards the t intersection
  341:     219A BD 2207                                jsr Linetrack           ; moves the robot back to the t intersection
  342:                                 
  343:     219D BD 22B7                                jsr go_forward          ; 
  344:     21A0 86 05                                  ldaa #5
  345:     21A2 BD 23CC                                jsr pause
  346:                                 
  347:                                                 
  348:                                 
  349:     21A5 32                                     pula
  350:                                 
  351:     21A6 39                                     rts
  352:                                 ;******************************************************************************************************
  353:                                 ; this section moves from the 1st t intersection to the 3rd plane and to the 1st t intersection
  354:                                 ;******************************************************************************************************
  355:     21A7                        Plane3:
  356:     21A7 BD 22B7                                jsr go_forward          ; moves forward to make linetrack work
  357:     21AA 86 05                                  ldaa #5
  358:     21AC BD 23CC                                jsr pause               
  359:     21AF BD 2207                                jsr Linetrack           ; moves forward until 3th plus
  360:     21B2 BD 22B7                                jsr go_forward          ; moves forward so line track will work
  361:     21B5 86 05                                  ldaa #5
  362:     21B7 BD 23CC                                jsr pause               
  363:                                                 
  364:     21BA BD 2290                                jsr counterclck         ; turning left until white line agian           
  365:     21BD BD 2207                                jsr Linetrack           ; moves to the 5th plus sign
  366:     21C0 BD 22B7                                jsr go_forward          ; 
  367:     21C3 86 05                                  ldaa #5
  368:     21C5 BD 23CC                                jsr pause
  369:                                 
  370:     21C8 BD 2207                                jsr Linetrack           ; moves to the side of the board
  371:                                 
  372:     21CB BD 23EA                                jsr Right90             ; turns to move to the plane
  373:     21CE BD 22A5                                jsr go_stop
  374:     21D1 86 05                                  ldaa #5
  375:     21D3 BD 23CC                                jsr pause
  376:                                                                 ;sonar goes here
  377:     21D6 BD 231A                                jsr go_Open             ; simple robot code here where comp code goes
  378:     21D9 86 0A                                  ldaa #10                ; *
  379:     21DB BD 23CC                                jsr pause               ; this section moves the robot back to the line
  380:                                                 
  381:     21DE BD 227B                                jsr clockw              ; turns the robot back towards the 5th plus sign
  382:                                                 
  383:     21E1 BD 2207                                jsr linetrack           ; moves the robot to the 5th plus sign
  384:     21E4 BD 22B7                                jsr go_forward          ; moves robot past the 5th plus sign
  385:     21E7 86 05                                  ldaa #5         
  386:     21E9 BD 23CC                                jsr pause
  387:     21EC BD 2207                                jsr linetrack           ; moves robot to the 3rd plus sign
  388:                                 
  389:     21EF BD 22B7                                jsr go_forward  
  390:     21F2 86 0A                                  ldaa #10
  391:     21F4 BD 23CC                                jsr pause
  392:                                 
  393:     21F7 BD 227B                                jsr clockw              ; turns back to the t intersection
  394:                                         
  395:     21FA BD 2207                                jsr Linetrack           ; moves to the t intersection
  396:                                                 
  397:     21FD BD 22B7                                jsr go_forward          ;
  398:     2200 86 05                                  ldaa #5
  399:     2202 BD 23CC                                jsr pause
  400:                                                 
  401:     2205 32                                     pula
  402:     2206 39                                     rts
  403:                                 ;**************************************************************************
  404:                                 ;Name:          LineTrack
  405:                                 ;Author:        Dominic Lawrence
  406:                                 ;Date:          unknown
  407:                                 ;Modifications: 
  408:                                 ;               
  409:                                 ;               PE3     ADR4/Line Track 3       left   \
  410:                                 ;               PE2     ADR3/Line Track 2       center  - looking from the back of robot
  411:                                 ;               PE1     ADR2/Line Track 1       Right  /
  412:                                 ;               DK 3/4/06 
  413:                                 ;                  add tests for LTCB=6 and LTCB = 3 to improve line
  414:                                 ;                  following. 
  415:                                 ;               LTL             equ $94         ; comparison number for more black and less is white? 
  416:                                 ;Process:       First it calls LT_CONT that sets the LTCB. Then LTCB is  
  417:                                 ;               tested and the appropriate sub routine is called to 
  418:                                 ;               turn turned on/off the drive motors accordingly.
  419:                                 ;**************************************************************************
  420:                                 
  421:     2207 36                     LineTrack:      psha
  422:     2208 3C                                     pshx
  423:                                                 
  424:     2209 BD 224A                Lt_loop:        jsr Lt_cont
  425:                                                 
  426:     220C B6 2012                FirstT:         ldaa LTCB       ; checks the center sensors
  427:     220F 81 02                                  cmpa #$02
  428:     2211 27 26                                  beq  FForward
  429:                                                 
  430:     2213 81 04                                  cmpa #$04       ; checks sensors for if to far left
  431:     2215 27 16                                  beq  RTurn
  432:     2217 81 06                                  cmpa #$06
  433:     2219 27 12                                  beq  Rturn
  434:                                                         
  435:     221B 81 01                                  cmpa #$01       ; checks sensors for if to far right
  436:     221D 27 14                                  beq  LTurn
  437:     221F 81 03                                  cmpa #$03
  438:     2221 27 10                                  beq  LTurn
  439:                                                         
  440:     2223 81 07                                  cmpa #$07       ; stops the robot if all three sensors are white
  441:     2225 27 18                                  beq  SStop
  442:                                                 
  443:     2227 BD 22B7                                jsr go_forward
  444:     222A 7E 2209                                jmp Lt_loop
  445:                                                 
  446:                                  
  447:     222D BD 22B1                RTurn:          jsr  go_right           ; jumps to sub that moves robot to the right    
  448:     2230 7E 2209                                jmp  Lt_loop
  449:                                 
  450:     2233 BD 22AB                LTurn:          jsr  go_left            ; jumps to sub that moves robot to the left
  451:     2236 7E 2209                                jmp  Lt_loop
  452:                                 
  453:     2239 BD 22B7                FForward:       jsr  go_Forward         ; jumps to sub that moves robot forward
  454:     223C 7E 2209                                jmp  Lt_loop
  455:                                 
  456:     223F BD 22A5                SStop:          jsr go_stop             ; jumps to stop sub
  457:     2242 86 0A                                  ldaa #10
  458:     2244 BD 23CC                                jsr pause 
  459:                                                 
  460:     2247 38                                     pulx            
  461:     2248 32                                     pula
  462:     2249 39                                     rts             
  463:                                 ;**************************************************************************
  464:                                 ;Name:          Lt_cont - Line Track Control Word
  465:                                 ;Author:        Dominic Lawrence
  466:                                 ;Date:          unknown
  467:                                 ;Modifications: 
  468:                                 ;               AA 03/??/06
  469:                                 ;                  Made into a separate sub routine
  470:                                 ;               PE3     ADR4/Line Track 3       left   \
  471:                                 ;               PE2     ADR3/Line Track 2       center  - looking from the back of robot
  472:                                 ;               PE1     ADR2/Line Track 1       Right  /
  473:                                 ;Function:      Takes the inputs for each linetrack sensor and compares 
  474:                                 ;               it to the LTL (Line Track Limit). If it is below LTL the 
  475:                                 ;               sensor is inidcating it is on the line and the
  476:                                 ;               corresponding bit is set in LTCB (Line Track Control Byte).
  477:                                 ;
  478:                                 ;               LTCB = xxxxx000
  479:                                 ;               LTL             equ $94  comparison number for more black and less is white? 
  480:                                 ;On Return:     LTCL is set as per above
  481:                                 ;**************************************************************************
  482:     224A 36                     Lt_cont:        psha
  483:     224B 3C                                     pshx
  484:                                 
  485:     224C 86 00                                  Ldaa #$0        ; getting the right side info and if wrong setting 
  486:     224E B7 2012                                Staa LTCB       ; LTCB to reflect this so linetrack sub routine will know       
  487:     2251 B6 1032                                Ldaa Adr2       ;*
  488:     2254 81 94                                  Cmpa #LTL       ;*
  489:     2256 24 06                                  BHS  CheckCenter;*
  490:     2258 CE 2012                                Ldx  #LTCB      ;*
  491:     225B 1C 00 04                               Bset 0,x #$04   ;*
  492:                                 
  493:     225E B6 1033                CheckCenter:    Ldaa Adr3       ; get the Center info and if wrong setting 
  494:     2261 81 9F                                  Cmpa #$9F       ; LTCB to reflect this so Linetrack sub routine will know
  495:     2263 24 06                                  BHS  CheckLeft  ;*
  496:     2265 CE 2012                                Ldx  #LTCB      ;*
  497:     2268 1C 00 02                               Bset 0,x #$02   ;*
  498:                                 
  499:     226B B6 1034                CheckLeft:      Ldaa Adr4       ;getting the left side info and if wrong setting
  500:     226E 81 94                                  cmpa #LTL       ; LTCB to reflect this so line track sub routine will know
  501:     2270 24 06                                  BHS  lt_exit    ;*
  502:     2272 CE 2012                                Ldx  #LTCB      ;*
  503:     2275 1C 00 01                               Bset 0,x #$01   ;*
  504:                                 
  505:     2278 38                     lt_exit:        pulx
  506:     2279 32                                     pula
  507:                                                 
  508:     227A 39                                     rts
  509:                                 ;**************************************************************************
  510:                                 ; This section will cause the robot to turn to the right until it hits a 
  511:                                 ; white line with the line tracking sensors
  512:                                 ;**************************************************************************
  513:     227B                        clockw:         
  514:     227B 36                                     psha
  515:     227C BD 22B1                                jsr go_right
  516:     227F 86 05                                  ldaa #5
  517:     2281 BD 23CC                                jsr pause
  518:     2284 BD 224A                clockw_Loop:    jsr LT_cont             
  519:     2287 B6 2012                                ldaa LTCB               
  520:     228A 81 02                                  cmpa #$02
  521:     228C 26 F6                                  bne clockw_Loop 
  522:                                                 
  523:     228E 32                                     pula
  524:     228F 39                                     rts
  525:                                 ;**************************************************************************
  526:                                 ; This section will cause the robot to turn to the Left until it hits a 
  527:                                 ; white line with the line tracking sensors
  528:                                 ;*************************************************************************
  529:     2290                        counterclck:    
  530:     2290 36                                     psha
  531:     2291 BD 22AB                                jsr go_left
  532:     2294 86 05                                  ldaa #5
  533:     2296 BD 23CC                                jsr pause
  534:     2299 BD 224A                counter_Loop:   jsr LT_cont             
  535:     229C B6 2012                                ldaa LTCB               
  536:     229F 81 02                                  cmpa #$02
  537:     22A1 26 F6                                  bne  counter_Loop
  538:                                                 
  539:     22A3 32                                     pula
  540:     22A4 39                                     rts
  541:                                 ;**************************************************************************
  542:                                 ;Name:          Drive Motor Functions
  543:                                 ;Author:        Dan Kohn
  544:                                 ;Date:          Dec 9, 2005
  545:                                 ;Functions:     Each separtate function will do the indicated function 
  546:                                 ;               to the robot drive motors
  547:                                 ;
  548:                                 ;               go_Stop
  549:                                 ;               go_Left
  550:                                 ;               go_Right
  551:                                 ;               go_Forward
  552:                                 ;               go_Reverse
  553:                                 ;               never enter at robot_do! (Stack will be corrupted)
  554:                                 ;**************************************************************************
  555:                                 
  556:     22A5 3C                     go_Stop         pshx
  557:     22A6 CE 22D9                                ldx #Stop
  558:     22A9 20 18                                  bra robot_do
  559:                                 
  560:     22AB 3C                     go_Left         pshx
  561:     22AC CE 22F9                                ldx #Left
  562:     22AF 20 12                                  bra robot_do
  563:                                 
  564:     22B1 3C                     go_Right        pshx
  565:     22B2 CE 22F1                                ldx #Right
  566:     22B5 20 0C                                  bra robot_do
  567:                                 
  568:     22B7 3C                     go_Forward      pshx
  569:     22B8 CE 22E9                                ldx #Forward
  570:     22BB 20 06                                  bra robot_do
  571:                                 
  572:     22BD 3C                     go_Reverse      pshx
  573:     22BE CE 22E1                                ldx #Reverse
  574:     22C1 20 00                                  bra robot_do
  575:                                 
  576:     22C3 EC 00                  robot_do        ldd 0,x
  577:     22C5 FD 2021                                std On_cnts_R
  578:     22C8 EC 02                                  ldd 2,x
  579:     22CA FD 2023                                std Off_cnts_R
  580:     22CD EC 04                                  ldd 4,x
  581:     22CF FD 200E                                std On_cnts_L
  582:     22D2 EC 06                                  ldd 6,x
  583:     22D4 FD 2010                                std Off_cnts_L
  584:     22D7 38                                     pulx
  585:     22D8 39                                     rts
  586:                                 
  587:                                 ;Table for Drive Motor Functions
  588:                                 ;                       On_cnts_R       Off_cnts_R      On_cnts_L       Off_cnts_L
  589:                                 
  590:     22D9 0BB8 9088 0BB8         Stop            fdb     3000,           37000,          3000,           37000
           22DF 9088 
  591:     22E1 07D0 9470 0FA0         REVERSE         fdb     2000,           38000,          4000,           36000
           22E7 8CA0 
  592:     22E9 0FA0 8CA0 07D0         FORWARD         fdb     4000,           36000,          2000,           38000
           22EF 9470 
  593:     22F1 07D0 9470 07D0         RIGHT           fdb     2000,           38000,          2000,           38000
           22F7 9470 
  594:     22F9 0FA0 8CA0 0FA0         LEFT            fdb     4000,           36000,          4000,           36000
           22FF 8CA0 
  595:                                 
  596:                                 ;Servo Motor notes:
  597:                                 ;       1ms on time = 2000 counts = forward
  598:                                 ;       2ms on time = 4000 counts = reverse
  599:                                 ;       total counts for a 50hz square wave (20mSec - suggested for servos) is 40000 counts
  600:                                 ;**************************************************************************
  601:                                 ;Name:          A2D
  602:                                 ;Author:        Dan Kohn
  603:                                 ;Date:          Jan 5, 2006
  604:                                 ;Functions:     Set up A/D to read PE0..PE3 continuously and  
  605:                                 ;               place the converted values in ADR1..ADR4
  606:                                 ;
  607:                                 ;On call:       NONE
  608:                                 ;
  609:                                 ;On Return;     A/D is turned on and running continously 
  610:                                 ;**************************************************************************
  611:                                 
  612:     2301 3C                     A2D:            pshx
  613:     2302 36                                     psha
  614:                                         
  615:     2303 CE 1039                                ldx #option             ;setup A/D
  616:     2306 1C 00 80                               bset 0,x #$80           ;Turn on A/D - ADPU
  617:     2309 1D 00 40                               bclr 0,x #$40           ;Use E clock
  618:                                                 
  619:     230C 86 30                                  ldaa #$30               ;Set up to read PE0..PE3
  620:     230E B7 1030                                staa ADCTL              ;Continuously
  621:                                 
  622:     2311 32                                     pula
  623:     2312 38                                     pulx
  624:                                                 
  625:     2313 39                                     rts
  626:                                 ;**************************************************************************
  627:                                 ;Name:          Multiplexed Motor Functions
  628:                                 ;Author:        Michael mcneill
  629:                                 ;Date:          Feb 9, 2006
  630:                                 ;Functions:     Each separtate function will do the indicated function 
  631:                                 ;               to the robot drive motors
  632:                                 ;
  633:                                 ;               go_Gstop
  634:                                 ;               go_Open
  635:                                 ;               go_Close
  636:                                 ;               go_Forward
  637:                                 ;               go_Reverse
  638:                                 ;
  639:                                 ;               never enter at robot_go! (Stack will be corrupted)
  640:                                 ;**************************************************************************
  641:                                 ;Gripper:
  642:                                 
  643:     2314 3C                     go_Gstop        pshx
  644:     2315 CE 2376                                ldx #Gstop
  645:     2318 20 0C                                  bra robot_go
  646:                                 
  647:     231A 3C                     go_Open         pshx
  648:     231B CE 2372                                ldx #Open
  649:     231E 20 06                                  bra robot_go
  650:                                 
  651:     2320 3C                     go_Close        pshx
  652:     2321 CE 236E                                ldx #Close
  653:     2324 20 00                                  bra robot_go
  654:                                 
  655:     2326 EC 00                  robot_go        ldd 0,x
  656:     2328 FD 200A                                std On_cnts_G
  657:     232B EC 02                                  ldd 2,x
  658:     232D FD 200C                                std Off_cnts_G
  659:                                                 
  660:     2330 38                                     pulx
  661:     2331 39                                     rts
  662:                                 ;******************************************
  663:                                 ; code for movement of the robot arm
  664:                                 ;*************************************
  665:     2332 3C                     go_Astop        pshx
  666:     2333 CE 2382                                ldx #Astop
  667:     2336 20 0C                                  bra robot_arm
  668:                                 
  669:     2338 3C                     go_Up           pshx
  670:     2339 CE 237A                                ldx #UP
  671:     233C 20 06                                  bra robot_arm
  672:                                 
  673:     233E 3C                     go_Down         pshx
  674:     233F CE 236E                                ldx #Close
  675:     2342 20 00                                  bra robot_arm
  676:                                 
  677:                                 
  678:                                 
  679:                                 
  680:     2344 EC 00                  robot_arm       ldd 0,x
  681:     2346 FD 2013                                std On_cnts_A
  682:     2349 EC 02                                  ldd 2,x
  683:     234B FD 2015                                std Off_cnts_A
  684:                                                 
  685:     234E 38                                     pulx
  686:     234F 39                                     rts
  687:                                 
  688:                                 
  689:                                 
  690:     2350 3C                     go_Bstop        pshx
  691:     2351 CE 238E                                ldx #Bstop
  692:     2354 20 0C                                  bra robot_bin
  693:                                 
  694:     2356 3C                     go_Clockw       pshx
  695:     2357 CE 2386                                ldx #bin_Clockw
  696:     235A 20 06                                  bra robot_bin
  697:                                 
  698:     235C 3C                     go_Counterw     pshx
  699:     235D CE 238A                                ldx #bin_Counterw
  700:     2360 20 00                                  bra robot_bin
  701:                                 
  702:                                 
  703:                                 
  704:                                 
  705:     2362 EC 00                  robot_bin       ldd 0,x
  706:     2364 FD 2017                                std On_cnts_B
  707:     2367 EC 02                                  ldd 2,x
  708:     2369 FD 2019                                std Off_cnts_B
  709:                                                 
  710:     236C 38                                     pulx
  711:     236D 39                                     rts
  712:                                 
  713:                                 ;Table for Multiplexed Servo
  714:                                 ;                       On_cnts_G       Off_cnts_G
  715:     236E 0FA0 8CA0              CLOSE           fdb     4000,           36000                           
  716:     2372 07D0 9470              Open            fdb     2000,           38000
  717:     2376 0BB8 9088              Gstop           fdb     3000,           37000
  718:                                 ;Table for arm motor Functions
  719:                                 ;                       On_cnts_A       Off_cnts_A
  720:     237A 07D0 4650              UP              fdb     2000,           18000           
  721:     237E 1194 39D0              DOWN            fdb     4500,           14800
  722:     2382 0BB8 4268              Astop           fdb     3000,           17000
  723:                                 ;Table for bin motor Functions
  724:                                 ;                       On_cnts_B       Off_cnts_B
  725:     2386 07D0 4650              bin_Clockw      fdb     2000,           18000           ;Clockwise maybe
  726:     238A 1194 39D0              bin_Counterw    fdb     4500,           14800           ;Counterwise maybe
  727:     238E 0BB8 4268              Bstop           fdb     3000,           17000
  728:                                 ;Servo Motor notes:
  729:                                 ;       1ms on time = 2000 counts = forward
  730:                                 ;       2ms on time = 4000 counts = reverse
  731:                                 ;       total counts for a 50hz square wave (20mSec - suggested for servos) is 40000 counts
  732:                                 ;**************************************************************************     
  733:                                 ;this section closes the gripper with a small section at the beginning 
  734:                                 ;that deals with a use through a multiplexer
  735:                                 ;
  736:                                 ;**************************************************************************
  737:     2392 36                     gripperC:       psha
  738:                                 
  739:     2393 86 00                                  LDAA #$0000             ;this section for a multiplexer
  740:     2395 B7 B580                                STAA cs0                ;*
  741:     2398 86 01                                  ldaa #1                 ;*
  742:     239A BD 23CC                                jsr pause               ;*
  743:                                                 
  744:     239D BD 2320                                jsr go_Close            
  745:     23A0 86 03                                  ldaa #3
  746:     23A2 BD 23CC                                jsr pause
  747:                                 
  748:     23A5 BD 2314                                jsr go_GStop
  749:     23A8 86 02                                  ldaa #2
  750:     23AA BD 23CC                                jsr pause
  751:                                 
  752:     23AD 32                                     pula
  753:     23AE 39                                     rts
  754:                                 ;**************************************************************************     
  755:                                 ;this section sets the gripper to open 
  756:                                 ;this includes a small section that controls the gripper 
  757:                                 ;through a multiplexer
  758:                                 ;**************************************************************************
  759:     23AF 36                     gripperO:       psha
  760:                                 
  761:     23B0 86 00                                  LDAA #$0000
  762:     23B2 B7 B580                                STAA cs0
  763:     23B5 86 01                                  ldaa #1
  764:     23B7 BD 23CC                                jsr pause
  765:                                 
  766:     23BA BD 231A                                jsr go_Open             ; call sub that Opens the gripper hand
  767:     23BD 86 03                                  ldaa #3
  768:     23BF BD 23CC                                jsr pause
  769:                                 
  770:     23C2 BD 2314                                jsr go_GStop
  771:     23C5 86 02                                  ldaa #2
  772:     23C7 BD 23CC                                jsr pause
  773:                                 
  774:     23CA 32                                     pula
  775:     23CB 39                                     rts
  776:                                 ;**************************************************************************
  777:                                 ;Name:          Pause
  778:                                 ;Author:        Dan Kohn
  779:                                 ;Date:          Dec 19, 2005
  780:                                 ;Functions:     Pause for multiple of 0.1 sec 
  781:                                 ;               (setup for a 0.1 sec counter)
  782:                                 ;
  783:                                 ;On call:       Reg A Contains the number of 0.1 sec to pause
  784:                                 ;
  785:                                 ;On Return;     Sec_Count and Sec_Temp were changed (cleared at start of 
  786:                                 ;               pause.
  787:                                 ;**************************************************************************
  788:     23CC 36                     Pause:          psha
  789:     23CD 37                                     pshb
  790:     23CE C6 00                                  ldab #$00
  791:     23D0 F7 2025                                stab SEC_TEMP
  792:     23D3 F7 2026                                stab SEC_COUNT
  793:                                                 
  794:     23D6 F6 2026                PauseL1:        ldab sec_count
  795:     23D9 11                                     cba
  796:     23DA 26 FA                                  bne PauseL1
  797:                                                 
  798:     23DC 33                                     pulb
  799:     23DD 32                                     pula
  800:     23DE 39                                     rts
  801:                                 ;**************************************************************************
  802:                                 ;**************************************************************************
  803:     23DF 36                     Left90: psha
  804:                                                 
  805:     23E0 BD 22AB                                jsr go_left
  806:     23E3 86 09                                  ldaa #9
  807:     23E5 BD 23CC                                jsr pause
  808:                                                 
  809:     23E8 32                                     pula 
  810:     23E9 39                                     rts
  811:                                 ;**************************************************************************
  812:                                 ;**************************************************************************
  813:     23EA 36                     Right90:        psha
  814:                                 
  815:     23EB BD 22B1                                jsr go_right
  816:     23EE 86 09                                  ldaa #9
  817:     23F0 BD 23CC                                jsr pause               
  818:                                                 
  819:     23F3 32                                     pula
  820:     23F4 39                                     rts
  821:                                 ;**************************************************************************
  822:                                 ;Name:          TOF_init
  823:                                 ;Author:        Dan Kohn
  824:                                 ;Date:          Dec 14, 2005
  825:                                 ;Functions:     Initializes the TOF Function 
  826:                                 ;               (setup for a 0.5 sec counter)
  827:                                 ;**************************************************************************
  828:                                 
  829:     23F5 36                     TOF_init        psha
  830:     23F6 3C                                     pshx
  831:     23F7 183C                                   pshy
  832:                                 
  833:     23F9 0F                                     SEI
  834:                                 
  835:     23FA 86 7E                                  LDAA #$7E               ;setting the interrupt vector table
  836:     23FC 97 D0                                  STAA TOFIV
  837:                                 
  838:     23FE CC 2434                                LDD #TOF_CNT
  839:     2401 DD D1                                  STD TOFIV+1
  840:                                 
  841:     2403 86 80                                  ldaa #$80               ;clear TOF flag
  842:     2405 B7 1025                                staa TFLG2
  843:                                         
  844:     2408 CE 1024                                LDX #TMSK2              ;turn on TOF interrupt
  845:     240B 1C 00 80                               bset 0,x #$80
  846:                                 
  847:     240E 0E                                     cli 
  848:                                 
  849:     240F 18CE 0000                              ldy #0                  ;clear 1 sec counter for planes
  850:     2413 18FF 2027                              sty plane_temp
  851:                                 
  852:     2417 18CE 00B4                              ldy #180                ;set plane 1's time for 180sec
  853:     241B 18FF 2029                              sty plane1_cd
  854:                                 
  855:     241F 18CE 00F0                              ldy #240                ;set plane 2's time for 240sec
  856:     2423 18FF 202B                              sty plane2_cd
  857:                                 
  858:     2427 18CE 0168                              ldy #360                ;set plane 3's time for 300sec
  859:     242B 18FF 202D                              sty plane3_cd
  860:                                                 
  861:     242F 1838                                   puly
  862:     2431 38                                     pulx
  863:     2432 32                                     pula
  864:                                 
  865:     2433 39                                     rts
  866:                                 ;**************************************************************************
  867:                                 ;Name:          TOF_CNT
  868:                                 ;Author:        Dan Kohn
  869:                                 ;Date:          Dec 14, 2005
  870:                                 ;Functions:     count every 0.1 sec.  
  871:                                 ;
  872:                                 ;On Return:     Count of 0.1 sec intervals is in SEC_count
  873:                                 ;               Count of 32.77mSec intervals is in Sec_Temp
  874:                                 ;**************************************************************************
  875:     2434 86 80                  TOF_CNT         ldaa #$80
  876:     2436 B7 1025                                staa TFLG2      
  877:                                                 
  878:     2439 B6 2025                                ldaa Sec_temp           ;count # of times overflow occures (32.77ms)
  879:     243C 4C                                     inca 
  880:     243D B7 2025                                staa Sec_temp
  881:                                 
  882:     2440 81 03                                  cmpa #03                ;if ~0.1sec has NOT gone by -> exit
  883:     2442 25 0C                                  blo plane_time          ;      [3*32.77mSec = 0.0983100 Sec]
  884:                                 
  885:                                 
  886:     2444 86 00                                  ldaa #$00               ;if ~0.1sec has gone by -> clear Sec_temp
  887:     2446 B7 2025                                staa Sec_temp           ;and add one to the Sec_count
  888:                                 
  889:     2449 B6 2026                                ldaa Sec_count
  890:     244C 4C                                     inca 
  891:     244D B7 2026                                staa Sec_count
  892:                                                 
  893:     2450 18FE 2027              plane_time:     ldy plane_temp          ;count # of times overflow occures (32.77ms)
  894:     2454 1808                                   iny 
  895:     2456 18FF 2027                              sty plane_temp
  896:                                 
  897:     245A 188C 001E                              cpy #30                 ;if ~1sec has NOT gone by -> exit
  898:     245E 25 38                                  blo tof_exit            ;      [30*32.77mSec = .98310 Sec]
  899:                                 
  900:                                 
  901:     2460 18CE 0000                              ldy #$00                ;if ~0.1sec has gone by -> clear Sec_temp
  902:     2464 18FF 2027                              sty plane_temp          ;and add one to the Sec_count
  903:                                 
  904:     2468 18FE 2029                              ldy plane1_cd           ;count down timer for plane 1
  905:     246C 188C 0000                              cpy #0
  906:     2470 27 06                                  beq pt_2
  907:     2472 1809                                   dey
  908:     2474 18FF 2029                              sty plane1_cd
  909:                                 
  910:     2478 18FE 202B              pt_2:           ldy plane2_cd           ;count down timer for plane 2
  911:     247C 188C 0000                              cpy #0
  912:     2480 27 06                                  beq pt_3
  913:     2482 1809                                   dey
  914:     2484 18FF 202B                              sty plane2_cd
  915:                                 
  916:     2488 18FE 202D              pt_3:           ldy plane3_cd           ;count down timer for plane 3
  917:     248C 188C 0000                              cpy #0
  918:     2490 27 06                                  beq TOF_exit
  919:     2492 1809                                   dey
  920:     2494 18FF 202D                              sty plane3_cd
  921:                                 
  922:     2498 3B                     TOF_exit        RTI
  923:                                 
  924:                                 ;**************************************************************************
  925:                                 ;Name:          TOC2_init
  926:                                 ;Author:        Dan Kohn
  927:                                 ;Date:          Dec 8, 2005
  928:                                 ;Functions:     Initalize the Right Motor (OC2) 
  929:                                 ;
  930:                                 ;On Call:       go_stop MUST be called before initalizing 
  931:                                 ;**************************************************************************
  932:     2499 36                     TOC2_init       psha
  933:     249A 37                                     pshb
  934:     249B 3C                                     pshx
  935:                                 
  936:     249C 0F                                     SEI
  937:                                 
  938:     249D 86 7E                                  LDAA #$7E               ;setting the interrupt vector table
  939:     249F 97 DC                                  STAA TOC2IV
  940:                                 
  941:     24A1 CC 24C8                                LDD #TOC2RT
  942:     24A4 DD DD                                  STD TOC2IV+1
  943:                                 
  944:     24A6 FC 100E                                LDD TCNT                ;sets the first time of TOC2
  945:     24A9 F3 2021                                ADDD On_cnts_R
  946:     24AC FD 1018                                STD TOC2
  947:                                 
  948:     24AF 86 40                                  LDAA #$40               ;intializing the registers
  949:     24B1 B7 1023                                staa TFLG1
  950:                                 
  951:     24B4 CE 1022                                ldx #TMSK1
  952:     24B7 1C 00 40                               BSET 0,X #$40
  953:                                 
  954:     24BA CE 1020                                LDX #TCTL1              ;toggles the output
  955:     24BD 1C 00 40                               BSET 0,X #$40
  956:     24C0 1D 00 80                               BCLR 0,x #$80
  957:                                 
  958:                                 
  959:     24C3 0E                                     CLI                     ;turning on the interrupts
  960:                                 
  961:     24C4 38                                     pulx
  962:     24C5 33                                     pulb
  963:     24C6 32                                     pula 
  964:                                 
  965:     24C7 39                                     rts
  966:                                 ;**************************************************************************
  967:                                 ;Name:          TOC2IV
  968:                                 ;Author:        Gregory Reeves Jr.
  969:                                 ;Date:          July 30, 2005
  970:                                 ;Modified:      Dan Kohn Dec 8, 2005 For Dual Output Compares
  971:                                 ;Function:      Interrupt for PWM for Right Motor
  972:                                 ;On Call        On_cnts_R and Off_cnts_R 
  973:                                 ;**************************************************************************
  974:     24C8 86 40                  TOC2RT          LDAA #$40               ;resets the OC2F bit
  975:     24CA B7 1023                                STAA TFLG1
  976:                                 
  977:     24CD B6 1000                                LDAA PORTA              ;check oc2 pin for on or off state
  978:     24D0 84 40                                  ANDA #$40
  979:     24D2 26 0B                                  BNE ON_2
  980:                                 
  981:     24D4 FC 1018                                LDD TOC2                ;sets up for the off time sequence
  982:     24D7 F3 2023                                ADDD Off_cnts_R
  983:     24DA FD 1018                                STD TOC2
  984:     24DD 20 09                                  BRA EXIT_2
  985:                                 
  986:     24DF FC 1018                ON_2            LDD TOC2                ;sets up for the next ontime sequence
  987:     24E2 F3 2021                                ADDD On_cnts_R
  988:     24E5 FD 1018                                STD TOC2
  989:                                 
  990:     24E8 3B                     EXIT_2          RTI                     ;return from the interrupt
  991:                                 ;**************************************************************************
  992:                                 ;Name:          TOC3_init
  993:                                 ;Author:        Dan Kohn
  994:                                 ;Date:          Dec 8, 2005
  995:                                 ;Functions:     Initalize the Left Motor (OC3) 
  996:                                 ;
  997:                                 ;On Call:       go_stop MUST be called before initalizing 
  998:                                 ;**************************************************************************
  999:     24E9 36                     TOC3_init       psha
 1000:     24EA 37                                     pshb
 1001:     24EB 3C                                     pshx
 1002:                                 
 1003:     24EC 0F                                     SEI
 1004:                                 
 1005:     24ED 86 7E                                  LDAA #$7E               ;setting the interrupt vector table
 1006:     24EF 97 D9                                  STAA TOC3IV
 1007:                                 
 1008:     24F1 CC 2518                                LDD #TOC3RT
 1009:     24F4 DD DA                                  STD TOC3IV+1
 1010:                                 
 1011:     24F6 FC 100E                                LDD TCNT                ;sets the first time of TOC2
 1012:     24F9 F3 200E                                ADDD On_cnts_L
 1013:     24FC FD 101A                                STD TOC3
 1014:                                 
 1015:     24FF 86 20                                  LDAA #$20               ;intializing the registers
 1016:     2501 B7 1023                                staa TFLG1
 1017:                                 
 1018:     2504 CE 1022                                ldx #TMSK1
 1019:     2507 1C 00 20                               BSET 0,X #$20
 1020:                                 
 1021:     250A CE 1020                                LDX #TCTL1              ;toggles the output
 1022:     250D 1C 00 10                               BSET 0,X #$10
 1023:     2510 1D 00 20                               BCLR 0,x #$20
 1024:                                 
 1025:     2513 0E                                     CLI                     ;turning on the interrupts
 1026:                                 
 1027:     2514 38                                     pulx    
 1028:     2515 33                                     pulb
 1029:     2516 32                                     pula 
 1030:                                 
 1031:     2517 39                                     rts
 1032:                                 ;**************************************************************************
 1033:                                 ;Name:          TOC3IV
 1034:                                 ;Author:        Gregory Reeves Jr.
 1035:                                 ;Date:          July 30, 2005
 1036:                                 ;Modified:      Dan Kohn Dec 8, 2005 For Dual Output Compares
 1037:                                 ;Function:      Interrupt for PWM for Left Motor
 1038:                                 ;On Call        On_cnts_L and Off_cnts_L 
 1039:                                 ;**************************************************************************
 1040:     2518 86 20                  TOC3RT          LDAA #$20               ;resets the OC3F bit
 1041:     251A B7 1023                                STAA TFLG1
 1042:                                 
 1043:     251D B6 1000                                LDAA PORTA              ;check oc3 pin for on or off state
 1044:     2520 84 20                                  ANDA #$20
 1045:     2522 26 0B                                  BNE ON_3
 1046:                                 
 1047:     2524 FC 101A                                LDD TOC3                ;sets up for the off time sequence
 1048:     2527 F3 2010                                ADDD Off_cnts_L
 1049:     252A FD 101A                                STD TOC3
 1050:     252D 20 09                                  BRA EXIT_3
 1051:                                 
 1052:     252F FC 101A                ON_3            LDD TOC3                ;sets up for the next ontime sequence
 1053:     2532 F3 200E                                ADDD On_cnts_L
 1054:     2535 FD 101A                                STD TOC3
 1055:                                 
 1056:     2538 3B                     EXIT_3          RTI                     ;return from the interrupt
 1057:                                 
 1058:                                 ;**************************************************************************
 1059:                                 ;Name:          TOC3_init
 1060:                                 ;Author:        Michael McNeill, Jr.
 1061:                                 ;Date:          ??
 1062:                                 ;Functions:     Initalize the Multiplexed Servo (OC4) 
 1063:                                 ;
 1064:                                 ;On Call:       go_Gstop MUST be called before initalizing 
 1065:                                 ;**************************************************************************
 1066:     2539 36                     TOC4_init       psha
 1067:     253A 37                                     pshb
 1068:     253B 3C                                     pshx
 1069:                                 
 1070:     253C 0F                                     SEI
 1071:                                 
 1072:     253D 86 7E                                  LDAA #$7E               ;setting the interrupt vector table
 1073:     253F 97 D6                                  STAA TOC4IV
 1074:                                 
 1075:     2541 CC 2568                                LDD #TOC4RT
 1076:     2544 DD D7                                  STD TOC4IV+1
 1077:                                 
 1078:     2546 FC 100E                                LDD TCNT                ;sets the first time of TOC4
 1079:     2549 F3 200A                                ADDD On_cnts_G
 1080:     254C FD 101C                                STD TOC4
 1081:                                 
 1082:     254F 86 10                                  LDAA #$10               ;intializing the registers
 1083:     2551 B7 1023                                staa TFLG1
 1084:                                 
 1085:     2554 CE 1022                                ldx #TMSK1
 1086:     2557 1C 00 10                               BSET 0,X #$10
 1087:                                 
 1088:     255A CE 1020                                LDX #TCTL1              ;toggles the output
 1089:     255D 1C 00 04                               BSET 0,X #$4
 1090:     2560 1D 00 08                               BCLR 0,x #$8
 1091:                                 
 1092:                                 
 1093:     2563 0E                                     CLI                     ;turning on the interrupts
 1094:                                 
 1095:     2564 38                                     pulx
 1096:     2565 33                                     pulb
 1097:     2566 32                                     pula 
 1098:                                 
 1099:     2567 39                                     rts
 1100:                                 ;**************************************************************************
 1101:                                 ;Name:          TOC4IV
 1102:                                 ;Author:        Michael McNeill, Jr.
 1103:                                 ;Date:          Feb 1, 2006
 1104:                                 ;Function:      Interrupt for PWM for Gripper Motor
 1105:                                 ;On Call        On_cnts_G and Off_cnts_G 
 1106:                                 ;**************************************************************************
 1107:     2568 86 10                  TOC4RT          LDAA #$10
 1108:     256A B7 1023                                STAA TFLG1
 1109:                                 
 1110:     256D B6 1000                                LDAA PORTA
 1111:     2570 84 10                                  ANDA #$10
 1112:     2572 26 0B                                  BNE ON_4
 1113:                                 
 1114:     2574 FC 101C                                LDD TOC4
 1115:     2577 F3 200C                                ADDD off_cnts_G
 1116:     257A FD 101C                                STD TOC4
 1117:     257D 20 09                                  BRA EXIT_4
 1118:                                 
 1119:     257F FC 101C                ON_4            LDD TOC4                ;sets up for the next ontime sequence
 1120:     2582 F3 200A                                ADDD On_cnts_G
 1121:     2585 FD 101C                                STD TOC4
 1122:                                 
 1123:     2588 3B                     EXIT_4          RTI                     ;return from the interrupt
 1124:                                 
 1125:                                 ;**************************************************************************************************
 1126:                                 ;
 1127:                                 ;Name:          Scanner
 1128:                                 ;Author:        Michael McNeill, Jr.
 1129:                                 ;Date:          ??
 1130:                                 ;Functions:     Clears the Scanner buffer, then waits for the interrupt to 
 1131:                                 ;               recieve 33 bits. It then convers the returned bit pattern into plane
 1132:                                 ;               number based on the table below
 1133:                                 ;
 1134:                                 ;               Scanner reading $26 to $03
 1135:                                 ;                               $1e to $02
 1136:                                 ;                               $16 to $01
 1137:                                 ;
 1138:                                 ;Process:       the barcode scanner is read using the falling edge of PA0 (which is 
 1139:                                 ;               attached to the barcode clock). When a falling edge is detected, it 
 1140:                                 ;               reads the barcode data line (comming in on PE7). This data is placed
 1141:                                 ;               into the buffer from the left and shifted to the right. Each character
 1142:                                 ;               is actually 10 bits long. The first bit coming in is a START BIT, then
 1143:                                 ;               8 bits of data, then a PARITY BIT then a STOP bit. 
 1144:                                 ;
 1145:                                 ;               so the finish data buffer will look like this:
 1146:                                 ;
 1147:                                 ;               Byte        4       3       2       1       0
 1148:                                 ;               Bits 7654321076543210765432107654321076543210 
 1149:                                 ;
 1150:                                 ;                    sPxxxxxxxxSsPxxxxxxxxSsPxxxxxxxxS
 1151:                                 ;                    100010011001111110000010001001100
 1152:                                 ;                                            \      /
 1153:                                 ;                                             data representing plane #
 1154:                                 ;
 1155:                                 ;                            Data shifted -->
 1156:                                 ;
 1157:                                 ;               s=stop
 1158:                                 ;               P=Parity
 1159:                                 ;               S=START
 1160:                                 ;
 1161:                                 ;               the data is then compared to the values returned for planes 1,2,3 and
 1162:                                 ;               converted to the plane number. If the scan is bad, $FF will be the result.
 1163:                                 ;               This value is then stored in BOXCODE.
 1164:                                 ;
 1165:                                 ;On Call:       None
 1166:                                 ;
 1167:                                 ;On Return:     BOXCODE containes the plane number indicated by the barcode read ($FF
 1168:                                 ;               indicates an error when scanned).  
 1169:                                 ;*******************************************************************************************
 1170:                                         
 1171:                                 
 1172:     2589                        Scanner:
 1173:     2589 36                             psha
 1174:     258A BD 261B                        jsr BC_clear
 1175:                                 
 1176:                                 
 1177:     258D 86 00                          ldaa #$00
 1178:     258F B7 2026                        staa sec_count
 1179:                                         
 1180:     2592 B6 2026                sc_0:   ldaa sec_count          ;  watchdog timer for six seconds
 1181:     2595 81 3C                          cmpa #60                ;* exits after 6 seconds if 33 bits not recieved
 1182:     2597 24 34                          bhs  SC_3               ;* will return $ff as barcode error code
 1183:     2599 B6 2008                        lDAA BC_count
 1184:     259C 81 21                          cmpa #33
 1185:     259E 25 F2                          BLO sc_0
 1186:                                 
 1187:     25A0 B6 2006                        Ldaa Barcode+3          ;Barcode to read #$26 to plane 3
 1188:     25A3 81 26                          cmpa #$26
 1189:     25A5 26 08                          Bne  sc_1
 1190:     25A7 86 03                          ldaa #$03
 1191:     25A9 B7 2009                        staa Boxcode
 1192:                                 
 1193:     25AC 7E 25D2                        jmp sc_exit
 1194:                                 
 1195:     25AF                        Sc_1    
 1196:     25AF B6 2006                        Ldaa Barcode+3          ;Barcode to read #$1e to plane 2
 1197:     25B2 81 1E                          cmpa #$1e
 1198:     25B4 26 08                          Bne  sc_2
 1199:     25B6 86 02                          ldaa #$02
 1200:     25B8 B7 2009                        staa Boxcode
 1201:                                 
 1202:     25BB 7E 25D2                        jmp sc_exit
 1203:                                 
 1204:     25BE                        Sc_2    
 1205:     25BE B6 2006                        Ldaa Barcode+3          ;Barcode to read #$16 to plane 1
 1206:     25C1 81 16                          cmpa #$16
 1207:     25C3 26 08                          Bne  sc_3
 1208:     25C5 86 01                          ldaa #$01
 1209:     25C7 B7 2009                        staa Boxcode
 1210:                                 
 1211:     25CA 7E 25D2                        jmp sc_exit
 1212:                                         
 1213:     25CD                        Sc_3    
 1214:                                         
 1215:                                 
 1216:     25CD 86 FF                          ldaa #$ff               ;flag for bad scan
 1217:     25CF B7 2009                        staa Boxcode
 1218:                                 
 1219:     25D2                        sc_exit
 1220:                                 
 1221:     25D2 32                             pula
 1222:     25D3 39                             rts
 1223:                                 
 1224:                                 
 1225:                                 
 1226:                                 ;*******************************************************************************
 1227:                                 ;Name:          IC3_init
 1228:                                 ;Author:        Michael McNeill, Jr.
 1229:                                 ;Date:          ??
 1230:                                 ;Functions:     This initializes IC3 to capture a falling edge of the 
 1231:                                 ;               clock for the barcode reader. 
 1232:                                 ;
 1233:                                 ;********************************************************************************
 1234:     25D4 36                     IC3_init:       psha
 1235:     25D5 3C                                     pshx
 1236:                                                                         
 1237:     25D6 0F                                     sei
 1238:                                 
 1239:     25D7 86 7E                                  ldaa #$7E
 1240:     25D9 97 E2                                  staa IC3IV
 1241:                                 
 1242:     25DB CC 25F8                                LDD #IC3RT
 1243:     25DE DD E3                                  STD IC3IV+1
 1244:                                 
 1245:     25E0 CE 1021                                LDX #TCTL2
 1246:                                 
 1247:     25E3 1C 00 02                               Bset 0,X #$02   ;set for falling edge
 1248:     25E6 1D 00 01                               Bclr 0,X #$01
 1249:                                        
 1250:     25E9 86 01                                  LDAA #$01
 1251:     25EB B7 1023                                STAA TFLG1      ;clr flag
 1252:                                 
 1253:     25EE CE 1022                                LDX #TMSK1      ;turn on INT
 1254:     25F1 1C 00 01                               Bset 0,X #$01
 1255:                                 
 1256:     25F4 0E                                     cli
 1257:                                 
 1258:     25F5 38                                     pulx
 1259:     25F6 32                                     pula
 1260:     25F7 39                                     rts
 1261:                                 
 1262:                                 
 1263:                                 ;**************************************************************************
 1264:                                 ;Name:          IC3RT - Barcode interrupt 
 1265:                                 ;Author:        Dan Kohn
 1266:                                 ;Date:          ??
 1267:                                 ;Function:      This interrupt is triggered on a FALLING EDGE of the 
 1268:                                 ;               bar code clk signal. That that time, the data line is
 1269:                                 ;               captured and placed into the CARRY BIT which is then
 1270:                                 ;               shifted from the left into the barcode buffer.
 1271:                                 ;
 1272:                                 ;               [see SCANNER routine for more info]
 1273:                                 ;**************************************************************************
 1274:                                 
 1275:     25F8 86 01                  IC3RT:          ldaa #$01               ;resets the IC3 bit
 1276:     25FA B7 1023                                staa TFLG1
 1277:                                 
 1278:     25FD B6 100A                                Ldaa portE              ;check IC3 pin for on or off state
 1279:     2600 84 80                                  anda #$80
 1280:     2602 27 03                                  BEQ  BC_High
 1281:     2604 0D                                     sec
 1282:     2605 20 01                                  BRA BC_skip
 1283:                                 
 1284:     2607 0C                     BC_High         clc
 1285:                                 
 1286:     2608 76 2003                BC_Skip         ROR Barcode
 1287:     260B 76 2004                                ROR Barcode+1
 1288:     260E 76 2005                                ROR Barcode+2
 1289:     2611 76 2006                                ROR Barcode+3
 1290:     2614 76 2007                                ROR Barcode+4
 1291:     2617 7C 2008                                INC BC_count
 1292:     261A 3B                                     RTI                     ;return from the interrupt
 1293:                                 
 1294:                                 
 1295:                                 ;**************************************************************************
 1296:                                 ;Name:          BC_Clear - Clear Bar Code buffer 
 1297:                                 ;Author:        Dan Kohn
 1298:                                 ;Date:          ??
 1299:                                 ;Function:      Clear the buffer for the bar code buffer (fill with all ones)
 1300:                                 ;**************************************************************************
 1301:     261B 36                     BC_clear        psha
 1302:     261C 86 FF                                  LDAA #$FF
 1303:     261E B7 2003                                STAA Barcode
 1304:     2621 B7 2004                                STAA Barcode+1
 1305:     2624 B7 2005                                STAA Barcode+2
 1306:     2627 B7 2006                                STAA Barcode+3
 1307:     262A B7 2007                                STAA Barcode+4
 1308:     262D 86 00                                  LDAA #$0
 1309:     262F B7 2008                                STAA BC_count
 1310:                                 
 1311:     2632 32                                     Pula
 1312:     2633 39                                     RTS
 1313:                                 ;*****************************************************

Symbols:
a2d                             *00002301
adctl                           *00001030
adr2                            *00001032
adr3                            *00001033
adr4                            *00001034
astop                           *00002382
barcode                         *00002003
bc_clear                        *0000261b
bc_count                        *00002008
bc_high                         *00002607
bc_skip                         *00002608
bin_clockw                      *00002386
bin_counterw                    *0000238a
boxcode                         *00002009
bstop                           *0000238e
checkcenter                     *0000225e
checkleft                       *0000226b
clockw                          *0000227b
clockw_loop                     *00002284
close                           *0000236e
counter_loop                    *00002299
counterclck                     *00002290
cs0                             *0000b580
exit_2                          *000024e8
exit_3                          *00002538
exit_4                          *00002588
fforward                        *00002239
forward                         *000022e9
go_close                        *00002320
go_forward                      *000022b7
go_gstop                        *00002314
go_left                         *000022ab
go_open                         *0000231a
go_right                        *000022b1
go_stop                         *000022a5
gstop                           *00002376
ic3iv                           *000000e2
ic3rt                           *000025f8
leaveshoot                      *00002080
left                            *000022f9
left90                          *000023df
linetrack                       *00002207
lt_cont                         *0000224a
lt_exit                         *00002278
lt_loop                         *00002209
ltcb                            *00002012
ltl                             *00000094
lturn                           *00002233
main                            *0000202f
off_cnts_a                      *00002015
off_cnts_b                      *00002019
off_cnts_g                      *0000200c
off_cnts_l                      *00002010
off_cnts_r                      *00002023
on_2                            *000024df
on_3                            *0000252f
on_4                            *0000257f
on_cnts_a                       *00002013
on_cnts_b                       *00002017
on_cnts_g                       *0000200a
on_cnts_l                       *0000200e
on_cnts_r                       *00002021
open                            *00002372
option                          *00001039
pause                           *000023cc
pausel1                         *000023d6
plane1                          *000020a7
plane1_cd                       *00002029
plane2                          *00002139
plane2_cd                       *0000202b
plane3                          *000021a7
plane3_cd                       *0000202d
plane_temp                      *00002027
plane_time                      *00002450
porta                           *00001000
porte                           *0000100a
pt_2                            *00002478
pt_3                            *00002488
reg_base                        *00001000
reverse                         *000022e1
right                           *000022f1
right90                         *000023ea
robot_arm                       *00002344
robot_bin                       *00002362
robot_do                        *000022c3
robot_go                        *00002326
rturn                           *0000222d
sc_0                            *00002592
sc_1                            *000025af
sc_2                            *000025be
sc_3                            *000025cd
sc_exit                         *000025d2
sec_count                       *00002026
sec_temp                        *00002025
shoot2                          *0000210d
sstop                           *0000223f
start                           *0000206a
stop                            *000022d9
tcnt                            *0000100e
tctl1                           *00001020
tctl2                           *00001021
tflg1                           *00001023
tflg2                           *00001025
tmsk1                           *00001022
tmsk2                           *00001024
toc2                            *00001018
toc2_init                       *00002499
toc2iv                          *000000dc
toc2rt                          *000024c8
toc3                            *0000101a
toc3_init                       *000024e9
toc3iv                          *000000d9
toc3rt                          *00002518
toc4                            *0000101c
toc4_init                       *00002539
toc4iv                          *000000d6
toc4rt                          *00002568
tof_cnt                         *00002434
tof_exit                        *00002498
tof_init                        *000023f5
tofiv                           *000000d0
up                              *0000237a

