                         .module valve.c
--- 0000                   .dbfile valve.c
                         .area text
                       ;  IX -> 0,x
 9813                  _SCI_isr::
 9813                    .dbfile C:\ICCTJP\include/isrdecl.h
 9813                    .dbfunc SCI_isr
 9813                    .dbline 41
                       ; /************************************************************************
                       ; *   Program:        valve.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:           January 26, 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 <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 , unsigned int , unsigned int);
                       ; void PWM (unsigned int , unsigned int);
 9813                  L2:
 9813  3B                rti
                       ;  IX -> 0,x
 9814                  _SPI_isr::
 9814                    .dbfunc SPI_isr
 9814                    .dbline 47
                       ; void done();
                       ; /******************** End of Function Declarations  *********************/
                       ; 
                       ; /************************** Function Defintions *************************/
                       ; void valve_position (unsigned int position, unsigned int duty, unsigned int pd)
                       ; // This function sets the desired position of the pneumatic cylinder
 9814                  L3:
 9814  3B                rti
                       ;  IX -> 0,x
 9815                  _PAIE_isr::
 9815                    .dbfunc PAIE_isr
 9815                    .dbline 53
                       ; // shaft +/- the tolerance.  The cylinder moves to its new position
                       ; // at a speed determined by the PWM function.
                       ; {
                       ;     
                       ;     printf("You're  at the beginning of valve_position.\n");
                       ;     while (position > (valve_sensor + tolerance))   //If the cylinder is too far out, move it in
 9815                  L4:
 9815  3B                rti
                       ;  IX -> 0,x
 9816                  _PAV_isr::
 9816                    .dbfunc PAV_isr
 9816                    .dbline 59
                       ;     {
                       ;         printf("The analog value is:\t%d\n", valve_sensor);
                       ;         SET_BIT (PORTA, 0x80);      //This sets PORTA bit7 to move cylinder in
                       ;         PWM (duty, pd); //After the bit is set, PWM to move the cylinder
                       ;         /*if (valve_sensor - tolerance < position && position > valve_sensor + tolerance){
                       ;             done();
 9816                  L5:
 9816  3B                rti
                       ;  IX -> 0,x
 9817                  _TOF_isr::
 9817                    .dbfunc TOF_isr
 9817                    .dbline 65
                       ;             return;
                       ;             }*/
                       ;     } 
                       ;     while (position < (valve_sensor - tolerance))
                       ;     {
                       ;         printf("The analog value is:\t%d\n", valve_sensor);
 9817                  L6:
 9817  3B                rti
                       ;  IX -> 0,x
 9818                  _TOC3_isr::
 9818                    .dbfunc TOC3_isr
 9818                    .dbline 89
                       ;         CLEAR_BIT (PORTA, 0x80);
                       ;         PWM (duty, pd);
                       ;         /*if (valve_sensor - tolerance < position && position > valve_sensor + tolerance){
                       ;             done();
                       ;             return;
                       ;         }*/
                       ;     }   
                       ; }
                       ; 
                       ; void PWM ( unsigned int duty_cycle2, unsigned int period2)//This is the function to generate PWM
                       ; {
                       ;     printf("You're at PWM.\n");
                       ;     SET_BIT (TMSK1, 0x40); //Enable interrupt on OC2
                       ;     SET_BIT (TCTL1, 0x40); //Enable toggle
                       ;     duty_cycle = duty_cycle2;
                       ;     period = period2;
                       ;     
                       ; }
                       ; 
                       ; void done()
                       ; {
                       ;     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
 9818                  L7:
 9818  3B                rti
                       ;  IX -> 0,x
 9819                  _TIC3_isr::
 9819                    .dbfunc TIC3_isr
 9819                    .dbline 101
                       ; }
                       ; 
                       ; void TOC2_isr()
                       ; {
                       ; //  if (TCTL1 & 0x40)
                       ; //  {
                       ; //      CLEAR_BIT (TCTL1, 0x40); //Clear bit to set for falling edge next interrupt
                       ; 
                       ;         TOC2 += duty_cycle;     //Add time to TOC2 for duty cycle
                       ; //  }
                       ; //  if (!(TCTL1 & 0x40))
                       ; //  {
 9819                  L8:
 9819  3B                rti
                       ;  IX -> 0,x
 981A                  _TIC2_isr::
 981A                    .dbfunc TIC2_isr
 981A                    .dbline 107
                       ; //      SET_BIT (TCTL1, 0x40);
                       ; //      TOC2 += (period - duty_cycle);
                       ; //  }
                       ;     
                       ;     CLEAR_FLAG(TFLG1, 0x40); //Clear interrupt flag
                       ; }
 981A                  L9:
 981A  3B                rti
                       ;  IX -> 0,x
 981B                  _TIC1_isr::
 981B                    .dbfunc TIC1_isr
 981B                    .dbline 113
                       ; /************************** End of Function Defintions ******************/
                       ; 
                       ; /**************************** Main **************************************/
                       ; 
                       ; unsigned int x, y, z;
                       ; void main(void)
 981B                  L10:
 981B  3B                rti
                       ;  IX -> 0,x
 981C                  _RTI_isr::
 981C                    .dbfunc RTI_isr
 981C                    .dbline 119
                       ; {
                       ;     /* VT100 clear screen */ 
                       ;     char clear[]= "\x1b\x5B\x32\x4A\x04"; 
                       ;     
                       ;     /* VT100 position cursor at (x,y) = (3,12) command is "\x1b[3;12H"*/
                       ;     char place[]= "\x1b[1;1H";  /*Home*/
 981C                  L11:
 981C  3B                rti
                       ;  IX -> 0,x
 981D                  _IRQ_isr::
 981D                    .dbfunc IRQ_isr
 981D                    .dbline 125
                       ;     
                       ;     SET_BIT(PACTL, 0x80);   
                       ;     init_analog();
                       ;     init_clocktjp();
                       ;     init_serial();
                       ; 
 981D                  L12:
 981D  3B                rti
                       ;  IX -> 0,x
 981E                  _XIRQ_isr::
 981E                    .dbfunc XIRQ_isr
 981E                    .dbline 131
                       ;     INTR_ON(); /*turn on HC11 interrupt system*/
                       ; 
                       ;     printf("%s", clear);  
                       ;     printf("%s", place);
                       ;     
                       ;     printf("\tTitle:\t\tvalve.c\n"
 981E                  L13:
 981E  3B                rti
                       ;  IX -> 0,x
 981F                  _SWI_isr::
 981F                    .dbfunc SWI_isr
 981F                    .dbline 137
                       ;   "\tProgrammer:\tScott Nortman\n"
                       ;   "\tDate:\t\tJanuary, 2000\n"
                       ;   "\tVersion\t\t1\n\n");
                       ;   
                       ;     printf("PNEUMATIC CYLINDER DIAGNOSTIC PROGRAM\n\n");
                       ;     
 981F                  L14:
 981F  3B                rti
                       ;  IX -> 0,x
 9820                  _ILLOP_isr::
 9820                    .dbfunc ILLOP_isr
 9820                    .dbline 143
                       ;     while(1)
                       ;     {
                       ;         printf("Enter number of e clocks for the period\n");
                       ;         z = read_int();
                       ;         printf("Enter e clocks for duty cycle\n");
                       ;         y = read_int();
 9820                  L15:
 9820  3B                rti
                       ;  IX -> 0,x
 9821                  _COP_isr::
 9821                    .dbfunc COP_isr
 9821                    .dbline 149
                       ;         printf("Enter the desired position\n");
                       ;         x = read_int();
                       ;         
                       ;         valve_position(x, y, z);
                       ;         
                       ; //      printf("%s", clear);  
 9821                  L16:
 9821  3B                rti
                       ;  IX -> 0,x
 9822                  _CLMON_isr::
 9822                    .dbfunc CLMON_isr
 9822                    .dbline 155
                       ;  //     printf("%s", place);
                       ;         
                       ;     }/*End While*/
                       ;     
                       ; }/*End Main*/
                       ; 
 9822                  L17:
 9822  3B                rti
                         .area data
 9AE9                  _drew::
 9AE9                    .blkw 1
                         .area idata
