	.module valve2.c
	.dbfile valve2.c
	.area text
;  IX -> 0,x
_SCI_isr::
	.dbfile C:\ICCTJP\include/isrdecl.h
	.dbfunc SCI_isr
	.dbline 41
; /************************************************************************************************************************
; *	Program:		valve2.c							*
; *	Description:	This program was written to test the pneumatic		                *
; *					valves and cylinders.  It will prompt the user	*
; *					to select the desired function (manual or 		*
; *					automatic positioning) and to select the desired      *
; *					characteristics of the PWM signal for the		*
; *					valves.					*
; *	Programmer:		Scott Nortman					*
; *               Revised by:                             Scott Kanowitz
; *	Date:			January 28, 2000					*
; ************************************************************************************************************************/
; 
; /**************************** Constants *********************************/
; //#define valve TOC
; #define tolerance 10 
; #define valve_sensor analog(1)
; /**************************** End of Constants **************************/
; 
; /*************************** Interrupts *********************************/
; #pragma interrupt_handler TOC2_isr
; /*************************** End of Interrupts **************************/
; 
; /************************** Includes ************************************/
; #include <tjpbase.h>
; #include <analog.h>
; #include <vectors.h>
; #include <mil.h>
; #include <hc11.h>
; /************************ End of includes *******************************/
; 
; /************************** Global Variables*****************************/
; unsigned int duty_cycle, period;
; 
; /************************ End of Global Variables ***********************/
; 
; 
; /************************** Function Declarations  **********************/
; void valve_position (unsigned int);
; void PWM_ON ();
; void PWM_OFF();
L2:
	rti
;  IX -> 0,x
_SPI_isr::
	.dbfunc SPI_isr
	.dbline 47
; /******************** End of Function Declarations  *********************/
; 
; 
; /**************************** Main **************************************/
; 
; unsigned int x, y, z;
L3:
	rti
;  IX -> 0,x
_PAIE_isr::
	.dbfunc PAIE_isr
	.dbline 53
; void main(void)
; {
; 	/* VT100 clear screen */ 
; 	char clear[]= "\x1b\x5B\x32\x4A\x04"; 
; 	
; 	/* VT100 position cursor at (x,y) = (3,12) command is "\x1b[3;12H"*/
L4:
	rti
;  IX -> 0,x
_PAV_isr::
	.dbfunc PAV_isr
	.dbline 59
;   	char place[]= "\x1b[1;1H";	/*Home*/
; 	
; 	SET_BIT(PACTL, 0x80);  	
;   	init_analog();
;   	init_clocktjp();
;   	init_serial();
L5:
	rti
;  IX -> 0,x
_TOF_isr::
	.dbfunc TOF_isr
	.dbline 65
; 
;   	INTR_ON(); /*turn on HC11 interrupt system*/
; 
;   	printf("%s", clear);  
;   	printf("%s", place);
;   	
L6:
	rti
;  IX -> 0,x
_TOC3_isr::
	.dbfunc TOC3_isr
	.dbline 89
;   	printf("\tTitle:\t\tvalve.c\n"
;   "\tProgrammer:\tScott Nortman\n"
;   "\tDate:\t\tJanuary, 2000\n"
;   "\tVersion\t\t1\n\n");
;   
; 	printf("PNEUMATIC CYLINDER DIAGNOSTIC PROGRAM\n\n");
; 	
; 	while(1)
; 	{
; 		printf("Enter the number of clocks for the period\n");
; 		period = read_int();
; 		printf("Enter number of e clocks for the duty cycle\n");
; 		duty_cycle = read_int();
; 		printf("Enter the desired position\n");
; 		z = read_int();
; 		
; 		valve_position(z);
; 		
; //		printf("%s", clear);  
;  //		printf("%s", place);
; 		
; 	}/*End While*/
;   	
; }/*End Main*/
L7:
	rti
;  IX -> 0,x
_TIC3_isr::
	.dbfunc TIC3_isr
	.dbline 101
; 
; 
; /**************************** End of Main *******************************/
; 
; 
; 
; /************************** Function Defintions *************************/
; 
; /********************************valve_position**************************/
; void valve_position (unsigned int position)
; // This function sets the desired position of the pneumatic cylinder
; // shaft +/- the tolerance.  The cylinder moves to its new position
L8:
	rti
;  IX -> 0,x
_TIC2_isr::
	.dbfunc TIC2_isr
	.dbline 107
