                         .module valve2.c
 0000                   .dbfile valve2.c
                         .area text
                       ;  IX -> 0,x
 0000                 _SCI_isr::
 0000                   .dbfile C:\ICCTJP\include/isrdecl.h
 0000                   .dbfunc SCI_isr
 0000                   .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();
 0000                 L2:
 0000 3B                rti
                       ;  IX -> 0,x
 0001                 _SPI_isr::
 0001                   .dbfunc SPI_isr
 0001                   .dbline 47
                       ; /******************** End of Function Declarations  *********************/
                       ; 
                       ; 
                       ; /**************************** Main **************************************/
                       ; 
                       ; unsigned int x, y, z;
 0001                 L3:
 0001 3B                rti
                       ;  IX -> 0,x
 0002                 _PAIE_isr::
 0002                   .dbfunc PAIE_isr
 0002                   .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"*/
 0002                 L4:
 0002 3B                rti
                       ;  IX -> 0,x
 0003                 _PAV_isr::
 0003                   .dbfunc PAV_isr
 0003                   .dbline 59
                       ;     char place[]= "\x1b[1;1H";  /*Home*/
                       ;     
                       ;     SET_BIT(PACTL, 0x80);   
                       ;     init_analog();
                       ;     init_clocktjp();
                       ;     init_serial();
 0003                 L5:
 0003 3B                rti
                       ;  IX -> 0,x
 0004                 _TOF_isr::
 0004                   .dbfunc TOF_isr
 0004                   .dbline 65
                       ; 
                       ;     INTR_ON(); /*turn on HC11 interrupt system*/
                       ; 
                       ;     printf("%s", clear);  
                       ;     printf("%s", place);
                       ;     
 0004                 L6:
 0004 3B                rti
                       ;  IX -> 0,x
 0005                 _TOC3_isr::
 0005                   .dbfunc TOC3_isr
 0005                   .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*/
 0005                 L7:
 0005 3B                rti
                       ;  IX -> 0,x
 0006                 _TIC3_isr::
 0006                   .dbfunc TIC3_isr
 0006                   .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
 0006                 L8:
 0006 3B                rti
                       ;  IX -> 0,x
 0007                 _TIC2_isr::
 0007                   .dbfunc TIC2_isr
 0007                   .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
                       ;     {
 0007                 L9:
 0007 3B                rti
                       ;  IX -> 0,x
 0008                 _TIC1_isr::
 0008                   .dbfunc TIC1_isr
 0008                   .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);
 0008                 L10:
 0008 3B                rti
                       ;  IX -> 0,x
 0009                 _RTI_isr::
 0009                   .dbfunc RTI_isr
 0009                   .dbline 119
                       ;         }
                       ;         
                       ;         PWM_OFF(); //Turn off PWM system
                       ;         return;
                       ;     } 
                       ;     
 0009                 L11:
 0009 3B                rti
                       ;  IX -> 0,x
 000A                 _IRQ_isr::
 000A                   .dbfunc IRQ_isr
 000A                   .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
                       ;         
 000A                 L12:
 000A 3B                rti
                       ;  IX -> 0,x
 000B                 _XIRQ_isr::
 000B                   .dbfunc XIRQ_isr
 000B                   .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;
 000B                 L13:
 000B 3B                rti
                       ;  IX -> 0,x
 000C                 _SWI_isr::
 000C                   .dbfunc SWI_isr
 000C                   .dbline 137
                       ;     }
                       ; }
                       ;     
                       ; 
                       ; 
                       ; /***************************PWM_ON*****************************/
 000C                 L14:
 000C 3B                rti
                       ;  IX -> 0,x
 000D                 _ILLOP_isr::
 000D                   .dbfunc ILLOP_isr
 000D                   .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
                       ;     
 000D                 L15:
 000D 3B                rti
                       ;  IX -> 0,x
 000E                 _COP_isr::
 000E                   .dbfunc COP_isr
 000E                   .dbline 149
                       ; }
                       ; 
                       ; 
                       ; /****************************PWM_OFF***************************/
                       ; void PWM_OFF()
                       ; {//This turns off the PWM system on OC2 and sets the line to 0
 000E                 L16:
 000E 3B                rti
                       ;  IX -> 0,x
 000F                 _CLMON_isr::
 000F                   .dbfunc CLMON_isr
 000F                   .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
                       ; }
                       ; 
 000F                 L17:
 000F 3B                rti
                         .area data
 0000                 _drew::
 0000                   .blkw 1
                         .area idata
 0000 0000              .word _interrupt_vectors
                         .area text
 0010                 L19:
 0010 1B5B324A0400      .byte 27,91,50,'J,4,0
 0016                 L20:
 0016 1B5B313B314800    .byte 27,91,49,59,49,'H,0
                       ;  IX -> 0,x
                       ;          place -> 3,x
                       ;          clear -> 10,x
 001D                 _main::
 001D BD0000            jsr __enterb
 0020 10                .byte 0x10
 0021                   .dbfile valve2.c
 0021                   .dbfunc main
 0021                   .dbline 51
 0021 EC00              ldd 0,x
 0023 C3000A            addd #10
 0026 18CE0010          ldy #L19
 002A 3C                pshx
 002B 8F                xgdx
 002C CC0006            ldd #6
 002F BD0000            jsr __asgnblk
 0032 38                pulx
 0033                   .dbline 54
 0033 EC00              ldd 0,x
 0035 C30003            addd #3
 0038 18CE0016          ldy #L20
 003C 3C                pshx
 003D 8F                xgdx
 003E CC0007            ldd #7
 0041 BD0000            jsr __asgnblk
 0044 38                pulx
 0045                   .dbline 56
 0045 18CE1026          ldy #0x1026
 0049 181C0080          bset 0,y,#128
 004D                   .dbline 57
 004D BD0000            jsr _init_analog
 0050                   .dbline 58
 0050 BD0000            jsr _init_clocktjp
 0053                   .dbline 59
 0053 BD0000            jsr _init_serial
 0056 0E                        cli
                       
 0057                   .dbline 63
 0057 EC00              ldd 0,x
 0059 C3000A            addd #10
 005C 37                pshb
 005D 36                psha
 005E CC02A5            ldd #L21
 0061 BD0000            jsr _printf
 0064 1838              puly
 0066                   .dbline 64
 0066 EC00              ldd 0,x
 0068 C30003            addd #3
 006B 37                pshb
 006C 36                psha
 006D CC02A5            ldd #L21
 0070 BD0000            jsr _printf
 0073 1838              puly
 0075                   .dbline 66
 0075 CC0255            ldd #L22
 0078 BD0000            jsr _printf
 007B                   .dbline 71
 007B CC022D            ldd #L23
 007E BD0000            jsr _printf
 0081 202A              bra L25
 0083                 L24:
 0083                   .dbline 75
 0083 CC0202            ldd #L27
 0086 BD0000            jsr _printf
 0089                   .dbline 76
 0089 BD0000            jsr _read_int
 008C FD0006            std _period
 008F                   .dbline 77
 008F CC01D5            ldd #L28
 0092 BD0000            jsr _printf
 0095                   .dbline 78
 0095 BD0000            jsr _read_int
 0098 FD0008            std _duty_cycle
 009B                   .dbline 79
 009B CC01B9            ldd #L29
 009E BD0000            jsr _printf
 00A1                   .dbline 80
 00A1 BD0000            jsr _read_int
 00A4 FD0000            std _z
 00A7                   .dbline 82
 00A7 FC0000            ldd _z
 00AA BD00B7            jsr _valve_position
 00AD                   .dbline 87
 00AD                 L25:
 00AD                   .dbline 73
 00AD 20D4              bra L24
 00AF                 L18:
 00AF 8F                xgdx
 00B0 C30010            addd #16
 00B3 8F                xgdx
 00B4 35                txs
 00B5 38                pulx
 00B6 39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;       position -> 6,x
 00B7                 _valve_position::
 00B7 BD0000            jsr __enterb
 00BA 44                .byte 0x44
 00BB                   .dbfunc valve_position
 00BB                   .dbline 106
 00BB CC0001            ldd #1
 00BE BD0000            jsr _analog
 00C1 C3000A            addd #10
 00C4 ED02              std 2,x
 00C6 EC06              ldd 6,x
 00C8 1AA302            cpd 2,x
 00CB 2322              bls L31
 00CD                   .dbline 109
 00CD 18CE1000          ldy #0x1000
 00D1 181C0080          bset 0,y,#128
 00D5                   .dbline 110
 00D5 BD012A            jsr _PWM_ON
 00D8                 L33:
 00D8                   .dbline 114
 00D8                 L34:
 00D8 CC0001            ldd #1
 00DB BD0000            jsr _analog
 00DE C3000A            addd #10
 00E1 ED02              std 2,x
 00E3 EC06              ldd 6,x
 00E5 1AA302            cpd 2,x
 00E8 22EE              bhi L33
 00EA                   .dbline 116
 00EA BD0141            jsr _PWM_OFF
 00ED                   .dbline 117
 00ED 2032              bra L30
 00EF                 L31:
 00EF                   .dbline 120
 00EF CC0001            ldd #1
 00F2 BD0000            jsr _analog
 00F5 83000A            subd #10
 00F8 ED02              std 2,x
 00FA EC06              ldd 6,x
 00FC 1AA302            cpd 2,x
 00FF 2420              bhs L36
 0101                   .dbline 123
 0101 18CE1000          ldy #0x1000
 0105 181D0080          bclr 0,y,#0x80
 0109                   .dbline 124
 0109 BD012A            jsr _PWM_ON
 010C                 L38:
 010C                   .dbline 128
 010C                 L39:
 010C CC0001            ldd #1
 010F BD0000            jsr _analog
 0112 83000A            subd #10
 0115 ED02              std 2,x
 0117 EC06              ldd 6,x
 0119 1AA302            cpd 2,x
 011C 25EE              blo L38
 011E                   .dbline 130
 011E BD0141            jsr _PWM_OFF
 0121                   .dbline 131
 0121                 L36:
 0121                   .dbline 133
 0121                 L30:
 0121 08                inx
 0122 08                inx
 0123 08                inx
 0124 08                inx
 0125 35                txs
 0126 38                pulx
 0127 1838              puly
 0129 39                rts
                       ;  IX -> 0,x
 012A                 _PWM_ON::
 012A                   .dbfunc PWM_ON
 012A                   .dbline 140
 012A CC01A9            ldd #L42
 012D BD0000            jsr _printf
 0130                   .dbline 141
 0130 18CE1022          ldy #0x1022
 0134 181C0040          bset 0,y,#64
 0138                   .dbline 142
 0138 18CE1020          ldy #0x1020
 013C 181C00C0          bset 0,y,#192
 0140                   .dbline 144
 0140                 L41:
 0140 39                rts
                       ;  IX -> 0,x
 0141                 _PWM_OFF::
 0141                   .dbfunc PWM_OFF
 0141                   .dbline 151
 0141 18CE1022          ldy #0x1022
 0145 181D0040          bclr 0,y,#0x40
 0149                   .dbline 152
 0149 18CE1020          ldy #0x1020
 014D 181C0080          bset 0,y,#128
 0151                   .dbline 153
 0151 18CE100B          ldy #0x100b
 0155 181C0040          bset 0,y,#64
 0159                   .dbline 154
 0159                 L43:
 0159 39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
 015A                 _TOC2_isr::
 015A BD0000            jsr __enterb
 015D 04                .byte 0x4
 015E                   .dbfunc TOC2_isr
 015E                   .dbline 161
                       ; 
                       ; /***************************OC2_ISR****************************/
                       ; void TOC2_isr()
                       ; {//OC2 interrupt; adds duty cycle time to next interrupt and clears flags
                       ; 
                       ;     if (TCTL1 & 0x40)
 015E 18CE1020          ldy #0x1020
 0162 181F00401B        brclr 0,y,#64,L45
 0167                   .dbline 163
                       ;         {
                       ;             CLEAR_BIT (TCTL1, 0x40); //Clear bit to set for falling edge next interrupt
 0167 18CE1020          ldy #0x1020
 016B 181D0040          bclr 0,y,#0x40
 016F                   .dbline 164
                       ;             SET_BIT(TCTL1, 0x80);
 016F 18CE1020          ldy #0x1020
 0173 181C0080          bset 0,y,#128
 0177                   .dbline 165
                       ;             TOC2 += duty_cycle;     //Add time to TOC2 for duty cycle
                         ; vol
 0177 FC1018            ldd 0x1018
 017A F30008            addd _duty_cycle
 017D FD1018            std 0x1018
 0180                   .dbline 166
                       ;         }
 0180 2018              bra L46
 0182                 L45:
 0182                   .dbline 170
                       ; 
                       ;     else
                       ;         {
                       ;             SET_BIT (TCTL1, 0xC0);
 0182 18CE1020          ldy #0x1020
 0186 181C00C0          bset 0,y,#192
 018A                   .dbline 171
                       ;             TOC2 += (period - duty_cycle);
 018A FC0006            ldd _period
 018D B30008            subd _duty_cycle
 0190 ED02              std 2,x
                         ; vol
 0192 FC1018            ldd 0x1018
 0195 E302              addd 2,x
 0197 FD1018            std 0x1018
 019A                   .dbline 172
                       ;         }
 019A                 L46:
 019A                   .dbline 175
                       ; 
                       ;     
                       ;     CLEAR_FLAG(TFLG1, 0x40); //Clear interrupt flag
 019A 18CE1023          ldy #0x1023
 019E 181D00BF          bclr 0,y,#0xbf
 01A2                   .dbline 176
                       ; }
 01A2                 L44:
 01A2 08                inx
 01A3 08                inx
 01A4 08                inx
 01A5 08                inx
 01A6 35                txs
 01A7 38                pulx
 01A8 3B                rti
                         .area bss
 0000                 _z::
 0000                   .blkb 2
 0002                 _y::
 0002                   .blkb 2
 0004                 _x::
 0004                   .blkb 2
 0006                 _period::
 0006                   .blkb 2
 0008                 _duty_cycle::
 0008                   .blkb 2
 000A                 _timertjp::
 000A                   .blkb 2
 000C                 _days::
 000C                   .blkb 2
 000E                 _hours::
 000E                   .blkb 2
 0010                 _minutes::
 0010                   .blkb 2
 0012                 _seconds::
 0012                   .blkb 2
 0014                 _msec::
 0014                   .blkb 2
                         .area text
 01A9                 L42:
 01A9 596F752772652061742050574D2E0A00  .byte 'Y,'o,'u,39,'r,'e,32,'a,'t,32,'P,'W,'M,46,10,0
 01B9                 L29:
 01B9 456E7465722074686520646573697265  .byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'e,'s,'i,'r,'e
 01C9 6420706F736974696F6E0A00  .byte 'd,32,'p,'o,'s,'i,'t,'i,'o,'n,10,0
 01D5                 L28:
 01D5 456E746572206E756D626572206F6620  .byte 'E,'n,'t,'e,'r,32,'n,'u,'m,'b,'e,'r,32,'o,'f,32
 01E5 6520636C6F636B7320666F7220746865  .byte 'e,32,'c,'l,'o,'c,'k,'s,32,'f,'o,'r,32,'t,'h,'e
 01F5 2064757479206379636C650A00    .byte 32,'d,'u,'t,'y,32,'c,'y,'c,'l,'e,10,0
 0202                 L27:
 0202 456E74657220746865206E756D626572  .byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'n,'u,'m,'b,'e,'r
 0212 206F6620636C6F636B7320666F722074  .byte 32,'o,'f,32,'c,'l,'o,'c,'k,'s,32,'f,'o,'r,32,'t
 0222 686520706572696F640A00    .byte 'h,'e,32,'p,'e,'r,'i,'o,'d,10,0
 022D                 L23:
 022D 504E45554D415449432043594C494E44  .byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'C,'Y,'L,'I,'N,'D
 023D 455220444941474E4F53544943205052  .byte 'E,'R,32,'D,'I,'A,'G,'N,'O,'S,'T,'I,'C,32,'P,'R
 024D 4F4752414D0A0A00  .byte 'O,'G,'R,'A,'M,10,10,0
 0255                 L22:
 0255 095469746C653A090976616C76652E63  .byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
 0265 0A0950726F6772616D6D65723A095363  .byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
 0275 6F7474204E6F72746D616E0A09446174  .byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
 0285 653A09094A616E756172792C20323030  .byte 'e,58,9,9,'J,'a,'n,'u,'a,'r,'y,44,32,50,48,48
 0295 300A0956657273696F6E0909310A0A00  .byte 48,10,9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10,0
 02A5                 L21:
 02A5 257300            .byte 37,'s,0