--- 0000 0000              .word _interrupt_vectors
                         .area text
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;             pd -> 12,x
                       ;           duty -> 10,x
                       ;       position -> 6,x
 9823                  _valve_position::
 9823  BD86BA            jsr __enterb
 9826  44                .byte 0x44
 9827                    .dbfile valve.c
 9827                    .dbfunc valve_position
 9827                    .dbline 52
 9827  CC9ABA            ldd #L19
 982A  BD9442            jsr _printf
 982D  2023              bra L21
 982F                  L20:
 982F                    .dbline 55
 982F  CC0001            ldd #1
 9832  BD8144            jsr _analog
 9835  37                pshb
 9836  36                psha
 9837  CC9AA1            ldd #L23
 983A  BD9442            jsr _printf
 983D  1838              puly
 983F                    .dbline 56
 983F  18CE1000          ldy #0x1000
 9843  181C0080          bset 0,y,#128
 9847                    .dbline 57
 9847  EC0C              ldd 12,x
 9849  37                pshb
 984A  36                psha
 984B  EC0A              ldd 10,x
 984D  BD98A4            jsr _PWM
 9850  1838              puly
 9852                    .dbline 62
 9852                  L21:
 9852                    .dbline 53
 9852  CC0001            ldd #1
 9855  BD8144            jsr _analog
 9858  C3000A            addd #10
 985B  ED02              std 2,x
 985D  EC06              ldd 6,x
 985F  1AA302            cpd 2,x
 9862  22CB              bhi L20
 9864  2023              bra L25
 9866                  L24:
 9866                    .dbline 65
 9866  CC0001            ldd #1
 9869  BD8144            jsr _analog
 986C  37                pshb
 986D  36                psha
 986E  CC9AA1            ldd #L23
 9871  BD9442            jsr _printf
 9874  1838              puly
 9876                    .dbline 66
 9876  18CE1000          ldy #0x1000
 987A  181D0080          bclr 0,y,#0x80
 987E                    .dbline 67
 987E  EC0C              ldd 12,x
 9880  37                pshb
 9881  36                psha
 9882  EC0A              ldd 10,x
 9884  BD98A4            jsr _PWM
 9887  1838              puly
 9889                    .dbline 72
 9889                  L25:
 9889                    .dbline 63
 9889  CC0001            ldd #1
 988C  BD8144            jsr _analog
 988F  83000A            subd #10
 9892  ED02              std 2,x
 9894  EC06              ldd 6,x
 9896  1AA302            cpd 2,x
 9899  25CB              blo L24
 989B                    .dbline 73
 989B                  L18:
 989B  08                inx
 989C  08                inx
 989D  08                inx
 989E  08                inx
 989F  35                txs
 98A0  38                pulx
 98A1  1838              puly
 98A3  39                rts
                       ;  IX -> 0,x
                       ;        period2 -> 8,x
                       ;    duty_cycle2 -> 4,x
 98A4                  _PWM::
 98A4  37                pshb
 98A5  36                psha
 98A6  3C                pshx
 98A7  3C                pshx
 98A8  30                tsx
 98A9  EF00              stx 0,x
 98AB                    .dbfunc PWM
 98AB                    .dbline 77
 98AB  CC9A91            ldd #L28
 98AE  BD9442            jsr _printf
 98B1                    .dbline 78
 98B1  18CE1022          ldy #0x1022
 98B5  181C0040          bset 0,y,#64
 98B9                    .dbline 79
 98B9  18CE1020          ldy #0x1020
 98BD  181C0040          bset 0,y,#64
 98C1                    .dbline 80
 98C1  EC04              ldd 4,x
 98C3  FD9B0A            std _duty_cycle
 98C6                    .dbline 81
 98C6  EC08              ldd 8,x
 98C8  FD9B08            std _period
 98CB                    .dbline 83
 98CB                  L27:
 98CB  08                inx
 98CC  08                inx
 98CD  35                txs
 98CE  38                pulx
 98CF  1838              puly
 98D1  39                rts
                       ;  IX -> 0,x
 98D2                  _done::
 98D2                    .dbfunc done
 98D2                    .dbline 87
 98D2  18CE1022          ldy #0x1022
 98D6  181D0040          bclr 0,y,#0x40
 98DA                    .dbline 88
 98DA  18CE1020          ldy #0x1020
 98DE  181C0080          bset 0,y,#128
 98E2                    .dbline 89
 98E2  18CE100B          ldy #0x100b
 98E6  181C0040          bset 0,y,#64
 98EA                    .dbline 90
 98EA                  L29:
 98EA  39                rts
                       ;  IX -> 0,x
 98EB                  _TOC2_isr::
 98EB                    .dbfunc TOC2_isr
 98EB                    .dbline 98
                         ; vol
 98EB  FC1018            ldd 0x1018
 98EE  F39B0A            addd _duty_cycle
 98F1  FD1018            std 0x1018
 98F4                    .dbline 106
 98F4  18CE1023          ldy #0x1023
 98F8  181D00BF          bclr 0,y,#0xbf
 98FC                    .dbline 107
 98FC                  L30:
 98FC  3B                rti
 98FD                  L32:
 98FD  1B5B324A0400      .byte 27,91,50,'J,4,0
 9903                  L33:
 9903  1B5B313B314800    .byte 27,91,49,59,49,'H,0
                       ;  IX -> 0,x
                       ;          place -> 3,x
                       ;          clear -> 10,x
 990A                  _main::
 990A  BD86BA            jsr __enterb
 990D  10                .byte 0x10
 990E                    .dbfunc main
 990E                    .dbline 116
 990E  EC00              ldd 0,x
 9910  C3000A            addd #10
 9913  18CE98FD          ldy #L32
 9917  3C                pshx
 9918  8F                xgdx
 9919  CC0006            ldd #6
 991C  BD86A2            jsr __asgnblk
 991F  38                pulx
 9920                    .dbline 119
 9920  EC00              ldd 0,x
 9922  C30003            addd #3
 9925  18CE9903          ldy #L33
 9929  3C                pshx
 992A  8F                xgdx
 992B  CC0007            ldd #7
 992E  BD86A2            jsr __asgnblk
 9931  38                pulx
 9932                    .dbline 121
 9932  18CE1026          ldy #0x1026
 9936  181C0080          bset 0,y,#128
 993A                    .dbline 122
 993A  BD813B            jsr _init_analog
 993D                    .dbline 123
 993D  BD8040            jsr _init_clocktjp
 9940                    .dbline 124
 9940  BD8381            jsr _init_serial
 9943  0E                        cli
                       
 9944                    .dbline 128
 9944  EC00              ldd 0,x
 9946  C3000A            addd #10
 9949  37                pshb
 994A  36                psha
 994B  CC9A8E            ldd #L34
 994E  BD9442            jsr _printf
 9951  1838              puly
 9953                    .dbline 129
 9953  EC00              ldd 0,x
 9955  C30003            addd #3
 9958  37                pshb
 9959  36                psha
 995A  CC9A8E            ldd #L34
 995D  BD9442            jsr _printf
 9960  1838              puly
 9962                    .dbline 131
 9962  CC9A3E            ldd #L35
 9965  BD9442            jsr _printf
 9968                    .dbline 136
 9968  CC9A16            ldd #L36
 996B  BD9442            jsr _printf
 996E  2038              bra L38
 9970                  L37:
 9970                    .dbline 140
 9970  CC99ED            ldd #L40
 9973  BD9442            jsr _printf
 9976                    .dbline 141
 9976  BD856F            jsr _read_int
 9979  FD9B02            std _z
 997C                    .dbline 142
 997C  CC99CE            ldd #L41
 997F  BD9442            jsr _printf
 9982                    .dbline 143
 9982  BD856F            jsr _read_int
 9985  FD9B04            std _y
 9988                    .dbline 144
 9988  CC99B2            ldd #L42
 998B  BD9442            jsr _printf
 998E                    .dbline 145
 998E  BD856F            jsr _read_int
 9991  FD9B06            std _x
 9994                    .dbline 147
 9994  FC9B02            ldd _z
 9997  37                pshb
 9998  36                psha
 9999  FC9B04            ldd _y
 999C  37                pshb
 999D  36                psha
 999E  FC9B06            ldd _x
 99A1  BD9823            jsr _valve_position
 99A4  1838              puly
 99A6  1838              puly
 99A8                    .dbline 152
 99A8                  L38:
 99A8                    .dbline 138
 99A8  20C6              bra L37
 99AA                  L31:
 99AA  8F                xgdx
 99AB  C30010            addd #16
 99AE  8F                xgdx
 99AF  35                txs
 99B0  38                pulx
 99B1  39                rts
                         .area bss
 9B02                  _z::
 9B02                    .blkb 2
 9B04                  _y::
 9B04                    .blkb 2
 9B06                  _x::
 9B06                    .blkb 2
 9B08                  _period::
 9B08                    .blkb 2
 9B0A                  _duty_cycle::
 9B0A                    .blkb 2
 9B0C                  _timertjp::
 9B0C                    .blkb 2
 9B0E                  _days::
 9B0E                    .blkb 2
 9B10                  _hours::
 9B10                    .blkb 2
 9B12                  _minutes::
 9B12                    .blkb 2
 9B14                  _seconds::
 9B14                    .blkb 2
 9B16                  _msec::
 9B16                    .blkb 2
                         .area text
