;****************************************************************
;* 15x7 Display    Started 7/4/2008						*
;* 								*
;****************************************************************

	list P = 16F628		;microcontroller 
	include <P16F628.inc>	;registers for F628


	__Config 	_cp_off & _lvp_off & _pwrte_on & _wdt_off & _intRC_osc_noclkout & _mclre_off
	
;code protection - off
;low-voltage programming - off
;power-up timer -  on
;watchdog timer - off
;use internal RC for 4MHz - all pins for in-out


;****************************************************************
; variables - names and files
;****************************************************************


		;Files for F628 start at 20h 
 
						 			
temp1		equ 20h	
temp2		equ 21h	
temp3		equ 22h	
timera		equ	23h	;
timerb		equ	24h	;
timerc		equ	25h	;
timerd		equ	26h	;
flags		equ	27h	;
Jump_1		equ 28h		;jump counter for table1
Jump_2		equ 29h		;jump counter for table2
temp_sw		equ	2Ah
temp_sw3	equ	2Bh
eefile		equ	2Ch
eetemp1		equ	2Dh
eetemp2		equ	2Eh

file30		equ	30h	;general purpose file
file31		equ	31h	;general purpose file
file32		equ	32h	;general purpose file
file33		equ	33h	;general purpose file

file3A		equ	3Ah	;counter for speed on shifting characters left on screen



file40h

file7Fh

;****************************************************************
;Equates
;****************************************************************
status		equ	0x03
cmcon		equ	0x1F
rp1			equ	0x06
rp0			equ	0x05
	      	




;****************************************************************
;Beginning of program
;****************************************************************
reset	org		00				;reset vector address	
		goto	SetUp			;goto SetUp
			

