	.module valve5.c
	.dbfile valve5.c
	.area text
;  IX -> 0,x
_SCI_isr::
	.dbfile C:\ICCTJP\include/isrdecl.h
	.dbfunc SCI_isr
	.dbline 41
; /************************************************************************************************************************
; *	Program:		valve5.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					*
; *	Date:			February 3, 2000					*
; ************************************************************************************************************************/
; 
; /**************************** Constants *********************************/
; #define pulse_handler TOC2_isr
; #define TOLERANCE 5 
; #define valve_sensor analog(1)
; #define in	0
; #define out 1
; /**************************** End of Constants **************************/
; 
; /*************************** Interrupts *********************************/
; #pragma interrupt_handler TOC2_isr, TOF_isr, RTI_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;	//duty_cycle in e clocks
; unsigned int period;		//period in e clocks
; int position;
; /************************ End of Global Variables ***********************/
; 
; 
; /************************** Function Declarations  **********************/
; void init_pulse();		//Initilizes TOC for PWM interrupts
L2:
	rti
;  IX -> 0,x
_SPI_isr::
	.dbfunc SPI_isr
	.dbline 47
; void move(int);
; void pulse_handler();	//This is the function executed at each TOC2_isr
; void move_cylinder(int);
; /******************** End of Function Declarations  *********************/
; 
; 
L3:
	rti
;  IX -> 0,x
_PAIE_isr::
	.dbfunc PAIE_isr
	.dbline 53
; /**************************** Main **************************************/
; 
; void main(void)
; {
; 	/* VT100 clear screen */ 
; 	char clear[]= "\x1b\x5B\x32\x4A\x04"; 
L4:
	rti
;  IX -> 0,x
_PAV_isr::
	.dbfunc PAV_isr
	.dbline 59
; 	
; 	/* VT100 position cursor at (x,y) = (3,12) command is "\x1b[3;12H"*/
;   	char place_home[]= "\x1b[1;1H";	/*Home*/
;   	
;   	char place_text[] = "\x1b[10;1H";/*position for text to be entered*/
;   	
L5:
	rti
;  IX -> 0,x
_TOC3_isr::
	.dbfunc TOC3_isr
	.dbline 89
;   	int duty_cycle_P;
; 	int period_ms;
; 	int desired_position  = 150;
; 	int option;
; 	
; 	SET_BIT(PACTL, 0x80);  	
;  	init_pulse();
;   	init_analog();
;   	init_serial();
; 
;   	printf("%s", clear);  
;     printf("%s", place_home);
;   	
;   	printf("\tTitle:\t\tvalve.c\n"
;   "\tProgrammer:\tScott Nortman\n"
;   "\tDate:\t\tFebruary, 2000\n"
;   "\tVersion\t\t1\n\n");
;   
; 	printf("PNEUMATIC CYLINDER DIAGNOSTIC PROGRAM\n\n");
; 	period = 30000;
; 	duty_cycle = 15000;
; 	INTR_OFF();
; 	while (1){
; 		INTR_ON();
; 		while (desired_position < valve_sensor){
; 			CLEAR_BIT(PORTA, 0x20);
; 		}
; 		while (desired_position > valve_sensor) {
; 			SET_BIT(PORTA, 0x20);
; 		}
L6:
	rti
;  IX -> 0,x
_TIC3_isr::
	.dbfunc TIC3_isr
	.dbline 101
; 		while ((desired_position <= valve_sensor + TOLERANCE) && (desired_position >= valve_sensor - TOLERANCE)){
; 			INTR_OFF();
; 		}
; 	}
; 	
; }
; 
; 
; /**************************** End of Main *******************************/
; 
; 
; 
L7:
	rti
;  IX -> 0,x
_TIC2_isr::
	.dbfunc TIC2_isr
	.dbline 107
