; Progam STRING_2.ASM
;
; Illustrates how to write strings to a the PIC-n-LCD.
;
; Program clears the display and writes "Hello World" to the first line.
;
; It then writes "T_C = 17 , where 23 (decimal) is assumed to be the
; result of a measurment.
;
; Note that this uses program LCD_CTRL.ASM which is inlcuded at the bottom
; of this program.
;
; PORTA, Bit 0 (terminal 17) ------ TX ----------> to RX on Serial LCD
;
; copyright, Peter H. Anderson, Morgan State University, Feb 18, '97

	LIST p=16f84	

#include <c:\mplab\p16f84.inc>	
	__CONFIG 11h

	CONSTANT VARS=0CH

T_C		EQU VARS+0	; used for illustration	
STR_INDEX	EQU VARS+1

	ORG 000H

	BSF STATUS, RP0		; RP1 = 0, RP0 = 1, BANK1
	BCF TRISA, 0		
	BCF STATUS, RP0		; bank 0
	
	BCF PORTA, 0		; serial output low

MAIN:
	; perform a temperature measurement	
	MOVLW .23		; but i will dummy the vaue of T_C = 23
	MOVWF T_C

	MOVLW 0CH		; clear LCD, cursor at beginning of line 1
	CALL LCD_CHAR
	
	CALL OUT_STR_1		; output first string to serial LCD

	CALL OUT_STR_2		; "T="

	MOVF T_C, W
	CALL LCD_VAL	

	CALL OUT_STR_3		; "Degrees C"

DONE: 	GOTO DONE

OUT_STR_1:
	CLRF STR_INDEX
OUT_STR_11:
	MOVF STR_INDEX, W
	CALL STR_1_LOOKUP	; fetch the character
	ADDLW 0			; set flags
	BTFSC STATUS, Z
	GOTO OUT_STR_12		; done if null		
	CALL LCD_CHAR
        INCF STR_INDEX, F
	GOTO OUT_STR_11		; keep going
OUT_STR_12:
	RETURN

STR_1_LOOKUP:
	ADDWF PCL, F
	DT "Hello World", 0AH, 0AH, 0DH, 0

OUT_STR_2:
	CLRF STR_INDEX
OUT_STR_21:
	MOVF STR_INDEX, W
	CALL STR_2_LOOKUP	; fetch the character
	ADDLW 0			; set flags
	BTFSC STATUS, Z
	GOTO OUT_STR_22		; done if null		
	CALL LCD_CHAR
        INCF STR_INDEX, F
	GOTO OUT_STR_21		; keep going
OUT_STR_22:
	RETURN

STR_2_LOOKUP:
	ADDWF PCL, F
	DT 09H, "T=", 0

OUT_STR_3:
	CLRF STR_INDEX
OUT_STR_31:
	MOVF STR_INDEX, W
	CALL STR_3_LOOKUP	; fetch the character
	ADDLW 0			; set flags
	BTFSC STATUS, Z
	GOTO OUT_STR_32		; done if null		
	CALL LCD_CHAR
        INCF STR_INDEX, F
	GOTO OUT_STR_31		; keep going
OUT_STR_32:
	RETURN

STR_3_LOOKUP:
	ADDWF PCL, F
	DT 09H, " Degrees C", 0

#include <a:\lcd_ctrl.asm>	

	END