--- 019F                 L42:
--- 019F 456E7465722074686520646573697265  .byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'e,'s,'i,'r,'e
--- 01AF 6420706F736974696F6E0A00  .byte 'd,32,'p,'o,'s,'i,'t,'i,'o,'n,10,0
--- 01BB                 L41:
--- 01BB 456E746572206520636C6F636B732066  .byte 'E,'n,'t,'e,'r,32,'e,32,'c,'l,'o,'c,'k,'s,32,'f
--- 01CB 6F722064757479206379636C650A00    .byte 'o,'r,32,'d,'u,'t,'y,32,'c,'y,'c,'l,'e,10,0
--- 01DA                 L40:
--- 01DA 456E746572206E756D626572206F6620  .byte 'E,'n,'t,'e,'r,32,'n,'u,'m,'b,'e,'r,32,'o,'f,32
--- 01EA 6520636C6F636B7320666F7220746865  .byte 'e,32,'c,'l,'o,'c,'k,'s,32,'f,'o,'r,32,'t,'h,'e
--- 01FA 20706572696F640A00    .byte 32,'p,'e,'r,'i,'o,'d,10,0
--- 0203                 L36:
--- 0203 504E45554D415449432043594C494E44  .byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'C,'Y,'L,'I,'N,'D
--- 0213 455220444941474E4F53544943205052  .byte 'E,'R,32,'D,'I,'A,'G,'N,'O,'S,'T,'I,'C,32,'P,'R
--- 0223 4F4752414D0A0A00  .byte 'O,'G,'R,'A,'M,10,10,0
--- 022B                 L35:
--- 022B 095469746C653A090976616C76652E63  .byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
--- 023B 0A0950726F6772616D6D65723A095363  .byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
--- 024B 6F7474204E6F72746D616E0A09446174  .byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
--- 025B 653A09094A616E756172792C20323030  .byte 'e,58,9,9,'J,'a,'n,'u,'a,'r,'y,44,32,50,48,48
--- 026B 300A0956657273696F6E0909310A0A00  .byte 48,10,9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10,0
--- 027B                 L34:
--- 027B 257300            .byte 37,'s,0
--- 027E                 L28:
--- 027E 596F752772652061742050574D2E0A00  .byte 'Y,'o,'u,39,'r,'e,32,'a,'t,32,'P,'W,'M,46,10,0
--- 028E                 L23:
--- 028E 54686520616E616C6F672076616C7565  .byte 'T,'h,'e,32,'a,'n,'a,'l,'o,'g,32,'v,'a,'l,'u,'e
--- 029E 2069733A0925640A00    .byte 32,'i,'s,58,9,37,'d,10,0
--- 02A7                 L19:
--- 02A7 596F7527726520206174207468652062  .byte 'Y,'o,'u,39,'r,'e,32,32,'a,'t,32,'t,'h,'e,32,'b
--- 02B7 6567696E6E696E67206F662076616C76  .byte 'e,'g,'i,'n,'n,'i,'n,'g,32,'o,'f,32,'v,'a,'l,'v
--- 02C7 655F706F736974696F6E2E0A00    .byte 'e,95,'p,'o,'s,'i,'t,'i,'o,'n,46,10,0
