                        .module MOTORSTOP.c
                        .area data
 0000           _T_counts::
 0000                   .blkb 2
                        .area idata
 0000 4E20              .word 20000
                        .area data
 0002           _per_on2::
 0002                   .blkb 2
                        .area idata
 0002 0014              .word 20
                        .area data
 0004           _per_on3::
 0004                   .blkb 2
                        .area idata
 0004 0014              .word 20
                        .area data
 0006           _stopper::
 0006                   .blkb 2
                        .area idata
 0006 0000              .word 0
                        .area data
                        .area text
 0000           _main::
 0000           ; /* C Listing 11.4 */
 0000           ; 
 0000           ; #include <hc11.h>	/* Include register definitions */
 0000           ; #include <stdio.h>
 0000           ; #define motcont *(unsigned char volatile *)(0xB590)
 0000           ; 
 0000           ; 
 0000           ; 
 0000           ; /* Declarations */
 0000           ; unsigned int OC2hi, OC2lo, OC3hi, OC3lo;	/* Duty cycle data */
 0000           ; unsigned int T_counts=0x4E20, per_on2=20, per_on3=20, stopper=0;
 0000           ; 
 0000           ; 
 0000           ; /* Prototypes */
 0000           ; void initoc(void);
 0000           ; void rtoc2(void);
 0000           ; void rtoc3(void);
 0000           ; void cnts2(void);
 0000           ; void cnts3(void);
 0000           ; 
 0000           ; 
 0000           ; 
 0000           ; void main(void)
 0000           ; {
 0000           ;  	
 0000           ; 	
 0000           ; 	setbaud(BAUD9600);
 0000 CC0030            ldd #48
 0003 BD0000            jsr _setbaud
 0006           ;       INTR_OFF();
 0006 0F                                sei
 0007           
 0007           ;       /* set up jump vector for buffalo */
 0007           ;       asm("   ldaa #$7e");
 0007 867E                              ldaa #$7e
 0009           
 0009           ;       asm("   staa $dc");
 0009 97DC                              staa $dc
 000B           
 000B           ;       asm("   staa $d9");
 000B 97D9                              staa $d9
 000D           
 000D           ;       asm("   ldd #_rtoc2");
 000D CC0082                            ldd #_rtoc2
 0010           
 0010           ;       asm("   std $dd");
 0010 DDDD                              std $dd
 0012           
 0012           ;       asm("   ldd #_rtoc3");
 0012 CC00B8                            ldd #_rtoc3
 0015           
 0015           ;       asm("   std $da");
 0015 DDDA                              std $da
 0017           
 0017           ;       
 0017           ;       
 0017           ;     initoc();
 0017 BD0067            jsr _initoc
 001A           ;       cnts2();
 001A BD00EE            jsr _cnts2
 001D           ;       cnts3();
 001D BD01CB            jsr _cnts3
 0020 203B              bra L5
 0022           L4:
 0022           ; 
 0022           ; 	
 0022           ; 	while(stopper <= 500)
 0022           ; 	{		
 0022           ; 		
 0022           ; 		
 0022           ; 		TMSK1 = 0x00;
 0022 7F1022            clr 0x1022
 0025           ;               PORTA = 0x00;
 0025 7F1000            clr 0x1000
 0028 2016              bra L8
 002A           L7:
 002A FC0006            ldd _stopper
 002D C30001            addd #1
 0030 FD0006            std _stopper
 0033 FC0006            ldd _stopper
 0036 37                pshb
 0037 36                psha
 0038 CC02B4            ldd #L10
 003B BD0000            jsr _printf
 003E 1838              puly
 0040           L8:
 0040 FC0006            ldd _stopper
 0043 1A8300FA          cpd #250
 0047 23E1              bls L7
 0049 C660              ldab #96
 004B F71022            stab 0x1022
 004E BD00EE            jsr _cnts2
 0051 BD01CB            jsr _cnts3
 0054 FC0006            ldd _stopper
 0057 C30001            addd #1
 005A FD0006            std _stopper
 005D           L5:
 005D FC0006            ldd _stopper
 0060 1A8301F4          cpd #500
 0064 23BC              bls L4
 0066           ;               while (stopper <= 250){
 0066           ;               stopper ++;
 0066           ;               printf("%d\n", stopper);
 0066           ;               }
 0066           ;               TMSK1 = 0x60;
 0066           ;               cnts2();
 0066           ;               cnts3();
 0066           ;               stopper ++;
 0066           ;       }
 0066           ; }
 0066           L3:
 0066                   .dbline 0 ; func end
 0066 39                rts
 0067           _initoc::
 0067           ; 
 0067           ; void initoc(void)
 0067           ; /* Initialize OC2 */
 0067           ; {
 0067           ; 	TOC2 = TCNT;
 0067           	; vol
 0067 FC100E            ldd 0x100e
 006A FD1018            std 0x1018
 006D           ;       TOC3 = TCNT;
 006D                   ; vol
 006D FC100E            ldd 0x100e
 0070 FD101A            std 0x101a
 0073           ;       TCTL1 = 0x00;
 0073 7F1020            clr 0x1020
 0076           ;       TFLG1 = 0x60;
 0076 C660              ldab #96
 0078 F71023            stab 0x1023
 007B           ;       TMSK1 = 0x60;
 007B C660              ldab #96
 007D F71022            stab 0x1022
 0080           ;       INTR_ON();
 0080 0E                                cli
 0081           
 0081           ; }
 0081           L11:
 0081                   .dbline 0 ; func end
 0081 39                rts
 0082           _rtoc2::
 0082           ; 
 0082           ; void rtoc2(void)
 0082           ; /* Interrupt Service Routine for OC2 PWM */
 0082           ; {   
 0082           ; 	if ((PORTA & 0X40) == 0){ 
 0082 18CE1000          ldy #0x1000
 0086 181F004002        brclr 0,y,#64,X0
 008B 2013              bra L13
 008D           X0:
 008D           ; 		TOC2 = TOC2 + OC2hi;
 008D           	; vol
 008D FC1018            ldd 0x1018
 0090 F30006            addd _OC2hi
 0093 FD1018            std 0x1018
 0096           ;               PORTA = PORTA | 0x40;
 0096 18CE1000          ldy #0x1000
 009A 181C0040          bset 0,y,#64
 009E           ;               }
 009E 2011              bra L14
 00A0           L13:
 00A0           ; 	else{
 00A0           ; 		TOC2 = TOC2 + OC2lo;
 00A0           	; vol
 00A0 FC1018            ldd 0x1018
 00A3 F30004            addd _OC2lo
 00A6 FD1018            std 0x1018
 00A9           ;               PORTA = PORTA & 0xBF;
 00A9 18CE1000          ldy #0x1000
 00AD 181D0040          bclr 0,y,#0x40
 00B1           ;               }
 00B1           L14:
 00B1           ; 	//TCTL1 = TCTL1 ^ 0x40;	/* invert OL2 to toggle next OC2 edge */
 00B1           ; 	TFLG1 = 0x40;	/* Clear flag OC2F */
 00B1 C640              ldab #64
 00B3 F71023            stab 0x1023
 00B6           ;       asm("   rti");  /* This is an interrupt service routine */
 00B6 3B                                rti
 00B7           
 00B7           ; }
 00B7           L12:
 00B7                   .dbline 0 ; func end
 00B7 39                rts
 00B8           _rtoc3::
 00B8           ; 
 00B8           ; void rtoc3(void)
 00B8           ; {	
 00B8           ; 	if ((PORTA & 0X20) == 0) {
 00B8 18CE1000          ldy #0x1000
 00BC 181F002002        brclr 0,y,#32,X1
 00C1 2013              bra L16
 00C3           X1:
 00C3           ; 		TOC3 = TOC3 + OC3hi;
 00C3           	; vol
 00C3 FC101A            ldd 0x101a
 00C6 F30002            addd _OC3hi
 00C9 FD101A            std 0x101a
 00CC           ;               PORTA = PORTA | 0x20;
 00CC 18CE1000          ldy #0x1000
 00D0 181C0020          bset 0,y,#32
 00D4           ;       }       
 00D4 2011              bra L17
 00D6           L16:
 00D6           ; 	else{
 00D6           ; 		TOC3 = TOC3 + OC3lo;
 00D6           	; vol
 00D6 FC101A            ldd 0x101a
 00D9 F30000            addd _OC3lo
 00DC FD101A            std 0x101a
 00DF           ;               PORTA = PORTA & 0xDF;
 00DF 18CE1000          ldy #0x1000
 00E3 181D0020          bclr 0,y,#0x20
 00E7           ;       }
 00E7           L17:
 00E7           ; 	//TCTL1 = TCTL1 ^ 0x10;	/* invert OL2 to toggle next OC2 edge */
 00E7           ; 	TFLG1 = 0x20;	/* Clear flag OC2F */
 00E7 C620              ldab #32
 00E9 F71023            stab 0x1023
 00EC           ;       asm("   rti");  /* This is an interrupt service routine */
 00EC 3B                                rti
 00ED           
 00ED           ; }
 00ED           L15:
 00ED                   .dbline 0 ; func end
 00ED 39                rts
 00EE           ;  lreg1 -> -4,x
 00EE           ;  lreg2 -> -8,x
 00EE           ;  IX -> 0,x
 00EE           ;          ?temp -> +2,x
 00EE           ;          ?temp -> +6,x
 00EE           _cnts2::
 00EE BD0000            jsr __enterb
 00F1 88                .byte 0x88
 00F2           ; void cnts2 (void)
 00F2           ; {
 00F2           ;       OC2hi=T_counts * (float)per_on2/100;
 00F2 FC0002            ldd _per_on2
 00F5 04                lsrd
 00F6 BD0000            jsr __d2lreg
 00F9 BD0000            jsr __long2fp
 00FC BD0000            jsr __fpmov
 00FF 18CE02B0          ldy #L22
 0103 BD0000            jsr __tofp1
 0106 BD0000            jsr __fpmul
 0109 FC0002            ldd _per_on2
 010C 8400              anda #0
 010E C401              andb #1
 0110 BD0000            jsr __d2lreg
 0113 BD0000            jsr __pshfp1 ; spill
 0116 BD0000            jsr __long2fp
 0119 BD0000            jsr __fpmov
 011C BD0000            jsr __pulfp1 ; reload
 011F BD0000            jsr __fpadd
 0122 BD0000            jsr __fpmov
 0125 FC0000            ldd _T_counts
 0128 04                lsrd
 0129 BD0000            jsr __d2lreg
 012C BD0000            jsr __long2fp
 012F BD0000            jsr __pshfp2 ; spill
 0132 BD0000            jsr __fpmov
 0135 18CE02B0          ldy #L22
 0139 BD0000            jsr __tofp1
 013C BD0000            jsr __fpmul
 013F FC0000            ldd _T_counts
 0142 8400              anda #0
 0144 C401              andb #1
 0146 BD0000            jsr __d2lreg
 0149 BD0000            jsr __pshfp1 ; spill
 014C BD0000            jsr __long2fp
 014F BD0000            jsr __fpmov
 0152 BD0000            jsr __pulfp1 ; reload
 0155 BD0000            jsr __fpadd
 0158 BD0000            jsr __pulfp2 ; reload
 015B BD0000            jsr __fpmul
 015E 18CE02AC          ldy #L23
 0162 BD0000            jsr __tofp2
 0165 BD0000            jsr __fpdiv
 0168 EC00              ldd 0,x
 016A C30002            addd #2
 016D 188F              xgdy
 016F BD0000            jsr __fromfp1
 0172 EC00              ldd 0,x
 0174 C30002            addd #2
 0177 188F              xgdy
 0179 BD0000            jsr __tofp1
 017C 18CE02A8          ldy #L24
 0180 BD0000            jsr __tofp2
 0183 BD0000            jsr __fpcmp
 0186 2D1E              blt L20
 0188 EC00              ldd 0,x
 018A C30002            addd #2
 018D 188F              xgdy
 018F BD0000            jsr __tofp1
 0192 18CE02A8          ldy #L24
 0196 BD0000            jsr __tofp2
 0199 BD0000            jsr __fpsub
 019C BD0000            jsr __fp2int
 019F C38000            addd #0x8000
 01A2 ED06              std 6,x
 01A4 200F              bra L21
 01A6           L20:
 01A6 EC00              ldd 0,x
 01A8 C30002            addd #2
 01AB 188F              xgdy
 01AD BD0000            jsr __tofp1
 01B0 BD0000            jsr __fp2int
 01B3 ED06              std 6,x
 01B5           L21:
 01B5 EC06              ldd 6,x
 01B7 FD0006            std _OC2hi
 01BA           ;       OC2lo=T_counts - OC2hi;
 01BA FC0000            ldd _T_counts
 01BD B30006            subd _OC2hi
 01C0 FD0004            std _OC2lo
 01C3           ; }
 01C3           L18:
 01C3 8F                xgdx
 01C4 C30008            addd #8
 01C7 8F                xgdx
 01C8 35                txs
 01C9 38                pulx
 01CA                   .dbline 0 ; func end
 01CA 39                rts
 01CB           ;  lreg1 -> -4,x
 01CB           ;  lreg2 -> -8,x
 01CB           ;  IX -> 0,x
 01CB           ;          ?temp -> +2,x
 01CB           ;          ?temp -> +6,x
 01CB           _cnts3::
 01CB BD0000            jsr __enterb
 01CE 88                .byte 0x88
 01CF           ; 
 01CF           ; void cnts3 (void)
 01CF           ; {
 01CF           ;       OC3hi=T_counts * (float)per_on3/100;
 01CF FC0004            ldd _per_on3
 01D2 04                lsrd
 01D3 BD0000            jsr __d2lreg
 01D6 BD0000            jsr __long2fp
 01D9 BD0000            jsr __fpmov
 01DC 18CE02B0          ldy #L22
 01E0 BD0000            jsr __tofp1
 01E3 BD0000            jsr __fpmul
 01E6 FC0004            ldd _per_on3
 01E9 8400              anda #0
 01EB C401              andb #1
 01ED BD0000            jsr __d2lreg
 01F0 BD0000            jsr __pshfp1 ; spill
 01F3 BD0000            jsr __long2fp
 01F6 BD0000            jsr __fpmov
 01F9 BD0000            jsr __pulfp1 ; reload
 01FC BD0000            jsr __fpadd
 01FF BD0000            jsr __fpmov
 0202 FC0000            ldd _T_counts
 0205 04                lsrd
 0206 BD0000            jsr __d2lreg
 0209 BD0000            jsr __long2fp
 020C BD0000            jsr __pshfp2 ; spill
 020F BD0000            jsr __fpmov
 0212 18CE02B0          ldy #L22
 0216 BD0000            jsr __tofp1
 0219 BD0000            jsr __fpmul
 021C FC0000            ldd _T_counts
 021F 8400              anda #0
 0221 C401              andb #1
 0223 BD0000            jsr __d2lreg
 0226 BD0000            jsr __pshfp1 ; spill
 0229 BD0000            jsr __long2fp
 022C BD0000            jsr __fpmov
 022F BD0000            jsr __pulfp1 ; reload
 0232 BD0000            jsr __fpadd
 0235 BD0000            jsr __pulfp2 ; reload
 0238 BD0000            jsr __fpmul
 023B 18CE02AC          ldy #L23
 023F BD0000            jsr __tofp2
 0242 BD0000            jsr __fpdiv
 0245 EC00              ldd 0,x
 0247 C30002            addd #2
 024A 188F              xgdy
 024C BD0000            jsr __fromfp1
 024F EC00              ldd 0,x
 0251 C30002            addd #2
 0254 188F              xgdy
 0256 BD0000            jsr __tofp1
 0259 18CE02A8          ldy #L24
 025D BD0000            jsr __tofp2
 0260 BD0000            jsr __fpcmp
 0263 2D1E              blt L27
 0265 EC00              ldd 0,x
 0267 C30002            addd #2
 026A 188F              xgdy
 026C BD0000            jsr __tofp1
 026F 18CE02A8          ldy #L24
 0273 BD0000            jsr __tofp2
 0276 BD0000            jsr __fpsub
 0279 BD0000            jsr __fp2int
 027C C38000            addd #0x8000
 027F ED06              std 6,x
 0281 200F              bra L28
 0283           L27:
 0283 EC00              ldd 0,x
 0285 C30002            addd #2
 0288 188F              xgdy
 028A BD0000            jsr __tofp1
 028D BD0000            jsr __fp2int
 0290 ED06              std 6,x
 0292           L28:
 0292 EC06              ldd 6,x
 0294 FD0002            std _OC3hi
 0297           ;       OC3lo=T_counts - OC3hi;
 0297 FC0000            ldd _T_counts
 029A B30002            subd _OC3hi
 029D FD0000            std _OC3lo
 02A0           ; }     
 02A0           L25:
 02A0 8F                xgdx
 02A1 C30008            addd #8
 02A4 8F                xgdx
 02A5 35                txs
 02A6 38                pulx
 02A7                   .dbline 0 ; func end
 02A7 39                rts
                        .area bss
 0000           _OC3lo::
 0000                   .blkb 2
 0002           _OC3hi::
 0002                   .blkb 2
 0004           _OC2lo::
 0004                   .blkb 2
 0006           _OC2hi::
 0006                   .blkb 2
                        .area text
 02A8           L24:
 02A8 47000000          .word 0x4700,0x0
 02AC           L23:
 02AC 42C80000          .word 0x42c8,0x0
 02B0           L22:
 02B0 40000000          .word 0x4000,0x0
 02B4           L10:
 02B4 25640A00          .byte 37,'d,10,0