table2	addwf 02h,1	  ;add W to program counter
		nop
		retlw 7Eh	;A - 01h
		retlw 09h
		retlw 09h
		retlw 09h
		retlw 0FEh		
			
		
		retlw 7Fh	;B - 06h
		retlw 49h
		retlw 49h
		retlw 49h
		retlw 0B6h		
			
		
		retlw 3Eh	;C - 0Bh
		retlw 41h
		retlw 41h
		retlw 41h
		retlw 0A2h		
		
		
		retlw 7Fh	;D - 10h
		retlw 41h
		retlw 41h
		retlw 22h
		retlw 9Ch		
		
		
		retlw 7Fh	;E - 15h
		retlw 49h
		retlw 49h
		retlw 0C1h		
			
		
		retlw 7Fh	;F - 19h
		retlw 09h
		retlw 09h
		retlw 81h		
			

		retlw 3Eh	;G - 1Dh
		retlw 41h
		retlw 49h
		retlw 49h
		retlw 0BAh		
		
		retlw 7Fh	;H - 22h
		retlw 08h
		retlw 08h
		retlw 08h
		retlw 0FFh		
		
		
		retlw 0FFh	;I	- 27h			
		
		
		retlw 20h	;J - 28h
		retlw 40h
		retlw 40h
		retlw 0BFh		
		
		
		retlw 7Fh	;K - 2Ch
		retlw 08h
		retlw 14h
		retlw 22h
		retlw 0C1h		
		
		
		
		retlw 7Fh	;L - 31h
		retlw 40h
		retlw 40h
		retlw 0C0h		
		
		
		retlw 7Fh	;M - 35h
		retlw 02h
		retlw 04h
		retlw 08h
		retlw 04h
		retlw 02h
		retlw 0FFh				
		
		
		
		retlw 7Fh	;N - 3Ch
		retlw 04h
		retlw 08h
		retlw 10h
		retlw 0FFh		
		
		
		retlw 3Eh	;O - 41h
		retlw 41h
		retlw 41h
		retlw 41h
		retlw 0BEh		
		
			
		retlw 7Fh	;P - 46h
		retlw 09h
		retlw 09h
		retlw 09h
		retlw 86h		
				
		
		retlw 1Eh	;Q - 4Bh
		retlw 21h
		retlw 31h
		retlw 21h
		retlw 0DEh		
		
			
		retlw 7Fh	;R - 50h
		retlw 09h
		retlw 19h
		retlw 29h
		retlw 0C6h		
				
		
				
		retlw 26h	;S - 55h
		retlw 49h
		retlw 49h
		retlw 49h
		retlw 0B2h		
				
		
				
		retlw 01h	;T - 5Ah
		retlw 01h
		retlw 7Fh
		retlw 01h
		retlw 81h		
				
		
				
		retlw 3Fh	;U - 5Fh
		retlw 40h
		retlw 40h
		retlw 40h
		retlw 0BFh		
					
			
		retlw 0Fh	;V - 64h
		retlw 30h
		retlw 40h
		retlw 30h
		retlw 8Fh		
				
		
		retlw 3Fh	;W - 69h
		retlw 40h
		retlw 38h
		retlw 40h
		retlw 0BFh			
			
		
		retlw 63h	;X - 6Eh
		retlw 14h
		retlw 08h
		retlw 14h
		retlw 0E3h	
				
					
		retlw 03h	;Y - 73h
		retlw 0Ch
		retlw 70h
		retlw 0Ch	
		retlw 83h
				
					
		retlw 61h	;Z - 78h
		retlw 51h
		retlw 49h
		retlw 45h	
		retlw 0C3h
				
						
		retlw 42h	;1 - 7Dh
		retlw 7Fh
		retlw 0C0h
		
		
		retlw 72h	;2 - 80h
		retlw 49h
		retlw 49h
		retlw 49h	
		retlw 0C6h
					
		
		retlw 22h	;3 - 85h
		retlw 41h
		retlw 49h
		retlw 49h	
		retlw 0B6h
					
		
		retlw 18h	;4 - 8Ah
		retlw 14h
		retlw 12h
		retlw 7Fh	
		retlw 90h

		
		retlw 2Fh	;5 - 8Fh
		retlw 49h
		retlw 49h
		retlw 49h	
		retlw 0B1h
				
		retlw 3Eh	;6 - 94h
		retlw 49h
		retlw 49h
		retlw 49h	
		retlw 0B2h
		
		retlw 01h	;7 - 99h
		retlw 71h
		retlw 09h
		retlw 05h	
		retlw 83h
				
		
		retlw 36h	;8 - 9Eh
		retlw 49h
		retlw 49h
		retlw 49h	
		retlw 0B6h
		
		retlw 26h	;9 - A3h
		retlw 49h
		retlw 49h
		retlw 49h	
		retlw 0BEh
			
		
		retlw 80h	;space - A8h
		retlw 80h
		retlw 80h
		retlw 80h		
		retlw 00h	;end for space	
		
		retlw 40h	;0AD -  underline for starting	
		retlw 40h		
		retlw 40h		
		retlw 40h		
		retlw 0C0h		
		
					
		

;****************************************************************
;* table for start loction of letters and numbers in table 2		*
;****************************************************************
		
		
		
		
		
table1	addwf 02,1	  ;add W to Program Counter
		
		retlw 0F4h
		retlw 0ADh	;_	01h
		retlw 01h	;A  02h
		retlw 06h	;B  03h
		retlw 0Bh	;C  04h
		retlw 10h	;D  05h
		retlw 15h	;E  06h
		retlw 19h	;F  07h
		retlw 1Dh	;G  08h
		retlw 22h	;H  09h
		retlw 27h	;I  0Ah
		retlw 28h	;J  0Bh
		retlw 2Ch	;K  0Ch
		retlw 31h	;L  0Dh
		retlw 35h	;M  0Eh
		retlw 3Ch	;N  0Fh
		retlw 41h	;O  10h
		retlw 46h	;P  11h
		retlw 4Bh	;Q  12h
		retlw 50h	;R  13h
		retlw 55h	;S  14h
		retlw 5Ah	;T  15h
		retlw 5Fh	;U  16h
		retlw 64h	;V  17h
		retlw 69h	;W  18h
		retlw 6Eh	;X  19h
		retlw 73h	;Y  1AH
		retlw 78h	;Z  1Bh
		
		
		retlw 7Dh	;1  1Ch
		retlw 80h	;2  1Dh
		retlw 85h	;3  1Eh
		retlw 8Ah	;4  1Fh
		retlw 8Fh	;5  20h
		retlw 94h	;6  21h
		retlw 99h	;7  22h
		retlw 9Eh	;8  23h
		retlw 0A3h	;9  24h	
		retlw 41h	;0  25h	
		retlw 0A8h	;space 26h	
		
		retlw 0EEh
			
		nop	
		nop				
		nop
		nop
		nop