; // at a speed determined by the PWM function.
; {
; 	
; 	//printf("You're  at the beginning of valve_position.\n");
; 	if (position > (valve_sensor + tolerance))	//If the cylinder is too far out, move it in
; 	{
L9:
	rti
;  IX -> 0,x
_TIC1_isr::
	.dbfunc TIC1_isr
	.dbline 113
; 		//printf("The analog value is:\t%d\n", valve_sensor);
; 		SET_BIT (PORTA, 0x80);  //This sets PORTA bit7 to move cylinder in
; 		PWM_ON();  //After the bit is set, turn on PWM to move the cylinder
; 		
; 		while (position > (valve_sensor + tolerance)){//wait until position is in desired range
; 		//printf("The analog value is:\t%d\n", valve_sensor);
L10:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 119
; 		}
; 		
; 		PWM_OFF(); //Turn off PWM system
; 		return;
; 	} 
; 	
L11:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 125
; 	if (position < (valve_sensor - tolerance))
; 	{
; 		//printf("The analog value is:\t%d\n", valve_sensor);
; 		CLEAR_BIT (PORTA, 0x80);  //Tnis sets PORTA bit 7 to move the cylinder out
; 		PWM_ON();  //After the bit is set, turn on the PWM to move cylinder
; 		
L12:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 131
; 		while (position < (valve_sensor - tolerance)){//wait until position is in desired range
; 			//printf("The analog value is:\t%d\n", valve_sensor);
; 			}	
; 		
; 		PWM_OFF();
; 		return;
L13:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 137
; 	}
; }
;     
; 
; 
; /***************************PWM_ON*****************************/
L14:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 143
; void PWM_ON()//This is the function to generate PWM
; {//This turns on the PWM system on OC2 and enables on
; 	printf("You're at PWM.\n");
; 	SET_BIT (TMSK1, 0x40); //Enable interrupt on OC2
; 	SET_BIT (TCTL1, 0xC0); //Enable on
; 	
L15:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 149
; }
; 
; 
; /****************************PWM_OFF***************************/
; void PWM_OFF()
; {//This turns off the PWM system on OC2 and sets the line to 0
L16:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 155
; //	CLEAR_BIT(TCTL1, 0xC0); //disconnect pin fom interrupt
; 	CLEAR_BIT (TMSK1, 0x40); //Disable interrupt on OC2
; 	SET_BIT (TCTL1, 0x80); //set OC2 line to 0 on compare
; 	SET_BIT (CFORC, 0x40); //force successful compare
; }
; 
L17:
	rti
	.area data
_drew::
	.blkw 1
	.area idata
	.word _interrupt_vectors
	.area text
L19:
	.byte 27,91,50,'J,4,0
L20:
	.byte 27,91,49,59,49,'H,0
;  IX -> 0,x
;          place -> 3,x
;          clear -> 10,x
_main::
	jsr __enterb
	.byte 0x10
	.dbfile valve2.c
	.dbfunc main
	.dbline 51
	ldd 0,x
	addd #10
	ldy #L19
	pshx
	xgdx
	ldd #6
	jsr __asgnblk
	pulx
	.dbline 54
	ldd 0,x
	addd #3
	ldy #L20
	pshx
	xgdx
	ldd #7
	jsr __asgnblk
	pulx
	.dbline 56
	ldy #0x1026
	bset 0,y,#128
	.dbline 57
	jsr _init_analog
	.dbline 58
	jsr _init_clocktjp
	.dbline 59
	jsr _init_serial
			cli

	.dbline 63
	ldd 0,x
	addd #10
	pshb
	psha
	ldd #L21
	jsr _printf
	puly
	.dbline 64
	ldd 0,x
	addd #3
	pshb
	psha
	ldd #L21
	jsr _printf
	puly
	.dbline 66
	ldd #L22
	jsr _printf
	.dbline 71
	ldd #L23
	jsr _printf
	bra L25
L24:
	.dbline 75
	ldd #L27
	jsr _printf
	.dbline 76
	jsr _read_int
	std _period
	.dbline 77
	ldd #L28
	jsr _printf
	.dbline 78
	jsr _read_int
	std _duty_cycle
	.dbline 79
	ldd #L29
	jsr _printf
	.dbline 80
	jsr _read_int
	std _z
	.dbline 82
	ldd _z
	jsr _valve_position
	.dbline 87
L25:
	.dbline 73
	bra L24
L18:
	xgdx
	addd #16
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
;  rMEM -> 2,x
;       position -> 6,x
_valve_position::
	jsr __enterb
	.byte 0x44
	.dbfunc valve_position
	.dbline 106
	ldd #1
	jsr _analog
	addd #10
	std 2,x
	ldd 6,x
	cpd 2,x
	bls L31
	.dbline 109
	ldy #0x1000
	bset 0,y,#128
	.dbline 110
	jsr _PWM_ON
L33:
	.dbline 114
L34:
	ldd #1
	jsr _analog
	addd #10
	std 2,x
	ldd 6,x
	cpd 2,x
	bhi L33
	.dbline 116
	jsr _PWM_OFF
	.dbline 117
	bra L30
