	.module finally2.c
	.dbfile finally2.c
	.area text
;  IX -> 0,x
_SCI_isr::
	.dbfile C:\ICCTJP\include/isrdecl.h
	.dbfunc SCI_isr
	.dbline 41
; /************************************************************************************************************************
; *	Program:		finally.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 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*****************************/
; long duty_cycle;	//duty_cycle in e clocks
; long period;		//period in e clocks
; int error = 0;
; int gain;
; int desired;
; long count = 0;
; 	
; /************************ End of Global Variables ***********************/
; 
; 
L2:
	rti
;  IX -> 0,x
_SPI_isr::
	.dbfunc SPI_isr
	.dbline 47
; /************************** Function Declarations  **********************/
; void init_pulse();		//Initilizes TOC for PWM interrupts
; void pulse_handler();	//This is the function executed at each TOC2_isr
; /******************** 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[]= "\x1b[1;1H";	/*Home*/
;  
; 	SET_BIT(PACTL, 0x80);
; 	CLEAR_BIT(PACTL, 0x03); //Set RTI rate
L5:
	rti
;  IX -> 0,x
_TOF_isr::
	.dbfunc TOF_isr
	.dbline 65
; 	//SET_BIT(TMSK2, 0x40);//Enable RTI interrupt
; 	   	
;  	init_pulse();
;   	init_analog();
;   	init_serial();
; 
L6:
	rti
;  IX -> 0,x
_TOC3_isr::
	.dbfunc TOC3_isr
	.dbline 89
;   	//printf("%s", clear);  
;   	//printf("%s", place);
;   	
;   	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");
; 	printf("Enter the desired period in e clocks / 1000:\n");
; 	period = (read_int() * 1000);
; 	printf("Enter the duty cycle in e clocks / 1000: \n");
; 	duty_cycle = (read_int() * 1000);
; 	INTR_ON();
; 	desired = 150;
; 	INTR_OFF();
; 
; 	
; 	
; 	while(1)
; 	{
; 		SET_BIT(TMSK1, 0x40);//Enable TOC
; 		
; 		if (desired < valve_sensor){
L7:
	rti
;  IX -> 0,x
_TIC3_isr::
	.dbfunc TIC3_isr
	.dbline 101
; 			CLEAR_BIT(PORTA, 0x20);
; 		}
; 		else if (desired> valve_sensor) {
; 			SET_BIT(PORTA, 0x20);
; 		}
; 		else if ((desired <= valve_sensor + TOLERANCE) && (desired >= valve_sensor - TOLERANCE)){
; 			
; 			printf("Here\n");
; 			CLEAR_BIT(TMSK1, 0x40); //Disable TOC
; 		}
; 		
; 	}/*End While*/
L8:
	rti
;  IX -> 0,x
_TIC2_isr::
	.dbfunc TIC2_isr
	.dbline 107
;   	
; }/*End Main*/
; 
; 
; /**************************** End of Main *******************************/
; 
L9:
	rti
;  IX -> 0,x
_TIC1_isr::
	.dbfunc TIC1_isr
	.dbline 113
