Use of the PIC-an-LCD with the PIC16C72

copyright, Peter H. Anderson, Baltimore, MD, '98

Introduction

Over the Spring semster, my students used a common library of routines to interface with our PIC-an-LCD. This library was originally written for the PIC16F84 and it went through a number of versions during the semester as new features were added and problems corrected. These proved invaluable in permitting students to debug thier code and in providing user output.

This program has been renamed LCD_F84.ASM. The apparent complexity of the code arose from my desire to save W and STATUS and cram the whole thing into 256 bytes.

In moving to the PIC16C62 and C72, this library has been modified and named LCD_C72.ASM.

This is primarily for the benefit of my Morgan Students. However, it may be of interest to other hobbyists and most new material related to PICs will assume the use of these libraries.

However, note that the code has been written to use various special features of the PIC-an-LCD which other serial LCD modules do not support.

Modifications in LCD_C72.ASM.

I have decided to retain RA.0 as the serial output to the PIC-an-LCD. For one thing, it is easy to find, terminal 2. This permits PORTB to be used as an 8-bit I/O port and leaves the various bits on PORTC feee. Many of these bits on PORTC double in performing various special functions. RA.0 doubles as an A/D input. However, there are four other inputs which may be used for A/D.

On the PIC16F84, the code occupied address locations $0300 - $03FF. With the 16C72, this has been modified to locations $0700 - $07FF. On the 16F84, RAM locations $40 - $4F were used. This has been modified to locations $70 - $7F.

In the version for the 16F84, LCD_DEBUG displayed the values of RAM locations $10 - $17. This has been revised to locations $20 - $27.

A summary of the routines follows. Note that the maximum stack depth of any routine is is three. Four, including your call to the subroutine. Thus, your call should be made at a stack level of no more than four.

That is, if your main calls X, which calls XX, which calls XXX, which calls XXX and you call LCD_DEBUG, you are okay. LCD_DEBUG calls LCD_VAL which calls _SEROUT.

LCD_RESET    - provides a means for the user to manually reset the LCD
             - brings RA.0 (serial lead) low for 2.5 secs.  During this
	       time, the user should manually reset the LCD.
	     - routine then clears the LCD and outputs ten dots.
	     - LCD is then cleared again.
	     - W and STATUS are saved.

A sample call;

	CALL LCD_RESET
This routine is useful near the beginning of a program. It is a quick way to verify the PIC and the LCD are alive.
LCD_DELAY   - provides a delay of the number of msecs contained in W.
	    - W and STATUS are saved.	

Sample call;

	MOVLW .250
	CALL LCD_DELAY	; 250 msec delay
Although, this is not inherently a function associated with the LCD, it has proven to be worthwhile in avoiding writing a delay routine for each program.
LCD_DEBUG 
	- displays W content and the state of the Z and C flags on line 1.
        - prints value of location 70H as a character on line 2.
 	- displays values of locations 20, 21, 22, 23 on line 3.
 	- locations 24, 25, 26, 27 on line 4.
	- this is followed by a one second delay.  
	- the W and STATUS registers are saved and restored in returning 
	  to the calling program. 	 

Sample call;

	CALL LCD_DEBUG

or
	MOVLW "!"
	MOVWF 70H
	CALL LCD_DEBUG
Note that as this displays the values in the variables at locations $20 - $27, it is important that you assign the variables you are interested in observing in this range.

The display of the location of 70H as a character is useful in determining where your program is going. Thus, in one area of code you might use a "!" and in another, a "*".

LCD_CHAR - displays character in W on LCD.  W and STATUS are saved.

Sample call;

	MOVLW "H"
	CALL LCD_CHAR
	MOVLW "="
	CALL LCD_CHAR

	MOVLW 17H
	CALL LCD_CHAR	; print next character as an unsigned decimal

	MOVF VAL, W
	CALL LCD_CHAR

	MOVLW 0DH	; new line
	CALL LCD_CHAR

	MOVLW 0AH
	CALL LCD_CHAR
Note that in addition to displaying text, the ability to pass such control
codes as 16H and 17H to print the next character as a signed or unsigned
decimal number saves a great deal of fiddling with decimal conversion
routines.

For displaying a word, see LCD_BCD_WORD.

LCD_VAL - converts value in W to two hex characters and displays on LCD.

Sample call.

	MOVF VAL, F
	CALL LCD_VAL

LCD_BCD_WORD - displays quantity in 71H and 72H as unsigned decimal 
quantity.  Note, this is limited to 9999 decimal.

Sample call;

	MOVF VAL_H, W	; get the high and low bytes in locs 71 and 72
	MOVWF 71H
	MOVF VAL_L, W
	MOVWF 72H

	CALL LCD_BCD_WORD