;
;       (CHANGE TIMING DELAYS TO SUIT YOUR PREFERENCE)
;
;       |  Port RA  |     |  Port RB  |   Port RB |
;       | 3| 2| 1| 0|     | 7| 6| 5| 4| 3| 2| 1| 0|
;       _____________     _________________________
;       | R| E|  |  |     | L| L| L| L|  |  | R| G|
;       | S| N|  |  |     | C| C| C| C|  |  | E| R|
;                         | D| D| D| D|       D  E
;
;
;                           Tom Allard
;                           611 N. Washington Ave
;                           Ludington , MI  49431
;                           (616) 843-4837 or 845-1536
;


             DEVICE  PIC16C54,RC_OSC,WDT_OFF,PROTECT_OFF

             RESET START


RS           =       RA.3   ; LCD R/S LINE
E            =       RA.2   ; LCD ENABLE LINE
GREEN        =       RA.0   ; GREEN LED'S
RED          =       RA.1   ; RED LED'S


             ORG     8


COUNT        DS      1      ; USED IN INNER LOOPS 0-255
LCD          DS      1      ; LCD CONTROL CODE OR DATA BYTE
INDEX        DS      1      ; INDEX USED TO COUNT INDEX TIMES
POINTER      DS      1      ; POINTS TO DATA LOCATION IN TABLE
FLAG         DS      1      ; FLAG CONTROL = 0 / DATA = 1
POSITION     DS      1      ; LCD SCREEN POSITION (16X2)
CHARS        DS      1      ; NO. OF CHARACTERS TO RETRIEVE


             ORG     0




START        CLR     POINTER ; 1ST LOCATION IN TABLE
             CALL    MDELAY  ; GIVE LCD A CHANCE TO FIRE UP
             CALL    SET     ; INITIALIZE /PORTS/LCD SCREEN/
             SETB    RED     ; ENERGIZE RED LED (BANK 1)
             CALL    MDELAY  ; DELAYS MAY NOT BE NECESSARY

:LOOP        CALL    MDELAY
             MOV     POSITION,#128  ; LCD SCREEN LOCATION - DOUBLE DUTY
             MOV     CHARS,#80      ; NO. OF CHARS. W/HELP FROM POSITION
             CALL    LOAD           ; LOAD LCD W/BYTES FOUND IN TABLE



:ROTATE      CALL    SENDCODE       ; SEND CODE #24 SHIFT SCREEN
             XOR     RA,#3          ; INVERT LIGHTS
             CALL    MDELAY         ; DELAY

             CALL    SENDCODE       ; SEND CODE AGAIN
             CLRB    GREEN          ; LED'S
             CALL    MDELAY

             CALL    SENDCODE
             XOR     RA,#3
             CALL    MDELAY         ; CHANGE TO YOUR LIKING ...

             CALL    SENDCODE       ;
             XOR     RA,#3
             CALL    MDELAY

             CALL    SENDCODE
             XOR     RA,#3
             CALL    MDELAY

             CALL    SENDCODE
             XOR     RA,#3
             CALL    MDELAY

             CALL    SENDCODE
             SETB    GREEN
             CALL    MDELAY

             JMP     :ROTATE


SENDCODE    MOV     LCD,#24
            CALL    DISPLAY
            RET



               ;   LOAD POSITION WITH SCREEN XY LOCATION
               ;   LOAD CHARS WITH NO. OF BYTES TO BE LOADED
               ;   LOAD POINTER WITH LOCATION OF CHARACTERS



LOAD        CLR     FLAG           ; SET FOR CONTROL CODE
            MOV     LCD,POSITION   ; SCREEN LOCATION USED THEN CLEAR FOR OHTER
            CALL    DISPLAY        ; SEND BYTE
            CLR     POSITION       ; CHAR. POSITION COUNTER


:LOOP       MOV     W,POINTER      ; USED IN RETW

            CALL    MESSAGE                  ; LOAD CHARS IN W
            MOV     LCD,W                    ; LOAD FOR DISPLAY
            MOV     FLAG,#1                  ; SET FOR DATA
            CALL    DISPLAY                  ; SEND BYTE
            INC     POSITION                 ; INC POSITION COUNTER
            INC     POINTER                  ; INC TABLE POINTER
            CJNE    CHARS,POSITION,:LOOP     ; UNTIL NO. BYTES READ
            RET

                    ; DELAY ROUTINE


MDELAY      MOV     INDEX,#8         ; DELAY BETWEEN SCREENS
:LOOP       DJNZ    COUNT,:LOOP      ; CHANGE IF MESSAGE IS FAST/SLOW
            DJNZ    INDEX,:LOOP
            RET



            ; DISPLAY MESSAGES (FLAG=1 CONTROL/FLAG=0 DATA)


DISPLAY     CSB     FLAG,#1H        ; COMPARE FLAG TO 1 DATA OR CONTROL
            SETB    RS              ; IF DATA TURN ON R/S
            MOV     RB,LCD          ; WRITE NIBBLE TO LCD DATA LINE
            SETB    E               ; ENABLE ENERGIZED
            CLRB    E               ; ENABLE UN-ENERGIZED
            SWAP    LCD             ; SWAP NIBBLES
            MOV     RB,LCD          ; WRITE NIBBLE TO LCD DATA LINE
            SETB    E               ; ENABLE ENERGIZED
            CLRB    E               ; ENABLE UN-ENERGIZED
            CLRB    RS              ; R/S OFF BEFORE LEAVING
            CLR     FLAG            ; SET FLAG BYTE TO DEFAULT (CONTROL)
            RET



; INITIALIZE LCD - 2 LINES - CURSOR OFF


SET         CLR     FLAG                ; CONTROL BYTE(s) ONLY
            MOV     !RA,#00000000B      ; PORT A - OUTPUT
            MOV     !RB,#00001111B      ; PORT B - OUTPUT
            CLR     RA                  ; PORT A LOW
            MOV     RB,#00100000B       ; SET FOR 4 BIT INTERFACE
            SETB    E                   ; ENABLE ON
            CLRB    E                   ; ENABLE OFF

            CLR     FLAG                ; SET FOR CONTROL DATA

            MOV     LCD,#00100100B      ; 4 BIT/DISP. LINES/5X7
            CALL    DISPLAY             ; SEND DATA TO LCD
            MOV     LCD,#00001100B      ; DISP ON/CURSOR OFF/BLINK CURSOR
            CALL    DISPLAY             ; SEND DATA TO LCD
            MOV     LCD,#00000110B      ; MOVE DIR. INCR./NO SHIFT
            CALL    DISPLAY             ; SEND DATA TO LCD
            MOV     LCD,#00000001B      ; CLEAR SCREEN
            CALL    DISPLAY             ; WRITE BYTE
            RET



MESSAGE     JMP     PC+W

               ;            1          2         3
               ; 0123456789012345678990123456789012

            RETW ' [ THIS MESSAGE WILL RUN ACROSS '
            RETW ' THE SCREEN - USE FOR THAT UNCHA'
            RETW 'NGING MESSAGE ] '
