                         .module valve.c
 0000                   .dbfile valve.c
                         .area text
                       ;  IX -> 0,x
 0000                 _SCI_isr::
 0000                   .dbfile C:\ICCTJP\include/isrdecl.h
 0000                   .dbfunc SCI_isr
 0000                   .dbline 41
                       ; /************************************************************************
                       ; *   Program:        valve.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:           January 26, 2000                                    *
                       ; *************************************************************************/
                       ; 
                       ; /**************************** Constants *********************************/
                       ; //#define valve TOC
                       ; #define tolerance 10 
                       ; #define valve_sensor analog(1)
                       ; /**************************** End of Constants **************************/
                       ; 
                       ; /*************************** Interrupts *********************************/
                       ; #pragma interrupt_handler TOC2_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 , unsigned int , unsigned int);
                       ; void PWM (unsigned int , unsigned int);
 0000                 L2:
 0000 3B                rti
                       ;  IX -> 0,x
 0001                 _SPI_isr::
 0001                   .dbfunc SPI_isr
 0001                   .dbline 47
                       ; void done();
                       ; /******************** End of Function Declarations  *********************/
                       ; 
                       ; /************************** Function Defintions *************************/
                       ; void valve_position (unsigned int position, unsigned int duty, unsigned int pd)
                       ; // This function sets the desired position of the pneumatic cylinder
 0001                 L3:
 0001 3B                rti
                       ;  IX -> 0,x
 0002                 _PAIE_isr::
 0002                   .dbfunc PAIE_isr
 0002                   .dbline 53
                       ; // shaft +/- the tolerance.  The cylinder moves to its new position
                       ; // at a speed determined by the PWM function.
                       ; {
                       ;     
                       ;     printf("You're  at the beginning of valve_position.\n");
                       ;     while (position > (valve_sensor + tolerance))   //If the cylinder is too far out, move it in
 0002                 L4:
 0002 3B                rti
                       ;  IX -> 0,x
 0003                 _PAV_isr::
 0003                   .dbfunc PAV_isr
 0003                   .dbline 59
                       ;     {
                       ;         printf("The analog value is:\t%d\n", valve_sensor);
                       ;         SET_BIT (PORTA, 0x80);      //This sets PORTA bit7 to move cylinder in
                       ;         PWM (duty, pd); //After the bit is set, PWM to move the cylinder
                       ;         /*if (valve_sensor - tolerance < position && position > valve_sensor + tolerance){
                       ;             done();
 0003                 L5:
 0003 3B                rti
                       ;  IX -> 0,x
 0004                 _TOF_isr::
 0004                   .dbfunc TOF_isr
 0004                   .dbline 65
                       ;             return;
                       ;             }*/
                       ;     } 
                       ;     while (position < (valve_sensor - tolerance))
                       ;     {
                       ;         printf("The analog value is:\t%d\n", valve_sensor);
 0004                 L6:
 0004 3B                rti
                       ;  IX -> 0,x
 0005                 _TOC3_isr::
 0005                   .dbfunc TOC3_isr
 0005                   .dbline 89
                       ;         CLEAR_BIT (PORTA, 0x80);
                       ;         PWM (duty, pd);
                       ;         /*if (valve_sensor - tolerance < position && position > valve_sensor + tolerance){
                       ;             done();
                       ;             return;
                       ;         }*/
                       ;     }   
                       ; }
                       ; 
                       ; void PWM ( unsigned int duty_cycle2, unsigned int period2)//This is the function to generate PWM
                       ; {
                       ;     printf("You're at PWM.\n");
                       ;     SET_BIT (TMSK1, 0x40); //Enable interrupt on OC2
                       ;     SET_BIT (TCTL1, 0x40); //Enable toggle
                       ;     duty_cycle = duty_cycle2;
                       ;     period = period2;
                       ;     
                       ; }
                       ; 
                       ; void done()
                       ; {
                       ;     CLEAR_BIT (TMSK1, 0x40); //Disable interrupt on OC2
                       ;     SET_BIT (TCTL1, 0x80); //set OC2 line to 0 on compare
                       ;     SET_BIT (CFORC, 0x40); //force successful compare
 0005                 L7:
 0005 3B                rti
                       ;  IX -> 0,x
 0006                 _TIC3_isr::
 0006                   .dbfunc TIC3_isr
 0006                   .dbline 101
                       ; }
                       ; 
                       ; void TOC2_isr()
                       ; {
                       ; //  if (TCTL1 & 0x40)
                       ; //  {
                       ; //      CLEAR_BIT (TCTL1, 0x40); //Clear bit to set for falling edge next interrupt
                       ; 
                       ;         TOC2 += duty_cycle;     //Add time to TOC2 for duty cycle
                       ; //  }
                       ; //  if (!(TCTL1 & 0x40))
                       ; //  {
 0006                 L8:
 0006 3B                rti
                       ;  IX -> 0,x
 0007                 _TIC2_isr::
 0007                   .dbfunc TIC2_isr
 0007                   .dbline 107
                       ; //      SET_BIT (TCTL1, 0x40);
                       ; //      TOC2 += (period - duty_cycle);
                       ; //  }
                       ;     
                       ;     CLEAR_FLAG(TFLG1, 0x40); //Clear interrupt flag
                       ; }
 0007                 L9:
 0007 3B                rti
                       ;  IX -> 0,x
 0008                 _TIC1_isr::
 0008                   .dbfunc TIC1_isr
 0008                   .dbline 113
                       ; /************************** End of Function Defintions ******************/
                       ; 
                       ; /**************************** Main **************************************/
                       ; 
                       ; unsigned int x, y, z;
                       ; void main(void)
 0008                 L10:
 0008 3B                rti
                       ;  IX -> 0,x
 0009                 _RTI_isr::
 0009                   .dbfunc RTI_isr
 0009                   .dbline 119
                       ; {
                       ;     /* VT100 clear screen */ 
                       ;     char clear[]= "\x1b\x5B\x32\x4A\x04"; 
                       ;     
                       ;     /* VT100 position cursor at (x,y) = (3,12) command is "\x1b[3;12H"*/
                       ;     char place[]= "\x1b[1;1H";  /*Home*/
 0009                 L11:
 0009 3B                rti
                       ;  IX -> 0,x
 000A                 _IRQ_isr::
 000A                   .dbfunc IRQ_isr
 000A                   .dbline 125
                       ;     
                       ;     SET_BIT(PACTL, 0x80);   
                       ;     init_analog();
                       ;     init_clocktjp();
                       ;     init_serial();
                       ; 
 000A                 L12:
 000A 3B                rti
                       ;  IX -> 0,x
 000B                 _XIRQ_isr::
 000B                   .dbfunc XIRQ_isr
 000B                   .dbline 131
                       ;     INTR_ON(); /*turn on HC11 interrupt system*/
                       ; 
                       ;     printf("%s", clear);  
                       ;     printf("%s", place);
                       ;     
                       ;     printf("\tTitle:\t\tvalve.c\n"
 000B                 L13:
 000B 3B                rti
                       ;  IX -> 0,x
 000C                 _SWI_isr::
 000C                   .dbfunc SWI_isr
 000C                   .dbline 137
                       ;   "\tProgrammer:\tScott Nortman\n"
                       ;   "\tDate:\t\tJanuary, 2000\n"
                       ;   "\tVersion\t\t1\n\n");
                       ;   
                       ;     printf("PNEUMATIC CYLINDER DIAGNOSTIC PROGRAM\n\n");
                       ;     
 000C                 L14:
 000C 3B                rti
                       ;  IX -> 0,x
 000D                 _ILLOP_isr::
 000D                   .dbfunc ILLOP_isr
 000D                   .dbline 143
                       ;     while(1)
                       ;     {
                       ;         printf("Enter number of e clocks for the period\n");
                       ;         z = read_int();
                       ;         printf("Enter e clocks for duty cycle\n");
                       ;         y = read_int();
 000D                 L15:
 000D 3B                rti
                       ;  IX -> 0,x
 000E                 _COP_isr::
 000E                   .dbfunc COP_isr
 000E                   .dbline 149
                       ;         printf("Enter the desired position\n");
                       ;         x = read_int();
                       ;         
                       ;         valve_position(x, y, z);
                       ;         
                       ; //      printf("%s", clear);  
 000E                 L16:
 000E 3B                rti
                       ;  IX -> 0,x
 000F                 _CLMON_isr::
 000F                   .dbfunc CLMON_isr
 000F                   .dbline 155
                       ;  //     printf("%s", place);
                       ;         
                       ;     }/*End While*/
                       ;     
                       ; }/*End Main*/
                       ; 
 000F                 L17:
 000F 3B                rti
                         .area data
 0000                 _drew::
 0000                   .blkw 1
                         .area idata
 0000 0000              .word _interrupt_vectors
                         .area text
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;             pd -> 12,x
                       ;           duty -> 10,x
                       ;       position -> 6,x
 0010                 _valve_position::
 0010 BD0000            jsr __enterb
 0013 44                .byte 0x44
 0014                   .dbfile valve.c
 0014                   .dbfunc valve_position
 0014                   .dbline 52
 0014 CC02A7            ldd #L19
 0017 BD0000            jsr _printf
 001A 2023              bra L21
 001C                 L20:
 001C                   .dbline 55
 001C CC0001            ldd #1
 001F BD0000            jsr _analog
 0022 37                pshb
 0023 36                psha
 0024 CC028E            ldd #L23
 0027 BD0000            jsr _printf
 002A 1838              puly
 002C                   .dbline 56
 002C 18CE1000          ldy #0x1000
 0030 181C0080          bset 0,y,#128
 0034                   .dbline 57
 0034 EC0C              ldd 12,x
 0036 37                pshb
 0037 36                psha
 0038 EC0A              ldd 10,x
 003A BD0091            jsr _PWM
 003D 1838              puly
 003F                   .dbline 62
 003F                 L21:
 003F                   .dbline 53
 003F CC0001            ldd #1
 0042 BD0000            jsr _analog
 0045 C3000A            addd #10
 0048 ED02              std 2,x
 004A EC06              ldd 6,x
 004C 1AA302            cpd 2,x
 004F 22CB              bhi L20
 0051 2023              bra L25
 0053                 L24:
 0053                   .dbline 65
 0053 CC0001            ldd #1
 0056 BD0000            jsr _analog
 0059 37                pshb
 005A 36                psha
 005B CC028E            ldd #L23
 005E BD0000            jsr _printf
 0061 1838              puly
 0063                   .dbline 66
 0063 18CE1000          ldy #0x1000
 0067 181D0080          bclr 0,y,#0x80
 006B                   .dbline 67
 006B EC0C              ldd 12,x
 006D 37                pshb
 006E 36                psha
 006F EC0A              ldd 10,x
 0071 BD0091            jsr _PWM
 0074 1838              puly
 0076                   .dbline 72
 0076                 L25:
 0076                   .dbline 63
 0076 CC0001            ldd #1
 0079 BD0000            jsr _analog
 007C 83000A            subd #10
 007F ED02              std 2,x
 0081 EC06              ldd 6,x
 0083 1AA302            cpd 2,x
 0086 25CB              blo L24
 0088                   .dbline 73
 0088                 L18:
 0088 08                inx
 0089 08                inx
 008A 08                inx
 008B 08                inx
 008C 35                txs
 008D 38                pulx
 008E 1838              puly
 0090 39                rts
                       ;  IX -> 0,x
                       ;        period2 -> 8,x
                       ;    duty_cycle2 -> 4,x
 0091                 _PWM::
 0091 37                pshb
 0092 36                psha
 0093 3C                pshx
 0094 3C                pshx
 0095 30                tsx
 0096 EF00              stx 0,x
 0098                   .dbfunc PWM
 0098                   .dbline 77
 0098 CC027E            ldd #L28
 009B BD0000            jsr _printf
 009E                   .dbline 78
 009E 18CE1022          ldy #0x1022
 00A2 181C0040          bset 0,y,#64
 00A6                   .dbline 79
 00A6 18CE1020          ldy #0x1020
 00AA 181C0040          bset 0,y,#64
 00AE                   .dbline 80
 00AE EC04              ldd 4,x
 00B0 FD0008            std _duty_cycle
 00B3                   .dbline 81
 00B3 EC08              ldd 8,x
 00B5 FD0006            std _period
 00B8                   .dbline 83
 00B8                 L27:
 00B8 08                inx
 00B9 08                inx
 00BA 35                txs
 00BB 38                pulx
 00BC 1838              puly
 00BE 39                rts
                       ;  IX -> 0,x
 00BF                 _done::
 00BF                   .dbfunc done
 00BF                   .dbline 87
 00BF 18CE1022          ldy #0x1022
 00C3 181D0040          bclr 0,y,#0x40
 00C7                   .dbline 88
 00C7 18CE1020          ldy #0x1020
 00CB 181C0080          bset 0,y,#128
 00CF                   .dbline 89
 00CF 18CE100B          ldy #0x100b
 00D3 181C0040          bset 0,y,#64
 00D7                   .dbline 90
 00D7                 L29:
 00D7 39                rts
                       ;  IX -> 0,x
 00D8                 _TOC2_isr::
 00D8                   .dbfunc TOC2_isr
 00D8                   .dbline 98
                         ; vol
 00D8 FC1018            ldd 0x1018
 00DB F30008            addd _duty_cycle
 00DE FD1018            std 0x1018
 00E1                   .dbline 106
 00E1 18CE1023          ldy #0x1023
 00E5 181D00BF          bclr 0,y,#0xbf
 00E9                   .dbline 107
 00E9                 L30:
 00E9 3B                rti
 00EA                 L32:
 00EA 1B5B324A0400      .byte 27,91,50,'J,4,0
 00F0                 L33:
 00F0 1B5B313B314800    .byte 27,91,49,59,49,'H,0
                       ;  IX -> 0,x
                       ;          place -> 3,x
                       ;          clear -> 10,x
 00F7                 _main::
 00F7 BD0000            jsr __enterb
 00FA 10                .byte 0x10
 00FB                   .dbfunc main
 00FB                   .dbline 116
 00FB EC00              ldd 0,x
 00FD C3000A            addd #10
 0100 18CE00EA          ldy #L32
 0104 3C                pshx
 0105 8F                xgdx
 0106 CC0006            ldd #6
 0109 BD0000            jsr __asgnblk
 010C 38                pulx
 010D                   .dbline 119
 010D EC00              ldd 0,x
 010F C30003            addd #3
 0112 18CE00F0          ldy #L33
 0116 3C                pshx
 0117 8F                xgdx
 0118 CC0007            ldd #7
 011B BD0000            jsr __asgnblk
 011E 38                pulx
 011F                   .dbline 121
 011F 18CE1026          ldy #0x1026
 0123 181C0080          bset 0,y,#128
 0127                   .dbline 122
 0127 BD0000            jsr _init_analog
 012A                   .dbline 123
 012A BD0000            jsr _init_clocktjp
 012D                   .dbline 124
 012D BD0000            jsr _init_serial
 0130 0E                        cli
                       
 0131                   .dbline 128
 0131 EC00              ldd 0,x
 0133 C3000A            addd #10
 0136 37                pshb
 0137 36                psha
 0138 CC027B            ldd #L34
 013B BD0000            jsr _printf
 013E 1838              puly
 0140                   .dbline 129
 0140 EC00              ldd 0,x
 0142 C30003            addd #3
 0145 37                pshb
 0146 36                psha
 0147 CC027B            ldd #L34
 014A BD0000            jsr _printf
 014D 1838              puly
 014F                   .dbline 131
 014F CC022B            ldd #L35
 0152 BD0000            jsr _printf
 0155                   .dbline 136
 0155 CC0203            ldd #L36
 0158 BD0000            jsr _printf
 015B 2038              bra L38
 015D                 L37:
 015D                   .dbline 140
 015D CC01DA            ldd #L40
 0160 BD0000            jsr _printf
 0163                   .dbline 141
 0163 BD0000            jsr _read_int
 0166 FD0000            std _z
 0169                   .dbline 142
 0169 CC01BB            ldd #L41
 016C BD0000            jsr _printf
 016F                   .dbline 143
 016F BD0000            jsr _read_int
 0172 FD0002            std _y
 0175                   .dbline 144
 0175 CC019F            ldd #L42
 0178 BD0000            jsr _printf
 017B                   .dbline 145
 017B BD0000            jsr _read_int
 017E FD0004            std _x
 0181                   .dbline 147
 0181 FC0000            ldd _z
 0184 37                pshb
 0185 36                psha
 0186 FC0002            ldd _y
 0189 37                pshb
 018A 36                psha
 018B FC0004            ldd _x
 018E BD0010            jsr _valve_position
 0191 1838              puly
 0193 1838              puly
 0195                   .dbline 152
 0195                 L38:
 0195                   .dbline 138
 0195 20C6              bra L37
 0197                 L31:
 0197 8F                xgdx
 0198 C30010            addd #16
 019B 8F                xgdx
 019C 35                txs
 019D 38                pulx
 019E 39                rts
                         .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
 019F                 L42:
 019F 456E7465722074686520646573697265  .byte 'E,'n,'t,'e,'r,32,'t,'h,'e,32,'d,'e,'s,'i,'r,'e
 01AF 6420706F736974696F6E0A00  .byte 'd,32,'p,'o,'s,'i,'t,'i,'o,'n,10,0
 01BB                 L41:
 01BB 456E746572206520636C6F636B732066  .byte 'E,'n,'t,'e,'r,32,'e,32,'c,'l,'o,'c,'k,'s,32,'f
 01CB 6F722064757479206379636C650A00    .byte 'o,'r,32,'d,'u,'t,'y,32,'c,'y,'c,'l,'e,10,0
 01DA                 L40:
 01DA 456E746572206E756D626572206F6620  .byte 'E,'n,'t,'e,'r,32,'n,'u,'m,'b,'e,'r,32,'o,'f,32
 01EA 6520636C6F636B7320666F7220746865  .byte 'e,32,'c,'l,'o,'c,'k,'s,32,'f,'o,'r,32,'t,'h,'e
 01FA 20706572696F640A00    .byte 32,'p,'e,'r,'i,'o,'d,10,0
 0203                 L36:
 0203 504E45554D415449432043594C494E44  .byte 'P,'N,'E,'U,'M,'A,'T,'I,'C,32,'C,'Y,'L,'I,'N,'D
 0213 455220444941474E4F53544943205052  .byte 'E,'R,32,'D,'I,'A,'G,'N,'O,'S,'T,'I,'C,32,'P,'R
 0223 4F4752414D0A0A00  .byte 'O,'G,'R,'A,'M,10,10,0
 022B                 L35:
 022B 095469746C653A090976616C76652E63  .byte 9,'T,'i,'t,'l,'e,58,9,9,'v,'a,'l,'v,'e,46,'c
 023B 0A0950726F6772616D6D65723A095363  .byte 10,9,'P,'r,'o,'g,'r,'a,'m,'m,'e,'r,58,9,'S,'c
 024B 6F7474204E6F72746D616E0A09446174  .byte 'o,'t,'t,32,'N,'o,'r,'t,'m,'a,'n,10,9,'D,'a,'t
 025B 653A09094A616E756172792C20323030  .byte 'e,58,9,9,'J,'a,'n,'u,'a,'r,'y,44,32,50,48,48
 026B 300A0956657273696F6E0909310A0A00  .byte 48,10,9,'V,'e,'r,'s,'i,'o,'n,9,9,49,10,10,0
 027B                 L34:
 027B 257300            .byte 37,'s,0
 027E                 L28:
 027E 596F752772652061742050574D2E0A00  .byte 'Y,'o,'u,39,'r,'e,32,'a,'t,32,'P,'W,'M,46,10,0
 028E                 L23:
 028E 54686520616E616C6F672076616C7565  .byte 'T,'h,'e,32,'a,'n,'a,'l,'o,'g,32,'v,'a,'l,'u,'e
 029E 2069733A0925640A00    .byte 32,'i,'s,58,9,37,'d,10,0
 02A7                 L19:
 02A7 596F7527726520206174207468652062  .byte 'Y,'o,'u,39,'r,'e,32,32,'a,'t,32,'t,'h,'e,32,'b
 02B7 6567696E6E696E67206F662076616C76  .byte 'e,'g,'i,'n,'n,'i,'n,'g,32,'o,'f,32,'v,'a,'l,'v
 02C7 655F706F736974696F6E2E0A00    .byte 'e,95,'p,'o,'s,'i,'t,'i,'o,'n,46,10,0
