                        .module robot.c
                        .area memory(abs)
                        .org 0x3e5e
 3E5E           _IRQ_TOF_vector::
 3E5E 0162              .word _TOF_isr
                        .area data
                        .area memory(abs)
                        .org 0x3e52
 3E52           _IRQ_ATD0_vector::
 3E52 02C8              .word _ATD0_Interrupt
                        .area data
                        .area memory(abs)
                        .org 0x3e50
 3E50           _IRQ_ATD1_vector::
 3E50 0315              .word _ATD1_Interrupt
                        .area data
                        .area memory(abs)
                        .org 0x3e64
 3E64           _IRQ_OC5_vector::
 3E64 040A              .word _OC5_ISR
                        .area data
                        .area text
                ;           time -> -8,x
                ;              i -> -4,x
                ;              t -> -2,x
 0000           _main::
 0000 34                pshx
 0001 B775              tfr s,x
 0003 1B98              leas -8,sp
 0005           ; //*****************************************************************************
 0005           ; // Name:                              2007 Robot Code
 0005           ; // Vers:                          0.1
 0005           ; // Last Revised:              1/27/07 10:16pm
 0005           ; //*****************************************************************************                                       
 0005           ; 
 0005           ; #include<mc9S12dp256.h>
 0005           ; #include<stdio.h>
 0005           ; 
 0005           ; //define 16 bit PWM registers
 0005           ; #define PWMPERW1 _LP(0xB4) 
 0005           ; #define PWMPERW3 _LP(0xB6)
 0005           ; #define PWMPERW5 _LP(0xB8)
 0005           ; #define PWMPERW7 _LP(0xBA)
 0005           ; 
 0005           ; #define PWMDTYW1 _LP(0xBC)
 0005           ; #define PWMDTYW3 _LP(0xBE)
 0005           ; #define PWMDTYW5 _LP(0xC0)
 0005           ; #define PWMDTYW7 _LP(0xC2)
 0005           ; 
 0005           ; // Function Prototypes
 0005           ; void init_pwm(void);
 0005           ; void init_timer(void);
 0005           ; void ob_led(int);
 0005           ; void pause(int);
 0005           ; void s_pause(int pause_time);
 0005           ; void init_tof(void);
 0005           ; void init_atd0(void);
 0005           ; void Speaker(void);
 0005           ; void stop(void);
 0005           ; void forward(void);
 0005           ; void reverse(void);
 0005           ; void left(void);
 0005           ; void right(void);
 0005           ; 
 0005           ; //General 
 0005           ; #define CLI asm("CLI")
 0005           ; #define SEI asm("SEI")
 0005           ; 
 0005           ; //TOF Interrupt Setup
 0005           ; void TOF_isr(void); 
 0005           ; #pragma interrupt_handler TOF_isr
 0005           ; #pragma abs_address: 0x3e5e
 0005           ; void (*IRQ_TOF_vector[])()={TOF_isr};
 0005           ; #pragma end_abs_address
 0005           ; 
 0005           ; //ATD0 Interrupt Setup
 0005           ; void ATD0_Interrupt();
 0005           ; #pragma interrupt_handler ATD0_Interrupt()
 0005           ; #pragma abs_address: 0x3E52
 0005           ; void (*IRQ_ATD0_vector[])()={ATD0_Interrupt};
 0005           ; #pragma end_abs_address
 0005           ; 
 0005           ; //ATD1 Interrupt Setup
 0005           ; void ATD1_Interrupt();
 0005           ; #pragma interrupt_handler ATD1_Interrupt()
 0005           ; #pragma abs_address: 0x3E50
 0005           ; void (*IRQ_ATD1_vector[])()={ATD1_Interrupt};
 0005           ; #pragma end_abs_address
 0005           ; 
 0005           ; //OC5 Interrupt Setup
 0005           ; void OC5_ISR();
 0005           ; #pragma interrupt_handler OC5_ISR()
 0005           ; #pragma abs_address: 0x3E64
 0005           ; void (*IRQ_OC5_vector[])()={OC5_ISR};
 0005           ; #pragma end_abs_address
 0005           ; 
 0005           ; //declare global variable
 0005           ; long int t_counts;
 0005           ; long int t_tenths;
 0005           ; long int t_hundredths;
 0005           ; unsigned int atd0[8];
 0005           ; int atd1[8];
 0005           ; int dela;
 0005           ; 
 0005           ; void main(void)
 0005           ; {
 0005           ; 
 0005           ;    int t,i;
 0005           ;    long int time;
 0005           ;    
 0005           ;    init_pwm();
 0005 160092            jsr _init_pwm
 0008           ;    init_tof();
 0008 16014E            jsr _init_tof
 000B           ;    init_atd0();
 000B 1602B4            jsr _init_atd0
 000E           ;    init_atd1();
 000E 160301            jsr _init_atd1
 0011           ;    pause(1);
 0011 CC0001            ldd #1
 0014 16022E            jsr _pause
 0017           ;    ATD0CTL5 = 0x30;
 0017 C630              ldab #48
 0019 7B0085            stab 0x85
 001C           ;    ATD1CTL5 = 0x30;
 001C C630              ldab #48
 001E 7B0125            stab 0x125
 0021 200E              bra L5
 0023           L4:
 0023 EC1E              ldd -2,x
 0025 160057            jsr _ob_led
 0028 CC000A            ldd #10
 002B 16022E            jsr _pause
 002E 16010F            jsr _reverse
 0031           L5:
 0031           ; 
 0031           ;    while(1)
 0031 20F0              bra L4
 0033           X0:
 0033           ;    {
 0033           ;      // t++;
 0033           ; 	 // if (t>15)
 0033           ; 	  //   t=0;
 0033           ;       		 
 0033           ;       ob_led(t);
 0033           ; 	  pause(10);
 0033           ; 	 // for (i=0;i<=7;i++)
 0033           ; 	  //{
 0033           ; 	    // printf ("atd0[%u] = %u   atd1[%u] = %u\n\r",i,atd0[i],i,atd1[i]);
 0033           ; 	 // }
 0033           ; 	  //printf("%ld %ld\n\r",t_tenths,t_hundredths);
 0033           ; 	 // 
 0033           ; 	 // if (atd0[4]<100)
 0033           ; 	  //{
 0033           ; 	   //  printf ("forward\n\r");
 0033           ; 	    // forward();
 0033           ; 	  //}
 0033           ; 	  //else
 0033           ; 	//  {
 0033           ; 	 //    printf ("reverse\n\r");
 0033           ; 	//     reverse();
 0033           ; 	 // }
 0033           ;      // printf("\n\r");	  
 0033           ; 	  
 0033           ; 	  reverse();
 0033           ; 	  
 0033           ; 	  
 0033           ; //	  Speaker();
 0033           ; //	  printf ("Timer = %ld \n\r",t_tenths);
 0033           ;    }
 0033           ; }
 0033           L3:
 0033 B757              tfr x,s
 0035 30                pulx
 0036                   .dbline 0 ; func end
 0036 3D                rts
 0037           L8:
 0037 003F              .word 63
 0039 0006              .word 6
 003B 005B              .word 91
 003D 004F              .word 79
 003F 0066              .word 102
 0041 006D              .word 109
 0043 007D              .word 125
 0045 0007              .word 7
 0047 007F              .word 127
 0049 006F              .word 111
 004B 0077              .word 119
 004D 007C              .word 124
 004F 0039              .word 57
 0051 005E              .word 94
 0053 0079              .word 121
 0055 0071              .word 113
 0057           ;            out -> -32,x
 0057           ;              t -> 2,x
 0057           _ob_led::
 0057 3B                pshd
 0058 34                pshx
 0059 B775              tfr s,x
 005B 1BF1DE            leas -34,sp
 005E           ; 
 005E           ; 
 005E           ; // Display value passed to function on on board 7-seg LED of MiniDragon Board
 005E           ; void ob_led(int t)               
 005E           ; {
 005E           ; 
 005E           ;   int out[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
 005E 19E1E0            leay -32,x
 0061 B7C6              xgdy
 0063 CD0037            ldy #L8
 0066 34                pshx
 0067 B745              tfr d,x
 0069 CC0010            ldd #16
 006C           X1:
 006C 18027131          movw 2,y+,2,x+
 0070 0434F9            dbne d,X1
 0073 30                pulx
 0074           ;     0x39,0x5e,0x79,0x71};
 0074           ;   
 0074           ;   DDRH=0xff;
 0074 C6FF              ldab #255
 0076 7B0262            stab 0x262
 0079           ;   
 0079           ;   PTH=out[t];
 0079 19E1E0            leay -32,x
 007C 6DE1DE            sty -34,x
 007F EC02              ldd 2,x
 0081 59                lsld
 0082 E3E1DE            addd -34,x
 0085 B7C6              xgdy
 0087 EC40              ldd 0,y
 0089 7B0260            stab 0x260
 008C           ; 
 008C           ;   
 008C           ; }
 008C           L7:
 008C B757              tfr x,s
 008E 30                pulx
 008F 1B82              leas 2,sp
 0091                   .dbline 0 ; func end
 0091 3D                rts
 0092           _init_pwm::
 0092           ; 
 0092           ; // Set up 4-16bit PWM 
 0092           ; void init_pwm()
 0092           ; {
 0092           ;   PWMTST = 0x00; 		   			  // turn off all PWM special Modes
 0092 7900A6            clr 0xa6
 0095           ;   PWMCAE = 0x00;                                        // PWM left aligned output mode 
 0095 7900A4            clr 0xa4
 0098           ;   PWMCTL = 0xf0;                                        // Use Concatenated Mode (16-bit)
 0098 C6F0              ldab #240
 009A 7B00A5            stab 0xa5
 009D           ;   
 009D           ;   
 009D           ;   PWMPRCLK = 0x33;                                      // E/8 for A and B       
 009D C633              ldab #51
 009F 7B00A3            stab 0xa3
 00A2           ;   
 00A2           ;   PWMCLK = 0x00;                                        // PW Chan 1, 5 clock A
 00A2 7900A2            clr 0xa2
 00A5           ;                                                                         // PW chan 3, 7 clock B
 00A5           ;                                                                         
 00A5           ;   PWMPOL= 0xaa;                                                 // High Polarity for all channels
 00A5 C6AA              ldab #170
 00A7 7B00A1            stab 0xa1
 00AA           ;   DDRP= 0xaa;                                           // Set Port P to output 
 00AA C6AA              ldab #170
 00AC 7B025A            stab 0x25a
 00AF           ; 
 00AF           ;   PWMPERW1 = 60000;                                     //stop (7.5%) all motors
 00AF CCEA60            ldd #0xea60
 00B2 7C00B4            std 0xb4
 00B5           ;   PWMDTYW1 = 4500;
 00B5 CC1194            ldd #4500
 00B8 7C00BC            std 0xbc
 00BB           ;   
 00BB           ;   PWMPERW3 = 60000;                                   
 00BB CCEA60            ldd #0xea60
 00BE 7C00B6            std 0xb6
 00C1           ;   PWMDTYW3 = 4500;
 00C1 CC1194            ldd #4500
 00C4 7C00BE            std 0xbe
 00C7           ;   
 00C7           ;   PWMPERW5 = 60000;                                   
 00C7 CCEA60            ldd #0xea60
 00CA 7C00B8            std 0xb8
 00CD           ;   PWMDTYW5 = 4500;
 00CD CC1194            ldd #4500
 00D0 7C00C0            std 0xc0
 00D3           ; 
 00D3           ;   PWMPERW7 = 60000;                                    
 00D3 CCEA60            ldd #0xea60
 00D6 7C00BA            std 0xba
 00D9           ;   PWMDTYW7 = 4500;
 00D9 CC1194            ldd #4500
 00DC 7C00C2            std 0xc2
 00DF           ;   PWME= 0xaa;                                           // Enable ALL PWM Channels
 00DF C6AA              ldab #170
 00E1 7B00A0            stab 0xa0
 00E4           ; 
 00E4           ; }
 00E4           L9:
 00E4                   .dbline 0 ; func end
 00E4 3D                rts
 00E5           _stop::
 00E5           ; 
 00E5           ; // Stop
 00E5           ; void stop(void)
 00E5           ; {
 00E5           ;    PWME = 0x00;
 00E5 7900A0            clr 0xa0
 00E8           ;    PWMDTYW1 = 4500;
 00E8 CC1194            ldd #4500
 00EB 7C00BC            std 0xbc
 00EE           ;    PWMDTYW3 = 4500;
 00EE CC1194            ldd #4500
 00F1 7C00BE            std 0xbe
 00F4           ;    PWME = 0xaa;
 00F4 C6AA              ldab #170
 00F6 7B00A0            stab 0xa0
 00F9           ; }
 00F9           L10:
 00F9                   .dbline 0 ; func end
 00F9 3D                rts
 00FA           _forward::
 00FA           ;    
 00FA           ; // forward
 00FA           ; void forward(void)
 00FA           ; {
 00FA           ;    PWME = 0x00;
 00FA 7900A0            clr 0xa0
 00FD           ;    PWMDTYW1 = 3000;
 00FD CC0BB8            ldd #3000
 0100 7C00BC            std 0xbc
 0103           ;    PWMDTYW3 = 6000;
 0103 CC1770            ldd #6000
 0106 7C00BE            std 0xbe
 0109           ;    PWME = 0xaa;
 0109 C6AA              ldab #170
 010B 7B00A0            stab 0xa0
 010E           ; }
 010E           L11:
 010E                   .dbline 0 ; func end
 010E 3D                rts
 010F           _reverse::
 010F           ; // reverse
 010F           ; void reverse(void)
 010F           ; {
 010F           ;    PWME = 0x00;
 010F 7900A0            clr 0xa0
 0112           ;    PWMDTYW1 = 6000;
 0112 CC1770            ldd #6000
 0115 7C00BC            std 0xbc
 0118           ;    PWMDTYW3 = 3000;
 0118 CC0BB8            ldd #3000
 011B 7C00BE            std 0xbe
 011E           ;    PWME = 0xaa;
 011E C6AA              ldab #170
 0120 7B00A0            stab 0xa0
 0123           ; }
 0123           L12:
 0123                   .dbline 0 ; func end
 0123 3D                rts
 0124           _right::
 0124           ;    
 0124           ; // right
 0124           ; void right(void)
 0124           ; {
 0124           ;    PWME = 0x00;
 0124 7900A0            clr 0xa0
 0127           ;    PWMDTYW1 = 6000;
 0127 CC1770            ldd #6000
 012A 7C00BC            std 0xbc
 012D           ;    PWMDTYW3 = 6000;
 012D CC1770            ldd #6000
 0130 7C00BE            std 0xbe
 0133           ;    PWME = 0xaa;
 0133 C6AA              ldab #170
 0135 7B00A0            stab 0xa0
 0138           ; }
 0138           L13:
 0138                   .dbline 0 ; func end
 0138 3D                rts
 0139           _left::
 0139           ; 
 0139           ; // left
 0139           ; void left(void)
 0139           ; {
 0139           ;    PWME = 0x00;
 0139 7900A0            clr 0xa0
 013C           ;    PWMDTY1 = 3000;
 013C CC0BB8            ldd #3000
 013F 7B00BD            stab 0xbd
 0142           ;    PWMDTY3 = 3000;
 0142 CC0BB8            ldd #3000
 0145 7B00BF            stab 0xbf
 0148           ;    PWME = 0xaa;
 0148 C6AA              ldab #170
 014A 7B00A0            stab 0xa0
 014D           ; }
 014D           L14:
 014D                   .dbline 0 ; func end
 014D 3D                rts
 014E           _init_tof::
 014E           ; 
 014E           ; //Initialize Timer Overflow 
 014E           ; void init_tof()
 014E           ; {
 014E           ;    SEI;
 014E 1410                      SEI
 0150           
 0150           ;    TSCR1 = 0x80;                                        //turn on Timer
 0150 C680              ldab #128
 0152 7B0046            stab 0x46
 0155           ;    TFLG2 = 0x80;                                        //clear TOF flag
 0155 C680              ldab #128
 0157 7B004F            stab 0x4f
 015A           ;    TSCR2 = 0x80;                                        //turn on TOF interrupt
 015A C680              ldab #128
 015C 7B004D            stab 0x4d
 015F           ;    CLI;
 015F 10EF                      CLI
 0161           
 0161           ; }
 0161           L15:
 0161                   .dbline 0 ; func end
 0161 3D                rts
 0162           ;  lreg1 -> -4,x
 0162           ;  lreg2 -> -8,x
 0162           _TOF_isr::
 0162 34                pshx
 0163 B775              tfr s,x
 0165 1B98              leas -8,sp
 0167           ; 
 0167           ; //Timer Overflow Counter (ISR)
 0167           ; void TOF_isr(void)  
 0167           ; {
 0167           ;    t_counts++;
 0167 CD002A            ldy #_t_counts
 016A 1802401C          movw 0,y,-4,x
 016E 1802421E          movw 2,y,-2,x
 0172 CD0425            ldy #L17
 0175 18024018          movw 0,y,-8,x
 0179 1802421A          movw 2,y,-6,x
 017D 160000            jsr __ladd
 0180 CD002A            ldy #_t_counts
 0183 18021C40          movw -4,x,0,y
 0187 18021E42          movw -2,x,2,y
 018B           ;    if ((t_counts%38)==0)
 018B CD002A            ldy #_t_counts
 018E 1802401C          movw 0,y,-4,x
 0192 1802421E          movw 2,y,-2,x
 0196 CD0421            ldy #L20
 0199 18024018          movw 0,y,-8,x
 019D 1802421A          movw 2,y,-6,x
 01A1 160000            jsr __lmod
 01A4 CD041D            ldy #L21
 01A7 18024018          movw 0,y,-8,x
 01AB 1802421A          movw 2,y,-6,x
 01AF 160000            jsr __lcmp
 01B2 2624              bne L18
 01B4           ;    {
 01B4           ;         t_tenths++;
 01B4 CD0026            ldy #_t_tenths
 01B7 1802401C          movw 0,y,-4,x
 01BB 1802421E          movw 2,y,-2,x
 01BF CD0425            ldy #L17
 01C2 18024018          movw 0,y,-8,x
 01C6 1802421A          movw 2,y,-6,x
 01CA 160000            jsr __ladd
 01CD CD0026            ldy #_t_tenths
 01D0 18021C40          movw -4,x,0,y
 01D4 18021E42          movw -2,x,2,y
 01D8           ;    }
 01D8           L18:
 01D8           ;    if ((t_counts%4)==0)
 01D8 CD002A            ldy #_t_counts
 01DB 1802401C          movw 0,y,-4,x
 01DF 1802421E          movw 2,y,-2,x
 01E3 CD0419            ldy #L24
 01E6 18024018          movw 0,y,-8,x
 01EA 1802421A          movw 2,y,-6,x
 01EE 160000            jsr __lmod
 01F1 CD041D            ldy #L21
 01F4 18024018          movw 0,y,-8,x
 01F8 1802421A          movw 2,y,-6,x
 01FC 160000            jsr __lcmp
 01FF 2624              bne L22
 0201           ;    {
 0201           ;       t_hundredths++;
 0201 CD0022            ldy #_t_hundredths
 0204 1802401C          movw 0,y,-4,x
 0208 1802421E          movw 2,y,-2,x
 020C CD0425            ldy #L17
 020F 18024018          movw 0,y,-8,x
 0213 1802421A          movw 2,y,-6,x
 0217 160000            jsr __ladd
 021A CD0022            ldy #_t_hundredths
 021D 18021C40          movw -4,x,0,y
 0221 18021E42          movw -2,x,2,y
 0225           ;    }
 0225           L22:
 0225           ;    
 0225           ;    TFLG2 = 0x80;
 0225 C680              ldab #128
 0227 7B004F            stab 0x4f
 022A           ; }
 022A           L16:
 022A B757              tfr x,s
 022C 30                pulx
 022D                   .dbline 0 ; func end
 022D 0B                rti
 022E           ;  lreg1 -> -4,x
 022E           ;  lreg2 -> -8,x
 022E           ;       end_time -> -12,x
 022E           ;     pause_time -> 2,x
 022E           _pause::
 022E 3B                pshd
 022F 34                pshx
 0230 B775              tfr s,x
 0232 1B94              leas -12,sp
 0234           ; 
 0234           ; //pause for pause_time*0.1 sec
 0234           ; void pause(int pause_time)
 0234           ; {
 0234           ;    long int end_time;
 0234           ;    end_time = t_tenths + pause_time;
 0234 CD0026            ldy #_t_tenths
 0237 1802401C          movw 0,y,-4,x
 023B 1802421E          movw 2,y,-2,x
 023F EC02              ldd 2,x
 0241 160000            jsr __d2lreg2
 0244 160000            jsr __ladd
 0247 1914              leay -12,x
 0249 18021C40          movw -4,x,0,y
 024D 18021E42          movw -2,x,2,y
 0251           L26:
 0251           L27:
 0251           ; //   printf ("%ld = %ld + %d\n\r",end_time,t_tenths,pause_time);
 0251           ;    while(end_time>t_tenths)
 0251 1914              leay -12,x
 0253 1802401C          movw 0,y,-4,x
 0257 1802421E          movw 2,y,-2,x
 025B CD0026            ldy #_t_tenths
 025E 18024018          movw 0,y,-8,x
 0262 1802421A          movw 2,y,-6,x
 0266 160000            jsr __lcmp
 0269 2EE6              bgt L26
 026B           ;    {
 026B           ;    }
 026B           ; }
 026B           L25:
 026B B757              tfr x,s
 026D 30                pulx
 026E 1B82              leas 2,sp
 0270                   .dbline 0 ; func end
 0270 3D                rts
 0271           ;  lreg1 -> -4,x
 0271           ;  lreg2 -> -8,x
 0271           ;       end_time -> -12,x
 0271           ;     pause_time -> 2,x
 0271           _s_pause::
 0271 3B                pshd
 0272 34                pshx
 0273 B775              tfr s,x
 0275 1B94              leas -12,sp
 0277           ; 
 0277           ; //pause for pause_time*0.01 sec
 0277           ; void s_pause(int pause_time)
 0277           ; {
 0277           ;    long int end_time;
 0277           ;    end_time = t_hundredths + pause_time;
 0277 CD0022            ldy #_t_hundredths
 027A 1802401C          movw 0,y,-4,x
 027E 1802421E          movw 2,y,-2,x
 0282 EC02              ldd 2,x
 0284 160000            jsr __d2lreg2
 0287 160000            jsr __ladd
 028A 1914              leay -12,x
 028C 18021C40          movw -4,x,0,y
 0290 18021E42          movw -2,x,2,y
 0294           L30:
 0294           L31:
 0294           ; //   printf ("%ld = %ld + %d\n\r",end_time,t_tenths,pause_time);
 0294           ;    while(end_time>t_hundredths)
 0294 1914              leay -12,x
 0296 1802401C          movw 0,y,-4,x
 029A 1802421E          movw 2,y,-2,x
 029E CD0022            ldy #_t_hundredths
 02A1 18024018          movw 0,y,-8,x
 02A5 1802421A          movw 2,y,-6,x
 02A9 160000            jsr __lcmp
 02AC 2EE6              bgt L30
 02AE           ;    {
 02AE           ;    }
 02AE           ; }
 02AE           L29:
 02AE B757              tfr x,s
 02B0 30                pulx
 02B1 1B82              leas 2,sp
 02B3                   .dbline 0 ; func end
 02B3 3D                rts
 02B4           _init_atd0::
 02B4           ; 
 02B4           ; // ******************* Initialize ATD *******************
 02B4           ; void init_atd0()
 02B4           ; {
 02B4           ;    SEI;
 02B4 1410                      SEI
 02B6           
 02B6           ;    ATD0CTL2 = 0xC2;
 02B6 C6C2              ldab #194
 02B8 7B0082            stab 0x82
 02BB           ;    ATD0CTL3 = 0x40;
 02BB C640              ldab #64
 02BD 7B0083            stab 0x83
 02C0           ;    ATD0CTL4 = 0xE7;
 02C0 C6E7              ldab #231
 02C2 7B0084            stab 0x84
 02C5           ;    CLI;
 02C5 10EF                      CLI
 02C7           
 02C7           ; }
 02C7           L33:
 02C7                   .dbline 0 ; func end
 02C7 3D                rts
 02C8           _ATD0_Interrupt::
 02C8           ; 
 02C8           ; /********************************************************************/
 02C8           ; /* This code is primarily taken from example 7.3.5 in the text      */
 02C8           ; /* and then converted to act as an ISR                              */
 02C8           ; /********************************************************************/
 02C8           ;   	  
 02C8           ; void ATD0_Interrupt(void)
 02C8           ; {
 02C8           ; /*print results to PC screen for testing             */
 02C8           ;    atd0[0]= ATD0DR0H;	
 02C8           	; vol
 02C8 F60090            ldab 0x90
 02CB 87                clra
 02CC 7C0012            std _atd0
 02CF           ;    atd0[1]= ATD0DR1H;
 02CF                   ; vol
 02CF F60092            ldab 0x92
 02D2 87                clra
 02D3 7C0014            std _atd0+2
 02D6           ;    atd0[2]= ATD0DR2H;
 02D6                   ; vol
 02D6 F60094            ldab 0x94
 02D9 87                clra
 02DA 7C0016            std _atd0+4
 02DD           ;    atd0[3]= ATD0DR3H;
 02DD                   ; vol
 02DD F60096            ldab 0x96
 02E0 87                clra
 02E1 7C0018            std _atd0+6
 02E4           ;    atd0[4]= ATD0DR4H;
 02E4                   ; vol
 02E4 F60098            ldab 0x98
 02E7 87                clra
 02E8 7C001A            std _atd0+8
 02EB           ;    atd0[5]= ATD0DR5H;
 02EB                   ; vol
 02EB F6009A            ldab 0x9a
 02EE 87                clra
 02EF 7C001C            std _atd0+10
 02F2           ;    atd0[6]= ATD0DR6H;
 02F2                   ; vol
 02F2 F6009C            ldab 0x9c
 02F5 87                clra
 02F6 7C001E            std _atd0+12
 02F9           ;    atd0[7]= ATD0DR7H;         
 02F9                   ; vol
 02F9 F6009E            ldab 0x9e
 02FC 87                clra
 02FD 7C0020            std _atd0+14
 0300           ; // printf("%x %x %x %x\n\r", ATD0DR0L, ATD0DR1L, ATD0DR2L, ATD0DR3L); 
 0300           ; }
 0300           L34:
 0300                   .dbline 0 ; func end
 0300 0B                rti
 0301           _init_atd1::
 0301           ; 
 0301           ; // ******************* Initialize ATD *******************
 0301           ; void init_atd1()
 0301           ; {
 0301           ;    SEI;
 0301 1410                      SEI
 0303           
 0303           ;    ATD1CTL2 = 0xC2;
 0303 C6C2              ldab #194
 0305 7B0122            stab 0x122
 0308           ;    ATD1CTL3 = 0x40;
 0308 C640              ldab #64
 030A 7B0123            stab 0x123
 030D           ;    ATD1CTL4 = 0xE7;
 030D C6E7              ldab #231
 030F 7B0124            stab 0x124
 0312           ;    CLI;
 0312 10EF                      CLI
 0314           
 0314           ; }
 0314           L42:
 0314                   .dbline 0 ; func end
 0314 3D                rts
 0315           _ATD1_Interrupt::
 0315           ; 
 0315           ; /********************************************************************/
 0315           ; /* This code is primarily taken from example 7.3.5 in the text      */
 0315           ; /* and then converted to act as an ISR                              */
 0315           ; /********************************************************************/
 0315           ;   	  
 0315           ; void ATD1_Interrupt(void)
 0315           ; {
 0315           ; /*print results to PC screen for testing             */
 0315           ;    atd1[0]= ATD1DR0H;	
 0315           	; vol
 0315 F60130            ldab 0x130
 0318 87                clra
 0319 7C0002            std _atd1
 031C           ;    atd1[1]= ATD1DR1H;
 031C                   ; vol
 031C F60132            ldab 0x132
 031F 87                clra
 0320 7C0004            std _atd1+2
 0323           ;    atd1[2]= ATD1DR2H;
 0323                   ; vol
 0323 F60134            ldab 0x134
 0326 87                clra
 0327 7C0006            std _atd1+4
 032A           ;    atd1[3]= ATD1DR3H;
 032A                   ; vol
 032A F60136            ldab 0x136
 032D 87                clra
 032E 7C0008            std _atd1+6
 0331           ;    atd1[4]= ATD1DR4H;
 0331                   ; vol
 0331 F60138            ldab 0x138
 0334 87                clra
 0335 7C000A            std _atd1+8
 0338           ;    atd1[5]= ATD1DR5H;
 0338                   ; vol
 0338 F6013A            ldab 0x13a
 033B 87                clra
 033C 7C000C            std _atd1+10
 033F           ;    atd1[6]= ATD1DR6H;
 033F                   ; vol
 033F F6013C            ldab 0x13c
 0342 87                clra
 0343 7C000E            std _atd1+12
 0346           ;    atd1[7]= ATD1DR7H;         
 0346                   ; vol
 0346 F6013E            ldab 0x13e
 0349 87                clra
 034A 7C0010            std _atd1+14
 034D           ; // printf("%x %x %x %x\n\r", ATD0DR0L, ATD0DR1L, ATD0DR2L, ATD0DR3L); 
 034D           ; }
 034D           L43:
 034D                   .dbline 0 ; func end
 034D 0B                rti
 034E           L52:
 034E BAB9              .word 47801
 0350 A65D              .word 42589
 0352 9430              .word 37936
 0354 8BE9              .word 35817
 0356 7C90              .word 31888
 0358 6EF9              .word 28409
 035A 62D7              .word 25303
 035C 5D5C              .word 23900
 035E           L53:
 035E 0005              .word 5
 0360 0005              .word 5
 0362 0005              .word 5
 0364 0005              .word 5
 0366 0005              .word 5
 0368 0005              .word 5
 036A 0005              .word 5
 036C 0005              .word 5
 036E           ;              i -> -36,x
 036E           ;            dur -> -34,x
 036E           ;          score -> -18,x
 036E           ;              j -> -2,x
 036E           _Speaker::
 036E 34                pshx
 036F B775              tfr s,x
 0371 1BF1DA            leas -38,sp
 0374           ; 
 0374           ; //*****************************************************************************
 0374           ; #define  C5  47801
 0374           ; #define  C5S 45126
 0374           ; #define  D5    42589
 0374           ; #define        D5S 40193
 0374           ; #define        E5  37936
 0374           ; #define  F5    35817
 0374           ; #define  F5S 33784
 0374           ; #define        G5      31888
 0374           ; #define  G5S 30084
 0374           ; #define  A5    28409
 0374           ; #define  A5S 26824
 0374           ; #define  B5    25303
 0374           ; #define  C6    23900
 0374           ; #define  C6S 22542
 0374           ; #define  D6  21276
 0374           ; #define  D6S 20096
 0374           ; #define  E6  18825
 0374           ; #define  F6  17895
 0374           ; #define  F6S 16892
 0374           ; #define  G6    15944
 0374           ; #define  G6S 15051
 0374           ; #define  A6  14204
 0374           ; #define  A6S 13404
 0374           ; #define  B6  12658
 0374           ; 
 0374           ; 
 0374           ; #define  notes  8
 0374           ; #define  toggle 0x04
 0374           ; 
 0374           ; void Speaker (void)
 0374           ; {
 0374           ;    int j;
 0374           ;    int i;
 0374           ;    unsigned int score[notes] = {C5,D5,E5,F5,G5,A5,B5,C6};
 0374 19E1EE            leay -18,x
 0377 B7C6              xgdy
 0379 CD034E            ldy #L52
 037C 34                pshx
 037D B745              tfr d,x
 037F CC0008            ldd #8
 0382           X2:
 0382 18027131          movw 2,y+,2,x+
 0386 0434F9            dbne d,X2
 0389 30                pulx
 038A           ;    unsigned int dur[notes] = {5,5,5,5,5,5,5,5};
 038A 19E1DE            leay -34,x
 038D B7C6              xgdy
 038F CD035E            ldy #L53
 0392 34                pshx
 0393 B745              tfr d,x
 0395 CC0008            ldd #8
 0398           X3:
 0398 18027131          movw 2,y+,2,x+
 039C 0434F9            dbne d,X3
 039F 30                pulx
 03A0           ; 
 03A0           ; //   TSCR1 = 0x90;   //Enable TCNT, fast timer flag clear
 03A0           ; //   TSCR2 = 0x83;   //Set TCNT prescaler to 8
 03A0           ;    TFLG1 = 0x20;   //Clear all TxF flags
 03A0 C620              ldab #32
 03A2 7B004E            stab 0x4e
 03A5           ;    TIE  |= 0x20;   //Enable TC5 interrupt
 03A5 1C004C20          bset 0x4c,#32
 03A9           ;    TIOS |= 0x20;   //Enable OC5 function
 03A9 1C004020          bset 0x40,#32
 03AD           ;    TCTL1 = toggle; //Select toggle option as OC5 pin action
 03AD C604              ldab #4
 03AF 7B0048            stab 0x48
 03B2           ;    j = 0;
 03B2 CC0000            ldd #0
 03B5 6C1E              std -2,x
 03B7           ;    dela = score[0];
 03B7 ECE1EE            ldd -18,x
 03BA 7C0000            std _dela
 03BD           ;    TC5 = TCNT + dela;      //Play the first note
 03BD                   ; vol
 03BD FC0044            ldd 0x44
 03C0 F30000            addd _dela
 03C3 7C005A            std 0x5a
 03C6 202D              bra L55
 03C8           L54:
 03C8 19E1EE            leay -18,x
 03CB 6DE1DA            sty -38,x
 03CE EC1E              ldd -2,x
 03D0 59                lsld
 03D1 E3E1DA            addd -38,x
 03D4 B7C6              xgdy
 03D6 EC40              ldd 0,y
 03D8 7C0000            std _dela
 03DB 19E1DE            leay -34,x
 03DE 6DE1DA            sty -38,x
 03E1 EC1E              ldd -2,x
 03E3 59                lsld
 03E4 E3E1DA            addd -38,x
 03E7 B7C6              xgdy
 03E9 EC40              ldd 0,y
 03EB 160271            jsr _s_pause
 03EE EC1E              ldd -2,x
 03F0 C30001            addd #1
 03F3 6C1E              std -2,x
 03F5           L55:
 03F5           ;    while(j < notes)
 03F5 EC1E              ldd -2,x
 03F7 8C0008            cpd #8
 03FA 2DCC              blt L54
 03FC           ;    {
 03FC           ;       dela = score[j];     //Play the jth note
 03FC           ;         s_pause(dur[j]);
 03FC           ;         j++;
 03FC           ;    }
 03FC           ; 
 03FC           ;    TIE  &= ~0x20;   //Disable TC5 interrupt
 03FC 1D004C20          bclr 0x4c,#0x20
 0400           ; //   TSCR1 = 0x00;   //Turn off the Timer System
 0400           ;    PTT = 0x00;     //Blank Port T
 0400 790240            clr 0x240
 0403           ;    TCTL1 = 0;
 0403 790048            clr 0x48
 0406           ; }
 0406           L51:
 0406 B757              tfr x,s
 0408 30                pulx
 0409                   .dbline 0 ; func end
 0409 3D                rts
 040A           _OC5_ISR::
 040A           ; 
 040A           ; //******************************** OC5_ISR *************************************
 040A           ; 
 040A           ; #pragma interrupt_handler OC5_ISR()
 040A           ; void OC5_ISR ()
 040A           ; {
 040A           ;    TC5 += dela;
 040A           	; vol
 040A FC005A            ldd 0x5a
 040D F30000            addd _dela
 0410 7C005A            std 0x5a
 0413           ;    TFLG1 = 0x20;
 0413 C620              ldab #32
 0415 7B004E            stab 0x4e
 0418           ; }
 0418           L57:
 0418                   .dbline 0 ; func end
 0418 0B                rti
                        .area bss
 0000           _dela::
 0000                   .blkb 2
 0002           _atd1::
 0002                   .blkb 16
 0012           _atd0::
 0012                   .blkb 16
 0022           _t_hundredths::
 0022                   .blkb 4
 0026           _t_tenths::
 0026                   .blkb 4
 002A           _t_counts::
 002A                   .blkb 4
                        .area text
 0419           L24:
 0419 00000004          .word 0,4
 041D           L21:
 041D 00000000          .word 0,0
 0421           L20:
 0421 00000026          .word 0,38
 0425           L17:
 0425 00000001          .word 0,1
