                         .module demoone.c
 0000                   .dbfile demoone.c
                         .area data
 0000                 _servo_limits::
 0000                   .blkb 2
                         .area idata
 0000 0258              .word 600
                         .area data
 0002                   .blkb 2
                         .area idata
 0002 12C0              .word 4800
                         .area data
 0004                   .blkb 2
                         .area idata
 0004 0258              .word 600
                         .area data
 0006                   .blkb 2
                         .area idata
 0006 12C0              .word 4800
                         .area data
 0008                   .blkb 2
                         .area idata
 0008 0258              .word 600
                         .area data
 000A                   .blkb 2
                         .area idata
 000A 12C0              .word 4800
                         .area data
 000C                   .blkb 2
                         .area idata
 000C 0258              .word 600
                         .area data
 000E                   .blkb 2
                         .area idata
 000E 12C0              .word 4800
                         .area data
 0010                   .blkb 2
                         .area idata
 0010 0258              .word 600
                         .area data
 0012                   .blkb 2
                         .area idata
 0012 12C0              .word 4800
                         .area data
 0014                 _srv_lim_default::
 0014                   .blkb 1
                         .area idata
 0014 01                .byte 1
                         .area text
                       ;  IX -> 0,x
 0000                 _SCI_isr::
 0000                   .dbfile C:\ICCME\include/isrdecl.h
 0000                   .dbfunc SCI_isr
 0000                   .dbline 41
                       ; /********************************************************
                       ; *                                                       *
                       ; * Title:       demoone.c                                *
                       ; * Programmer:  Andrew Sinclair (from code by A. Arroyo) *
                       ; * Date:        8 June 2000                              *
                       ; * Version:     1.0                                      *
                       ; *                                                       *
                       ; * Description:                                          *
                       ; * A simple collision avoidance program for EEL 5666     *
                       ; * using the MMPP robot. The robot will read each IR     *
                       ; * detector and turn away from any obstacle in its path  *
                       ; * if the IR value exceeds a threshold. If the bumper is *
                       ; * sensed then the robot will back up, turn away, and go *
                       ; * on. The robot will also wait for the bumper to be     *
                       ; * sensed before beginning operation.                    *
                       ; *                                                       *
                       ; ********************************************************/
                       ; 
                       ; 
                       ; /******************** Includes *************************/
                       ; #include <analog.h>
                       ; #include <motorme.h>
                       ; #include <servome.h>
                       ; #include <clocktjp.h>
                       ; #include <isrdecl.h>
                       ; #include <vectors.h>
                       ; #include <stdio.h>
                       ; /***************** End of Includes *********************/
                       ; 
                       ; 
                       ; /******************** Constants ************************/
                       ; #define LEFT_MOTOR  1
                       ; #define RIGHT_MOTOR 0
                       ; #define MAX_SPEED   100
                       ; #define ZERO_SPEED  0
                       ; #define AVOID_THRESHOLD 100
                       ; #define BUMPER analog(3)
                       ; #define LEFT_IR analog(4)
                       ; #define RIGHT_IR analog(0)
                       ; /**************** End of Constants *********************/
                       ; 
 0000                 L2:
 0000 3B                rti
                       ;  IX -> 0,x
 0001                 _SPI_isr::
 0001                   .dbfunc SPI_isr
 0001                   .dbline 47
                       ; 
                       ; /******************* Prototypes ************************/
                       ; void turn(void);
                       ; /**************** End of Prototypes ********************/
                       ; 
                       ; 
 0001                 L3:
 0001 3B                rti
                       ;  IX -> 0,x
 0002                 _PAIE_isr::
 0002                   .dbfunc PAIE_isr
 0002                   .dbline 53
                       ; void main(void)
                       ; /********************** Main ***************************/
                       ; {
                       ; int irdr, irdl, speedr, speedl;
                       ;     
                       ; init_analog();
 0002                 L4:
 0002 3B                rti
                       ;  IX -> 0,x
 0003                 _PAV_isr::
 0003                   .dbfunc PAV_isr
 0003                   .dbline 59
                       ; init_motorme();
                       ; init_clocktjp();
                       ; 
                       ;     
                       ; *(unsigned char *) 0x7000=0x07; /*Turn on the IR emitters*/
                       ;     
 0003                 L5:
 0003 3B                rti
                       ;  IX -> 0,x
 0004                 _TOF_isr::
 0004                   .dbfunc TOF_isr
 0004                   .dbline 65
                       ; /*while(BUMPER<120); /*Press the rear bumper to start the program*/
                       ;     while(1)
                       ;     {
                       ;      irdr = RIGHT_IR;
                       ;      irdl = LEFT_IR;
                       ; 
 0004                 L6:
 0004 3B                rti
                       ;  IX -> 0,x
 0005                 _TOC2_isr::
 0005                   .dbfunc TOC2_isr
 0005                   .dbline 83
                       ;      if (irdl > AVOID_THRESHOLD)
                       ;          speedr = -MAX_SPEED;
                       ;      else speedr = MAX_SPEED;
                       ; 
                       ;      if (irdr > AVOID_THRESHOLD)
                       ;          speedl = -MAX_SPEED;
                       ;      else speedl = MAX_SPEED;
                       ;     
                       ;      motorme(RIGHT_MOTOR, speedr);
                       ;      motorme(LEFT_MOTOR, speedl);
                       ;     
                       ;      /* Back Bump Switch */
                       ;      if((BUMPER>10)&&(BUMPER<30))
                       ;      {
                       ;       motorme(LEFT_MOTOR, MAX_SPEED);
                       ;       motorme(RIGHT_MOTOR, MAX_SPEED);
                       ;       wait(600);
                       ;       turn();
 0005                 L7:
 0005 3B                rti
                       ;  IX -> 0,x
 0006                 _TOC3_isr::
 0006                   .dbfunc TOC3_isr
 0006                   .dbline 89
                       ;      }
                       ;      
                       ;      /* Right-Front Bump Switch */
                       ;      if((BUMPER>35)&&(BUMPER<55))
                       ;      {
                       ;       motorme(LEFT_MOTOR, -MAX_SPEED);
 0006                 L8:
 0006 3B                rti
                       ;  IX -> 0,x
 0007                 _TIC3_isr::
 0007                   .dbfunc TIC3_isr
 0007                   .dbline 101
                       ;       motorme(RIGHT_MOTOR, MAX_SPEED);
                       ;       wait(600);
                       ;       turn();
                       ;      }
                       ; 
                       ;      /* Front Bump Switch */
                       ;      if((BUMPER>70)&&(BUMPER<90))
                       ;      {
                       ;       motorme(LEFT_MOTOR, -MAX_SPEED);
                       ;       motorme(RIGHT_MOTOR, -MAX_SPEED);
                       ;       wait(600);
                       ;       turn();
 0007                 L9:
 0007 3B                rti
                       ;  IX -> 0,x
 0008                 _TIC2_isr::
 0008                   .dbfunc TIC2_isr
 0008                   .dbline 107
                       ;      }
                       ; 
                       ;      /* Left-Front Bump Switch */
                       ;      if((BUMPER>120)&&(BUMPER<140))
                       ;      {
                       ;       motorme(LEFT_MOTOR, MAX_SPEED);
 0008                 L10:
 0008 3B                rti
                       ;  IX -> 0,x
 0009                 _TIC1_isr::
 0009                   .dbfunc TIC1_isr
 0009                   .dbline 113
                       ;       motorme(RIGHT_MOTOR, -MAX_SPEED);
                       ;       wait(600);
                       ;       turn();
                       ;      }
                       ; 
                       ; 
 0009                 L11:
 0009 3B                rti
                       ;  IX -> 0,x
 000A                 _RTI_isr::
 000A                   .dbfunc RTI_isr
 000A                   .dbline 119
                       ;      wait(35);
                       ;     }
                       ; }
                       ; /******************* End of Main ***********************/
                       ; 
                       ; 
 000A                 L12:
 000A 3B                rti
                       ;  IX -> 0,x
 000B                 _IRQ_isr::
 000B                   .dbfunc IRQ_isr
 000B                   .dbline 125
                       ; void turn(void)
                       ; /********************************************************
                       ; * Function: Will turn in a random direction for a       *
                       ; * "random" amount of time, dictated by the fast         *
                       ; * changing lower bits in mseconds().                    *
                       ; *                                                       *
 000B                 L13:
 000B 3B                rti
                       ;  IX -> 0,x
 000C                 _XIRQ_isr::
 000C                   .dbfunc XIRQ_isr
 000C                   .dbline 131
                       ; * Returns: None                                         *
                       ; *                                                       *
                       ; * Inputs                                                *
                       ; *  Parameters: None                                     *
                       ; *  Globals:    None                                     *
                       ; *  Registers:  TCNT                                     *
 000C                 L14:
 000C 3B                rti
                       ;  IX -> 0,x
 000D                 _SWI_isr::
 000D                   .dbfunc SWI_isr
 000D                   .dbline 137
                       ; * Outputs                                               *
                       ; *  Parameters: None                                     *
                       ; *  Globals:    None                                     *
                       ; *  Registers:  None                                     *
                       ; * Functions called: motorme(), wait()                   *
                       ; ********************************************************/
 000D                 L15:
 000D 3B                rti
                       ;  IX -> 0,x
 000E                 _ILLOP_isr::
 000E                   .dbfunc ILLOP_isr
 000E                   .dbline 143
                       ; {
                       ;  int i;
                       ;  unsigned rand;
                       ;  
                       ;  rand = TCNT;
                       ;  
 000E                 L16:
 000E 3B                rti
                       ;  IX -> 0,x
 000F                 _COP_isr::
 000F                   .dbfunc COP_isr
 000F                   .dbline 149
                       ;  if (rand & 0x0001)
                       ;  /* turn left */
                       ;  {
                       ;   motorme(RIGHT_MOTOR, MAX_SPEED);
                       ;   motorme(LEFT_MOTOR, -MAX_SPEED);
                       ;  }
 000F                 L17:
 000F 3B                rti
                       ;  IX -> 0,x
 0010                 _CLMON_isr::
 0010                   .dbfunc CLMON_isr
 0010                   .dbline 155
                       ;  else
                       ;  /* turn right */
                       ;  {
                       ;   motorme(RIGHT_MOTOR, -MAX_SPEED);
                       ;   motorme(LEFT_MOTOR, MAX_SPEED);
                       ;  }
 0010                 L18:
 0010 3B                rti
                         .area data
 0015                 _drew::
 0015                   .blkw 1
                         .area idata
 0015 0000              .word _interrupt_vectors
                         .area text
                       ;  IX -> 0,x
                       ;         speedl -> 2,x
                       ;         speedr -> 4,x
                       ;           irdl -> 6,x
                       ;           irdr -> 8,x
 0011                 _main::
 0011 BD0000            jsr __enterb
 0014 0A                .byte 0xa
 0015                   .dbfile demoone.c
 0015                   .dbfunc main
 0015                   .dbline 53
 0015 BD0000            jsr _init_analog
 0018                   .dbline 54
 0018 BD0000            jsr _init_motorme
 001B                   .dbline 55
 001B BD0000            jsr _init_clocktjp
 001E                   .dbline 58
 001E C607              ldab #7
 0020 F77000            stab 0x7000
 0023 7E0168            jmp L21
 0026                 L20:
 0026                   .dbline 63
 0026 CC0000            ldd #0
 0029 BD0000            jsr _analog
 002C ED08              std 8,x
 002E                   .dbline 64
 002E CC0004            ldd #4
 0031 BD0000            jsr _analog
 0034 ED06              std 6,x
 0036                   .dbline 66
 0036 EC06              ldd 6,x
 0038 1A830064          cpd #100
 003C 2F07              ble L23
 003E                   .dbline 67
 003E CCFF9C            ldd #-100
 0041 ED04              std 4,x
 0043 2005              bra L24
 0045                 L23:
 0045                   .dbline 68
 0045 CC0064            ldd #100
 0048 ED04              std 4,x
 004A                 L24:
 004A                   .dbline 70
 004A EC08              ldd 8,x
 004C 1A830064          cpd #100
 0050 2F07              ble L25
 0052                   .dbline 71
 0052 CCFF9C            ldd #-100
 0055 ED02              std 2,x
 0057 2005              bra L26
 0059                 L25:
 0059                   .dbline 72
 0059 CC0064            ldd #100
 005C ED02              std 2,x
 005E                 L26:
 005E                   .dbline 74
 005E EC04              ldd 4,x
 0060 37                pshb
 0061 36                psha
 0062 CC0000            ldd #0
 0065 BD0000            jsr _motorme
 0068 1838              puly
 006A                   .dbline 75
 006A EC02              ldd 2,x
 006C 37                pshb
 006D 36                psha
 006E CC0001            ldd #1
 0071 BD0000            jsr _motorme
 0074 1838              puly
 0076                   .dbline 78
 0076 CC0003            ldd #3
 0079 BD0000            jsr _analog
 007C 1A83000A          cpd #10
 0080 2F2F              ble L27
 0082 CC0003            ldd #3
 0085 BD0000            jsr _analog
 0088 1A83001E          cpd #30
 008C 2C23              bge L27
 008E                   .dbline 80
 008E CC0064            ldd #100
 0091 37                pshb
 0092 36                psha
 0093 CC0001            ldd #1
 0096 BD0000            jsr _motorme
 0099 1838              puly
 009B                   .dbline 81
 009B CC0064            ldd #100
 009E 37                pshb
 009F 36                psha
 00A0 CC0000            ldd #0
 00A3 BD0000            jsr _motorme
 00A6 1838              puly
 00A8                   .dbline 82
 00A8 CC0258            ldd #600
 00AB BD0000            jsr _wait
 00AE                   .dbline 83
 00AE BD0173            jsr _turn
 00B1                   .dbline 84
 00B1                 L27:
 00B1                   .dbline 87
 00B1 CC0003            ldd #3
 00B4 BD0000            jsr _analog
 00B7 1A830023          cpd #35
 00BB 2F2F              ble L29
 00BD CC0003            ldd #3
 00C0 BD0000            jsr _analog
 00C3 1A830037          cpd #55
 00C7 2C23              bge L29
 00C9                   .dbline 89
 00C9 CCFF9C            ldd #-100
 00CC 37                pshb
 00CD 36                psha
 00CE CC0001            ldd #1
 00D1 BD0000            jsr _motorme
 00D4 1838              puly
 00D6                   .dbline 90
 00D6 CC0064            ldd #100
 00D9 37                pshb
 00DA 36                psha
 00DB CC0000            ldd #0
 00DE BD0000            jsr _motorme
 00E1 1838              puly
 00E3                   .dbline 91
 00E3 CC0258            ldd #600
 00E6 BD0000            jsr _wait
 00E9                   .dbline 92
 00E9 BD0173            jsr _turn
 00EC                   .dbline 93
 00EC                 L29:
 00EC                   .dbline 96
 00EC CC0003            ldd #3
 00EF BD0000            jsr _analog
 00F2 1A830046          cpd #70
 00F6 2F2F              ble L31
 00F8 CC0003            ldd #3
 00FB BD0000            jsr _analog
 00FE 1A83005A          cpd #90
 0102 2C23              bge L31
 0104                   .dbline 98
 0104 CCFF9C            ldd #-100
 0107 37                pshb
 0108 36                psha
 0109 CC0001            ldd #1
 010C BD0000            jsr _motorme
 010F 1838              puly
 0111                   .dbline 99
 0111 CCFF9C            ldd #-100
 0114 37                pshb
 0115 36                psha
 0116 CC0000            ldd #0
 0119 BD0000            jsr _motorme
 011C 1838              puly
 011E                   .dbline 100
 011E CC0258            ldd #600
 0121 BD0000            jsr _wait
 0124                   .dbline 101
 0124 BD0173            jsr _turn
 0127                   .dbline 102
 0127                 L31:
 0127                   .dbline 105
 0127 CC0003            ldd #3
 012A BD0000            jsr _analog
 012D 1A830078          cpd #120
 0131 2F2F              ble L33
 0133 CC0003            ldd #3
 0136 BD0000            jsr _analog
 0139 1A83008C          cpd #140
 013D 2C23              bge L33
 013F                   .dbline 107
 013F CC0064            ldd #100
 0142 37                pshb
 0143 36                psha
 0144 CC0001            ldd #1
 0147 BD0000            jsr _motorme
 014A 1838              puly
 014C                   .dbline 108
 014C CCFF9C            ldd #-100
 014F 37                pshb
 0150 36                psha
 0151 CC0000            ldd #0
 0154 BD0000            jsr _motorme
 0157 1838              puly
 0159                   .dbline 109
 0159 CC0258            ldd #600
 015C BD0000            jsr _wait
 015F                   .dbline 110
 015F BD0173            jsr _turn
 0162                   .dbline 111
 0162                 L33:
 0162                   .dbline 114
 0162 CC0023            ldd #35
 0165 BD0000            jsr _wait
 0168                   .dbline 115
 0168                 L21:
 0168                   .dbline 61
 0168 7E0026            jmp L20
 016B                 L19:
 016B 8F                xgdx
 016C C3000A            addd #10
 016F 8F                xgdx
 0170 35                txs
 0171 38                pulx
 0172 39                rts
                       ;  IX -> 0,x
                       ;              i -> 2,x
                       ;           rand -> 4,x
 0173                 _turn::
 0173 BD0000            jsr __enterb
 0176 06                .byte 0x6
 0177                   .dbfunc turn
 0177                   .dbline 142
                         ; vol
 0177 FC100E            ldd 0x100e
 017A ED04              std 4,x
 017C                   .dbline 144
 017C EC04              ldd 4,x
 017E 8400              anda #0
 0180 C401              andb #1
 0182 1A830000          cpd #0
 0186 271C              beq L36
 0188                   .dbline 147
 0188 CC0064            ldd #100
 018B 37                pshb
 018C 36                psha
 018D CC0000            ldd #0
 0190 BD0000            jsr _motorme
 0193 1838              puly
 0195                   .dbline 148
 0195 CCFF9C            ldd #-100
 0198 37                pshb
 0199 36                psha
 019A CC0001            ldd #1
 019D BD0000            jsr _motorme
 01A0 1838              puly
 01A2                   .dbline 149
 01A2 201A              bra L37
 01A4                 L36:
 01A4                   .dbline 153
 01A4 CCFF9C            ldd #-100
 01A7 37                pshb
 01A8 36                psha
 01A9 CC0000            ldd #0
 01AC BD0000            jsr _motorme
 01AF 1838              puly
 01B1                   .dbline 154
 01B1 CC0064            ldd #100
 01B4 37                pshb
 01B5 36                psha
 01B6 CC0001            ldd #1
 01B9 BD0000            jsr _motorme
 01BC 1838              puly
 01BE                   .dbline 155
 01BE                 L37:
 01BE                   .dbline 157
                       ;  
                       ;  i=(rand % 1024);
 01BE EC04              ldd 4,x
 01C0 8403              anda #3
 01C2 C4FF              andb #255
 01C4 ED02              std 2,x
 01C6                   .dbline 158
                       ;  if(i>250)
 01C6 EC02              ldd 2,x
 01C8 1A8300FA          cpd #250
 01CC 2F07              ble L38
 01CE                   .dbline 159
                       ;   wait(i);
 01CE EC02              ldd 2,x
 01D0 BD0000            jsr _wait
 01D3 2006              bra L39
 01D5                 L38:
 01D5                   .dbline 160
                       ;  else wait(250);
 01D5 CC00FA            ldd #250
 01D8 BD0000            jsr _wait
 01DB                 L39:
 01DB                   .dbline 161
                       ; }
 01DB                 L35:
 01DB 8F                xgdx
 01DC C30006            addd #6
 01DF 8F                xgdx
 01E0 35                txs
 01E1 38                pulx
 01E2 39                rts
                         .area bss
 0000                 _timertjp::
 0000                   .blkb 2
 0002                 _days::
 0002                   .blkb 2
 0004                 _hours::
 0004                   .blkb 2
 0006                 _minutes::
 0006                   .blkb 2
 0008                 _seconds::
 0008                   .blkb 2
 000A                 _msec::
 000A                   .blkb 2
 000C                 _servo_width::
 000C                   .blkb 10
