
$TITLE(*****)

; This program is to test the *****
; circuit via the µ-controller circuit.

CSEG AT 0
JMP START

START:

; Define control lines specific to this project

SBIT TE = P3.2		; T**** E**** (active high)
SBIT MANW = P3.3	; Manual Write, (active low)
SBIT MR = P3.4		; Master Reset *****, (actve low)
SBIT CS = P3.5		; **** Chip Select, (active low)
SBIT ****S = P3.6	; **** Select, (~*****/*****)

; Set UART Mode and BAUD rate

	MOV SCON, #0x50	; Mode 1, 8-bit UART, enable receiver
	MOV TMOD, #0x20	; Timer 1, mode 2, 8-bit reload
	MOV TH1, #0xFD	; TH1 = 253, 9600 baud w/11.0592 MHz xtal
	SETB TR1	; Turn on Timer 1
	MOV SBUF, #'.'	; Send ACK to host
	JNB TI, $	; Wait for send
	CLR TI		; Reset flag

; Initialize µ-controller control lines

	CLR TE			; Put TE low, in-active state
	SETB MANW		; Put MANW hi, in-active state
	SETB MR			; Put MR hi, in-active state
	SETB CS			; Put CS hi, in-active state
	CLR ****S		; Put ****S low, select *****

; Body of program. Structure is a single pass loop. Program
; operation will normally idle at the instruction labeled LOOP.

LOOP:	JNB RI, $		; Wait for host command
	CLR RI			; Command received, clear flag
	MOV A, SBUF		; Move command to Accumulator
	CJNE A, #'L', RUN	; If not (L)oad, test (R)un

; Reset *****
	CLR TE			; Put TE low, in-active state
	SETB MANW		; Put MANW hi, in-active state
				; These are necessary for MR to
				; be effective.
	CLR MR			; Before loading new data,	SETB MR			; clear the old one.

LOAD:	MOV SBUF, A		; Echo 'L' command
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, reset flag
	MOV SBUF, #'.'		; Confirm command accepted
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, clear flag
	JNB RI, $		; Wait for next data byte
	CLR RI			; Data received, clear flag
	MOV A, SBUF		; Move data byte into accumulator
	CJNE A, #'.', L2	; Test for end of data
	MOV SBUF, #'x'		; Acknowledge end of data
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, reset flag
	MOV P0, #0xFF		; Set port to hi states
	JMP LOOP		; If end of data, return
L2:	MOV P0, A		; Write data byte to Port 0
	CLR MANW		; Clock into *****
	SETB MANW		; Reset MANW to non-active state
	JMP LOAD		; Go get next data byte

RUN:	CJNE A, #'R', STOP	; If not (R)un, test (S)top
	MOV SBUF, A		; Echo 'R' command
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, reset flag
	MOV SBUF, #'.'		; Confirm command accepted
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, clear flag
	CLR CS			; Enable ****
	SETB TE			; Turn on ******
	JMP LOOP		; Return to main loop

STOP:	CJNE A, #'S', GAIN	; Ifnot (S)top, test (G)ain
	MOV SBUF, A		; Echo 'S' command
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, reset flag
	MOV SBUF, #'.'		; Confirm command accepted
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, clear flag
	CLR TE			; Turn off ******
	SETB CS			; Disable ****
	JMP LOOP		; Return to main loop

GAIN:	CJNE A, #'G', OUT	; If not (G)ain, go to (O)ut
	MOV SBUF, A		; Echo 'G' command
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, reset flag
	MOV SBUF, #'.'		; Confirm command accepted
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, clear flag
	CLR TE			; Turn off ****** 
	SETB CS			; Disable ****
G2:	JNB RI, $		; Wait for gain setpoint byte
	CLR RI			; Byte received, clear flag
	MOV P0, SBUF		; Put gain byte on Port 0
	MOV SBUF, #'.'		; Confirm Data set
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, reset flag
	SETB ****S		; Select *****
	CLR CS			; Select **** for input
	CLR MANW		; Clock gain setpoint into *****
	SETB MANW		; Return MANW to in-active state
	SETB CS			; Return **** CS to in-active	CLR ****S		; Select ***** again
	MOV P0, #0xFF		; Reset the data bus
	JMP LOOP		; Return to main loop

OUT:	MOV SBUF, A		; Echo unknown command
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, clear flag
	MOV SBUF, #'x'		; Confirm command unrecognized
	JNB TI, $		; Wait for send
	CLR TI			; Send complete, reset flag
	JMP LOOP		; Go back to beginning of program

	END
[/quote]