;****************************************************************
;* port A and B initialisation					*
;****************************************************************

SetUp	bsf		status,rp0
	
		movlw	b'00000000'		;A in/out
		movwf	05h			
		movlw	b'00000000'		;B output
		movwf	06h
		
		movlw	b'10000000'		;Turn off T0CKI, prescale for TMR0 = 1:
		movwf	option_reg
		
		clrf	eeadr	
		bcf		status,rp0		;select programming area - bank0 
		clrf 	05h				;Clear Port A of junk 
		clrf 	06h				;Clear Port B of junk 
		movlw	07h				;turn comparators off and enable
		movwf	cmcon			;    pins for I/O functions
		
		
		
		
		
		
		
		movlw	22h
		movwf	temp1			
wipe	movf	temp1,0
		movwf	04h		;put into FSR		
		clrf	temp2	
		movf	temp2,0
		movwf	00h		;put w into indf
		incf	temp1,1
		movf	temp1,0
		xorlw	07Eh		;see if end of files             
		btfss	03,2		;
		goto	wipe
		
		incf	Jump_1,1		
		
							;program starts with BLANK and 1 char in EEPROM at 7Fh
		
		movlw	7Fh			;get saved-value for number of characters in EEPROM
							
		
		bsf		status,rp0	; select bank 1
		movwf	eeadr		; look at 7Fh
		bsf		eecon1,rd	; initiate the read
		movf	eedata,w	; put the read data into w (9Ah)
		
		bcf		status,rp0	;			
		movwf	eefile		; and store in eefile (2Ch)
		
		clrf	eeadr		; (9Bh)
				
		goto 	Main						
					


;****************************************************************
;* Delay sub-routines  					*
;****************************************************************


			;Delay 4uS
			
_4uS	retlw	00		

	
			
			;Delay  10uS
			
_10uS	nop		
		nop
		nop			 
		nop
		nop			 
		nop			 	
		retlw	00			
			
			
			

Delay1	movlw	01h
		movwf	timerb
Del_a	decfsz timera,1
		goto Del_a
		decfsz timerb,1
		goto Del_a	
		retlw 00
		
	
Delay2	DECFSZ timera,1
		GOTO Delay2
		DECFSZ timerb,1
		GOTO Delay2
		retlw 00	



;****************************************************************
;* sub-routines  					*
;* Raster - The data for the display is held from: 50h to 5Fh.
;* Data from 50h to 5Fh is sent to "GHOST FILES:" 60h to 6Fh for scanning
;* Data from 60h to 6Fh is RLF (shifted up) and passed via 
;* CARRY into port A and port B for scanning.
;* No output from RA5 so gap is closed.
;* Pin 9 of 4017 goes to RA5 to detect the start of scan for 4017
;

								;Set 4017 to drive first output of display. 
								;4017 is clocked by RA0
								;9th output is pin9. 
								;9th output goes to RA5 to detect a HIGH
;****************************************************************								
		
		;Clock the 4017
		
		
clock	movlw	b'00000001'		;clock the 4017  
		movwf	05h						
		call	_10uS			
		movlw	b'00000000'		;
		movwf	05h						
		call	_10uS	
		retlw	00
	
	
			
		
clr		clrf	50h	;clear screen to prevent mirroring
		clrf	51h
		clrf	52h
		clrf	53h
		clrf	54h
		clrf	55h
		clrf	56h
		clrf	57h							
		clrf	58h
		clrf	59h	
		clrf	5Ah
		clrf	5Bh
		clrf	5Ch
		clrf	5Dh
		clrf	5Eh
		clrf	5Fh
		retlw	00	
		
		
		;Load ports A and B
		
