                         .module finally2.c
 0000                   .dbfile finally2.c
                         .area text
                       ;  IX -> 0,x
 0000                 _SCI_isr::
 0000                   .dbfile C:\ICCTJP\include/isrdecl.h
 0000                   .dbfunc SCI_isr
 0000                   .dbline 41
                       ; /************************************************************************************************************************
                       ; *   Program:        finally.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 10 
                       ; #define valve_sensor analog(1)
                       ; /**************************** End of Constants **************************/
                       ; 
                       ; /*************************** Interrupts *********************************/
                       ; #pragma interrupt_handler TOC2_isr;
                       ; /*************************** End of Interrupts **************************/
                       ; 
                       ; /************************** Includes ************************************/
                       ; #include <tjpbase.h>
                       ; #include <analog.h>
                       ; #include <vectors.h>
                       ; #include <mil.h>
                       ; #include <hc11.h>
                       ; /************************ End of includes *******************************/
                       ; 
                       ; /************************** Global Variables*****************************/
                       ; long duty_cycle;    //duty_cycle in e clocks
                       ; long period;        //period in e clocks
                       ; int error = 0;
                       ; int gain;
                       ; int desired;
                       ; long count = 0;
                       ;     
                       ; /************************ End of Global Variables ***********************/
                       ; 
                       ; 
 0000                 L2:
 0000 3B                rti
                       ;  IX -> 0,x
 0001                 _SPI_isr::
 0001                   .dbfunc SPI_isr
 0001                   .dbline 47
                       ; /************************** Function Declarations  **********************/
                       ; void init_pulse();      //Initilizes TOC for PWM interrupts
                       ; void pulse_handler();   //This is the function executed at each TOC2_isr
                       ; /******************** 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[]= "\x1b[1;1H";  /*Home*/
                       ;  
                       ;     SET_BIT(PACTL, 0x80);
                       ;     CLEAR_BIT(PACTL, 0x03); //Set RTI rate
 0003                 L5:
 0003 3B                rti
                       ;  IX -> 0,x
 0004                 _TOF_isr::
 0004                   .dbfunc TOF_isr
 0004                   .dbline 65
                       ;     //SET_BIT(TMSK2, 0x40);//Enable RTI interrupt
                       ;         
                       ;     init_pulse();
                       ;     init_analog();
                       ;     init_serial();
                       ; 
 0004                 L6:
 0004 3B                rti
                       ;  IX -> 0,x
 0005                 _TOC3_isr::
 0005                   .dbfunc TOC3_isr
 0005                   .dbline 89
                       ;     //printf("%s", clear);  
                       ;     //printf("%s", place);
                       ;     
                       ;     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");
                       ;     printf("Enter the desired period in e clocks / 1000:\n");
                       ;     period = (read_int() * 1000);
                       ;     printf("Enter the duty cycle in e clocks / 1000: \n");
                       ;     duty_cycle = (read_int() * 1000);
                       ;     INTR_ON();
                       ;     desired = 150;
                       ;     INTR_OFF();
                       ; 
                       ;     
                       ;     
                       ;     while(1)
                       ;     {
                       ;         SET_BIT(TMSK1, 0x40);//Enable TOC
                       ;         
                       ;         if (desired < valve_sensor){
 0005                 L7:
 0005 3B                rti
                       ;  IX -> 0,x
 0006                 _TIC3_isr::
 0006                   .dbfunc TIC3_isr
 0006                   .dbline 101
                       ;             CLEAR_BIT(PORTA, 0x20);
                       ;         }
                       ;         else if (desired> valve_sensor) {
                       ;             SET_BIT(PORTA, 0x20);
                       ;         }
                       ;         else if ((desired <= valve_sensor + TOLERANCE) && (desired >= valve_sensor - TOLERANCE)){
                       ;             
                       ;             printf("Here\n");
                       ;             CLEAR_BIT(TMSK1, 0x40); //Disable TOC
                       ;         }
                       ;         
                       ;     }/*End While*/
 0006                 L8:
 0006 3B                rti
                       ;  IX -> 0,x
 0007                 _TIC2_isr::
 0007                   .dbfunc TIC2_isr
 0007                   .dbline 107
                       ;     
                       ; }/*End Main*/
                       ; 
                       ; 
                       ; /**************************** End of Main *******************************/
                       ; 
 0007                 L9:
 0007 3B                rti
                       ;  IX -> 0,x
 0008                 _TIC1_isr::
 0008                   .dbfunc TIC1_isr
 0008                   .dbline 113
                       ; 
                       ; 
                       ; /************************** Function Defintions *************************/
                       ; 
                       ; void init_pulse(void)
                       ; {
 0008                 L10:
 0008 3B                rti
                       ;  IX -> 0,x
 0009                 _RTI_isr::
 0009                   .dbfunc RTI_isr
 0009                   .dbline 119
                       ;     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
                       ;     //INTR_ON();
 0009                 L11:
 0009 3B                rti
                       ;  IX -> 0,x
 000A                 _IRQ_isr::
 000A                   .dbfunc IRQ_isr
 000A                   .dbline 125
                       ;     
                       ;     printf("End of Init pulse\n\n");
                       ; }
                       ; 
                       ; void pulse_handler()
                       ; {   printf("ISR");
 000A                 L12:
 000A 3B                rti
                       ;  IX -> 0,x
 000B                 _XIRQ_isr::
 000B                   .dbfunc XIRQ_isr
 000B                   .dbline 131
                       ; 
                       ; 
                       ;     //enable toggle
                       ;     //CLEAR_BIT(TCTL1, 0x80);
                       ;     //SET_BIT(TCTL1, 0x40);
                       ;     if (duty_cycle <= 100)  
 000B                 L13:
 000B 3B                rti
                       ;  IX -> 0,x
 000C                 _SWI_isr::
 000C                   .dbfunc SWI_isr
 000C                   .dbline 137
                       ;     //This handles if duty cycle is less than or equal to 50 e clocks ( almost always off)
                       ;     {
                       ;         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
                       ;     }
 000C                 L14:
 000C 3B                rti
                       ;  IX -> 0,x
 000D                 _ILLOP_isr::
 000D                   .dbfunc ILLOP_isr
 000D                   .dbline 143
                       ;     
                       ;     else if ((period - duty_cycle) <= 100)  //This handles what to do if the pin should almost always be high
                       ;     {
                       ;         CLEAR_BIT(TCTL1, 0x80); //Set the pin to rising edge
                       ;         SET_BIT(TCTL1, 0X40);
                       ;         TOC2 += period;         //Add period
 000D                 L15:
 000D 3B                rti
                       ;  IX -> 0,x
 000E                 _COP_isr::
 000E                   .dbfunc COP_isr
 000E                   .dbline 149
                       ;     }
                       ;     
                       ;     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
                       ;         {
 000E                 L16:
 000E 3B                rti
                       ;  IX -> 0,x
 000F                 _CLMON_isr::
 000F                   .dbfunc CLMON_isr
 000F                   .dbline 155
                       ;             CLEAR_BIT(TCTL1, 0x40);  //Clear bit 6 to set for falling edge on next interrupt
                       ;             SET_BIT(TCTL1, 0X80);
                       ;             TOC2 += duty_cycle;     //Add the duty cycle e clocks if you are now high
                       ;         }
                       ;         
                       ;         else //if(!(TCTL1 & 0x40))  //Test bit 6.  If it is low, you are now low and must change to go high
 000F                 L17:
 000F 3B                rti
                         .area data
 0000                 _drew::
 0000                   .blkw 1
                         .area idata
 0000 0000              .word _interrupt_vectors
                         .area data
 0002                 _error::
 0002                   .blkb 2
                         .area idata
 0002 0000              .word 0
                         .area data
 0004                 _count::
 0004                   .blkb 4
                         .area idata
 0004 00000000          .word 0,0
                         .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
                       ;  lreg1 -> -4,x
                       ;  lreg2 -> -8,x
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;  func temp: 4,x - 12,x
                       ;          place -> 13,x
                       ;          clear -> 20,x
 001D                 _main::
 001D BD0000            jsr __enterb
 0020 9A                .byte 0x9a
 0021                   .dbfile finally2.c
 0021                   .dbfunc main
 0021                   .dbline 53
 0021 EC00              ldd 0,x
 0023 C30014            addd #20
 0026 18CE0010          ldy #L19
 002A 3C                pshx
 002B 8F                xgdx
 002C CC0006            ldd #6
 002F BD0000            jsr __asgnblk
 0032 38                pulx
 0033                   .dbline 56
 0033 EC00              ldd 0,x
 0035 C3000D            addd #13
 0038 18CE0016          ldy #L20
 003C 3C                pshx
 003D 8F                xgdx
 003E CC0007            ldd #7
 0041 BD0000            jsr __asgnblk
 0044 38                pulx
 0045                   .dbline 58
 0045 18CE1026          ldy #0x1026
 0049 181C0080          bset 0,y,#128
 004D                   .dbline 59
 004D 18CE1026          ldy #0x1026
 0051 181D0003          bclr 0,y,#0x3
 0055                   .dbline 62
 0055 BD012C            jsr _init_pulse
 0058                   .dbline 63
 0058 BD0000            jsr _init_analog
 005B                   .dbline 64
 005B BD0000            jsr _init_serial
 005E                   .dbline 69
 005E CC02E9            ldd #L21
 0061 BD0000            jsr _printf
 0064                   .dbline 74
 0064 CC02C1            ldd #L22
 0067 BD0000            jsr _printf
 006A                   .dbline 75
 006A CC0293            ldd #L23
 006D BD0000            jsr _printf
 0070                   .dbline 76
 0070 BD0000            jsr _read_int
 0073 ED04              std 4,x
 0075 CC03E8            ldd #1000
 0078 1AEE04            ldy 4,x
 007B BD0000            jsr __muli
 007E BD0000            jsr __d2lreg
 0081 18CE0004          ldy #_period
 0085 BD0000            jsr __lreg2y
 0088                   .dbline 77
 0088 CC0268            ldd #L24
 008B BD0000            jsr _printf
 008E                   .dbline 78
 008E BD0000            jsr _read_int
 0091 ED06              std 6,x
 0093 CC03E8            ldd #1000
 0096 1AEE06            ldy 6,x
 0099 BD0000            jsr __muli
 009C BD0000            jsr __d2lreg
 009F 18CE0008          ldy #_duty_cycle
 00A3 BD0000            jsr __lreg2y
 00A6 0E                        cli
                       
 00A7                   .dbline 80
 00A7 CC0096            ldd #150
 00AA FD0000            std _desired
 00AD 0F                        sei
                       
 00AE                   .dbline 81
 00AE 7E0121            jmp L26
 00B1                 L25:
 00B1                   .dbline 87
 00B1 18CE1022          ldy #0x1022
 00B5 181C0040          bset 0,y,#64
 00B9                   .dbline 89
 00B9 CC0001            ldd #1
 00BC BD0000            jsr _analog
 00BF ED08              std 8,x
 00C1 FC0000            ldd _desired
 00C4 1AA308            cpd 8,x
 00C7 2C0A              bge L28
 00C9                   .dbline 90
 00C9 18CE1000          ldy #0x1000
 00CD 181D0020          bclr 0,y,#0x20
 00D1                   .dbline 91
 00D1 204E              bra L29
 00D3                 L28:
 00D3                   .dbline 92
 00D3 CC0001            ldd #1
 00D6 BD0000            jsr _analog
 00D9 ED0A              std 10,x
 00DB FC0000            ldd _desired
 00DE 1AA30A            cpd 10,x
 00E1 2F0A              ble L30
 00E3                   .dbline 93
 00E3 18CE1000          ldy #0x1000
 00E7 181C0020          bset 0,y,#32
 00EB                   .dbline 94
 00EB 2034              bra L31
 00ED                 L30:
 00ED                   .dbline 95
 00ED CC0001            ldd #1
 00F0 BD0000            jsr _analog
 00F3 C3000A            addd #10
 00F6 ED02              std 2,x
 00F8 FC0000            ldd _desired
 00FB 1AA302            cpd 2,x
 00FE 2E21              bgt L32
 0100 CC0001            ldd #1
 0103 BD0000            jsr _analog
 0106 83000A            subd #10
 0109 ED02              std 2,x
 010B FC0000            ldd _desired
 010E 1AA302            cpd 2,x
 0111 2D0E              blt L32
 0113                   .dbline 97
 0113 CC0262            ldd #L34
 0116 BD0000            jsr _printf
 0119                   .dbline 98
 0119 18CE1022          ldy #0x1022
 011D 181D0040          bclr 0,y,#0x40
 0121                   .dbline 99
 0121                 L32:
 0121                 L31:
 0121                 L29:
 0121                   .dbline 101
 0121                 L26:
 0121                   .dbline 85
 0121 7E00B1            jmp L25
 0124                 L18:
 0124 8F                xgdx
 0125 C3001A            addd #26
 0128 8F                xgdx
 0129 35                txs
 012A 38                pulx
 012B 39                rts
                       ;  IX -> 0,x
 012C                 _init_pulse::
 012C 0F                        sei
                       
 012D                   .dbfunc init_pulse
 012D                   .dbline 115
 012D 18CE1020          ldy #0x1020
 0131 181C0080          bset 0,y,#128
 0135                   .dbline 116
 0135 18CE1020          ldy #0x1020
 0139 181D0040          bclr 0,y,#0x40
 013D                   .dbline 117
 013D CC0000            ldd #0
 0140 FD1018            std 0x1018
 0143                   .dbline 118
 0143 18CE1022          ldy #0x1022
 0147 181C0040          bset 0,y,#64
 014B                   .dbline 121
 014B CC024E            ldd #L36
 014E BD0000            jsr _printf
 0151                   .dbline 122
 0151                 L35:
 0151 39                rts
                       ;  lreg1 -> -4,x
                       ;  lreg2 -> -8,x
                       ;  IX -> 0,x
 0152                 _TOC2_isr::
 0152 BD0000            jsr __enterb
 0155 82                .byte 0x82
 0156                   .dbfunc TOC2_isr
 0156                   .dbline 125
 0156 CC024A            ldd #L38
 0159 BD0000            jsr _printf
 015C                   .dbline 131
 015C 18CE0008          ldy #_duty_cycle
 0160 BD0000            jsr __ly2reg
 0163 18CE0246          ldy #L41
 0167 BD0000            jsr __ly2reg2
 016A BD0000            jsr __lcmp
 016D 2E29              bgt L39
 016F                   .dbline 134
 016F 18CE1020          ldy #0x1020
 0173 181C0080          bset 0,y,#128
 0177                   .dbline 135
 0177 18CE1020          ldy #0x1020
 017B 181D0040          bclr 0,y,#0x40
 017F                   .dbline 136
 017F 18CE0004          ldy #_period
 0183 BD0000            jsr __ly2reg2
                         ; vol
 0186 FC1018            ldd 0x1018
 0189 BD0000            jsr __ud2lreg
 018C BD0000            jsr __ladd
 018F BD0000            jsr __lreg2d
 0192 FD1018            std 0x1018
 0195                   .dbline 137
 0195 7E0239            jmp L40
 0198                 L39:
 0198                   .dbline 139
 0198 18CE0004          ldy #_period
 019C BD0000            jsr __ly2reg
 019F 18CE0008          ldy #_duty_cycle
 01A3 BD0000            jsr __ly2reg2
 01A6 BD0000            jsr __lsub
 01A9 18CE0246          ldy #L41
 01AD BD0000            jsr __ly2reg2
 01B0 BD0000            jsr __lcmp
 01B3 2E28              bgt L42
 01B5                   .dbline 141
 01B5 18CE1020          ldy #0x1020
 01B9 181D0080          bclr 0,y,#0x80
 01BD                   .dbline 142
 01BD 18CE1020          ldy #0x1020
 01C1 181C0040          bset 0,y,#64
 01C5                   .dbline 143
 01C5 18CE0004          ldy #_period
 01C9 BD0000            jsr __ly2reg2
                         ; vol
 01CC FC1018            ldd 0x1018
 01CF BD0000            jsr __ud2lreg
 01D2 BD0000            jsr __ladd
 01D5 BD0000            jsr __lreg2d
 01D8 FD1018            std 0x1018
 01DB                   .dbline 144
 01DB 205C              bra L43
 01DD                 L42:
 01DD                   .dbline 148
 01DD 18CE1020          ldy #0x1020
 01E1 181F004028        brclr 0,y,#64,L44
 01E6                   .dbline 150
 01E6 18CE1020          ldy #0x1020
 01EA 181D0040          bclr 0,y,#0x40
 01EE                   .dbline 151
 01EE 18CE1020          ldy #0x1020
 01F2 181C0080          bset 0,y,#128
 01F6                   .dbline 152
 01F6 18CE0008          ldy #_duty_cycle
 01FA BD0000            jsr __ly2reg2
                         ; vol
 01FD FC1018            ldd 0x1018
 0200 BD0000            jsr __ud2lreg
 0203 BD0000            jsr __ladd
 0206 BD0000            jsr __lreg2d
 0209 FD1018            std 0x1018
 020C                   .dbline 153
 020C 202B              bra L45
 020E                 L44:
 020E                   .dbline 157
                       ;         {
                       ;             SET_BIT(TCTL1, 0xC0);   //Set bit 6 to go high next interrupt
 020E 18CE1020          ldy #0x1020
 0212 181C00C0          bset 0,y,#192
 0216                   .dbline 158
                       ;             TOC2 += (period - duty_cycle);
 0216 18CE0004          ldy #_period
 021A BD0000            jsr __ly2reg
 021D 18CE0008          ldy #_duty_cycle
 0221 BD0000            jsr __ly2reg2
 0224 BD0000            jsr __lsub
 0227 BD0000            jsr __lregmov
                         ; vol
 022A FC1018            ldd 0x1018
 022D BD0000            jsr __ud2lreg
 0230 BD0000            jsr __ladd
 0233 BD0000            jsr __lreg2d
 0236 FD1018            std 0x1018
 0239                   .dbline 159
                       ;         }
 0239                 L45:
 0239                   .dbline 160
                       ;     }
 0239                 L43:
 0239                 L40:
 0239                   .dbline 163
                       ;     
                       ;     
                       ;     CLEAR_FLAG(TFLG1, 0x40) //Clear the interrupt flag
 0239 18CE1023          ldy #0x1023
 023D 181D00BF          bclr 0,y,#0xbf
 0241                   .dbline 164
                       ; }   //This is the end of the interrupt routine
 0241                 L37:
 0241 08                inx
 0242 08                inx
 0243 35                txs
 0244 38                pulx
 0245 3B                rti
                         .area bss
 0000                 _desired::
 0000                   .blkb 2
 0002                 _gain::
 0002                   .blkb 2
 0004                 _period::
 0004                   .blkb 4
 0008                 _duty_cycle::
 0008                   .blkb 4
 000C                 _timertjp::
 000C                   .blkb 2
 000E                 _days::
 000E                   .blkb 2
 0010                 _hours::
 0010                   .blkb 2
 0012                 _minutes::
 0012                   .blkb 2
 0014                 _seconds::
 0014                   .blkb 2
 0016                 _msec::
 0016                   .blkb 2
                         .area text
 0246                 L41:
 0246 00000064          .word 0,100
 024A                 L38:
 024A 49535200          .byte 'I,'S,'R,0
 024E                 L36:
 024E 456E64206F6620496E69742070756C73  .byte 'E,'n,'d,32,'o,'f,32,'I,'n,'i,'t,32,'p,'u,'l,'s
 025E 650A0A00          .byte 'e,10,10,0
 0262                 L34:
 0262 486572650A00      .byte 'H,'e,'r,'e,10,0
 0268                 L24:
 0268 456E7465722074686520647574792063  .byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'u,'t,'y,32,'c
 0278 79636C6520696E206520636C6F636B73  .byte 'y,'c,'l,'e,32,'i,'n,32,'e,32,'c,'l,'o,'c,'k,'s
 0288 202F20313030303A200A00    .byte 32,47,32,49,48,48,48,58,32,10,0
 0293                 L23:
 0293 456E7465722074686520646573697265  .byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'e,'s,'i,'r,'e
 02A3 6420706572696F6420696E206520636C  .byte 'd,32,'p,'e,'r,'i,'o,'d,32,'i,'n,32,'e,32,'c,'l
 02B3 6F636B73202F20313030303A0A00  .byte 'o,'c,'k,'s,32,47,32,49,48,48,48,58,10,0
 02C1                 L22:
 02C1 504E45554D415449432043594C494E44  .byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'C,'Y,'L,'I,'N,'D
 02D1 455220444941474E4F53544943205052  .byte 'E,'R,32,'D,'I,'A,'G,'N,'O,'S,'T,'I,'C,32,'P,'R
 02E1 4F4752414D0A0A00  .byte 'O,'G,'R,'A,'M,10,10,0
 02E9                 L21:
 02E9 095469746C653A090976616C76652E63  .byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
 02F9 0A0950726F6772616D6D65723A095363  .byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
 0309 6F7474204E6F72746D616E0A09446174  .byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
 0319 653A090946656272756172792C203230  .byte 'e,58,9,9,'F,'e,'b,'r,'u,'a,'r,'y,44,32,50,48
 0329 30300A0956657273696F6E0909310A0A  .byte 48,48,10,9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10
 0339 00                .byte 0
