	.module TESTMO~1.C
	.area text
_main::
; #include<stdio.h>
; #include<mc9s12dp256.h>
; 
; void delay_100us();
; 
; char c;
; 
; main()
; {
; 
;    SCI1BDL = 0x46;  // sets Baud rate to 2400 
	ldab #70
	stab 0xd1
;    SCI1BDH = 0x01;  //
	ldab #1
	stab 0xd0
;    SCI1CR1 = 0x00;  // sets 8-bit communication, w/o parity
	clr 0xd2
;    SCI1CR2 = 0x08;  //ENABLE TRANSMIT BIT
	ldab #8
	stab 0xd3
;    
;   
; 
; printf("To make the motors go full backwords press B, to make them go full foward press F.  To stop them press S.\r\n");
	ldd #L4
	jsr _printf
; printf("To turn right type R.  To turn left type L.\r\n");
	ldd #L5
	jsr _printf
; c = 'null';
	ldab #110
	stab _c
; 
; //while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
; //SCI1DRL = 0x10;			/*motor 1*/
; delay_100us();
	jsr _delay_100us
; delay_100us();
	jsr _delay_100us
; delay_100us();
	jsr _delay_100us
	lbra L7
L6:
; 
; while(1){
; 
; c=getcSCI0();
	jsr _getcSCI0
	stab _c
; 
; if (c == '6'){    			//Right Turn
	ldab _c
	cmpb #54
	bne L9
L11:
L12:
; 
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L11
; SCI1DRL = 80;			/*motor 1*/
	ldab #80
	stab 0xd7
; delay_100us();
	jsr _delay_100us
L14:
L15:
; 
; 
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L14
; SCI1DRL = 174; 		/*motor 2*/
	ldab #174
	stab 0xd7
; printf("\r\nCommand Sent\r\n");
	ldd #L17
	jsr _printf
; }
L9:
; if (c == '4'){				//Left Turn
	ldab _c
	cmpb #52
	bne L18
L20:
L21:
; 
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L20
; SCI1DRL = 50;			/*motor 1*/
	ldab #50
	stab 0xd7
; delay_100us();
	jsr _delay_100us
L23:
L24:
; 
; 
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L23
; SCI1DRL = 208; 		/*motor 2*/
	ldab #208
	stab 0xd7
; printf("\r\nCommand Sent\r\n");
	ldd #L17
	jsr _printf
; }
L18:
; if (c == '2'){ 		  	//Drive Backwords
	ldab _c
	cmpb #50
	bne L26
L28:
L29:
; 
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L28
; SCI1DRL = 50;			/*motor 1*/
	ldab #50
	stab 0xd7
; delay_100us();
	jsr _delay_100us
L31:
L32:
; 
; 
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L31
; SCI1DRL = 178; 		/*motor 2*/
	ldab #178
	stab 0xd7
; printf("\r\nCommand Sent\r\n");
	ldd #L17
	jsr _printf
; }
	bra L27
L26:
; 
; 
; else if (c == '8'){      //Drive Forwords
	ldab _c
	cmpb #56
	bne L34
L36:
L37:
; 
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L36
; SCI1DRL = 80;		/*motor 1*/
	ldab #80
	stab 0xd7
; delay_100us();
	jsr _delay_100us
L39:
L40:
; 
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L39
; SCI1DRL = 208;		/*motor 2*/
	ldab #208
	stab 0xd7
; printf("\r\nCommand Sent\r\n");
	ldd #L17
	jsr _printf
; 
; }
	bra L35
L34:
; else if (c == 's'){       //Stop Both Motors
	ldab _c
	cmpb #115
	bne L42
L44:
L45:
; while(!(SCI1SR1 & 0x80));	/*wait for TDRE*/
	brclr 0xd4,#128,L44
; SCI1DRL = 0x00;		        /*motor 1*/
	clr 0xd7
; printf("\r\nCommand Sent, Motors Stopped\r\n");
	ldd #L47
	jsr _printf
; }
L42:
; 
; else;
L43:
L35:
L27:
	ldab #110
	stab _c
L7:
	lbra L6
X0:
; c = 'null';
; }
; }
L3:
	.dbline 0 ; func end
	rts
;              i -> -2,x
_delay_100us::
	pshx
	tfr s,x
	leas -2,sp
; 
; void delay_100us(void){ 
; int i;
; for (i=0; i<50;i++)
	ldd #0
	std -2,x
L49:
		nop

L50:
	ldd -2,x
	addd #1
	std -2,x
	ldd -2,x
	cpd #50
	blt L49
; asm("nop");
; }
L48:
	tfr x,s
	pulx
	.dbline 0 ; func end
	rts
	.area bss
_c::
	.blkb 1
	.area text
L47:
	.byte 13,10,'C,'o,'m,'m,'a,'n,'d,32,'S,'e,'n,'t,44,32
	.byte 'M,'o,'t,'o,'r,'s,32,'S,'t,'o,'p,'p,'e,'d,13,10
	.byte 0
L17:
	.byte 13,10,'C,'o,'m,'m,'a,'n,'d,32,'S,'e,'n,'t,13,10
	.byte 0
L5:
	.byte 'T,'o,32,'t,'u,'r,'n,32,'r,'i,'g,'h,'t,32,'t,'y
	.byte 'p,'e,32,'R,46,32,32,'T,'o,32,'t,'u,'r,'n,32,'l
	.byte 'e,'f,'t,32,'t,'y,'p,'e,32,'L,46,13,10,0
L4:
	.byte 'T,'o,32,'m,'a,'k,'e,32,'t,'h,'e,32,'m,'o,'t,'o
	.byte 'r,'s,32,'g,'o,32,'f,'u,'l,'l,32,'b,'a,'c,'k,'w
	.byte 'o,'r,'d,'s,32,'p,'r,'e,'s,'s,32,'B,44,32,'t,'o
	.byte 32,'m,'a,'k,'e,32,'t,'h,'e,'m,32,'g,'o,32,'f,'u
	.byte 'l,'l,32,'f,'o,'w,'a,'r,'d,32,'p,'r,'e,'s,'s,32
	.byte 'F,46,32,32,'T,'o,32,'s,'t,'o,'p,32,'t,'h,'e,'m
	.byte 32,'p,'r,'e,'s,'s,32,'S,46,13,10,0