load	rrf		76h,1		;put lowest bit into carry
		rlf		file30,1	;put lowest bit into file 30	
		rrf		75h,1
		rlf		file30,1
		rlf		file30,1	;this is RA5 - the in-only pin 
		rrf		74h,1
		rlf		file30,1
		rrf		73h,1
		rlf		file30,1
		rrf		72h,1
		rlf		file30,1
		rrf		71h,1
		rlf		file30,1
		rrf		70h,1
		rlf		file30,1	;file 70h will be lowest bit
		
		
		rrf		7Eh,1		;put lowest bit into carry
		rlf		file31,1	;put lowest bit into file 30	
		rrf		7Dh,1
		rlf		file31,1
		rrf		7Ch,1
		rlf		file31,1	;this is RA5 - the in-only pin 
		rrf		7Bh,1
		rlf		file31,1
		rrf		7Ah,1
		rlf		file31,1
		rrf		79h,1
		rlf		file31,1
		rrf		78h,1
		rlf		file31,1
		rrf		77h,1
		rlf		file31,1	;file 77h will be lowest bit
		retlw	00	
		
		;raster files are 50h to 5Fh plus 60h to 68h where new characters are added
		;raster files are passed to GHOST FILES 70h to 7Fh for scanning
		
		
		;Ldscr (load screen) takes a value from EEPROM and puts it into: 60h to 68h
		;  Ldscr looks for last character, to re-cycle message
		;  Ldscr inserts new character when 60h is empty. 
		;  eefile	equ	2Ch  - the number of characters in EEPROM  
		;  eetemp1 equ	2Dh - keeps track of current location in EEPROM - will be put into eeadr
		;  eetemp2  equ  2Eh - look-up value for table1
		
		
Ldscr	movlw	61h			;This puts a blank between characters!
		movwf	04h			;load FSR
		movf	60h,0
		xorlw	00h			;see if file 60h is empty             
		btfss	03,2
		retlw	00			;return, 60h is filled		
		movf	eetemp1,0	;move current location into w			
		bsf		status,rp0	; select bank 1
		movwf	eeadr		; load address from eetemp1
		bsf		eecon1,rd	; initiate the read
		movf	eedata,w	; get the read data into w
		
		bcf		status,rp0	;			
		movwf	eetemp2		; and store in eetemp2
		movf	eetemp2,0	;move EEPROM character look-up value, into w. 
		call 	table1
		movwf	jump_2		;load start of character value for table 2 into Jump_2			
Ldscr1	movf	Jump_2,0	;
		call	table2		;get character first column  
		movwf	temp1
		
		
		movlw	081h		;end of character is 81h or greater
		subwf	temp1,0
		btfsc	03,0		;test carry   carry SET when result is above 81h
		
		
		goto	Ldscr2		;add last column and insert a blank into last location
		
		movlw	00h			;end of space
		xorwf	temp1,0
		btfsc	03,2		;
		
		goto	Ldscr2		;add last blank and insert a another blank 
		
		movf	temp1,0
		movwf	00h			;move table value to indf
		incf	04h,1		;put display value into a file starting 60h
		incf	Jump_2,1
		goto	Ldscr1	
Ldscr2	movf	temp1,0
		movwf	00h			;move table value to indf
		incf	04h,1		;put display value into a file 
		movlw	00h	
		movwf	00h			;put 00h into last location in (60h to 68h)		
		incf	eetemp1,1
		movf	eetemp1,0	;see if eetemp1 is equal to eefile (for end of characters)
		xorwf	eefile,0
		btfss	03,2
		retlw	00	
		clrf	eetemp1
		retlw	00
		
		
		

move	movf	50h,0	;move file 50h to W		 				
		movwf	70h
		movf	51h,0
		movwf	71h
		movf	52h,0
		movwf	72h
		movf	53h,0
		movwf	73h
		movf	54h,0
		movwf	74h
		movf	55h,0
		movwf	75h
		movf	56h,0
		movwf	76h
		movf	57h,0
		movwf	77h
		movf	58h,0
		movwf	78h
		movf	59h,0
		movwf	79h
		movf	5Ah,0
		movwf	7Ah
		movf	5Bh,0
		movwf	7Bh
		movf	5Ch,0
		movwf	7Ch
		movf	5Dh,0
		movwf	7Dh
		movf	5Eh,0
		movwf	7Eh
		movf	5Fh,0
		movwf	7Fh
		retlw	00
		
	
						
		
