                         .module valve3.c
 0000                   .dbfile valve3.c
                         .area text
                       ;  IX -> 0,x
 0000                 _SCI_isr::
 0000                   .dbfile C:\ICCTJP\include/isrdecl.h
 0000                   .dbfunc SCI_isr
 0000                   .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);
 0000                 L2:
 0000 3B                rti
                       ;  IX -> 0,x
 0001                 _SPI_isr::
 0001                   .dbfunc SPI_isr
 0001                   .dbline 47
                       ; void PWM_ON ();
                       ; void PWM_OFF();
                       ; /******************** End of Function Declarations  *********************/
                       ; 
                       ; 
                       ; /**************************** Main **************************************/
 0001                 L3:
 0001 3B                rti
                       ;  IX -> 0,x
 0002                 _PAIE_isr::
 0002                   .dbfunc PAIE_isr
 0002                   .dbline 53
                       ; 
                       ; unsigned int x, y, z;
                       ; 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);   
                       ;     init_analog();
 0003                 L5:
 0003 3B                rti
                       ;  IX -> 0,x
 0004                 _TOF_isr::
 0004                   .dbfunc TOF_isr
 0004                   .dbline 65
                       ;     init_clocktjp();
                       ;     init_serial();
                       ; 
                       ;     INTR_ON(); /*turn on HC11 interrupt system*/
                       ; 
                       ;     printf("%s", clear);  
 0004                 L6:
 0004 3B                rti
                       ;  IX -> 0,x
 0005                 _TOC2_isr::
 0005                   .dbfunc TOC2_isr
 0005                   .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);
                       ;         
 0005                 L7:
 0005 3B                rti
                       ;  IX -> 0,x
 0006                 _TIC3_isr::
 0006                   .dbfunc TIC3_isr
 0006                   .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
 0006                 L8:
 0006 3B                rti
                       ;  IX -> 0,x
 0007                 _TIC2_isr::
 0007                   .dbfunc TIC2_isr
 0007                   .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
                       ;     {
 0007                 L9:
 0007 3B                rti
                       ;  IX -> 0,x
 0008                 _TIC1_isr::
 0008                   .dbfunc TIC1_isr
 0008                   .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
                       ;         }
 0008                 L10:
 0008 3B                rti
                       ;  IX -> 0,x
 0009                 _RTI_isr::
 0009                   .dbfunc RTI_isr
 0009                   .dbline 119
                       ;         
                       ;         PWM_OFF(); //Turn off PWM system
                       ;         return;
                       ;     } 
                       ;     
                       ;     if (position < (valve_sensor - tolerance))
 0009                 L11:
 0009 3B                rti
                       ;  IX -> 0,x
 000A                 _IRQ_isr::
 000A                   .dbfunc IRQ_isr
 000A                   .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
 000A                 L12:
 000A 3B                rti
                       ;  IX -> 0,x
 000B                 _XIRQ_isr::
 000B                   .dbfunc XIRQ_isr
 000B                   .dbline 131
                       ;             }   
                       ;         
                       ;         PWM_OFF();
                       ;         return;
                       ;     }
                       ; }
 000B                 L13:
 000B 3B                rti
                       ;  IX -> 0,x
 000C                 _SWI_isr::
 000C                   .dbfunc SWI_isr
 000C                   .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
 000C                 L14:
 000C 3B                rti
                       ;  IX -> 0,x
 000D                 _ILLOP_isr::
 000D                   .dbfunc ILLOP_isr
 000D                   .dbline 143
                       ;     printf("You're at PWM.\n");
                       ;     SET_BIT(TMSK1, 0x20); //Enable interrupt on OC2
                       ;     SET_BIT(TCTL1, 0x10); //Enable toggle
                       ;     
                       ; }
                       ; 
 000D                 L15:
 000D 3B                rti
                       ;  IX -> 0,x
 000E                 _COP_isr::
 000E                   .dbfunc COP_isr
 000E                   .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
 000E                 L16:
 000E 3B                rti
                       ;  IX -> 0,x
 000F                 _CLMON_isr::
 000F                   .dbfunc CLMON_isr
 000F                   .dbline 155
                       ;     SET_BIT(CFORC, 0x20); //force successful compare
                       ; }
                       ; 
                       ; 
                       ; /***************************OC3_ISR****************************/
                       ; void TOC3_isr()
 000F                 L17:
 000F 3B                rti
                         .area data
 0000                 _drew::
 0000                   .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
 001D                 _main::
 001D BD0000            jsr __enterb
 0020 10                .byte 0x10
 0021                   .dbfile valve3.c
 0021                   .dbfunc main
 0021                   .dbline 53
 0021 EC00              ldd 0,x
 0023 C3000A            addd #10
 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 C30003            addd #3
 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 BD0000            jsr _init_analog
 0050                   .dbline 60
 0050 BD0000            jsr _init_clocktjp
 0053                   .dbline 61
 0053 BD0000            jsr _init_serial
 0056 0E                        cli
                       
 0057                   .dbline 65
 0057 EC00              ldd 0,x
 0059 C3000A            addd #10
 005C 37                pshb
 005D 36                psha
 005E CC029D            ldd #L21
 0061 BD0000            jsr _printf
 0064 1838              puly
 0066                   .dbline 66
 0066 EC00              ldd 0,x
 0068 C30003            addd #3
 006B 37                pshb
 006C 36                psha
 006D CC029D            ldd #L21
 0070 BD0000            jsr _printf
 0073 1838              puly
 0075                   .dbline 68
 0075 CC024D            ldd #L22
 0078 BD0000            jsr _printf
 007B                   .dbline 73
 007B CC0225            ldd #L23
 007E BD0000            jsr _printf
 0081 201E              bra L25
 0083                 L24:
 0083                   .dbline 77
 0083 CC01F8            ldd #L27
 0086 BD0000            jsr _printf
 0089                   .dbline 78
 0089 BD0000            jsr _read_int
 008C FD0008            std _duty_cycle
 008F                   .dbline 79
 008F CC01DC            ldd #L28
 0092 BD0000            jsr _printf
 0095                   .dbline 80
 0095 BD0000            jsr _read_int
 0098 FD0000            std _z
 009B                   .dbline 82
 009B FC0000            ldd _z
 009E BD00AB            jsr _valve_position
 00A1                   .dbline 87
 00A1                 L25:
 00A1                   .dbline 75
 00A1 20E0              bra L24
 00A3                 L18:
 00A3 8F                xgdx
 00A4 C30010            addd #16
 00A7 8F                xgdx
 00A8 35                txs
 00A9 38                pulx
 00AA 39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;       position -> 6,x
 00AB                 _valve_position::
 00AB BD0000            jsr __enterb
 00AE 44                .byte 0x44
 00AF                   .dbfunc valve_position
 00AF                   .dbline 105
 00AF CC01AF            ldd #L30
 00B2 BD0000            jsr _printf
 00B5                   .dbline 106
 00B5 CC0001            ldd #1
 00B8 BD0000            jsr _analog
 00BB C3000A            addd #10
 00BE ED02              std 2,x
 00C0 EC06              ldd 6,x
 00C2 1AA302            cpd 2,x
 00C5 2332              bls L31
 00C7                   .dbline 108
 00C7 CC0001            ldd #1
 00CA BD0000            jsr _analog
 00CD 37                pshb
 00CE 36                psha
 00CF CC0196            ldd #L33
 00D2 BD0000            jsr _printf
 00D5 1838              puly
 00D7                   .dbline 109
 00D7 18CE1000          ldy #0x1000
 00DB 181C0080          bset 0,y,#128
 00DF                   .dbline 110
 00DF BD0144            jsr _PWM_ON
 00E2                 L34:
 00E2                   .dbline 113
 00E2                 L35:
 00E2 CC0001            ldd #1
 00E5 BD0000            jsr _analog
 00E8 C3000A            addd #10
 00EB ED02              std 2,x
 00ED EC06              ldd 6,x
 00EF 1AA302            cpd 2,x
 00F2 22EE              bhi L34
 00F4                   .dbline 115
 00F4 BD015B            jsr _PWM_OFF
 00F7                   .dbline 116
 00F7 2042              bra L29
 00F9                 L31:
 00F9                   .dbline 119
 00F9 CC0001            ldd #1
 00FC BD0000            jsr _analog
 00FF 83000A            subd #10
 0102 ED02              std 2,x
 0104 EC06              ldd 6,x
 0106 1AA302            cpd 2,x
 0109 2430              bhs L37
 010B                   .dbline 121
 010B CC0001            ldd #1
 010E BD0000            jsr _analog
 0111 37                pshb
 0112 36                psha
 0113 CC0196            ldd #L33
 0116 BD0000            jsr _printf
 0119 1838              puly
 011B                   .dbline 122
 011B 18CE1000          ldy #0x1000
 011F 181D0080          bclr 0,y,#0x80
 0123                   .dbline 123
 0123 BD0144            jsr _PWM_ON
 0126                 L39:
 0126                   .dbline 126
 0126                 L40:
 0126 CC0001            ldd #1
 0129 BD0000            jsr _analog
 012C 83000A            subd #10
 012F ED02              std 2,x
 0131 EC06              ldd 6,x
 0133 1AA302            cpd 2,x
 0136 25EE              blo L39
 0138                   .dbline 128
 0138 BD015B            jsr _PWM_OFF
 013B                   .dbline 129
 013B                 L37:
 013B                   .dbline 131
 013B                 L29:
 013B 08                inx
 013C 08                inx
 013D 08                inx
 013E 08                inx
 013F 35                txs
 0140 38                pulx
 0141 1838              puly
 0143 39                rts
                       ;  IX -> 0,x
 0144                 _PWM_ON::
 0144                   .dbfunc PWM_ON
 0144                   .dbline 138
 0144 CC0186            ldd #L43
 0147 BD0000            jsr _printf
 014A                   .dbline 139
 014A 18CE1022          ldy #0x1022
 014E 181C0020          bset 0,y,#32
 0152                   .dbline 140
 0152 18CE1020          ldy #0x1020
 0156 181C0010          bset 0,y,#16
 015A                   .dbline 142
 015A                 L42:
 015A 39                rts
                       ;  IX -> 0,x
 015B                 _PWM_OFF::
 015B                   .dbfunc PWM_OFF
 015B                   .dbline 148
 015B 18CE1022          ldy #0x1022
 015F 181D0020          bclr 0,y,#0x20
 0163                   .dbline 149
 0163 18CE1020          ldy #0x1020
 0167 181C0020          bset 0,y,#32
 016B                   .dbline 150
 016B 18CE100B          ldy #0x100b
 016F 181C0020          bset 0,y,#32
 0173                   .dbline 151
 0173                 L44:
 0173 39                rts
                       ;  IX -> 0,x
 0174                 _TOC3_isr::
 0174                   .dbfunc TOC3_isr
 0174                   .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
 0174 FC101A            ldd 0x101a
 0177 F30008            addd _duty_cycle
 017A FD101A            std 0x101a
 017D                   .dbline 158
                       ;     CLEAR_FLAG(TFLG1, 0x20); //Clear interrupt flag
 017D 18CE1023          ldy #0x1023
 0181 181D00DF          bclr 0,y,#0xdf
 0185                   .dbline 159
                       ; }
 0185                 L45:
 0185 3B                rti
                         .area bss
 0000                 _z::
 0000                   .blkb 2
 0002                 _y::
 0002                   .blkb 2
 0004                 _x::
 0004                   .blkb 2
 0006                 _period::
 0006                   .blkb 2
 0008                 _duty_cycle::
 0008                   .blkb 2
 000A                 _timertjp::
 000A                   .blkb 2
 000C                 _days::
 000C                   .blkb 2
 000E                 _hours::
 000E                   .blkb 2
 0010                 _minutes::
 0010                   .blkb 2
 0012                 _seconds::
 0012                   .blkb 2
 0014                 _msec::
 0014                   .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
