                         .module valve3.c
--- 0000                   .dbfile valve3.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 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);
 9813                  L2:
 9813  3B                rti
                       ;  IX -> 0,x
 9814                  _SPI_isr::
 9814                    .dbfunc SPI_isr
 9814                    .dbline 47
                       ; void PWM_ON ();
                       ; void PWM_OFF();
                       ; /******************** End of Function Declarations  *********************/
                       ; 
                       ; 
                       ; /**************************** Main **************************************/
 9814                  L3:
 9814  3B                rti
                       ;  IX -> 0,x
 9815                  _PAIE_isr::
 9815                    .dbfunc PAIE_isr
 9815                    .dbline 53
                       ; 
                       ; unsigned int x, y, z;
                       ; void main(void)
                       ; {
                       ;     /* VT100 clear screen */ 
                       ;     char clear[]= "\x1b\x5B\x32\x4A\x04"; 
 9815                  L4:
 9815  3B                rti
                       ;  IX -> 0,x
 9816                  _PAV_isr::
 9816                    .dbfunc PAV_isr
 9816                    .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();
 9816                  L5:
 9816  3B                rti
                       ;  IX -> 0,x
 9817                  _TOF_isr::
 9817                    .dbfunc TOF_isr
 9817                    .dbline 65
                       ;     init_clocktjp();
                       ;     init_serial();
                       ; 
                       ;     INTR_ON(); /*turn on HC11 interrupt system*/
                       ; 
                       ;     printf("%s", clear);  
 9817                  L6:
 9817  3B                rti
                       ;  IX -> 0,x
 9818                  _TOC2_isr::
 9818                    .dbfunc TOC2_isr
 9818                    .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);
                       ;         
 9818                  L7:
 9818  3B                rti
                       ;  IX -> 0,x
 9819                  _TIC3_isr::
 9819                    .dbfunc TIC3_isr
 9819                    .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
 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
                       ;         }
 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;
                       ;     } 
                       ;     
                       ;     if (position < (valve_sensor - tolerance))
 981C                  L11:
 981C  3B                rti
                       ;  IX -> 0,x
 981D                  _IRQ_isr::
 981D                    .dbfunc IRQ_isr
 981D                    .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
 981D                  L12:
 981D  3B                rti
                       ;  IX -> 0,x
 981E                  _XIRQ_isr::
 981E                    .dbfunc XIRQ_isr
 981E                    .dbline 131
                       ;             }   
                       ;         
                       ;         PWM_OFF();
                       ;         return;
                       ;     }
                       ; }
 981E                  L13:
 981E  3B                rti
                       ;  IX -> 0,x
 981F                  _SWI_isr::
 981F                    .dbfunc SWI_isr
 981F                    .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
 981F                  L14:
 981F  3B                rti
                       ;  IX -> 0,x
 9820                  _ILLOP_isr::
 9820                    .dbfunc ILLOP_isr
 9820                    .dbline 143
                       ;     printf("You're at PWM.\n");
                       ;     SET_BIT(TMSK1, 0x20); //Enable interrupt on OC2
                       ;     SET_BIT(TCTL1, 0x10); //Enable toggle
                       ;     
                       ; }
                       ; 
 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 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
 9821                  L16:
 9821  3B                rti
                       ;  IX -> 0,x
 9822                  _CLMON_isr::
 9822                    .dbfunc CLMON_isr
 9822                    .dbline 155
                       ;     SET_BIT(CFORC, 0x20); //force successful compare
                       ; }
                       ; 
                       ; 
                       ; /***************************OC3_ISR****************************/
                       ; void TOC3_isr()
 9822                  L17:
 9822  3B                rti
                         .area data
 9AB5                  _drew::
 9AB5                    .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 valve3.c
 9834                    .dbfunc main
 9834                    .dbline 53
 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 56
 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 58
 9858  18CE1026          ldy #0x1026
 985C  181C0080          bset 0,y,#128
 9860                    .dbline 59
 9860  BD813B            jsr _init_analog
 9863                    .dbline 60
 9863  BD8040            jsr _init_clocktjp
 9866                    .dbline 61
 9866  BD8381            jsr _init_serial
 9869  0E                        cli
                       
 986A                    .dbline 65
 986A  EC00              ldd 0,x
 986C  C3000A            addd #10
 986F  37                pshb
 9870  36                psha
 9871  CC9AB0            ldd #L21
 9874  BD9442            jsr _printf
 9877  1838              puly
 9879                    .dbline 66
 9879  EC00              ldd 0,x
 987B  C30003            addd #3
 987E  37                pshb
 987F  36                psha
 9880  CC9AB0            ldd #L21
 9883  BD9442            jsr _printf
 9886  1838              puly
 9888                    .dbline 68
 9888  CC9A60            ldd #L22
 988B  BD9442            jsr _printf
 988E                    .dbline 73
 988E  CC9A38            ldd #L23
 9891  BD9442            jsr _printf
 9894  201E              bra L25
 9896                  L24:
 9896                    .dbline 77
 9896  CC9A0B            ldd #L27
 9899  BD9442            jsr _printf
 989C                    .dbline 78
 989C  BD856F            jsr _read_int
 989F  FD9AD6            std _duty_cycle
 98A2                    .dbline 79
 98A2  CC99EF            ldd #L28
 98A5  BD9442            jsr _printf
 98A8                    .dbline 80
 98A8  BD856F            jsr _read_int
 98AB  FD9ACE            std _z
 98AE                    .dbline 82
 98AE  FC9ACE            ldd _z
 98B1  BD98BE            jsr _valve_position
 98B4                    .dbline 87
 98B4                  L25:
 98B4                    .dbline 75
 98B4  20E0              bra L24
 98B6                  L18:
 98B6  8F                xgdx
 98B7  C30010            addd #16
 98BA  8F                xgdx
 98BB  35                txs
 98BC  38                pulx
 98BD  39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;       position -> 6,x
 98BE                  _valve_position::
 98BE  BD86BA            jsr __enterb
 98C1  44                .byte 0x44
 98C2                    .dbfunc valve_position
 98C2                    .dbline 105
 98C2  CC99C2            ldd #L30
 98C5  BD9442            jsr _printf
 98C8                    .dbline 106
 98C8  CC0001            ldd #1
 98CB  BD8144            jsr _analog
 98CE  C3000A            addd #10
 98D1  ED02              std 2,x
 98D3  EC06              ldd 6,x
 98D5  1AA302            cpd 2,x
 98D8  2332              bls L31
 98DA                    .dbline 108
 98DA  CC0001            ldd #1
 98DD  BD8144            jsr _analog
 98E0  37                pshb
 98E1  36                psha
 98E2  CC99A9            ldd #L33
 98E5  BD9442            jsr _printf
 98E8  1838              puly
 98EA                    .dbline 109
 98EA  18CE1000          ldy #0x1000
 98EE  181C0080          bset 0,y,#128
 98F2                    .dbline 110
 98F2  BD9957            jsr _PWM_ON
 98F5                  L34:
 98F5                    .dbline 113
 98F5                  L35:
 98F5  CC0001            ldd #1
 98F8  BD8144            jsr _analog
 98FB  C3000A            addd #10
 98FE  ED02              std 2,x
 9900  EC06              ldd 6,x
 9902  1AA302            cpd 2,x
 9905  22EE              bhi L34
 9907                    .dbline 115
 9907  BD996E            jsr _PWM_OFF
 990A                    .dbline 116
 990A  2042              bra L29
 990C                  L31:
 990C                    .dbline 119
 990C  CC0001            ldd #1
 990F  BD8144            jsr _analog
 9912  83000A            subd #10
 9915  ED02              std 2,x
 9917  EC06              ldd 6,x
 9919  1AA302            cpd 2,x
 991C  2430              bhs L37
 991E                    .dbline 121
 991E  CC0001            ldd #1
 9921  BD8144            jsr _analog
 9924  37                pshb
 9925  36                psha
 9926  CC99A9            ldd #L33
 9929  BD9442            jsr _printf
 992C  1838              puly
 992E                    .dbline 122
 992E  18CE1000          ldy #0x1000
 9932  181D0080          bclr 0,y,#0x80
 9936                    .dbline 123
 9936  BD9957            jsr _PWM_ON
 9939                  L39:
 9939                    .dbline 126
 9939                  L40:
 9939  CC0001            ldd #1
 993C  BD8144            jsr _analog
 993F  83000A            subd #10
 9942  ED02              std 2,x
 9944  EC06              ldd 6,x
 9946  1AA302            cpd 2,x
 9949  25EE              blo L39
 994B                    .dbline 128
 994B  BD996E            jsr _PWM_OFF
 994E                    .dbline 129
 994E                  L37:
 994E                    .dbline 131
 994E                  L29:
 994E  08                inx
 994F  08                inx
 9950  08                inx
 9951  08                inx
 9952  35                txs
 9953  38                pulx
 9954  1838              puly
 9956  39                rts
                       ;  IX -> 0,x
 9957                  _PWM_ON::
 9957                    .dbfunc PWM_ON
 9957                    .dbline 138
 9957  CC9999            ldd #L43
 995A  BD9442            jsr _printf
 995D                    .dbline 139
 995D  18CE1022          ldy #0x1022
 9961  181C0020          bset 0,y,#32
 9965                    .dbline 140
 9965  18CE1020          ldy #0x1020
 9969  181C0010          bset 0,y,#16
 996D                    .dbline 142
 996D                  L42:
 996D  39                rts
                       ;  IX -> 0,x
 996E                  _PWM_OFF::
 996E                    .dbfunc PWM_OFF
 996E                    .dbline 148
 996E  18CE1022          ldy #0x1022
 9972  181D0020          bclr 0,y,#0x20
 9976                    .dbline 149
 9976  18CE1020          ldy #0x1020
 997A  181C0020          bset 0,y,#32
 997E                    .dbline 150
 997E  18CE100B          ldy #0x100b
 9982  181C0020          bset 0,y,#32
 9986                    .dbline 151
 9986                  L44:
 9986  39                rts
                       ;  IX -> 0,x
 9987                  _TOC3_isr::
 9987                    .dbfunc TOC3_isr
 9987                    .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
 9987  FC101A            ldd 0x101a
 998A  F39AD6            addd _duty_cycle
 998D  FD101A            std 0x101a
 9990                    .dbline 158
                       ;     CLEAR_FLAG(TFLG1, 0x20); //Clear interrupt flag
 9990  18CE1023          ldy #0x1023
 9994  181D00DF          bclr 0,y,#0xdf
 9998                    .dbline 159
                       ; }
 9998                  L45:
 9998  3B                rti
                         .area bss
 9ACE                  _z::
 9ACE                    .blkb 2
 9AD0                  _y::
 9AD0                    .blkb 2
 9AD2                  _x::
 9AD2                    .blkb 2
 9AD4                  _period::
 9AD4                    .blkb 2
 9AD6                  _duty_cycle::
 9AD6                    .blkb 2
 9AD8                  _timertjp::
 9AD8                    .blkb 2
 9ADA                  _days::
 9ADA                    .blkb 2
 9ADC                  _hours::
 9ADC                    .blkb 2
 9ADE                  _minutes::
 9ADE                    .blkb 2
 9AE0                  _seconds::
 9AE0                    .blkb 2
 9AE2                  _msec::
 9AE2                    .blkb 2
                         .area text