scan	movlw	07		;scan 7 rows 
		movwf	file32
scan1	call	load
		movlw	00h
		movwf	06h		;remove mirroring		
		btfss	file30,0	;see if bit zero is HIGH to clock 4017		
		call	clock
		movf	file30,0
		movwf	05h		;load portA 
		movf	file31,0
		movwf	06h		;load portB
		call	Delay1
		clrf	05h
		decfsz	file32,1
		goto	scan1
		retlw	00
		
			
Set4017	bsf		status,rp0
		movlw 	b'00100000'		;Set the TRIS for A in/out  
		movwf	05h										
		bcf		status,rp0
		
Set_	movlw	b'00000001'		;(turn off RA4)  Make RA0 HIGH
		movwf	05h						
		call	_10uS		
		movlw	b'00000000'		;Make RA0 LOW
		movwf	05h						
		call	_10uS			;clock 4017
		btfsc	05h,5			;see if 4017 is at 9th output 
		retlw	00
		goto	Set_
		
		
		
		;shift moves files 50h to 68h one-place LEFT  ie file 50h is dumped. 51h to 50h etc
		;A new character is inserted at 60h to 68h when 60h is empty via ldscr
		
shift	movlw 	18h
		movwf	temp1
		movlw	51h
		movwf	04h		;load FSR
shift1	movf	00h,0	;move value looked at by FSR into W
		decf	04,1	;decrement FSR	
		movwf	00h
		incf	04h,1
		incf	04h,1
		decfsz	temp1,1
		goto	shift1
		retlw	00
		
			
		
show	call	Set4017
		call	clock		
		call	move
		call	scan		
		retlw	00
		
		
	;detect switches
		
sw		bsf		status,rp0
		movlw 	b'11111111'		;Set the TRIS for Port B IN
		movwf	06h		
		movlw	b'00000000'		;enable Port B pull-ups    0xxxxxxx
		movwf	option_reg										
		bcf		status,rp0
		nop
		movf	06h,0
		movwf	file30			;switches saved in file30		
		bsf		status,rp0			
		movlw	b'10000000'		;disable Port B pull-ups 		
		movwf	option_reg	
		movlw	b'00000000'		;return PortB to output
		movwf	06h  									
		bcf		status,rp0
		
		btfss	file30,0	;first sw detected  "A-0 up" via a LOW
		goto	sw1																
		btfss	file30,1	;second sw detected  "A-0 down" via a LOW
		goto	sw2				; xxxxxxxxxxx   was  sw 2									
		btfss	file30,2	;third sw detected  "STORE" via a LOW
		goto	sw3
		btfss	file30,3	;fourth sw detected  "RUN" via a LOW
		goto	sw4
		btfss	file30,4	;fifth sw detected  "DELETE" via a LOW
		goto	sw5
		btfss	file30,5	;fifth sw detected  "EFFECTS" via a LOW
		goto	sw6
		clrf	flags		;no sw detected  clear sw flag
		
		retlw	00
				
		
				
	
		
sw1		btfsc	flags,1		;first pass? If no, return	
		retlw	00
		bsf		flags,1		;set sw1 flag
		incf	Jump_1,1	;incr jump value for next press of button
			
		clrf	58h
		clrf	59h
		clrf	5Ah
		clrf	5Bh
		clrf	5Ch
		clrf	5Dh
		clrf	5Eh
		clrf	5Fh	
		movf	Jump_1,0	;set-up jump value for table 1
		call	table1		;get jump value for table 2
		movwf	Jump_2		;load jump value for table 2 into Jump_2
		
		xorlw	0EEh		;see if end of table 1              
		btfss	03,2		;
		goto	sw1a
		clrf	Jump_1
		incf	Jump_1,1     
		clrf	flags
		goto	sw1	
		
sw1a	movlw	58h
		movwf	04h			;load FSR		
			
