                         .module valve5.c
--- 0000                   .dbfile valve5.c
                         .area text
                       ;  IX -> 0,x
 9813                  _SCI_isr::
 9813                    .dbfile C:\ICCTJP\include/isrdecl.h
 9813                    .dbfunc SCI_isr
 9813                    .dbline 41
                       ; /************************************************************************************************************************
                       ; *   Program:        valve5.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:           February 3, 2000                    *
                       ; ************************************************************************************************************************/
                       ; 
                       ; /**************************** Constants *********************************/
                       ; #define pulse_handler TOC2_isr
                       ; #define TOLERANCE 5 
                       ; #define valve_sensor analog(1)
                       ; #define in  0
                       ; #define out 1
                       ; /**************************** End of Constants **************************/
                       ; 
                       ; /*************************** Interrupts *********************************/
                       ; #pragma interrupt_handler TOC2_isr, TOF_isr, RTI_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;    //duty_cycle in e clocks
                       ; unsigned int period;        //period in e clocks
                       ; int position;
                       ; /************************ End of Global Variables ***********************/
                       ; 
                       ; 
                       ; /************************** Function Declarations  **********************/
                       ; void init_pulse();      //Initilizes TOC for PWM interrupts
 9813                  L2:
 9813  3B                rti
                       ;  IX -> 0,x
 9814                  _SPI_isr::
 9814                    .dbfunc SPI_isr
 9814                    .dbline 47
                       ; void move(int);
                       ; void pulse_handler();   //This is the function executed at each TOC2_isr
                       ; void move_cylinder(int);
                       ; /******************** End of Function Declarations  *********************/
                       ; 
                       ; 
 9814                  L3:
 9814  3B                rti
                       ;  IX -> 0,x
 9815                  _PAIE_isr::
 9815                    .dbfunc PAIE_isr
 9815                    .dbline 53
                       ; /**************************** Main **************************************/
                       ; 
                       ; 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_home[]= "\x1b[1;1H"; /*Home*/
                       ;     
                       ;     char place_text[] = "\x1b[10;1H";/*position for text to be entered*/
                       ;     
 9816                  L5:
 9816  3B                rti
                       ;  IX -> 0,x
 9817                  _TOC3_isr::
 9817                    .dbfunc TOC3_isr
 9817                    .dbline 89
                       ;     int duty_cycle_P;
                       ;     int period_ms;
                       ;     int desired_position  = 150;
                       ;     int option;
                       ;     
                       ;     SET_BIT(PACTL, 0x80);   
                       ;     init_pulse();
                       ;     init_analog();
                       ;     init_serial();
                       ; 
                       ;     printf("%s", clear);  
                       ;     printf("%s", place_home);
                       ;     
                       ;     printf("\tTitle:\t\tvalve.c\n"
                       ;   "\tProgrammer:\tScott Nortman\n"
                       ;   "\tDate:\t\tFebruary, 2000\n"
                       ;   "\tVersion\t\t1\n\n");
                       ;   
                       ;     printf("PNEUMATIC CYLINDER DIAGNOSTIC PROGRAM\n\n");
                       ;     period = 30000;
                       ;     duty_cycle = 15000;
                       ;     INTR_OFF();
                       ;     while (1){
                       ;         INTR_ON();
                       ;         while (desired_position < valve_sensor){
                       ;             CLEAR_BIT(PORTA, 0x20);
                       ;         }
                       ;         while (desired_position > valve_sensor) {
                       ;             SET_BIT(PORTA, 0x20);
                       ;         }
 9817                  L6:
 9817  3B                rti
                       ;  IX -> 0,x
 9818                  _TIC3_isr::
 9818                    .dbfunc TIC3_isr
 9818                    .dbline 101
                       ;         while ((desired_position <= valve_sensor + TOLERANCE) && (desired_position >= valve_sensor - TOLERANCE)){
                       ;             INTR_OFF();
                       ;         }
                       ;     }
                       ;     
                       ; }
                       ; 
                       ; 
                       ; /**************************** End of Main *******************************/
                       ; 
                       ; 
                       ; 
 9818                  L7:
 9818  3B                rti
                       ;  IX -> 0,x
 9819                  _TIC2_isr::
 9819                    .dbfunc TIC2_isr
 9819                    .dbline 107
                       ; /************************** Function Defintions *************************/
                       ; 
                       ; void move_cylinder(int desired_position)
                       ; {
                       ;     int real_position;
                       ;     //while (real_position != desired_position)
 9819                  L8:
 9819  3B                rti
                       ;  IX -> 0,x
 981A                  _TIC1_isr::
 981A                    .dbfunc TIC1_isr
 981A                    .dbline 113
                       ;     //{
                       ;         real_position = valve_sensor;
                       ;         if (real_position > desired_position)
                       ;         {
                       ;             CLEAR_BIT(PORTA, 0x20);
                       ;         }
 981A                  L9:
 981A  3B                rti
                       ;  IX -> 0,x
 981B                  _IRQ_isr::
 981B                    .dbfunc IRQ_isr
 981B                    .dbline 125
                       ;         else
                       ;         {
                       ;             SET_BIT(PORTA, 0x20);
                       ;         }
                       ;         INTR_ON();
                       ;     //}
                       ;     
                       ;     INTR_OFF(); 
                       ;     CLEAR_BIT(PORTA, 0x40);     //Set to go low when not interrupting
                       ; }
                       ; 
                       ; void init_pulse(void)
 981B                  L10:
 981B  3B                rti
                       ;  IX -> 0,x
 981C                  _XIRQ_isr::
 981C                    .dbfunc XIRQ_isr
 981C                    .dbline 131
                       ; {
                       ;     INTR_OFF();
                       ;     SET_BIT(TCTL1, 0x80);   //Enable OC2 for falling edge on first sucessful compare (safe default)
                       ;     CLEAR_BIT(TCTL1, 0x40);
                       ;     TOC2 = 0;   //Set TOC2 to zero
                       ;     SET_BIT(TMSK1, 0x40);   //Enable OC2 mask   
 981C                  L11:
 981C  3B                rti
                       ;  IX -> 0,x
 981D                  _SWI_isr::
 981D                    .dbfunc SWI_isr
 981D                    .dbline 137
                       ;     //printf("End of Init pulse\n\n");
                       ; }
                       ; 
                       ; void pulse_handler()
                       ; {   //printf("ISR\n");
                       ; 
 981D                  L12:
 981D  3B                rti
                       ;  IX -> 0,x
 981E                  _ILLOP_isr::
 981E                    .dbfunc ILLOP_isr
 981E                    .dbline 143
                       ;     //enable toggle
                       ;     //CLEAR_BIT(TCTL1, 0x80);
                       ;     //SET_BIT(TCTL1, 0x40);
                       ;     if (duty_cycle <= 100)  
                       ;     //This handles if duty cycle is less than or equal to 100 e clocks ( almost always off)
                       ;     {
 981E                  L13:
 981E  3B                rti
                       ;  IX -> 0,x
 981F                  _COP_isr::
 981F                    .dbfunc COP_isr
 981F                    .dbline 149
                       ;         SET_BIT(TCTL1, 0x80);   //Enable OC2 for falling edge (make sure pin goes low)
                       ;         CLEAR_BIT(TCTL1, 0X40);
                       ;         TOC2 += period;         //Add the period to TOC2
                       ;     }
                       ;     
                       ;     else if ((period - duty_cycle) <= 100)  //This handles what to do if the pin should almost always be high
 981F                  L14:
 981F  3B                rti
                       ;  IX -> 0,x
 9820                  _CLMON_isr::
 9820                    .dbfunc CLMON_isr
 9820                    .dbline 155
                       ;     {
                       ;         CLEAR_BIT(TCTL1, 0x80); //Set the pin to rising edge
                       ;         SET_BIT(TCTL1, 0X40);
                       ;         TOC2 += period;         //Add period
                       ;     }
                       ;     
 9820                  L15:
 9820  3B                rti
                         .area data
 9A95                  _drew::
 9A95                    .blkw 1
                         .area idata
--- 0000 0000              .word _interrupt_vectors
                         .area text
--- 000E                 L17:
--- 000E 1B5B324A0400      .byte 27,91,50,'J,4,0
--- 0014                 L18:
--- 0014 1B5B313B314800    .byte 27,91,49,59,49,'H,0
--- 001B                 L19:
--- 001B 1B5B31303B314800  .byte 27,91,49,48,59,49,'H,0
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;  func temp: 4,x - 8,x
                       ;         option -> 9,x
                       ;      period_ms -> 11,x
                       ;   duty_cycle_P -> 13,x
                       ;     place_text -> 15,x
                       ;     place_home -> 23,x
                       ;          clear -> 30,x
                       ; desired_position -> 36,x
 9836                  _main::
 9836  BD86BA            jsr __enterb
 9839  26                .byte 0x26
 983A                    .dbfile valve5.c
 983A                    .dbfunc main
 983A                    .dbline 53
 983A  EC00              ldd 0,x
 983C  C3001E            addd #30
 983F  18CE9821          ldy #L17
 9843  3C                pshx
 9844  8F                xgdx
 9845  CC0006            ldd #6
 9848  BD86A2            jsr __asgnblk
 984B  38                pulx
 984C                    .dbline 56
 984C  EC00              ldd 0,x
 984E  C30017            addd #23
 9851  18CE9827          ldy #L18
 9855  3C                pshx
 9856  8F                xgdx
 9857  CC0007            ldd #7
 985A  BD86A2            jsr __asgnblk
 985D  38                pulx
 985E                    .dbline 58
 985E  EC00              ldd 0,x
 9860  C3000F            addd #15
 9863  18CE982E          ldy #L19
 9867  3C                pshx
 9868  8F                xgdx
 9869  CC0008            ldd #8
 986C  BD86A2            jsr __asgnblk
 986F  38                pulx
 9870                    .dbline 62
 9870  CC0096            ldd #150
 9873  ED24              std 36,x
 9875                    .dbline 65
 9875  18CE1026          ldy #0x1026
 9879  181C0080          bset 0,y,#128
 987D                    .dbline 66
 987D  BD995B            jsr _init_pulse
 9880                    .dbline 67
 9880  BD813B            jsr _init_analog
 9883                    .dbline 68
 9883  BD8381            jsr _init_serial
 9886                    .dbline 70
 9886  EC00              ldd 0,x
 9888  C3001E            addd #30
 988B  37                pshb
 988C  36                psha
 988D  CC9A90            ldd #L20
 9890  BD9442            jsr _printf
 9893  1838              puly
 9895                    .dbline 71
 9895  EC00              ldd 0,x
 9897  C30017            addd #23
 989A  37                pshb
 989B  36                psha
 989C  CC9A90            ldd #L20
 989F  BD9442            jsr _printf
 98A2  1838              puly
 98A4                    .dbline 73
 98A4  CC9A3F            ldd #L21
 98A7  BD9442            jsr _printf
 98AA                    .dbline 78
 98AA  CC9A17            ldd #L22
 98AD  BD9442            jsr _printf
 98B0                    .dbline 79
 98B0  CC7530            ldd #30000
 98B3  FD9AB0            std _period
 98B6                    .dbline 80
 98B6  CC3A98            ldd #15000
 98B9  FD9AB2            std _duty_cycle
 98BC  0F                        sei
                       
 98BD                    .dbline 81
 98BD  205A              bra L24
 98BF                  L23:
 98BF  0E                        cli
                       
 98C0                    .dbline 83
 98C0  2008              bra L27
 98C2                  L26:
 98C2                    .dbline 85
 98C2  18CE1000          ldy #0x1000
 98C6  181D0020          bclr 0,y,#0x20
 98CA                    .dbline 86
 98CA                  L27:
 98CA  CC0001            ldd #1
 98CD  BD8144            jsr _analog
 98D0  ED04              std 4,x
 98D2  EC24              ldd 36,x
 98D4  1AA304            cpd 4,x
 98D7  2DE9              blt L26
 98D9  2008              bra L30
 98DB                  L29:
 98DB                    .dbline 88
 98DB  18CE1000          ldy #0x1000
 98DF  181C0020          bset 0,y,#32
 98E3                    .dbline 89
 98E3                  L30:
 98E3  CC0001            ldd #1
 98E6  BD8144            jsr _analog
 98E9  ED06              std 6,x
 98EB  EC24              ldd 36,x
 98ED  1AA306            cpd 6,x
 98F0  2EE9              bgt L29
 98F2  2001              bra L33
 98F4                  L32:
 98F4  0F                        sei
                       
 98F5                    .dbline 92
 98F5                  L33:
 98F5  CC0001            ldd #1
 98F8  BD8144            jsr _analog
 98FB  C30005            addd #5
 98FE  ED02              std 2,x
 9900  EC24              ldd 36,x
 9902  1AA302            cpd 2,x
 9905  2E12              bgt L35
 9907  CC0001            ldd #1
 990A  BD8144            jsr _analog
 990D  830005            subd #5
 9910  ED02              std 2,x
 9912  EC24              ldd 36,x
 9914  1AA302            cpd 2,x
 9917  2CDB              bge L32
 9919                  L35:
 9919                    .dbline 93
 9919                  L24:
 9919  20A4              bra L23
 991B                  L16:
 991B  8F                xgdx
 991C  C30026            addd #38
 991F  8F                xgdx
 9920  35                txs
 9921  38                pulx
 9922  39                rts
                       ;  IX -> 0,x
                       ;  real_position -> 2,x
                       ; desired_position -> 6,x
 9923                  _move_cylinder::
 9923  BD86BA            jsr __enterb
 9926  44                .byte 0x44
 9927                    .dbfunc move_cylinder
 9927                    .dbline 109
 9927  CC0001            ldd #1
 992A  BD8144            jsr _analog
 992D  ED02              std 2,x
 992F                    .dbline 110
 992F  EC02              ldd 2,x
 9931  1AA306            cpd 6,x
 9934  2F0A              ble L37
 9936                    .dbline 112
 9936  18CE1000          ldy #0x1000
 993A  181D0020          bclr 0,y,#0x20
 993E                    .dbline 113
 993E  2008              bra L38
 9940                  L37:
 9940                    .dbline 116
 9940  18CE1000          ldy #0x1000
 9944  181C0020          bset 0,y,#32
 9948                    .dbline 117
 9948                  L38:
 9948  0E                        cli
                       
 9949  0F                        sei
                       
 994A                    .dbline 122
 994A  18CE1000          ldy #0x1000
 994E  181D0040          bclr 0,y,#0x40
 9952                    .dbline 123
 9952                  L36:
 9952  08                inx
 9953  08                inx
 9954  08                inx
 9955  08                inx
 9956  35                txs
 9957  38                pulx
 9958  1838              puly
 995A  39                rts
                       ;  IX -> 0,x
 995B                  _init_pulse::
 995B  0F                        sei
                       
 995C                    .dbfunc init_pulse
 995C                    .dbline 128
 995C  18CE1020          ldy #0x1020
 9960  181C0080          bset 0,y,#128
 9964                    .dbline 129
 9964  18CE1020          ldy #0x1020
 9968  181D0040          bclr 0,y,#0x40
 996C                    .dbline 130
 996C  CC0000            ldd #0
 996F  FD1018            std 0x1018
 9972                    .dbline 131
 9972  18CE1022          ldy #0x1022
 9976  181C0040          bset 0,y,#64
 997A                    .dbline 133
 997A                  L39:
 997A  39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
 997B                  _TOC2_isr::
 997B  BD86BA            jsr __enterb
 997E  04                .byte 0x4
 997F                    .dbfunc TOC2_isr
 997F                    .dbline 141
 997F  FC9AB2            ldd _duty_cycle
 9982  1A830064          cpd #100
 9986  221B              bhi L41
 9988                    .dbline 144
 9988  18CE1020          ldy #0x1020
 998C  181C0080          bset 0,y,#128
 9990                    .dbline 145
 9990  18CE1020          ldy #0x1020
 9994  181D0040          bclr 0,y,#0x40
 9998                    .dbline 146
                         ; vol
 9998  FC1018            ldd 0x1018
 999B  F39AB0            addd _period
 999E  FD1018            std 0x1018
 99A1                    .dbline 147
 99A1  2063              bra L42
 99A3                  L41:
 99A3                    .dbline 149
 99A3  FC9AB0            ldd _period
 99A6  B39AB2            subd _duty_cycle
 99A9  1A830064          cpd #100
 99AD  221B              bhi L43
 99AF                    .dbline 151
 99AF  18CE1020          ldy #0x1020
 99B3  181D0080          bclr 0,y,#0x80
 99B7                    .dbline 152
 99B7  18CE1020          ldy #0x1020
 99BB  181C0040          bset 0,y,#64
 99BF                    .dbline 153
                         ; vol
 99BF  FC1018            ldd 0x1018
 99C2  F39AB0            addd _period
 99C5  FD1018            std 0x1018
 99C8                    .dbline 154
 99C8  203C              bra L44
 99CA                  L43:
 99CA                    .dbline 158
                       ;     else        //This is for the general case
                       ;     {
                       ;         if (TCTL1 & 0x40)   //Test bit 6.  If it is a one, you are now high and must change to go low
 99CA  18CE1020          ldy #0x1020
 99CE  181F00401B        brclr 0,y,#64,L45
 99D3                    .dbline 160
                       ;         {
                       ;             CLEAR_BIT(TCTL1, 0x40);  //Clear bit 6 to set for falling edge on next interrupt
 99D3  18CE1020          ldy #0x1020
 99D7  181D0040          bclr 0,y,#0x40
 99DB                    .dbline 161
                       ;             SET_BIT(TCTL1, 0X80);
 99DB  18CE1020          ldy #0x1020
 99DF  181C0080          bset 0,y,#128
 99E3                    .dbline 162
                       ;             TOC2 += duty_cycle;     //Add the duty cycle e clocks if you are now high
                         ; vol
 99E3  FC1018            ldd 0x1018
 99E6  F39AB2            addd _duty_cycle
 99E9  FD1018            std 0x1018
 99EC                    .dbline 163
                       ;         }
 99EC  2018              bra L46
 99EE                  L45:
 99EE                    .dbline 167
                       ;         
                       ;         else    //Test bit 6.  If it is low, you are now low and must change to go high
                       ;         {
                       ;             SET_BIT(TCTL1, 0xC0);   //Set bit 6 to go high next interrupt
 99EE  18CE1020          ldy #0x1020
 99F2  181C00C0          bset 0,y,#192
 99F6                    .dbline 168
                       ;             TOC2 += (period - duty_cycle);
 99F6  FC9AB0            ldd _period
 99F9  B39AB2            subd _duty_cycle
 99FC  ED02              std 2,x
                         ; vol
 99FE  FC1018            ldd 0x1018
 9A01  E302              addd 2,x
 9A03  FD1018            std 0x1018
 9A06                    .dbline 169
                       ;         }
 9A06                  L46:
 9A06                    .dbline 170
                       ;     }
 9A06                  L44:
 9A06                  L42:
 9A06                    .dbline 173
                       ;     
                       ;     
                       ;     CLEAR_FLAG(TFLG1, 0x40) //Clear the interrupt flag
 9A06  18CE1023          ldy #0x1023
 9A0A  181D00BF          bclr 0,y,#0xbf
 9A0E                    .dbline 174
                       ; }   //This is the end of the interrupt routine
 9A0E                  L40:
 9A0E  08                inx
 9A0F  08                inx
 9A10  08                inx
 9A11  08                inx
 9A12  35                txs
 9A13  38                pulx
 9A14  3B                rti
                       ;  IX -> 0,x
 9A15                  _TOF_isr::
 9A15                    .dbfunc TOF_isr
 9A15                    .dbline 176
                       ; 
                       ; void TOF_isr(void){}
 9A15                  L47:
 9A15  3B                rti
                       ;  IX -> 0,x
 9A16                  _RTI_isr::
 9A16                    .dbfunc RTI_isr
 9A16                    .dbline 178
                       ; 
                       ; void RTI_isr(void){}
 9A16                  L48:
 9A16  3B                rti
                         .area bss
 9AAE                  _position::
 9AAE                    .blkb 2
 9AB0                  _period::
 9AB0                    .blkb 2
 9AB2                  _duty_cycle::
 9AB2                    .blkb 2
 9AB4                  _timertjp::
 9AB4                    .blkb 2
 9AB6                  _days::
 9AB6                    .blkb 2
 9AB8                  _hours::
 9AB8                    .blkb 2
 9ABA                  _minutes::
 9ABA                    .blkb 2
 9ABC                  _seconds::
 9ABC                    .blkb 2
 9ABE                  _msec::
 9ABE                    .blkb 2
                         .area text
--- 0204                 L22:
--- 0204 504E45554D415449432043594C494E44  .byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'C,'Y,'L,'I,'N,'D
--- 0214 455220444941474E4F53544943205052  .byte 'E,'R,32,'D,'I,'A,'G,'N,'O,'S,'T,'I,'C,32,'P,'R
--- 0224 4F4752414D0A0A00  .byte 'O,'G,'R,'A,'M,10,10,0
--- 022C                 L21:
--- 022C 095469746C653A090976616C76652E63  .byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
--- 023C 0A0950726F6772616D6D65723A095363  .byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
--- 024C 6F7474204E6F72746D616E0A09446174  .byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
--- 025C 653A090946656272756172792C203230  .byte 'e,58,9,9,'F,'e,'b,'r,'u,'a,'r,'y,44,32,50,48
--- 026C 30300A0956657273696F6E0909310A0A  .byte 48,48,10,9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10
--- 027C 00                .byte 0
--- 027D                 L20:
--- 027D 257300            .byte 37,'s,0