; /************************** Function Defintions *************************/
; 
; void move_cylinder(int desired_position)
; {
; 	int real_position;
; 	//while (real_position != desired_position)
L8:
	rti
;  IX -> 0,x
_TIC1_isr::
	.dbfunc TIC1_isr
	.dbline 113
; 	//{
; 		real_position = valve_sensor;
; 		if (real_position > desired_position)
; 		{
; 			CLEAR_BIT(PORTA, 0x20);
; 		}
L9:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 125
; 		else
; 		{
; 			SET_BIT(PORTA, 0x20);
; 		}
; 		INTR_ON();
; 	//}
; 	
; 	INTR_OFF();	
; 	CLEAR_BIT(PORTA, 0x40);		//Set to go low when not interrupting
; }
; 
; void init_pulse(void)
L10:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 131
; {
; 	INTR_OFF();
; 	SET_BIT(TCTL1, 0x80);	//Enable OC2 for falling edge on first sucessful compare (safe default)
; 	CLEAR_BIT(TCTL1, 0x40);
; 	TOC2 = 0;	//Set TOC2 to zero
; 	SET_BIT(TMSK1, 0x40);	//Enable OC2 mask	
L11:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 137
; 	//printf("End of Init pulse\n\n");
; }
; 
; void pulse_handler()
; {	//printf("ISR\n");
; 
L12:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 143
; 	//enable toggle
; 	//CLEAR_BIT(TCTL1, 0x80);
; 	//SET_BIT(TCTL1, 0x40);
; 	if (duty_cycle <= 100)	
; 	//This handles if duty cycle is less than or equal to 100 e clocks ( almost always off)
; 	{
L13:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 149
; 		SET_BIT(TCTL1, 0x80);	//Enable OC2 for falling edge (make sure pin goes low)
; 		CLEAR_BIT(TCTL1, 0X40);
; 		TOC2 += period;			//Add the period to TOC2
; 	}
; 	
; 	else if ((period - duty_cycle) <= 100)	//This handles what to do if the pin should almost always be high
L14:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 155
; 	{
; 		CLEAR_BIT(TCTL1, 0x80);	//Set the pin to rising edge
; 		SET_BIT(TCTL1, 0X40);
; 		TOC2 += period;			//Add period
; 	}
; 	
L15:
	rti
	.area data
_drew::
	.blkw 1
	.area idata
	.word _interrupt_vectors
	.area text
L17:
	.byte 27,91,50,'J,4,0
L18:
	.byte 27,91,49,59,49,'H,0
L19:
	.byte 27,91,49,48,59,49,'H,0
;  IX -> 0,x
;  rMEM -> 2,x
;  func temp: 4,x - 8,x
;         option -> 9,x
;      period_ms -> 11,x
;   duty_cycle_P -> 13,x
;     place_text -> 15,x
;     place_home -> 23,x
;          clear -> 30,x
; desired_position -> 36,x
_main::
	jsr __enterb
	.byte 0x26
	.dbfile valve5.c
	.dbfunc main
	.dbline 53
	ldd 0,x
	addd #30
	ldy #L17
	pshx
	xgdx
	ldd #6
	jsr __asgnblk
	pulx
	.dbline 56
	ldd 0,x
	addd #23
	ldy #L18
	pshx
	xgdx
	ldd #7
	jsr __asgnblk
	pulx
	.dbline 58
	ldd 0,x
	addd #15
	ldy #L19
	pshx
	xgdx
	ldd #8
	jsr __asgnblk
	pulx
	.dbline 62
	ldd #150
	std 36,x
	.dbline 65
	ldy #0x1026
	bset 0,y,#128
	.dbline 66
	jsr _init_pulse
	.dbline 67
	jsr _init_analog
	.dbline 68
	jsr _init_serial
	.dbline 70
	ldd 0,x
	addd #30
	pshb
	psha
	ldd #L20
	jsr _printf
	puly
	.dbline 71
	ldd 0,x
	addd #23
	pshb
	psha
	ldd #L20
	jsr _printf
	puly
	.dbline 73
	ldd #L21
	jsr _printf
	.dbline 78
	ldd #L22
	jsr _printf
	.dbline 79
	ldd #30000
	std _period
	.dbline 80
	ldd #15000
	std _duty_cycle
			sei

	.dbline 81
	bra L24
L23:
			cli

	.dbline 83
	bra L27
L26:
	.dbline 85
	ldy #0x1000
	bclr 0,y,#0x20
	.dbline 86
L27:
	ldd #1
	jsr _analog
	std 4,x
	ldd 36,x
	cpd 4,x
	blt L26
	bra L30
L29:
	.dbline 88
	ldy #0x1000
	bset 0,y,#32
	.dbline 89
L30:
	ldd #1
	jsr _analog
	std 6,x
	ldd 36,x
	cpd 6,x
	bgt L29
	bra L33
L32:
			sei

	.dbline 92
L33:
	ldd #1
	jsr _analog
	addd #5
	std 2,x
	ldd 36,x
	cpd 2,x
	bgt L35
	ldd #1
	jsr _analog
	subd #5
	std 2,x
	ldd 36,x
	cpd 2,x
	bge L32
L35:
	.dbline 93
L24:
	bra L23
L16:
	xgdx
	addd #38
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
;  real_position -> 2,x
; desired_position -> 6,x
_move_cylinder::
	jsr __enterb
	.byte 0x44
	.dbfunc move_cylinder
	.dbline 109
	ldd #1
	jsr _analog
	std 2,x
	.dbline 110
	ldd 2,x
	cpd 6,x
	ble L37
	.dbline 112
	ldy #0x1000
	bclr 0,y,#0x20
	.dbline 113
	bra L38
L37:
	.dbline 116
	ldy #0x1000
	bset 0,y,#32
	.dbline 117
L38:
			cli

			sei

	.dbline 122
	ldy #0x1000
	bclr 0,y,#0x40
	.dbline 123
L36:
	inx
	inx
	inx
	inx
	txs
	pulx
	puly
	rts
;  IX -> 0,x
_init_pulse::
			sei

	.dbfunc init_pulse
	.dbline 128
	ldy #0x1020
	bset 0,y,#128
	.dbline 129
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 130
	ldd #0
	std 0x1018
	.dbline 131
	ldy #0x1022
	bset 0,y,#64
	.dbline 133
L39:
	rts
;  IX -> 0,x
;  rMEM -> 2,x
_TOC2_isr::
	jsr __enterb
	.byte 0x4
	.dbfunc TOC2_isr
	.dbline 141
	ldd _duty_cycle
	cpd #100
	bhi L41
	.dbline 144
	ldy #0x1020
	bset 0,y,#128
	.dbline 145
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 146
	; vol
	ldd 0x1018
	addd _period
	std 0x1018
	.dbline 147
	bra L42
L41:
	.dbline 149
	ldd _period
	subd _duty_cycle
	cpd #100
	bhi L43
	.dbline 151
	ldy #0x1020
	bclr 0,y,#0x80
	.dbline 152
	ldy #0x1020
	bset 0,y,#64
	.dbline 153
	; vol
	ldd 0x1018
	addd _period
	std 0x1018
	.dbline 154
	bra L44
L43:
	.dbline 158
; 	else		//This is for the general case
; 	{
; 		if (TCTL1 & 0x40)	//Test bit 6.  If it is a one, you are now high and must change to go low
	ldy #0x1020
	brclr 0,y,#64,L45
	.dbline 160
; 		{
; 			CLEAR_BIT(TCTL1, 0x40);  //Clear bit 6 to set for falling edge on next interrupt
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 161
; 			SET_BIT(TCTL1, 0X80);
	ldy #0x1020
	bset 0,y,#128
	.dbline 162
; 			TOC2 += duty_cycle;		//Add the duty cycle e clocks if you are now high
	; vol
	ldd 0x1018
	addd _duty_cycle
	std 0x1018
	.dbline 163
; 		}
	bra L46
L45:
	.dbline 167
; 		
; 		else 	//Test bit 6.  If it is low, you are now low and must change to go high
; 		{
; 			SET_BIT(TCTL1, 0xC0);	//Set bit 6 to go high next interrupt
	ldy #0x1020
	bset 0,y,#192
	.dbline 168
; 			TOC2 += (period - duty_cycle);
	ldd _period
	subd _duty_cycle
	std 2,x
	; vol
	ldd 0x1018
	addd 2,x
	std 0x1018
	.dbline 169
; 		}
L46:
	.dbline 170
; 	}
L44:
L42:
	.dbline 173
; 	
; 	
; 	CLEAR_FLAG(TFLG1, 0x40)	//Clear the interrupt flag
	ldy #0x1023
	bclr 0,y,#0xbf
	.dbline 174
; }	//This is the end of the interrupt routine
L40:
	inx
	inx
	inx
	inx
	txs
	pulx
	rti
;  IX -> 0,x
_TOF_isr::
	.dbfunc TOF_isr
	.dbline 176
; 
; void TOF_isr(void){}
L47:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 178
; 
; void RTI_isr(void){}
L48:
	rti
	.area bss
_position::
	.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
L22:
	.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
L21:
	.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,'F,'e,'b,'r,'u,'a,'r,'y,44,32,50,48
	.byte 48,48,10,9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10
	.byte 0
L20:
	.byte 37,'s,0