; 
; 
; /************************** Function Defintions *************************/
; 
; void init_pulse(void)
; {
L10:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 119
; 	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
; 	//INTR_ON();
L11:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 125
; 	
; 	printf("End of Init pulse\n\n");
; }
; 
; void pulse_handler()
; {	printf("ISR");
L12:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 131
; 
; 
; 	//enable toggle
; 	//CLEAR_BIT(TCTL1, 0x80);
; 	//SET_BIT(TCTL1, 0x40);
; 	if (duty_cycle <= 100)	
L13:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 137
; 	//This handles if duty cycle is less than or equal to 50 e clocks ( almost always off)
; 	{
; 		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
; 	}
L14:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 143
; 	
; 	else if ((period - duty_cycle) <= 100)	//This handles what to do if the pin should almost always be high
; 	{
; 		CLEAR_BIT(TCTL1, 0x80);	//Set the pin to rising edge
; 		SET_BIT(TCTL1, 0X40);
; 		TOC2 += period;			//Add period
L15:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 149
; 	}
; 	
; 	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
; 		{
L16:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 155
; 			CLEAR_BIT(TCTL1, 0x40);  //Clear bit 6 to set for falling edge on next interrupt
; 			SET_BIT(TCTL1, 0X80);
; 			TOC2 += duty_cycle;		//Add the duty cycle e clocks if you are now high
; 		}
; 		
; 		else //if(!(TCTL1 & 0x40))	//Test bit 6.  If it is low, you are now low and must change to go high
L17:
	rti
	.area data
_drew::
	.blkw 1
	.area idata
	.word _interrupt_vectors
	.area data
_error::
	.blkb 2
	.area idata
	.word 0
	.area data
_count::
	.blkb 4
	.area idata
	.word 0,0
	.area text
L19:
	.byte 27,91,50,'J,4,0
L20:
	.byte 27,91,49,59,49,'H,0
;  lreg1 -> -4,x
;  lreg2 -> -8,x
;  IX -> 0,x
;  rMEM -> 2,x
;  func temp: 4,x - 12,x
;          place -> 13,x
;          clear -> 20,x
_main::
	jsr __enterb
	.byte 0x9a
	.dbfile finally2.c
	.dbfunc main
	.dbline 53
	ldd 0,x
	addd #20
	ldy #L19
	pshx
	xgdx
	ldd #6
	jsr __asgnblk
	pulx
	.dbline 56
	ldd 0,x
	addd #13
	ldy #L20
	pshx
	xgdx
	ldd #7
	jsr __asgnblk
	pulx
	.dbline 58
	ldy #0x1026
	bset 0,y,#128
	.dbline 59
	ldy #0x1026
	bclr 0,y,#0x3
	.dbline 62
	jsr _init_pulse
	.dbline 63
	jsr _init_analog
	.dbline 64
	jsr _init_serial
	.dbline 69
	ldd #L21
	jsr _printf
	.dbline 74
	ldd #L22
	jsr _printf
	.dbline 75
	ldd #L23
	jsr _printf
	.dbline 76
	jsr _read_int
	std 4,x
	ldd #1000
	ldy 4,x
	jsr __muli
	jsr __d2lreg
	ldy #_period
	jsr __lreg2y
	.dbline 77
	ldd #L24
	jsr _printf
	.dbline 78
	jsr _read_int
	std 6,x
	ldd #1000
	ldy 6,x
	jsr __muli
	jsr __d2lreg
	ldy #_duty_cycle
	jsr __lreg2y
			cli

	.dbline 80
	ldd #150
	std _desired
			sei

	.dbline 81
	jmp L26
L25:
	.dbline 87
	ldy #0x1022
	bset 0,y,#64
	.dbline 89
	ldd #1
	jsr _analog
	std 8,x
	ldd _desired
	cpd 8,x
	bge L28
	.dbline 90
	ldy #0x1000
	bclr 0,y,#0x20
	.dbline 91
	bra L29
L28:
	.dbline 92
	ldd #1
	jsr _analog
	std 10,x
	ldd _desired
	cpd 10,x
	ble L30
	.dbline 93
	ldy #0x1000
	bset 0,y,#32
	.dbline 94
	bra L31
L30:
	.dbline 95
	ldd #1
	jsr _analog
	addd #10
	std 2,x
	ldd _desired
	cpd 2,x
	bgt L32
	ldd #1
	jsr _analog
	subd #10
	std 2,x
	ldd _desired
	cpd 2,x
	blt L32
	.dbline 97
	ldd #L34
	jsr _printf
	.dbline 98
	ldy #0x1022
	bclr 0,y,#0x40
	.dbline 99
L32:
L31:
L29:
	.dbline 101
L26:
	.dbline 85
	jmp L25
L18:
	xgdx
	addd #26
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
_init_pulse::
			sei

	.dbfunc init_pulse
	.dbline 115
	ldy #0x1020
	bset 0,y,#128
	.dbline 116
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 117
	ldd #0
	std 0x1018
	.dbline 118
	ldy #0x1022
	bset 0,y,#64
	.dbline 121
	ldd #L36
	jsr _printf
	.dbline 122
L35:
	rts
;  lreg1 -> -4,x
;  lreg2 -> -8,x
;  IX -> 0,x
_TOC2_isr::
	jsr __enterb
	.byte 0x82
	.dbfunc TOC2_isr
	.dbline 125
	ldd #L38
	jsr _printf
	.dbline 131
	ldy #_duty_cycle
	jsr __ly2reg
	ldy #L41
	jsr __ly2reg2
	jsr __lcmp
	bgt L39
	.dbline 134
	ldy #0x1020
	bset 0,y,#128
	.dbline 135
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 136
	ldy #_period
	jsr __ly2reg2
	; vol
	ldd 0x1018
	jsr __ud2lreg
	jsr __ladd
	jsr __lreg2d
	std 0x1018
	.dbline 137
	jmp L40
L39:
	.dbline 139
	ldy #_period
	jsr __ly2reg
	ldy #_duty_cycle
	jsr __ly2reg2
	jsr __lsub
	ldy #L41
	jsr __ly2reg2
	jsr __lcmp
	bgt L42
	.dbline 141
	ldy #0x1020
	bclr 0,y,#0x80
	.dbline 142
	ldy #0x1020
	bset 0,y,#64
	.dbline 143
	ldy #_period
	jsr __ly2reg2
	; vol
	ldd 0x1018
	jsr __ud2lreg
	jsr __ladd
	jsr __lreg2d
	std 0x1018
	.dbline 144
	bra L43
L42:
	.dbline 148
	ldy #0x1020
	brclr 0,y,#64,L44
	.dbline 150
	ldy #0x1020
	bclr 0,y,#0x40
	.dbline 151
	ldy #0x1020
	bset 0,y,#128
	.dbline 152
	ldy #_duty_cycle
	jsr __ly2reg2
	; vol
	ldd 0x1018
	jsr __ud2lreg
	jsr __ladd
	jsr __lreg2d
	std 0x1018
	.dbline 153
	bra L45
L44:
	.dbline 157
; 		{
; 			SET_BIT(TCTL1, 0xC0);	//Set bit 6 to go high next interrupt
	ldy #0x1020
	bset 0,y,#192
	.dbline 158
; 			TOC2 += (period - duty_cycle);
	ldy #_period
	jsr __ly2reg
	ldy #_duty_cycle
	jsr __ly2reg2
	jsr __lsub
	jsr __lregmov
	; vol
	ldd 0x1018
	jsr __ud2lreg
	jsr __ladd
	jsr __lreg2d
	std 0x1018
	.dbline 159
; 		}
L45:
	.dbline 160
; 	}
L43:
L40:
	.dbline 163
