home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / amiga-flight / programs / temperature.asm < prev    next >
Assembly Source File  |  1977-12-31  |  7KB  |  158 lines

  1. *****************************************************************************
  2. ***                          TEMPERATURE.ASM                              ***
  3. ***                                                                       ***
  4. ***    Author : Andrew Duffy                                              ***
  5. ***    Date   : February 1993                                             ***
  6. ***    Desc.  : This program demonstrates how to read the value of the    ***
  7. ***             heater/potentiometer using a simple binary chop routine.  ***
  8. ***                                                                       ***
  9. ***                          ©XCNT, 1992-1994.                            ***
  10. *****************************************************************************
  11.  
  12.  
  13. *****************************************************************************
  14. ***                              Includes                                 ***
  15. *****************************************************************************
  16.  
  17.         include    "subrts.h"    Included by default anyway
  18.  
  19. *****************************************************************************
  20. ***                          Initialisation routine                       ***
  21. *****************************************************************************
  22.  
  23.         move.b    #APPS_ALL_IN,d0    Initialise the applications board
  24.         jsr    APPS_INIT    (port A all input)
  25.  
  26.         movea.l    #Instructs,a6    Print instructions
  27.         jsr    OUTSTR
  28.  
  29. *****************************************************************************
  30. ***                         Main control routine                          ***
  31. *****************************************************************************
  32.  
  33. Main        bsr.s    Get.Temperature    Call Get.Temperature routine
  34.         bra.s    Main        Repeat forever
  35.  
  36.         rts            Exit (never gets here)
  37.  
  38. *****************************************************************************
  39. ***                        Get.Temperature routine                        ***
  40. *****************************************************************************
  41.  
  42. Get.Temperature    movem.l    d0-d2,-(a7)    Save all used registers
  43.         move.l    #127,d0        Set up d0 with starting value
  44.         move.l    #128,d1        Set up d1 to half of start value
  45. .Chop        lsr.b    #1,d1        Divide half value by half again
  46.         move.b    d0,APPS_PORTB    Send try value
  47.         move.b    APPS_PORTA,d2
  48.         btst    #3,d2        Check if value was higher or lower
  49.         bne.s    .Higher        If value was higher
  50. .Lower        sub.b    d1,d0        Subtract half value from main value
  51.         cmp.b    #1,d1        Check if all values have been done
  52.         beq.s    .Done
  53.         bra.s    .Chop        Try next value
  54. .Higher        add.b    d1,d0        Add half value to main value
  55.         cmp.b    #1,d1        Check if all values have been done
  56.         beq.s    .Done
  57.         bra.s    .Chop        Try next value
  58.  
  59. .Done        move.b    d0,APPS_PORTB    (This ensures an acurate reading
  60.         move.b    APPS_PORTA,d1    of the heater with single byte
  61.         btst    #3,d1        differences rather than 2 bytes)
  62.         beq.s    .Done2        Value is correct
  63.         add.b    #1,d0        Value incorrect, subtract 1 from it
  64. .Done2        move.w    d0,Temperature    Save Temperature
  65.  
  66. *****************************************************************************
  67. ***                  Temperature found - now draw graph                   ***
  68. *****************************************************************************
  69.  
  70.         move.b    #18,d0        Locate cursor to print
  71.         move.b    #47,d1        out temperature value.
  72.         bsr.s    Locate        Locate cursor
  73.         move.w    Temperature,d0    Temperature between 0 and 255
  74.         jsr    OUT2HEX        Output fan speed
  75.  
  76.         move.b    #15,d0        Locate cursor to print
  77.         move.b    #8,d1        out fan bar graph.
  78.         bsr.s    Locate        Locate cursor
  79.         moveq    #0,d1        Clear d1
  80.         move.w    Temperature,d1    Temperature between 0 and 255
  81.         lsr.b    #2,d1        Divide by four
  82.         move.b    #'*',d0
  83.         bsr.s    Chars        Output characters
  84.         movem.l    (a7)+,d0-d2    Unstack registers
  85.         rts
  86.  
  87. *****************************************************************************
  88. ***                          Locate routine                               ***
  89. *** Locates the cursor at d0 down, d1 across.                             ***
  90. *****************************************************************************
  91.  
  92. Locate        movem.l    d0-d3/a0/a6,-(a7)  Save all used registers
  93.         moveq    #0,d3
  94.         movea.l    #Locate_Seq+2,a0   ANSI locate sequence - Down
  95.         move.b    d0,d3
  96.         bsr.s    .Locate_1       Convert value to text value
  97.         movea.l    #Locate_Seq+5,a0   ANSI locate sequence - Across
  98.         move.b    d1,d3
  99.         bsr.s    .Locate_1       Convert value to text value
  100.         movea.l    #Locate_Seq,a6     Output escape sequence
  101.         jsr    OUTSTR
  102.         movem.l    (a7)+,d0-d3/a0/a6  Unstack registers
  103.         rts
  104.  
  105. .Locate_1    divu    #10,d3           Convert tens first
  106.         bsr    .Locate_1.2
  107. .Locate_1.2    add    #$30,d3           Then units
  108.         move.b    d3,(a0)+
  109.         move.w    #0,d3
  110.         swap    d3
  111.         rts
  112.  
  113. *****************************************************************************
  114. ***                            Chars routine                              ***
  115. *** Prints d1 number of d0.b characters                                   ***
  116. *****************************************************************************
  117.  
  118. Chars        movem.l    d0-d1/a6,-(a7)    Save all used registers
  119. .Chars_1    cmpi.b    #0,d1        Check if all characters done
  120.         beq.s    .Chars_1.2
  121.         jsr        OUTCH        Output 1 character
  122.         subi.b     #1,d1        Decrement number to do
  123.         bra.s    .Chars_1    Repeat
  124. .Chars_1.2    movea.l    #EraseToEnd,a6    Output clear to end string
  125.         jsr    OUTSTR
  126.          movem.l    (a7)+,d0-d1/a6    Unstack registers
  127.         rts                
  128.  
  129. *****************************************************************************
  130. ***                             Variables                                 ***
  131. *****************************************************************************
  132.  
  133. Temperature    ds.w    1
  134.  
  135. *****************************************************************************
  136. ***                              Strings                                  ***
  137. *****************************************************************************
  138.  
  139. EraseToEnd    dc.b    27,'[K',0
  140.         even
  141.  
  142. Locate_Seq    dc.b    27,'[  ;  f',0       ANSI sequence
  143.         even               Re-align code
  144.  
  145. Instructs    dc.b    "Temperature.asm",13,10,"===============",13,10,13,10
  146.         dc.b    "Ensure that the ADC is switched on.",13,10
  147.         dc.b    "Now select between the Heater and the Potentiometer using the",13,10
  148.         dc.b    "Heater/Pot switch.  If you select the potentiometer then use",13,10
  149.         dc.b    "the slider to adjust it''s value.",13,10
  150.         dc.b    "(LEDs may be left ON or OFF but will slow down on slower machines)"
  151.         dc.b    27,"[12;30fTemperature - (Percent)"
  152.         dc.b    27,"[14;8f00%  -     -     -     -     - 50% -     -     -     -     - 100%"
  153.         dc.b    27,"[18;32fActual Value :",0
  154.  
  155. *****************************************************************************
  156. ***                    End of file TEMPERATURE.ASM.                       ***
  157. *****************************************************************************
  158.