sw1b	movf	Jump_2,0	;set-up jump value for table 2
		call	table2		;get first column display value 
		movwf	temp_sw		;save value in a temporary file
		
			
		movlw	081h		;end of character is 81h or greater
		subwf	temp_sw,0
		btfsc	03,0		;test carry   carry SET when result is above 81h
		
		goto	sw1c
		movf	temp_sw,0
		movwf	00h			;move table value to indf
		incf	04h,1		;put display value into a file starting 58h
		incf	Jump_2,1
		goto	sw1b	
		
sw1c	movf	temp_sw,0
		movwf	00h			;move table value to indf
		incf	04h,1		;put display value into a file 
		movf	Jump_1,0	; 		
		bsf		status,rp0	;select bank1			
		movwf	9Ah			;the eedata file
		bcf		status,rp0	;select bank0	
		retlw	00			

		
			
		
sw2		btfsc	flags,2		;first pass? If no, return	
		retlw	00
		bsf		flags,2		;set sw2 flag
		decf	Jump_1,1	;decr jump value for next press of button
		clrf	58h
		clrf	59h
		clrf	5Ah
		clrf	5Bh
		clrf	5Ch
		clrf	5Dh
		clrf	5Eh
		clrf	5Fh	
		
		movf	Jump_1,0	;set-up jump value for table 1
		call	table1		;get jump value for table 2
		movwf	Jump_2		;load jump value for table 2 into Jump_2
		
		xorlw	0F4h		;see if start of table 1              
		btfss	03,2		;
		goto	sw2a
		movlw	26h
		movwf	Jump_1
		clrf	flags
		goto	sw2		
				
		
sw2a	movlw	58h
		movwf	04h			;load FSR		
			
sw2b	movf	Jump_2,0	;set-up jump value for table 2
		call	table2		;get first column display value 
		movwf	temp_sw		;save value in a temporary file
		
		
			
		movlw	081h		;end of character is 81h or greater
		subwf	temp_sw,0
		btfsc	03,0		;test carry   carry SET when result is above 81h
		goto	sw2c
		
		movf	temp_sw,0
		movwf	00h			;move table value to indf
		incf	04h,1		;put display value into a file starting 58h
		incf	Jump_2,1
		goto	sw2b	
		
		
sw2c	movf	temp_sw,0
		movwf	00h			;move table value to indf
		incf	04h,1		;put display value into a file 
		movf	Jump_1,0	; 		
		bsf		status,rp0	;select bank1			
		movwf	9Ah		
		bcf		status,rp0	;select bank0				
		retlw	00		
		
		
		
		
		;Sw3 = STORE  - stores character (table2) into EEPROM 
		;  eeadr is obtained from eetemp1
		;  eefile	equ	2Ch  - total number of characters in EEPROM
		;  eetemp1 equ	2Dh - keeps track of current location in EEPROM
		;  eetemp2  equ  2Eh - look-up value for table1			
		;eedata will be jump_1 value
		;eeadr (9Bh) will be zero at start-up
					
sw3		btfsc	flags,3		;first pass? If no, return	
		retlw	00
		bsf		flags,3		;set sw3 flag		
		
							
		movf	eefile,0
		bsf		status,rp0	;select bank1	
		movwf	eeadr	
		bcf		status,rp0	;select bank0
						
		call	write	
		
		bsf		status,rp0	;select bank1	
		incf	eeadr		;put a blank after last character
		movlw	26h
		movwf	eedata	
		bcf		status,rp0	;select bank0
		
		call	write	
		
		movf	eefile,0	;movwf	eefile		;save address of last location into EEPROM at 7Fh
												;this instruction must be outside bsf status,rp0
		
		bsf		status,rp0	;select bank1			
		movwf	eedata			;9Ah = eedata  save address of last location (1,2,3,etc)
		incf	eedata
		movlw	7Fh
		movwf	eeadr			;9Bh = eeadr  store at 7Fh
		bcf		status,rp0	;select bank0
			
		call	write		;store the number of characters at 7Fh
		incf	eefile,1	;location for last character in EEPROM   
		
		clrf	51h
		clrf	52h
		clrf	53h
		clrf	54h
		clrf	55h
		clrf	56h
		clrf	57h		
		
		movlw	51h
		movwf	04h			;load FSR
		
		movf	Jump_1,0	;Jump_1 will be one-value too high! 			
		call	table1		;get jump value for table 2
		movwf	Jump_2		;load jump value for table 2 into Jump_2
