	.module valve3.c
	.dbfile valve3.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 TOC3_isr
; /*************************** End of Interrupts **************************/
; 
; /************************** Includes ************************************/
; #include <stdio.h>
; #include <tjpbase.h>
; #include <analog.h>
; #include <vectors.h>
; #include <math.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);
L2:
	rti
;  IX -> 0,x
_SPI_isr::
	.dbfunc SPI_isr
	.dbline 47
; void PWM_ON ();
; void PWM_OFF();
; /******************** End of Function Declarations  *********************/
; 
; 
; /**************************** Main **************************************/
L3:
	rti
;  IX -> 0,x
_PAIE_isr::
	.dbfunc PAIE_isr
	.dbline 53
; 
; unsigned int x, y, z;
; 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);  	
;   	init_analog();
L5:
	rti
;  IX -> 0,x
_TOF_isr::
	.dbfunc TOF_isr
	.dbline 65
;   	init_clocktjp();
;   	init_serial();
; 
;   	INTR_ON(); /*turn on HC11 interrupt system*/
; 
;   	printf("%s", clear);  
L6:
	rti
;  IX -> 0,x
_TOC2_isr::
	.dbfunc TOC2_isr
	.dbline 83
;   	printf("%s", place);
;   	
;   	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 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);
; 		
L7:
	rti
;  IX -> 0,x
_TIC3_isr::
	.dbfunc TIC3_isr
	.dbline 101
; //		printf("%s", clear);  
;  //		printf("%s", place);
; 		
; 	}/*End While*/
;   	
; }/*End Main*/
; 
; 
; /**************************** 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
; 		}
L10:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 119
; 		
; 		PWM_OFF(); //Turn off PWM system
; 		return;
; 	} 
; 	
; 	if (position < (valve_sensor - tolerance))
L11:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 125
; 	{
; 		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
; 		
; 		while (position < (valve_sensor - tolerance)){//wait until position is in desired range
L12:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 131
; 			}	
; 		
; 		PWM_OFF();
; 		return;
; 	}
; }
L13:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 137
;     
; 
; 
; /***************************PWM_ON*****************************/
; void PWM_ON()//This is the function to generate PWM
; {//This turns on the PWM system on OC2 and enables toggle
L14:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 143
; 	printf("You're at PWM.\n");
; 	SET_BIT(TMSK1, 0x20); //Enable interrupt on OC2
; 	SET_BIT(TCTL1, 0x10); //Enable toggle
; 	
; }
; 
L15:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 149
; 
; /****************************PWM_OFF***************************/
; void PWM_OFF()
; {//This turns off the PWM system on OC3 and sets the line to 0
; 	CLEAR_BIT(TMSK1, 0x20); //Disable interrupt on OC3
; 	SET_BIT(TCTL1, 0x20); //set OC3 line to 0 on compare
L16:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 155
; 	SET_BIT(CFORC, 0x20); //force successful compare
; }
; 
; 
; /***************************OC3_ISR****************************/
; void TOC3_isr()
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 valve3.c
	.dbfunc main
	.dbline 53
	ldd 0,x
	addd #10
	ldy #L19
	pshx
	xgdx
	ldd #6
	jsr __asgnblk
	pulx
	.dbline 56
	ldd 0,x
	addd #3
	ldy #L20
	pshx
	xgdx
	ldd #7
	jsr __asgnblk
	pulx
	.dbline 58
	ldy #0x1026
	bset 0,y,#128
	.dbline 59
	jsr _init_analog
	.dbline 60
	jsr _init_clocktjp
	.dbline 61
	jsr _init_serial
			cli

	.dbline 65
	ldd 0,x
	addd #10
	pshb
	psha
	ldd #L21
	jsr _printf
	puly
	.dbline 66
	ldd 0,x
	addd #3
	pshb
	psha
	ldd #L21
	jsr _printf
	puly
	.dbline 68
	ldd #L22
	jsr _printf
	.dbline 73
	ldd #L23
	jsr _printf
	bra L25