; 	
; 	
; 	CLEAR_FLAG(TFLG1, 0x40)	//Clear the interrupt flag
	ldy #0x1023
	bclr 0,y,#0xbf
	.dbline 164
; }	//This is the end of the interrupt routine
L37:
	inx
	inx
	txs
	pulx
	rti
	.area bss
_desired::
	.blkb 2
_gain::
	.blkb 2
_period::
	.blkb 4
_duty_cycle::
	.blkb 4
_timertjp::
	.blkb 2
_days::
	.blkb 2
_hours::
	.blkb 2
_minutes::
	.blkb 2
_seconds::
	.blkb 2
_msec::
	.blkb 2
	.area text
L41:
	.word 0,100
L38:
	.byte 'I,'S,'R,0
L36:
	.byte 'E,'n,'d,32,'o,'f,32,'I,'n,'i,'t,32,'p,'u,'l,'s
	.byte 'e,10,10,0
L34:
	.byte 'H,'e,'r,'e,10,0
L24:
	.byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'u,'t,'y,32,'c
	.byte 'y,'c,'l,'e,32,'i,'n,32,'e,32,'c,'l,'o,'c,'k,'s
	.byte 32,47,32,49,48,48,48,58,32,10,0
L23:
	.byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'e,'s,'i,'r,'e
	.byte 'd,32,'p,'e,'r,'i,'o,'d,32,'i,'n,32,'e,32,'c,'l
	.byte 'o,'c,'k,'s,32,47,32,49,48,48,48,58,10,0
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