sw3b	movf	Jump_2,0
		call	table2		
		movwf	temp_sw3	;save value in a temporary file
		
		
			
		movlw	081h		;end of character is 81h or greater
		subwf	temp_sw3,0
		btfsc	03,0		;test carry   carry SET when result is above 81h
		goto	sw3c
		
				
		movf	temp_sw3,0
		movwf	00h			;move table value to indf
		incf	04h,1		;put display value into a file starting 58h
		incf	Jump_2,1
		goto	sw3b	
		
		
sw3c	movf	temp_sw3,0
		movwf	00h			;move table value to indf
		incf	04h,1		;put display value into a file 
		clrf	Jump_1		;re-start with underline
		call	sw1
		retlw	00
		
		
		
		
			
			;RUN   "Cycles the characters from EEPROM, on the screen" 

sw4		call	show  		; contains: Set4017 clock  move  scan
		call	clock
		call	clock
		call	clock
sw4a	movlw	0Ah			;speed of the shifting    
		movwf	file3A	
sw4b	call	move		;moves file from 50h to 70h etc
		call	scan		;scans the 7 rows
		call	clock
		call	sw			;look at switches
		call	clock
		call	clock			
		decfsz	file3A,1
		goto	sw4b
		call	shift		;shifts 50h to 68h one-place LEFT 	
		call	Ldscr
		goto	sw4a
		
				
		
		;Sw5 = DELETE
		;DELETE decrements eefile.   eefile holds the number of bytes in EEPROM
			

sw5		btfsc	flags,5		;first pass? If no, return	 
		retlw	00
		bsf		flags,5		;set sw5 flag          
		;decf	eefile,1	;decrement the number of bytes in EEPROM
		movf	eefile,0
		
		bsf		status,rp0	;select bank1	
		movwf	eeadr		;	
		movlw	26h			;put a blank at last address
		movwf	eedata		;
		bcf		status,rp0	;select bank0
		
		call	write
		
		decf	eefile,1	;decrement the number of bytes in EEPROM
		
		movlw	00h			;Check for zero bytes in EEPROM
		xorwf	eefile,0
		btfsc	03,2
		incf	eefile,1
				
		movf	eefile,0	
		bsf		status,rp0	;select bank1			
		movwf	eedata		;9Ah = eedata  save address of last location (1,2,3,etc)
		movlw	7Fh
		movwf	eeadr			;9Bh = eeadr  store at 7Fh
		bcf		status,rp0	;select bank0
			
		call	write		;store the number of characters at 7Fh
							
		clrf	eetemp1		;make scanning start from first character
		retlw	00
		
		
		;sw6 = EFFECTS
		
		
sw6		NOP
		goto	sw6	
		
					
					
write	bsf		status,rp0	;select bank1	
		bsf		eecon1,wren	;enable write		
		movlw	55h 		;unlock codes
		movwf	eecon2
		movlw	0aah
		movwf	eecon2
		bsf		eecon1,wr	;write begins
		bcf		status,rp0	;select bank0		
writeA	btfss	pir1,eeif	;wait for write to complete
		goto	writeA
		bcf		pir1,eeif
		bsf		status,rp0	;select bank1
		bcf		eecon1,wren	;disable other writes
		bcf		status,rp0	;select bank0					
		retlw	00				

;****************************************************************
;* Main 							*
;****************************************************************

Main	call	show
		call	clock
		call	clock
		call	clock	

Main1	call	move
		call	scan		
		call	clock
		call	sw			;look at switches
		call	clock
		call	clock	
			
		goto	Main1		
		
		
	
			
		
;****************************************************************
;*EEPROM     Values to burn into EEPROM							*
;****************************************************************
				
				
		org		2100h		
		
		de		26h	
				
		
		org		217Fh
		
		de		01h			;newly burnt chip:  01 for number of char in EEPROM
							; blank first char
		
		END
	
	
	
	
	
	
	
	
	
	
	