home *** CD-ROM | disk | FTP | other *** search
- \ SPCMDS.SEQ serial port commands.
-
- code GET_WORDL \ Get a word value into W0 from the serial port
- PUSH TTOS
- CALL SP_RX_TL
- JE 1 $ \ low byte
- LDB TTOS W0
- CALL SP_RX_TL \ high byte
- LDB TTOSH W0
- LD W0 TTOS \ now W0 is the value
- 1 $: POP TTOS
- RET
- end-code
-
- code SEND_WORDL \ Send the word value in W0 to the serial port
- PUSH W0
- CALL SP_SENDL \ send the low byte
- POP W0
- LDB W0 W1
- CALL SP_SENDL \ send the high byte
- RET
- end-code
-
- \ *************************************************************************
- \
- \ Serial port function to go call a subroutine
- \
- \ *************************************************************************
-
- CODE JUMP_TO
- CALL GET_WORDL \ get an address
- 0<> IF BR[] W0 THEN \ jump to it
- \ subsequent RET will be to idle loop
- RET
- end-code
-
-
- \ *************************************************************************
- \
- \ Write and Read bytes and words in
- \ regular memory, or the normal register set
- \
- \ *************************************************************************
-
- CODE WRITE_WORDS \ write memory word contents
- PUSH TTOS
- PUSH TTOS2
- CALL GET_WORDL \ get address
- JE 2 $
- LD TTOS W0
- CALL SP_RX_TL
- JE 2 $
- LDB TTOS2 W0 \ third byte is word count, put it in TTOS2
- 1 $:
- CALL GET_WORDL \ get a word of data to write
- JE 2 $
- ST W0 []+ TTOS \ write the word
- DJNZ TTOS2 1 $
- 2 $: POP TTOS2
- POP TTOS
- RET
- end-code
-
- CODE FILL_MEM \ fill memory with a byte value
- PUSH TTOS
- CALL GET_WORDL \ get address
- JE 2 $
- LD TTOS W0
- CALL GET_WORDL \ third and fourth are byte count
- JE 2 $
- PUSH W0
- CALL SP_RX_TL \ get the byte to write
- POP W2
- JE 2 $
- 1 $:
- STB W0 []+ TTOS \ write the byte
- DEC W2
- JNE 1 $
- 2 $:
- CALL SP_SENDL \ send a byte to say it is done
- POP TTOS
- RET
- end-code
-
- CODE READ_WORDS \ return memory word contents
- PUSH TTOS
- PUSH TTOS2
- CALL GET_WORDL \ get address into W0
- JE 2 $
- PUSH W0
- CALL SP_RX_TL \ third byte is word count
- LDB TTOS2 W0 \ put it in TTOS2
- POP TTOS \ address in TTOS
- JE 2 $
- 1 $:
- LD W0 []+ TTOS \ read a word
- CALL SEND_WORDL \ send the word
- DJNZ TTOS2 1 $
- 2 $: POP TTOS2
- POP TTOS
- RET
- end-code
-
-
- CODE WRITE_BYTES \ write memory byte contents
- PUSH TTOS
- PUSH TTOS2
- CALL GET_WORDL \ get address
- JE 2 $
- LD TTOS W0
- CALL SP_RX_TL
- JE 2 $
- LDB TTOS2 W0 \ third byte is byte count, put it in TTOS2
- 1 $:
- CALL SP_RX_TL \ get a byte of data to write
- JE 2 $
- STB W0 []+ TTOS \ write the byte
- DJNZ TTOS2 1 $
- 2 $: POP TTOS2
- POP TTOS
- RET
- end-code
-
- CODE READ_BYTES \ return memory byte contents
- PUSH TTOS
- PUSH TTOS2
- CALL GET_WORDL \ get address into W0
- JE 2 $
- PUSH W0
- CALL SP_RX_TL \ third byte is byte count
- LDB TTOS2 W0 \ put it in TTOS2
- POP TTOS \ address in TTOS
- JE 2 $
- 1 $:
- LDB W0 []+ TTOS \ read a byte
- CALL SP_SENDL \ send the byte
- DJNZ TTOS2 1 $
- 2 $: POP TTOS2
- POP TTOS
- RET
- end-code
-
- \S
- COMMENT:
- \ *************************************************************************
- \
- \ Write and Read bytes and words in the alternate register set
- \
- \ *************************************************************************
-
- CODE WRITE_WORDSW \ write memory word contents
- CALL GET_WORDL \ get address
- JE 2 $
- LD DX CX \ put it in DX
- CALL SP_RX_TL
- JE 2 $
- LDB EL AL \ third byte is word count, put it in EL
- 1 $:
- CALL GET_WORDL \ get a data word into CX
- JE 2 $
- LDB WSR # 15
- ST CX []+ DX \ write the word
- LDB WSR 0
- DJNZ EL 1 $
- 2 $: RET end-code
-
- CODE READ_WORDSW \ return memory word contents
- CALL GET_WORDL \ get address into CX
- JE 2 $
- CALL SP_RX_TL
- JE 2 $
- LDB EL AL \ third byte is word count, put it in EL
- 1 $:
- LDB WSR # 15
- LD DX []+ CX \ read a word
- LDB WSR 0
- CALL SEND_WORDL \ send the word
- DJNZ EL 1 $
- 2 $: RET end-code
-
-
- CODE WRITE_BYTESW \ write memory byte contents
- CALL GET_WORDL \ get address, into CX
- JE 2 $
- CALL SP_RX_TL
- JE 2 $
- LDB EL AL \ third byte is byte count, put it in EL
- 1 $:
- CALL SP_RX_TL
- JE 2 $ \ get a byte of data to write
- LDB WSR # 15
- STB AL []+ CX \ write the byte
- LDB WSR 0
- DJNZ EL 1 $
- 2 $: RET end-code
-
-
-
- CODE READ_BYTESW \ return memory byte contents
- CALL GET_WORDL \ get address, into CX
- JE 2 $
- CALL SP_RX_TL
- JE 2 $
- LDB EL AL \ third byte is byte count
- 1 $:
- LDB WSR # 15
- LDB AL []+ CX \ read a byte
- LDB WSR 0
- CALL SP_SEND \ send back the byte
- DJNZ EL 1 $
- 2 $: RET end-code
- COMMENT;
-
- \S
-
- \ ***************************************************************************
- \
- \ Analog-to-Digital converter operations
- \
- \ ***************************************************************************
-
- \ Measure an A to D channel
-
- CODE MEASURE_AD
- CALL SP_RX_TL
- JE 2 $
- ANDB AL # 7 \ next byte is channel number
-
- ORB AL # 8 \ conversion GO command
- LD AD_COMMAND AL \ initiate measurement
- 1 $:
- JBS AD_RESULT 3 1 $
-
- LD DX AD_RESULT \ send back the result
- CALL SEND_WORDL
- 2 $: RET end-code
-
- \ Measure all A to D channels repeatedly
-
- CODE MEASURE_ALL
- LDB CL 0
- 1 $:
- LDB AL CL
- ANDB AL # 7 \ next channel to measure
- ORB AL # 8 \ conversion GO command
- LD AD_COMMAND AL \ initiate measurement
- 2 $:
- JBS AD_RESULT 3 2 $ \ wait for the conversion
-
- LD DX AD_RESULT \ send back the result
- CALL SEND_WORDL
-
- INC CL
- CALL SP_RX_TL
- CMPB AL # '!'
- JNE 1 $ \ loop until a ! received
- RET end-code
-
- \ ***************************************************************************
- \
- \ EEPROM read and write operations
- \
- \ ***************************************************************************
-
-
- CODE EE_READ \ return a serial EEPROM byte
- CALL GET_WORDL \ get address
- JE 2 $
- LD AX CX
- CALL EEREAD \ read the byte
- LDB AL CL
- CALL SP_SEND \ send back the byte
- 2 $: RET end-code
-
-
- CODE EE_WRITE \ write a serial EEPROM byte
- CALL ENABLE \ enable the EEPROM for writes
- CALL GET_WORDL
- JE 2 $ \ get address into DX
- LD DX CX
-
- CALL SP_RX_TL
- JE 2 $ \ get the data to write
-
- LDB CL AL
- LD AX DX
- CALL EEWRITE \ write the byte
- 2 $: RET end-code
-
-
- \s
- TO_HEX: \ convert 4-bit in AL to a HEX digit
- ANDB AL # 0Fh
- ADDB AL # ( '0' )
- CMPB AL # ( '9' )
- JLE TO_HRET
- ADDB AL # ( 'A' - '9' -1 )
- TO_HRET:
- RET
-
- PUBLIC SEND_HEXB
- SEND_HEXB: \ send byte in AL as HEX ASCII
- PUSH AX
- SHR AX # 4
- CALL TO_HEX
- CALL SP_SEND
- POP AX
- CALL TO_HEX
- CALL SP_SEND
- RET
-
- PUBLIC SEND_HEXW
- SEND_HEXW: \ send word in AX as HEX ASCII
- PUSH AX
- SHR AX # 12
- CALL TO_HEX
- CALL SP_SEND
- POP AX
- PUSH AX
- SHR AX # 8
- CALL TO_HEX
- CALL SP_SEND
- POP AX
- PUSH AX
- SHR AX # 4
- CALL TO_HEX
- CALL SP_SEND
- POP AX
- CALL TO_HEX
- CALL SP_SEND
- RET
-
-