home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / ATODIN.AZM / ATODIN.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  2.0 KB  |  86 lines

  1. ;----------------------------------------------------------------
  2. ;          This is a module in the ASMLIB library
  3. ;
  4. ; This module uses registart DE as the channel on an analogue to
  5. ; digital converter to be read. The value is loaded onto HL and an FF
  6. ; is returned if an error / timeout has occurred.
  7. ;
  8. ; NOTE that this module suits an ADC-32 by SME Systems located at
  9. ; port 040h. Channels greater than 32 return FF in register HL.
  10. ; A successful channel read returns the zero flag true so that a
  11. ; jump non-zero should go to an error handler.
  12. ;
  13. ;            Written        R.C.H.        25/8/83
  14. ;            Last update    R.C.H.        22/10/83
  15. ;----------------------------------------------------------------
  16. ;
  17.     name    'atodin'
  18.     public    atodin
  19. ;
  20.     maclib    z80
  21. ;
  22. atod0    equ    040h
  23. atod1    equ    041h
  24. ;
  25. atodin:
  26.     ; Check if an illegal channel number
  27.     push    psw
  28.     mov    a,d
  29.     ora    a
  30.     jrz    not$d            ; error if d > 0 since only 32 channels
  31. ana$err:    ; return an error to the user
  32.     lxi    h,0ffffh
  33.     pop    psw
  34.     ret                ; return the error
  35. ;
  36. not$d:    ; Check if E <= 31
  37.     mov    a,e
  38.     cpi    32
  39.     jrnc    ana$err            ; error if >= 32
  40. ;
  41. ; Get the analogue channel into the accumulator
  42. ;
  43.     mov    a,e            ; Get the channel number
  44.     out    atod0
  45.     call    delay            ; A little delay for safety sake
  46. ; Now  pulse the start of conversion pin
  47.     ori    80h
  48.     out    atod0
  49.     call    delay
  50.     ani    07fh            ; Mask off top bit
  51.     out    atod0
  52. ;
  53.     lxi    h,8000h
  54. getac1:
  55.     in    atod1
  56.     ani    080h
  57.     jrnz    get$data        ; if 1 then get the data
  58. ; If here then we must decrement the HL register to trap a dead board
  59.     dcx    h
  60.     mov    a,l
  61.     ora    h            ; is h = l = 0 ??
  62.     jrnz    getac1            ; if not then try again
  63.     jr    ana$err            ; else we return a converter error
  64. ;
  65. get$data:
  66.     in    atod0
  67.     mov    l,a            ; Save value into c
  68.     xra    a
  69.     mov    h,a            ; clear top byte
  70.     pop    psw
  71.     ret
  72. ;
  73. ; Do a little delay to as to wait for the cmos a to d chip.
  74. delay:
  75.     push    psw
  76.     mvi    a,020h            ; Delay countdown value
  77. delay1:
  78.     dcr    a
  79.     jnz    delay1
  80.     pop    psw            ; Restore the accumulator
  81.     ret
  82. ;
  83.     end
  84.  
  85.  
  86.