--- 0186                 L43:
--- 0186 596F752772652061742050574D2E0A00  .byte 'Y,'o,'u,39,'r,'e,32,'a,'t,32,'P,'W,'M,46,10,0
--- 0196                 L33:
--- 0196 54686520616E616C6F672076616C7565  .byte 'T,'h,'e,32,'a,'n,'a,'l,'o,'g,32,'v,'a,'l,'u,'e
--- 01A6 2069733A0925640A00    .byte 32,'i,'s,58,9,37,'d,10,0
--- 01AF                 L30:
--- 01AF 596F7527726520206174207468652062  .byte 'Y,'o,'u,39,'r,'e,32,32,'a,'t,32,'t,'h,'e,32,'b
--- 01BF 6567696E6E696E67206F662076616C76  .byte 'e,'g,'i,'n,'n,'i,'n,'g,32,'o,'f,32,'v,'a,'l,'v
--- 01CF 655F706F736974696F6E2E0A00    .byte 'e,95,'p,'o,'s,'i,'t,'i,'o,'n,46,10,0
--- 01DC                 L28:
--- 01DC 456E7465722074686520646573697265  .byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'e,'s,'i,'r,'e
--- 01EC 6420706F736974696F6E0A00  .byte 'd,32,'p,'o,'s,'i,'t,'i,'o,'n,10,0
--- 01F8                 L27:
--- 01F8 456E746572206E756D626572206F6620  .byte 'E,'n,'t,'e,'r,32,'n,'u,'m,'b,'e,'r,32,'o,'f,32
--- 0208 6520636C6F636B7320666F7220746865  .byte 'e,32,'c,'l,'o,'c,'k,'s,32,'f,'o,'r,32,'t,'h,'e
--- 0218 2064757479206379636C650A00    .byte 32,'d,'u,'t,'y,32,'c,'y,'c,'l,'e,10,0
--- 0225                 L23:
--- 0225 504E45554D415449432043594C494E44  .byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'C,'Y,'L,'I,'N,'D
--- 0235 455220444941474E4F53544943205052  .byte 'E,'R,32,'D,'I,'A,'G,'N,'O,'S,'T,'I,'C,32,'P,'R
--- 0245 4F4752414D0A0A00  .byte 'O,'G,'R,'A,'M,10,10,0
--- 024D                 L22:
--- 024D 095469746C653A090976616C76652E63  .byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
--- 025D 0A0950726F6772616D6D65723A095363  .byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
--- 026D 6F7474204E6F72746D616E0A09446174  .byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
--- 027D 653A09094A616E756172792C20323030  .byte 'e,58,9,9,'J,'a,'n,'u,'a,'r,'y,44,32,50,48,48
--- 028D 300A0956657273696F6E0909310A0A00  .byte 48,10,9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10,0
--- 029D                 L21:
--- 029D 257300            .byte 37,'s,0
