home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tcom96 / samples / spcmds.seq < prev    next >
Encoding:
Text File  |  1991-03-21  |  9.5 KB  |  333 lines

  1. \ SPCMDS.SEQ    serial port commands.
  2.  
  3. code GET_WORDL         \ Get a word value into W0 from the serial port
  4.         PUSH    TTOS
  5.         CALL    SP_RX_TL
  6.         JE      1 $             \ low byte
  7.         LDB     TTOS W0
  8.         CALL    SP_RX_TL        \ high byte
  9.         LDB     TTOSH W0
  10.         LD      W0 TTOS         \ now W0 is the value
  11. 1 $:    POP     TTOS
  12.         RET
  13.         end-code
  14.  
  15. code SEND_WORDL        \ Send the word value in W0 to the serial port
  16.         PUSH    W0
  17.         CALL    SP_SENDL        \ send the low byte
  18.         POP     W0
  19.         LDB     W0  W1
  20.         CALL    SP_SENDL        \ send the high byte
  21.         RET
  22.         end-code
  23.  
  24. \ *************************************************************************
  25. \
  26. \       Serial port function to go call a subroutine
  27. \
  28. \ *************************************************************************
  29.  
  30. CODE JUMP_TO
  31.         CALL    GET_WORDL        \ get an address
  32.         0<> IF  BR[] W0  THEN    \ jump to it
  33.                         \ subsequent RET will be to idle loop
  34.         RET
  35.         end-code
  36.  
  37.  
  38. \ *************************************************************************
  39. \
  40. \       Write and Read bytes and words in
  41. \       regular memory, or the normal register set
  42. \
  43. \ *************************************************************************
  44.  
  45. CODE WRITE_WORDS        \ write memory word contents
  46.         PUSH    TTOS
  47.         PUSH    TTOS2
  48.         CALL    GET_WORDL        \ get address
  49.         JE      2 $
  50.         LD      TTOS W0
  51.         CALL    SP_RX_TL
  52.         JE      2 $
  53.         LDB     TTOS2 W0        \ third byte is word count, put it in TTOS2
  54. 1 $:
  55.         CALL    GET_WORDL       \ get a word of data to write
  56.         JE      2 $
  57.         ST      W0  []+ TTOS    \ write the word
  58.         DJNZ    TTOS2  1 $
  59. 2 $:    POP     TTOS2
  60.         POP     TTOS
  61.         RET
  62.         end-code
  63.  
  64. CODE FILL_MEM           \ fill memory with a byte value
  65.         PUSH    TTOS
  66.         CALL    GET_WORDL       \ get address
  67.         JE      2 $
  68.         LD      TTOS W0
  69.         CALL    GET_WORDL       \ third and fourth are byte count
  70.         JE      2 $
  71.         PUSH    W0
  72.         CALL    SP_RX_TL         \ get the byte to write
  73.         POP     W2
  74.         JE      2 $
  75. 1 $:
  76.         STB     W0  []+ TTOS    \ write the byte
  77.         DEC     W2
  78.         JNE     1 $
  79. 2 $:
  80.         CALL    SP_SENDL        \ send a byte to say it is done
  81.         POP     TTOS
  82.         RET
  83.         end-code
  84.  
  85. CODE READ_WORDS         \ return memory word contents
  86.         PUSH    TTOS
  87.         PUSH    TTOS2
  88.         CALL    GET_WORDL       \ get address into W0
  89.         JE      2 $
  90.         PUSH    W0
  91.         CALL    SP_RX_TL        \ third byte is word count
  92.         LDB     TTOS2 W0        \ put it in TTOS2
  93.         POP     TTOS            \ address in TTOS
  94.         JE      2 $
  95. 1 $:
  96.         LD      W0  []+ TTOS    \ read a word
  97.         CALL    SEND_WORDL      \ send the word
  98.         DJNZ    TTOS2 1 $
  99. 2 $:    POP     TTOS2
  100.         POP     TTOS
  101.         RET
  102.         end-code
  103.  
  104.  
  105. CODE WRITE_BYTES        \ write memory byte contents
  106.         PUSH    TTOS
  107.         PUSH    TTOS2
  108.         CALL    GET_WORDL       \ get address
  109.         JE      2 $
  110.         LD      TTOS W0
  111.         CALL    SP_RX_TL
  112.         JE      2 $
  113.         LDB     TTOS2 W0        \ third byte is byte count, put it in TTOS2
  114. 1 $:
  115.         CALL    SP_RX_TL        \ get a byte of data to write
  116.         JE      2 $
  117.         STB     W0  []+ TTOS    \ write the byte
  118.         DJNZ    TTOS2  1 $
  119. 2 $:    POP     TTOS2
  120.         POP     TTOS
  121.         RET
  122.         end-code
  123.  
  124. CODE READ_BYTES         \ return memory byte contents
  125.         PUSH    TTOS
  126.         PUSH    TTOS2
  127.         CALL    GET_WORDL       \ get address into W0
  128.         JE      2 $
  129.         PUSH    W0
  130.         CALL    SP_RX_TL        \ third byte is byte count
  131.         LDB     TTOS2 W0        \ put it in TTOS2
  132.         POP     TTOS            \ address in TTOS
  133.         JE      2 $
  134. 1 $:
  135.         LDB     W0  []+ TTOS    \ read a byte
  136.         CALL    SP_SENDL        \ send the byte
  137.         DJNZ    TTOS2 1 $
  138. 2 $:    POP     TTOS2
  139.         POP     TTOS
  140.         RET
  141.         end-code
  142.  
  143. \S
  144. COMMENT:
  145. \ *************************************************************************
  146. \
  147. \       Write and Read bytes and words in the alternate register set
  148. \
  149. \ *************************************************************************
  150.  
  151. CODE WRITE_WORDSW       \ write memory word contents
  152.         CALL    GET_WORDL        \ get address
  153.         JE      2 $
  154.         LD      DX  CX          \ put it in DX
  155.         CALL    SP_RX_TL
  156.         JE      2 $
  157.         LDB     EL  AL          \ third byte is word count, put it in EL
  158. 1 $:
  159.         CALL    GET_WORDL        \ get a data word into CX
  160.         JE      2 $
  161.         LDB     WSR  # 15
  162.         ST      CX  []+ DX       \ write the word
  163.         LDB     WSR  0
  164.         DJNZ    EL  1 $
  165. 2 $:    RET     end-code
  166.  
  167. CODE READ_WORDSW        \ return memory word contents
  168.         CALL    GET_WORDL        \ get address into CX
  169.         JE      2 $
  170.         CALL    SP_RX_TL
  171.         JE      2 $
  172.         LDB     EL  AL          \ third byte is word count, put it in EL
  173. 1 $:
  174.         LDB     WSR  # 15
  175.         LD      DX  []+ CX       \ read a word
  176.         LDB     WSR  0
  177.         CALL    SEND_WORDL       \ send the word
  178.         DJNZ    EL  1 $
  179. 2 $:    RET     end-code
  180.  
  181.  
  182. CODE WRITE_BYTESW       \ write memory byte contents
  183.         CALL    GET_WORDL        \ get address, into CX
  184.         JE      2 $
  185.         CALL    SP_RX_TL
  186.         JE      2 $
  187.         LDB     EL  AL          \ third byte is byte count, put it in EL
  188. 1 $:
  189.         CALL    SP_RX_TL
  190.         JE      2 $             \ get a byte of data to write
  191.         LDB     WSR  # 15
  192.         STB     AL  []+ CX       \ write the byte
  193.         LDB     WSR  0
  194.         DJNZ    EL  1 $
  195. 2 $:    RET     end-code
  196.  
  197.  
  198.  
  199. CODE READ_BYTESW                \ return memory byte contents
  200.         CALL    GET_WORDL        \ get address, into CX
  201.         JE      2 $
  202.         CALL    SP_RX_TL
  203.         JE      2 $
  204.         LDB     EL  AL          \ third byte is byte count
  205. 1 $:
  206.         LDB     WSR  # 15
  207.         LDB     AL  []+ CX       \ read a byte
  208.         LDB     WSR  0
  209.         CALL    SP_SEND         \ send back the byte
  210.         DJNZ    EL  1 $
  211. 2 $:    RET     end-code
  212. COMMENT;
  213.  
  214. \S
  215.  
  216. \ ***************************************************************************
  217. \
  218. \       Analog-to-Digital converter operations
  219. \
  220. \ ***************************************************************************
  221.  
  222. \       Measure an A to D channel
  223.  
  224. CODE MEASURE_AD
  225.         CALL    SP_RX_TL
  226.         JE      2 $
  227.         ANDB    AL  # 7          \ next byte is channel number
  228.  
  229.         ORB     AL  # 8          \ conversion GO command
  230.         LD      AD_COMMAND  AL          \ initiate measurement
  231. 1 $:
  232.         JBS     AD_RESULT  3  1 $
  233.  
  234.         LD      DX  AD_RESULT   \ send back the result
  235.         CALL    SEND_WORDL
  236. 2 $:    RET     end-code
  237.  
  238. \       Measure all A to D channels repeatedly
  239.  
  240. CODE MEASURE_ALL
  241.         LDB     CL  0
  242. 1 $:
  243.         LDB     AL  CL
  244.         ANDB    AL  # 7          \ next channel to measure
  245.         ORB     AL  # 8          \ conversion GO command
  246.         LD      AD_COMMAND  AL          \ initiate measurement
  247. 2 $:
  248.         JBS     AD_RESULT  3  2 $       \ wait for the conversion
  249.  
  250.         LD      DX  AD_RESULT   \ send back the result
  251.         CALL    SEND_WORDL
  252.  
  253.         INC     CL
  254.         CALL    SP_RX_TL
  255.         CMPB    AL  # '!'
  256.         JNE     1 $             \ loop until a ! received
  257.         RET     end-code
  258.  
  259. \ ***************************************************************************
  260. \
  261. \               EEPROM read and write operations
  262. \
  263. \ ***************************************************************************
  264.  
  265.  
  266. CODE EE_READ            \ return a serial EEPROM byte
  267.         CALL    GET_WORDL        \ get address
  268.         JE      2 $
  269.         LD      AX  CX
  270.         CALL    EEREAD          \ read the byte
  271.         LDB     AL  CL
  272.         CALL    SP_SEND         \ send back the byte
  273. 2 $:    RET     end-code
  274.  
  275.  
  276. CODE EE_WRITE           \ write a serial EEPROM byte
  277.         CALL    ENABLE          \ enable the EEPROM for writes
  278.         CALL    GET_WORDL
  279.         JE      2 $             \ get address into DX
  280.         LD      DX  CX
  281.  
  282.         CALL    SP_RX_TL
  283.         JE      2 $             \ get the data to write
  284.  
  285.         LDB     CL  AL
  286.         LD      AX  DX
  287.         CALL    EEWRITE         \ write the byte
  288. 2 $:    RET     end-code
  289.  
  290.  
  291. \s
  292. TO_HEX:                         \ convert 4-bit in AL to a HEX digit
  293.         ANDB    AL # 0Fh
  294.         ADDB    AL  # ( '0' )
  295.         CMPB    AL  # ( '9' )
  296.         JLE     TO_HRET
  297.         ADDB    AL  # ( 'A' - '9' -1 )
  298. TO_HRET:
  299.         RET
  300.  
  301. PUBLIC SEND_HEXB
  302. SEND_HEXB:                      \ send byte in AL as HEX ASCII
  303.         PUSH    AX
  304.         SHR     AX # 4
  305.         CALL    TO_HEX
  306.         CALL    SP_SEND
  307.         POP     AX
  308.         CALL    TO_HEX
  309.         CALL    SP_SEND
  310.         RET
  311.  
  312. PUBLIC SEND_HEXW
  313. SEND_HEXW:                      \ send word in AX as HEX ASCII
  314.         PUSH    AX
  315.         SHR     AX # 12
  316.         CALL    TO_HEX
  317.         CALL    SP_SEND
  318.         POP     AX
  319.         PUSH    AX
  320.         SHR     AX # 8
  321.         CALL    TO_HEX
  322.         CALL    SP_SEND
  323.         POP     AX
  324.         PUSH    AX
  325.         SHR     AX # 4
  326.         CALL    TO_HEX
  327.         CALL    SP_SEND
  328.         POP     AX
  329.         CALL    TO_HEX
  330.         CALL    SP_SEND
  331.         RET
  332.  
  333.