; ; LCDTEST.ASM -- Test the LCD attached to the Servo Gizmo Board ; Written: 03-JAN-03 ; $Id: lcdtest.asm,v 1.0 2003-01-02 18:27:00-08 chuck_mcmanis Exp chuck_mcmanis $ ; ; This program is designed to test the LCD that I've attached to the ; Servo Gizmo. From this code I can branch out and develop more diagnostic ; type codes to allow for more interesting applications. ; TITLE "LCDTEST - Generate some Counters for the LCD" LIST P=PIC16F628, C=120, N=50, R=HEX include "P16F628.inc" include "../16bits.inc" __FUSES _CP_OFF&_XT_OSC&_WDT_OFF&_LVP_OFF CBLOCK H'20' DLY_CNT CMD_DELAY CMD_TMP LCD_TMP L_DELAY C1 C2 COUNT:2 LO_COUNT HI_COUNT NUM:2 ; Number to convert low byte ... NUM_STR:5 ; ... high byte ENDC LED1 EQU 6 LED2 EQU 7 ORG H'0000' GOTO MAIN ; Let's get this puppy rolling MAIN: CLRF STATUS ; Set Bank 0 CLRF PORTA ; Clear PortA CLRF PORTB ; and clear PortB MOVLW H'07' ; Make PortA Digital I/O MOVWF CMCON ; By setting CMCON<0:3> BSF STATUS,RP0 ; Set Bank 1 CLRF TRISA ; Now A is all outputs CLRF TRISB ; B all outputs BSF TRISB,0 ; Button BSF TRISB,3 ; The Servo Input pin (CCP1) CLRF STATUS ; Back to BANK 0 BSF PORTB,LED1 ; Turn On LED1 CALL LCD_INIT ; Initialize the LCD BSF PORTB,LED1 ; Turn off LED1 (identifies Hangs in init) CLR16 COUNT ; Initialize Count to 0. ; ; Print out a simple message ; msg_loop: INC16 COUNT MOVLW H'80' ; Location of "Count:" CALL LCD_CMD ; Set cursor MOVLW 'C' CALL LCD_CHAR MOVLW 'o' CALL LCD_CHAR MOVLW 'u' CALL LCD_CHAR MOVLW 'n' CALL LCD_CHAR MOVLW 't' CALL LCD_CHAR MOVLW ':' CALL LCD_CHAR MOVLW 5 MOVWF C1 ; Temporary MOVLW NUM_STR+4 ; Pointer to the end of NUMSTR MOVWF FSR ; Put this in the indirect pointer MOVI16 D'10', DIVISOR ; Divide by 10 MOV16 COUNT, RESULT ; (tricky bit here) C_LOOP: MOV16 RESULT, DIVIDEND ; (See that trick?) CALL DIV16X16 ; Do the division MOVF DIVIDEND,W ; (remainder) MOVWF INDF ; Write thru indirection DECF FSR,F ; Point "back" one DECFSZ C1,F ; Count digits (need 5) GOTO C_LOOP ; Now number is in NUMSTR MOVLW H'88' ; First line, 8'th column CALL LCD_CMD ; Move the cursor there MOVLW 5 MOVWF C1 ; Reset the count to five INCF FSR,F ; Point to the first digit. P_LOOP: MOVF INDF,W ; Get the digit ADDLW '0' ; Add to ASCII "zero" CALL LCD_CHAR ; Print it INCF FSR,F ; Increment FSR DECFSZ C1,F ; Count down 5 digits GOTO P_LOOP wait_loop: MOVLW D'200' CALL LCD_DELAY MOVLW D'200' CALL LCD_DELAY MOVF PORTB,W ; Get port B XORLW H'FF' ; Toggle It XORLW H'3F' ; Revert it back MOVWF PORTB ; Now LED1 and LED2 are alternates GOTO msg_loop include "lcd.asm" include "div16.asm" END