                         .module valve2.c
--- 0000                   .dbfile valve2.c
                         .area text
                       ;  IX -> 0,x
 9813                  _SCI_isr::
 9813                    .dbfile C:\ICCTJP\include/isrdecl.h
 9813                    .dbfunc SCI_isr
 9813                    .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();
 9813                  L2:
 9813  3B                rti
                       ;  IX -> 0,x
 9814                  _SPI_isr::
 9814                    .dbfunc SPI_isr
 9814                    .dbline 47
                       ; /******************** End of Function Declarations  *********************/
                       ; 
                       ; 
                       ; /**************************** Main **************************************/
                       ; 
                       ; unsigned int x, y, z;
 9814                  L3:
 9814  3B                rti
                       ;  IX -> 0,x
 9815                  _PAIE_isr::
 9815                    .dbfunc PAIE_isr
 9815                    .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"*/
 9815                  L4:
 9815  3B                rti
                       ;  IX -> 0,x
 9816                  _PAV_isr::
 9816                    .dbfunc PAV_isr
 9816                    .dbline 59
                       ;     char place[]= "\x1b[1;1H";  /*Home*/
                       ;     
                       ;     SET_BIT(PACTL, 0x80);   
                       ;     init_analog();
                       ;     init_clocktjp();
                       ;     init_serial();
 9816                  L5:
 9816  3B                rti
                       ;  IX -> 0,x
 9817                  _TOF_isr::
 9817                    .dbfunc TOF_isr
 9817                    .dbline 65
                       ; 
                       ;     INTR_ON(); /*turn on HC11 interrupt system*/
                       ; 
                       ;     printf("%s", clear);  
                       ;     printf("%s", place);
                       ;     
 9817                  L6:
 9817  3B                rti
                       ;  IX -> 0,x
 9818                  _TOC3_isr::
 9818                    .dbfunc TOC3_isr
 9818                    .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*/
 9818                  L7:
 9818  3B                rti
                       ;  IX -> 0,x
 9819                  _TIC3_isr::
 9819                    .dbfunc TIC3_isr
 9819                    .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
 9819                  L8:
 9819  3B                rti
                       ;  IX -> 0,x
 981A                  _TIC2_isr::
 981A                    .dbfunc TIC2_isr
 981A                    .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
                       ;     {
 981A                  L9:
 981A  3B                rti
                       ;  IX -> 0,x
 981B                  _TIC1_isr::
 981B                    .dbfunc TIC1_isr
 981B                    .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);
 981B                  L10:
 981B  3B                rti
                       ;  IX -> 0,x
 981C                  _RTI_isr::
 981C                    .dbfunc RTI_isr
 981C                    .dbline 119
                       ;         }
                       ;         
                       ;         PWM_OFF(); //Turn off PWM system
                       ;         return;
                       ;     } 
                       ;     
 981C                  L11:
 981C  3B                rti
                       ;  IX -> 0,x
 981D                  _IRQ_isr::
 981D                    .dbfunc IRQ_isr
 981D                    .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
                       ;         
 981D                  L12:
 981D  3B                rti
                       ;  IX -> 0,x
 981E                  _XIRQ_isr::
 981E                    .dbfunc XIRQ_isr
 981E                    .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;
 981E                  L13:
 981E  3B                rti
                       ;  IX -> 0,x
 981F                  _SWI_isr::
 981F                    .dbfunc SWI_isr
 981F                    .dbline 137
                       ;     }
                       ; }
                       ;     
                       ; 
                       ; 
                       ; /***************************PWM_ON*****************************/
 981F                  L14:
 981F  3B                rti
                       ;  IX -> 0,x
 9820                  _ILLOP_isr::
 9820                    .dbfunc ILLOP_isr
 9820                    .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
                       ;     
 9820                  L15:
 9820  3B                rti
                       ;  IX -> 0,x
 9821                  _COP_isr::
 9821                    .dbfunc COP_isr
 9821                    .dbline 149
                       ; }
                       ; 
                       ; 
                       ; /****************************PWM_OFF***************************/
                       ; void PWM_OFF()
                       ; {//This turns off the PWM system on OC2 and sets the line to 0
 9821                  L16:
 9821  3B                rti
                       ;  IX -> 0,x
 9822                  _CLMON_isr::
 9822                    .dbfunc CLMON_isr
 9822                    .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
                       ; }
                       ; 
 9822                  L17:
 9822  3B                rti
                         .area data
 9ABD                  _drew::
 9ABD                    .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
 9830                  _main::
 9830  BD86BA            jsr __enterb
 9833  10                .byte 0x10
 9834                    .dbfile valve2.c
 9834                    .dbfunc main
 9834                    .dbline 51
 9834  EC00              ldd 0,x
 9836  C3000A            addd #10
 9839  18CE9823          ldy #L19
 983D  3C                pshx
 983E  8F                xgdx
 983F  CC0006            ldd #6
 9842  BD86A2            jsr __asgnblk
 9845  38                pulx
 9846                    .dbline 54
 9846  EC00              ldd 0,x
 9848  C30003            addd #3
 984B  18CE9829          ldy #L20
 984F  3C                pshx
 9850  8F                xgdx
 9851  CC0007            ldd #7
 9854  BD86A2            jsr __asgnblk
 9857  38                pulx
 9858                    .dbline 56
 9858  18CE1026          ldy #0x1026
 985C  181C0080          bset 0,y,#128
 9860                    .dbline 57
 9860  BD813B            jsr _init_analog
 9863                    .dbline 58
 9863  BD8040            jsr _init_clocktjp
 9866                    .dbline 59
 9866  BD8381            jsr _init_serial
 9869  0E                        cli
                       
 986A                    .dbline 63
 986A  EC00              ldd 0,x
 986C  C3000A            addd #10
 986F  37                pshb
 9870  36                psha
 9871  CC9AB8            ldd #L21
 9874  BD9442            jsr _printf
 9877  1838              puly
 9879                    .dbline 64
 9879  EC00              ldd 0,x
 987B  C30003            addd #3
 987E  37                pshb
 987F  36                psha
 9880  CC9AB8            ldd #L21
 9883  BD9442            jsr _printf
 9886  1838              puly
 9888                    .dbline 66
 9888  CC9A68            ldd #L22
 988B  BD9442            jsr _printf
 988E                    .dbline 71
 988E  CC9A40            ldd #L23
 9891  BD9442            jsr _printf
 9894  202A              bra L25
 9896                  L24:
 9896                    .dbline 75
 9896  CC9A15            ldd #L27
 9899  BD9442            jsr _printf
 989C                    .dbline 76
 989C  BD856F            jsr _read_int
 989F  FD9ADC            std _period
 98A2                    .dbline 77
 98A2  CC99E8            ldd #L28
 98A5  BD9442            jsr _printf
 98A8                    .dbline 78
 98A8  BD856F            jsr _read_int
 98AB  FD9ADE            std _duty_cycle
 98AE                    .dbline 79
 98AE  CC99CC            ldd #L29
 98B1  BD9442            jsr _printf
 98B4                    .dbline 80
 98B4  BD856F            jsr _read_int
 98B7  FD9AD6            std _z
 98BA                    .dbline 82
 98BA  FC9AD6            ldd _z
 98BD  BD98CA            jsr _valve_position
 98C0                    .dbline 87
 98C0                  L25:
 98C0                    .dbline 73
 98C0  20D4              bra L24
 98C2                  L18:
 98C2  8F                xgdx
 98C3  C30010            addd #16
 98C6  8F                xgdx
 98C7  35                txs
 98C8  38                pulx
 98C9  39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;       position -> 6,x
 98CA                  _valve_position::
 98CA  BD86BA            jsr __enterb
 98CD  44                .byte 0x44
 98CE                    .dbfunc valve_position
 98CE                    .dbline 106
 98CE  CC0001            ldd #1
 98D1  BD8144            jsr _analog
 98D4  C3000A            addd #10
 98D7  ED02              std 2,x
 98D9  EC06              ldd 6,x
 98DB  1AA302            cpd 2,x
 98DE  2322              bls L31
 98E0                    .dbline 109
 98E0  18CE1000          ldy #0x1000
 98E4  181C0080          bset 0,y,#128
 98E8                    .dbline 110
 98E8  BD993D            jsr _PWM_ON
 98EB                  L33:
 98EB                    .dbline 114
 98EB                  L34:
 98EB  CC0001            ldd #1
 98EE  BD8144            jsr _analog
 98F1  C3000A            addd #10
 98F4  ED02              std 2,x
 98F6  EC06              ldd 6,x
 98F8  1AA302            cpd 2,x
 98FB  22EE              bhi L33
 98FD                    .dbline 116
 98FD  BD9954            jsr _PWM_OFF
 9900                    .dbline 117
 9900  2032              bra L30
 9902                  L31:
 9902                    .dbline 120
 9902  CC0001            ldd #1
 9905  BD8144            jsr _analog
 9908  83000A            subd #10
 990B  ED02              std 2,x
 990D  EC06              ldd 6,x
 990F  1AA302            cpd 2,x
 9912  2420              bhs L36
 9914                    .dbline 123
 9914  18CE1000          ldy #0x1000
 9918  181D0080          bclr 0,y,#0x80
 991C                    .dbline 124
 991C  BD993D            jsr _PWM_ON
 991F                  L38:
 991F                    .dbline 128
 991F                  L39:
 991F  CC0001            ldd #1
 9922  BD8144            jsr _analog
 9925  83000A            subd #10
 9928  ED02              std 2,x
 992A  EC06              ldd 6,x
 992C  1AA302            cpd 2,x
 992F  25EE              blo L38
 9931                    .dbline 130
 9931  BD9954            jsr _PWM_OFF
 9934                    .dbline 131
 9934                  L36:
 9934                    .dbline 133
 9934                  L30:
 9934  08                inx
 9935  08                inx
 9936  08                inx
 9937  08                inx
 9938  35                txs
 9939  38                pulx
 993A  1838              puly
 993C  39                rts
                       ;  IX -> 0,x
 993D                  _PWM_ON::
 993D                    .dbfunc PWM_ON
 993D                    .dbline 140
 993D  CC99BC            ldd #L42
 9940  BD9442            jsr _printf
 9943                    .dbline 141
 9943  18CE1022          ldy #0x1022
 9947  181C0040          bset 0,y,#64
 994B                    .dbline 142
 994B  18CE1020          ldy #0x1020
 994F  181C00C0          bset 0,y,#192
 9953                    .dbline 144
 9953                  L41:
 9953  39                rts
                       ;  IX -> 0,x
 9954                  _PWM_OFF::
 9954                    .dbfunc PWM_OFF
 9954                    .dbline 151
 9954  18CE1022          ldy #0x1022
 9958  181D0040          bclr 0,y,#0x40
 995C                    .dbline 152
 995C  18CE1020          ldy #0x1020
 9960  181C0080          bset 0,y,#128
 9964                    .dbline 153
 9964  18CE100B          ldy #0x100b
 9968  181C0040          bset 0,y,#64
 996C                    .dbline 154
 996C                  L43:
 996C  39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
 996D                  _TOC2_isr::
 996D  BD86BA            jsr __enterb
 9970  04                .byte 0x4
 9971                    .dbfunc TOC2_isr
 9971                    .dbline 161
                       ; 
                       ; /***************************OC2_ISR****************************/
                       ; void TOC2_isr()
                       ; {//OC2 interrupt; adds duty cycle time to next interrupt and clears flags
                       ; 
                       ;     if (TCTL1 & 0x40)
 9971  18CE1020          ldy #0x1020
 9975  181F00401B        brclr 0,y,#64,L45
 997A                    .dbline 163
                       ;         {
                       ;             CLEAR_BIT (TCTL1, 0x40); //Clear bit to set for falling edge next interrupt
 997A  18CE1020          ldy #0x1020
 997E  181D0040          bclr 0,y,#0x40
 9982                    .dbline 164
                       ;             SET_BIT(TCTL1, 0x80);
 9982  18CE1020          ldy #0x1020
 9986  181C0080          bset 0,y,#128
 998A                    .dbline 165
                       ;             TOC2 += duty_cycle;     //Add time to TOC2 for duty cycle
                         ; vol
 998A  FC1018            ldd 0x1018
 998D  F39ADE            addd _duty_cycle
 9990  FD1018            std 0x1018
 9993                    .dbline 166
                       ;         }
 9993  2018              bra L46
 9995                  L45:
 9995                    .dbline 170
                       ; 
                       ;     else
                       ;         {
                       ;             SET_BIT (TCTL1, 0xC0);
 9995  18CE1020          ldy #0x1020
 9999  181C00C0          bset 0,y,#192
 999D                    .dbline 171
                       ;             TOC2 += (period - duty_cycle);
 999D  FC9ADC            ldd _period
 99A0  B39ADE            subd _duty_cycle
 99A3  ED02              std 2,x
                         ; vol
 99A5  FC1018            ldd 0x1018
 99A8  E302              addd 2,x
 99AA  FD1018            std 0x1018
 99AD                    .dbline 172
                       ;         }
 99AD                  L46:
 99AD                    .dbline 175
                       ; 
                       ;     
                       ;     CLEAR_FLAG(TFLG1, 0x40); //Clear interrupt flag
 99AD  18CE1023          ldy #0x1023
 99B1  181D00BF          bclr 0,y,#0xbf
 99B5                    .dbline 176
                       ; }
 99B5                  L44:
 99B5  08                inx
 99B6  08                inx
 99B7  08                inx
 99B8  08                inx
 99B9  35                txs
 99BA  38                pulx
 99BB  3B                rti
                         .area bss
 9AD6                  _z::
 9AD6                    .blkb 2
 9AD8                  _y::
 9AD8                    .blkb 2
 9ADA                  _x::
 9ADA                    .blkb 2
 9ADC                  _period::
 9ADC                    .blkb 2
 9ADE                  _duty_cycle::
 9ADE                    .blkb 2
 9AE0                  _timertjp::
 9AE0                    .blkb 2
 9AE2                  _days::
 9AE2                    .blkb 2
 9AE4                  _hours::
 9AE4                    .blkb 2
 9AE6                  _minutes::
 9AE6                    .blkb 2
 9AE8                  _seconds::
 9AE8                    .blkb 2
 9AEA                  _msec::
 9AEA                    .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