L24:
	.dbline 77
	ldd #L27
	jsr _printf
	.dbline 78
	jsr _read_int
	std _duty_cycle
	.dbline 79
	ldd #L28
	jsr _printf
	.dbline 80
	jsr _read_int
	std _z
	.dbline 82
	ldd _z
	jsr _valve_position
	.dbline 87
L25:
	.dbline 75
	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 105
	ldd #L30
	jsr _printf
	.dbline 106
	ldd #1
	jsr _analog
	addd #10
	std 2,x
	ldd 6,x
	cpd 2,x
	bls L31
	.dbline 108
	ldd #1
	jsr _analog
	pshb
	psha
	ldd #L33
	jsr _printf
	puly
	.dbline 109
	ldy #0x1000
	bset 0,y,#128
	.dbline 110
	jsr _PWM_ON
L34:
	.dbline 113
L35:
	ldd #1
	jsr _analog
	addd #10
	std 2,x
	ldd 6,x
	cpd 2,x
	bhi L34
	.dbline 115
	jsr _PWM_OFF
	.dbline 116
	bra L29
L31:
	.dbline 119
	ldd #1
	jsr _analog
	subd #10
	std 2,x
	ldd 6,x
	cpd 2,x
	bhs L37
	.dbline 121
	ldd #1
	jsr _analog
	pshb
	psha
	ldd #L33
	jsr _printf
	puly
	.dbline 122
	ldy #0x1000
	bclr 0,y,#0x80
	.dbline 123
	jsr _PWM_ON
L39:
	.dbline 126
L40:
	ldd #1
	jsr _analog
	subd #10
	std 2,x
	ldd 6,x
	cpd 2,x
	blo L39
	.dbline 128
	jsr _PWM_OFF
	.dbline 129
L37:
	.dbline 131
L29:
	inx
	inx
	inx
	inx
	txs
	pulx
	puly
	rts
;  IX -> 0,x
_PWM_ON::
	.dbfunc PWM_ON
	.dbline 138
	ldd #L43
	jsr _printf
	.dbline 139
	ldy #0x1022
	bset 0,y,#32
	.dbline 140
	ldy #0x1020
	bset 0,y,#16
	.dbline 142
L42:
	rts
;  IX -> 0,x
_PWM_OFF::
	.dbfunc PWM_OFF
	.dbline 148
	ldy #0x1022
	bclr 0,y,#0x20
	.dbline 149
	ldy #0x1020
	bset 0,y,#32
	.dbline 150
	ldy #0x100b
	bset 0,y,#32
	.dbline 151
L44:
	rts
;  IX -> 0,x
_TOC3_isr::
	.dbfunc TOC3_isr
	.dbline 157
; {//OC3 interrupt; adds duty cycle time to next interrupt and clears flags
; 	TOC3 += duty_cycle;   //Add time to TOC2 for duty cycle	
	; vol
	ldd 0x101a
	addd _duty_cycle
	std 0x101a
	.dbline 158
; 	CLEAR_FLAG(TFLG1, 0x20); //Clear interrupt flag
	ldy #0x1023
	bclr 0,y,#0xdf
	.dbline 159
; }
L45:
	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
L43:
	.byte 'Y,'o,'u,39,'r,'e,32,'a,'t,32,'P,'W,'M,46,10,0
L33:
	.byte 'T,'h,'e,32,'a,'n,'a,'l,'o,'g,32,'v,'a,'l,'u,'e
	.byte 32,'i,'s,58,9,37,'d,10,0
L30:
	.byte 'Y,'o,'u,39,'r,'e,32,32,'a,'t,32,'t,'h,'e,32,'b
	.byte 'e,'g,'i,'n,'n,'i,'n,'g,32,'o,'f,32,'v,'a,'l,'v
	.byte 'e,95,'p,'o,'s,'i,'t,'i,'o,'n,46,10,0
L28:
	.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
L27:
	.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
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
