                         .module valve5.c
 0000                   .dbfile valve5.c
                         .area text
                       ;  IX -> 0,x
 0000                 _SCI_isr::
 0000                   .dbfile C:\ICCTJP\include/isrdecl.h
 0000                   .dbfunc SCI_isr
 0000                   .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
 0000                 L2:
 0000 3B                rti
                       ;  IX -> 0,x
 0001                 _SPI_isr::
 0001                   .dbfunc SPI_isr
 0001                   .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  *********************/
                       ; 
                       ; 
 0001                 L3:
 0001 3B                rti
                       ;  IX -> 0,x
 0002                 _PAIE_isr::
 0002                   .dbfunc PAIE_isr
 0002                   .dbline 53
                       ; /**************************** Main **************************************/
                       ; 
                       ; void main(void)
                       ; {
                       ;     /* VT100 clear screen */ 
                       ;     char clear[]= "\x1b\x5B\x32\x4A\x04"; 
 0002                 L4:
 0002 3B                rti
                       ;  IX -> 0,x
 0003                 _PAV_isr::
 0003                   .dbfunc PAV_isr
 0003                   .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*/
                       ;     
 0003                 L5:
 0003 3B                rti
                       ;  IX -> 0,x
 0004                 _TOC3_isr::
 0004                   .dbfunc TOC3_isr
 0004                   .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);
                       ;         }
 0004                 L6:
 0004 3B                rti
                       ;  IX -> 0,x
 0005                 _TIC3_isr::
 0005                   .dbfunc TIC3_isr
 0005                   .dbline 101
                       ;         while ((desired_position <= valve_sensor + TOLERANCE) && (desired_position >= valve_sensor - TOLERANCE)){
                       ;             INTR_OFF();
                       ;         }
                       ;     }
                       ;     
                       ; }
                       ; 
                       ; 
                       ; /**************************** End of Main *******************************/
                       ; 
                       ; 
                       ; 
 0005                 L7:
 0005 3B                rti
                       ;  IX -> 0,x
 0006                 _TIC2_isr::
 0006                   .dbfunc TIC2_isr
 0006                   .dbline 107
                       ; /************************** Function Defintions *************************/
                       ; 
                       ; void move_cylinder(int desired_position)
                       ; {
                       ;     int real_position;
                       ;     //while (real_position != desired_position)
 0006                 L8:
 0006 3B                rti
                       ;  IX -> 0,x
 0007                 _TIC1_isr::
 0007                   .dbfunc TIC1_isr
 0007                   .dbline 113
                       ;     //{
                       ;         real_position = valve_sensor;
                       ;         if (real_position > desired_position)
                       ;         {
                       ;             CLEAR_BIT(PORTA, 0x20);
                       ;         }
 0007                 L9:
 0007 3B                rti
                       ;  IX -> 0,x
 0008                 _IRQ_isr::
 0008                   .dbfunc IRQ_isr
 0008                   .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)
 0008                 L10:
 0008 3B                rti
                       ;  IX -> 0,x
 0009                 _XIRQ_isr::
 0009                   .dbfunc XIRQ_isr
 0009                   .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   
 0009                 L11:
 0009 3B                rti
                       ;  IX -> 0,x
 000A                 _SWI_isr::
 000A                   .dbfunc SWI_isr
 000A                   .dbline 137
                       ;     //printf("End of Init pulse\n\n");
                       ; }
                       ; 
                       ; void pulse_handler()
                       ; {   //printf("ISR\n");
                       ; 
 000A                 L12:
 000A 3B                rti
                       ;  IX -> 0,x
 000B                 _ILLOP_isr::
 000B                   .dbfunc ILLOP_isr
 000B                   .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)
                       ;     {
 000B                 L13:
 000B 3B                rti
                       ;  IX -> 0,x
 000C                 _COP_isr::
 000C                   .dbfunc COP_isr
 000C                   .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
 000C                 L14:
 000C 3B                rti
                       ;  IX -> 0,x
 000D                 _CLMON_isr::
 000D                   .dbfunc CLMON_isr
 000D                   .dbline 155
                       ;     {
                       ;         CLEAR_BIT(TCTL1, 0x80); //Set the pin to rising edge
                       ;         SET_BIT(TCTL1, 0X40);
                       ;         TOC2 += period;         //Add period
                       ;     }
                       ;     
 000D                 L15:
 000D 3B                rti
                         .area data
 0000                 _drew::
 0000                   .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
 0023                 _main::
 0023 BD0000            jsr __enterb
 0026 26                .byte 0x26
 0027                   .dbfile valve5.c
 0027                   .dbfunc main
 0027                   .dbline 53
 0027 EC00              ldd 0,x
 0029 C3001E            addd #30
 002C 18CE000E          ldy #L17
 0030 3C                pshx
 0031 8F                xgdx
 0032 CC0006            ldd #6
 0035 BD0000            jsr __asgnblk
 0038 38                pulx
 0039                   .dbline 56
 0039 EC00              ldd 0,x
 003B C30017            addd #23
 003E 18CE0014          ldy #L18
 0042 3C                pshx
 0043 8F                xgdx
 0044 CC0007            ldd #7
 0047 BD0000            jsr __asgnblk
 004A 38                pulx
 004B                   .dbline 58
 004B EC00              ldd 0,x
 004D C3000F            addd #15
 0050 18CE001B          ldy #L19
 0054 3C                pshx
 0055 8F                xgdx
 0056 CC0008            ldd #8
 0059 BD0000            jsr __asgnblk
 005C 38                pulx
 005D                   .dbline 62
 005D CC0096            ldd #150
 0060 ED24              std 36,x
 0062                   .dbline 65
 0062 18CE1026          ldy #0x1026
 0066 181C0080          bset 0,y,#128
 006A                   .dbline 66
 006A BD0148            jsr _init_pulse
 006D                   .dbline 67
 006D BD0000            jsr _init_analog
 0070                   .dbline 68
 0070 BD0000            jsr _init_serial
 0073                   .dbline 70
 0073 EC00              ldd 0,x
 0075 C3001E            addd #30
 0078 37                pshb
 0079 36                psha
 007A CC027D            ldd #L20
 007D BD0000            jsr _printf
 0080 1838              puly
 0082                   .dbline 71
 0082 EC00              ldd 0,x
 0084 C30017            addd #23
 0087 37                pshb
 0088 36                psha
 0089 CC027D            ldd #L20
 008C BD0000            jsr _printf
 008F 1838              puly
 0091                   .dbline 73
 0091 CC022C            ldd #L21
 0094 BD0000            jsr _printf
 0097                   .dbline 78
 0097 CC0204            ldd #L22
 009A BD0000            jsr _printf
 009D                   .dbline 79
 009D CC7530            ldd #30000
 00A0 FD0002            std _period
 00A3                   .dbline 80
 00A3 CC3A98            ldd #15000
 00A6 FD0004            std _duty_cycle
 00A9 0F                        sei
                       
 00AA                   .dbline 81
 00AA 205A              bra L24
 00AC                 L23:
 00AC 0E                        cli
                       
 00AD                   .dbline 83
 00AD 2008              bra L27
 00AF                 L26:
 00AF                   .dbline 85
 00AF 18CE1000          ldy #0x1000
 00B3 181D0020          bclr 0,y,#0x20
 00B7                   .dbline 86
 00B7                 L27:
 00B7 CC0001            ldd #1
 00BA BD0000            jsr _analog
 00BD ED04              std 4,x
 00BF EC24              ldd 36,x
 00C1 1AA304            cpd 4,x
 00C4 2DE9              blt L26
 00C6 2008              bra L30
 00C8                 L29:
 00C8                   .dbline 88
 00C8 18CE1000          ldy #0x1000
 00CC 181C0020          bset 0,y,#32
 00D0                   .dbline 89
 00D0                 L30:
 00D0 CC0001            ldd #1
 00D3 BD0000            jsr _analog
 00D6 ED06              std 6,x
 00D8 EC24              ldd 36,x
 00DA 1AA306            cpd 6,x
 00DD 2EE9              bgt L29
 00DF 2001              bra L33
 00E1                 L32:
 00E1 0F                        sei
                       
 00E2                   .dbline 92
 00E2                 L33:
 00E2 CC0001            ldd #1
 00E5 BD0000            jsr _analog
 00E8 C30005            addd #5
 00EB ED02              std 2,x
 00ED EC24              ldd 36,x
 00EF 1AA302            cpd 2,x
 00F2 2E12              bgt L35
 00F4 CC0001            ldd #1
 00F7 BD0000            jsr _analog
 00FA 830005            subd #5
 00FD ED02              std 2,x
 00FF EC24              ldd 36,x
 0101 1AA302            cpd 2,x
 0104 2CDB              bge L32
 0106                 L35:
 0106                   .dbline 93
 0106                 L24:
 0106 20A4              bra L23
 0108                 L16:
 0108 8F                xgdx
 0109 C30026            addd #38
 010C 8F                xgdx
 010D 35                txs
 010E 38                pulx
 010F 39                rts
                       ;  IX -> 0,x
                       ;  real_position -> 2,x
                       ; desired_position -> 6,x
 0110                 _move_cylinder::
 0110 BD0000            jsr __enterb
 0113 44                .byte 0x44
 0114                   .dbfunc move_cylinder
 0114                   .dbline 109
 0114 CC0001            ldd #1
 0117 BD0000            jsr _analog
 011A ED02              std 2,x
 011C                   .dbline 110
 011C EC02              ldd 2,x
 011E 1AA306            cpd 6,x
 0121 2F0A              ble L37
 0123                   .dbline 112
 0123 18CE1000          ldy #0x1000
 0127 181D0020          bclr 0,y,#0x20
 012B                   .dbline 113
 012B 2008              bra L38
 012D                 L37:
 012D                   .dbline 116
 012D 18CE1000          ldy #0x1000
 0131 181C0020          bset 0,y,#32
 0135                   .dbline 117
 0135                 L38:
 0135 0E                        cli
                       
 0136 0F                        sei
                       
 0137                   .dbline 122
 0137 18CE1000          ldy #0x1000
 013B 181D0040          bclr 0,y,#0x40
 013F                   .dbline 123
 013F                 L36:
 013F 08                inx
 0140 08                inx
 0141 08                inx
 0142 08                inx
 0143 35                txs
 0144 38                pulx
 0145 1838              puly
 0147 39                rts
                       ;  IX -> 0,x
 0148                 _init_pulse::
 0148 0F                        sei
                       
 0149                   .dbfunc init_pulse
 0149                   .dbline 128
 0149 18CE1020          ldy #0x1020
 014D 181C0080          bset 0,y,#128
 0151                   .dbline 129
 0151 18CE1020          ldy #0x1020
 0155 181D0040          bclr 0,y,#0x40
 0159                   .dbline 130
 0159 CC0000            ldd #0
 015C FD1018            std 0x1018
 015F                   .dbline 131
 015F 18CE1022          ldy #0x1022
 0163 181C0040          bset 0,y,#64
 0167                   .dbline 133
 0167                 L39:
 0167 39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
 0168                 _TOC2_isr::
 0168 BD0000            jsr __enterb
 016B 04                .byte 0x4
 016C                   .dbfunc TOC2_isr
 016C                   .dbline 141
 016C FC0004            ldd _duty_cycle
 016F 1A830064          cpd #100
 0173 221B              bhi L41
 0175                   .dbline 144
 0175 18CE1020          ldy #0x1020
 0179 181C0080          bset 0,y,#128
 017D                   .dbline 145
 017D 18CE1020          ldy #0x1020
 0181 181D0040          bclr 0,y,#0x40
 0185                   .dbline 146
                         ; vol
 0185 FC1018            ldd 0x1018
 0188 F30002            addd _period
 018B FD1018            std 0x1018
 018E                   .dbline 147
 018E 2063              bra L42
 0190                 L41:
 0190                   .dbline 149
 0190 FC0002            ldd _period
 0193 B30004            subd _duty_cycle
 0196 1A830064          cpd #100
 019A 221B              bhi L43
 019C                   .dbline 151
 019C 18CE1020          ldy #0x1020
 01A0 181D0080          bclr 0,y,#0x80
 01A4                   .dbline 152
 01A4 18CE1020          ldy #0x1020
 01A8 181C0040          bset 0,y,#64
 01AC                   .dbline 153
                         ; vol
 01AC FC1018            ldd 0x1018
 01AF F30002            addd _period
 01B2 FD1018            std 0x1018
 01B5                   .dbline 154
 01B5 203C              bra L44
 01B7                 L43:
 01B7                   .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
 01B7 18CE1020          ldy #0x1020
 01BB 181F00401B        brclr 0,y,#64,L45
 01C0                   .dbline 160
                       ;         {
                       ;             CLEAR_BIT(TCTL1, 0x40);  //Clear bit 6 to set for falling edge on next interrupt
 01C0 18CE1020          ldy #0x1020
 01C4 181D0040          bclr 0,y,#0x40
 01C8                   .dbline 161
                       ;             SET_BIT(TCTL1, 0X80);
 01C8 18CE1020          ldy #0x1020
 01CC 181C0080          bset 0,y,#128
 01D0                   .dbline 162
                       ;             TOC2 += duty_cycle;     //Add the duty cycle e clocks if you are now high
                         ; vol
 01D0 FC1018            ldd 0x1018
 01D3 F30004            addd _duty_cycle
 01D6 FD1018            std 0x1018
 01D9                   .dbline 163
                       ;         }
 01D9 2018              bra L46
 01DB                 L45:
 01DB                   .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
 01DB 18CE1020          ldy #0x1020
 01DF 181C00C0          bset 0,y,#192
 01E3                   .dbline 168
                       ;             TOC2 += (period - duty_cycle);
 01E3 FC0002            ldd _period
 01E6 B30004            subd _duty_cycle
 01E9 ED02              std 2,x
                         ; vol
 01EB FC1018            ldd 0x1018
 01EE E302              addd 2,x
 01F0 FD1018            std 0x1018
 01F3                   .dbline 169
                       ;         }
 01F3                 L46:
 01F3                   .dbline 170
                       ;     }
 01F3                 L44:
 01F3                 L42:
 01F3                   .dbline 173
                       ;     
                       ;     
                       ;     CLEAR_FLAG(TFLG1, 0x40) //Clear the interrupt flag
 01F3 18CE1023          ldy #0x1023
 01F7 181D00BF          bclr 0,y,#0xbf
 01FB                   .dbline 174
                       ; }   //This is the end of the interrupt routine
 01FB                 L40:
 01FB 08                inx
 01FC 08                inx
 01FD 08                inx
 01FE 08                inx
 01FF 35                txs
 0200 38                pulx
 0201 3B                rti
                       ;  IX -> 0,x
 0202                 _TOF_isr::
 0202                   .dbfunc TOF_isr
 0202                   .dbline 176
                       ; 
                       ; void TOF_isr(void){}
 0202                 L47:
 0202 3B                rti
                       ;  IX -> 0,x
 0203                 _RTI_isr::
 0203                   .dbfunc RTI_isr
 0203                   .dbline 178
                       ; 
                       ; void RTI_isr(void){}
 0203                 L48:
 0203 3B                rti
                         .area bss
 0000                 _position::
 0000                   .blkb 2
 0002                 _period::
 0002                   .blkb 2
 0004                 _duty_cycle::
 0004                   .blkb 2
 0006                 _timertjp::
 0006                   .blkb 2
 0008                 _days::
 0008                   .blkb 2
 000A                 _hours::
 000A                   .blkb 2
 000C                 _minutes::
 000C                   .blkb 2
 000E                 _seconds::
 000E                   .blkb 2
 0010                 _msec::
 0010                   .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