L31:
	.dbline 120
	ldd #1
	jsr _analog
	subd #10
	std 2,x
	ldd 6,x
	cpd 2,x
	bhs L36
	.dbline 123
	ldy #0x1000
	bclr 0,y,#0x80
	.dbline 124
	jsr _PWM_ON
L38:
	.dbline 128
L39:
	ldd #1
	jsr _analog
	subd #10
	std 2,x
	ldd 6,x
	cpd 2,x
	blo L38
	.dbline 130
	jsr _PWM_OFF
	.dbline 131
L36:
	.dbline 133
L30:
	inx
	inx
	inx
	inx
	txs
	pulx
	puly
	rts
;  IX -> 0,x
_PWM_ON::
	.dbfunc PWM_ON
	.dbline 140
	ldd #L42
	jsr _printf
	.dbline 141
	ldy #0x1022
	bset 0,y,#64
	.dbline 142
	ldy #0x1020
	bset 0,y,#192
	.dbline 144
L41:
	rts
;  IX -> 0,x
_PWM_OFF::
	.dbfunc PWM_OFF
	.dbline 151
	ldy #0x1022
	bclr 0,y,#0x40
	.dbline 152
	ldy #0x1020
	bset 0,y,#128
	.dbline 153
	ldy #0x100b
	bset 0,y,#64
	.dbline 154
L43:
	rts
;  IX -> 0,x
;  rMEM -> 2,x
_TOC2_isr::
	jsr __enterb
	.byte 0x4
	.dbfunc TOC2_isr
	.dbline 161
; 
; /***************************OC2_ISR****************************/
; void TOC2_isr()
; {//OC2 interrupt; adds duty cycle time to next interrupt and clears flags
; 
; 	if (TCTL1 & 0x40)
	ldy #0x1020
	brclr 0,y,#64,L45
	.dbline 163
; 		{
; 			CLEAR_BIT (TCTL1, 0x40); //Clear bit to set for falling edge next interrupt
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 164
; 			SET_BIT(TCTL1, 0x80);
	ldy #0x1020
	bset 0,y,#128
	.dbline 165
; 			TOC2 += duty_cycle;		//Add time to TOC2 for duty cycle
	; vol
	ldd 0x1018
	addd _duty_cycle
	std 0x1018
	.dbline 166
; 		}
	bra L46
L45:
	.dbline 170
; 
; 	else
; 		{
; 			SET_BIT (TCTL1, 0xC0);
	ldy #0x1020
	bset 0,y,#192
	.dbline 171
; 			TOC2 += (period - duty_cycle);
	ldd _period
	subd _duty_cycle
	std 2,x
	; vol
	ldd 0x1018
	addd 2,x
	std 0x1018
	.dbline 172
; 		}
L46:
	.dbline 175
; 
; 	
; 	CLEAR_FLAG(TFLG1, 0x40); //Clear interrupt flag
	ldy #0x1023
	bclr 0,y,#0xbf
	.dbline 176
; }
L44:
	inx
	inx
	inx
	inx
	txs
	pulx
	rti
	.area bss
_z::
	.blkb 2
_y::
	.blkb 2
_x::
	.blkb 2
_period::
	.blkb 2
_duty_cycle::
	.blkb 2
_timertjp::
	.blkb 2
_days::
	.blkb 2
_hours::
	.blkb 2
_minutes::
	.blkb 2
_seconds::
	.blkb 2
_msec::
	.blkb 2
	.area text
L42:
	.byte 'Y,'o,'u,39,'r,'e,32,'a,'t,32,'P,'W,'M,46,10,0
L29:
	.byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'e,'s,'i,'r,'e
	.byte 'd,32,'p,'o,'s,'i,'t,'i,'o,'n,10,0
L28:
	.byte 'E,'n,'t,'e,'r,32,'n,'u,'m,'b,'e,'r,32,'o,'f,32
	.byte 'e,32,'c,'l,'o,'c,'k,'s,32,'f,'o,'r,32,'t,'h,'e
	.byte 32,'d,'u,'t,'y,32,'c,'y,'c,'l,'e,10,0
L27:
	.byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'n,'u,'m,'b,'e,'r
	.byte 32,'o,'f,32,'c,'l,'o,'c,'k,'s,32,'f,'o,'r,32,'t
	.byte 'h,'e,32,'p,'e,'r,'i,'o,'d,10,0
L23:
	.byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'C,'Y,'L,'I,'N,'D
	.byte 'E,'R,32,'D,'I,'A,'G,'N,'O,'S,'T,'I,'C,32,'P,'R
	.byte 'O,'G,'R,'A,'M,10,10,0
L22:
	.byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
	.byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
	.byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
	.byte 'e,58,9,9,'J,'a,'n,'u,'a,'r,'y,44,32,50,48,48
	.byte 48,10,9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10,0
L21:
	.byte 37,'s,0
