	
	;Sky12F629.asm
	;Magic Sky writer with 5 LEDs for PIC12F629  13-5-2010 


	list	p=12F629
	radix	dec
	include	"p12f629.inc"
	
	errorlevel	-302	; Dont complain about BANK 1 Registers

	__CONFIG _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _CP_OFF & _CPD_OFF ;Internal osc.

	
			; globals


fileA		equ		20h
fileB		equ		21h	
fileC		equ		22h	
jump1		equ		23h	
jump2		equ		24h	
			 	
     				
counter		equ		27h
jump2_savd	equ		28h
counter2	equ		29h

status		equ		03h
option_reg	equ 	81h


				; bits on GPIO
				
pin7		equ	0	;GP0  
pin6	 	equ	1	;GP1
pin5		equ	2	;GP2
pin4		equ	3	;GP3 input only
pin3		equ	4	;GP4 
pin2		equ	5	;GP5 


				;bits
				
rp0		equ	5	
		

Start	org	0x00		;program starts at location 000
		goto	SetUp
		

table1 			;characters

		ADDWF 	02h,1         ;add W to Program Counter
		RETLW	00
		RETLW 	17h	;A - jump value = 01h
       	RETLW 	24h
		RETLW 	24h
       	RETLW 	24h
		RETLW 	17h
       	RETLW 	08h
		RETLW 	37h	;B - jump value = 07h
       	RETLW 	25h
       	RETLW 	25h
       	RETLW 	25h
       	RETLW 	12h
       	RETLW 	08h
      	RETLW 	34h	;C - jump value = 0Dh
       	RETLW 	16h
		RETLW 	21h
       	RETLW 	21h	
       	RETLW 	21h
		RETLW 	08h       	
      	RETLW 	37h	;D - jump value = 13h
       	RETLW 	21h
		RETLW 	21h
       	RETLW 	21h	
       	RETLW 	16h
		RETLW 	08h
		RETLW 	37h	;E - jump value = 19h
		RETLW 	25h
		RETLW 	25h
		RETLW 	21h
       	RETLW 	08h
       	RETLW 	37h	;F - jump value = 1Eh
       	RETLW 	24h
       	RETLW 	24h
       	RETLW 	20h       	
		RETLW 	08h
		RETLW 	16h	;G - jump value = 23h
		RETLW 	21h
		RETLW 	25h
       	RETLW 	25h       	
		RETLW 	06h
		RETLW 	08h
		RETLW 	37h	;H - jump value = 29h
		RETLW 	04h
       	RETLW 	04h       	
		RETLW 	04h
		RETLW 	37h
		RETLW 	08h	;I - jump value = 2Eh
		RETLW 	37h       	
		RETLW 	08h
		RETLW 	02h	;J - jump value = 31h
		RETLW 	01h
		RETLW 	01h
       	RETLW 	36h       	
		RETLW 	08h
		RETLW 	37h	;K - jump value = 36h
		RETLW 	04h
		RETLW 	04h
       	RETLW 	12h       	
		RETLW 	21h
		RETLW 	08h
		RETLW 	37h	;L - jump value = 3Ch
		RETLW 	01h
		RETLW 	01h
       	RETLW 	01h
       	RETLW 	08h
       	RETLW 	17h	;M - jump value = 41h
       	RETLW 	20h
       	RETLW 	20h       	
		RETLW 	17h
		RETLW 	20h
		RETLW 	20h
		RETLW 	17h
		RETLW 	08h
       	RETLW 	37h	;N - jump value = 49h
       	RETLW 	10h
       	RETLW 	04h
       	RETLW 	02h
		RETLW 	37h
       	RETLW 	08h
       	RETLW 	16h	;O - jump value = 4Fh
       	RETLW 	21h
       	RETLW 	25h
       	RETLW 	23h	
       	RETLW 	17h
       	RETLW 	08h
       	RETLW 	37h	;P - jump value = 55h	
       	RETLW 	24h
       	RETLW 	24h
       	RETLW 	10h	
       	RETLW 	08h
       	RETLW 	16h	;Q - jump value = 5Ah
       	RETLW 	21h	
       	RETLW 	25h
       	RETLW 	23h
       	RETLW 	17h	
       	RETLW 	08h
       	RETLW 	37h	;R - jump value = 60h
       	RETLW 	24h	
       	RETLW 	24h
       	RETLW 	26h
       	RETLW 	11h	
       	RETLW 	08h
       	RETLW 	10h	;S - jump value = 66h
       	RETLW 	25h	
       	RETLW 	25h
       	RETLW 	25h
       	RETLW 	02h	
       	RETLW 	08h
       	RETLW 	20h	;T - jump value = 6Ch
       	RETLW 	20h	
       	RETLW 	37h
       	RETLW 	20h
       	RETLW 	20h	
       	RETLW 	08h
       	RETLW 	36h	;U - jump value = 72h
       	RETLW 	01h	
       	RETLW 	01h
       	RETLW 	01h
       	RETLW 	36h	
       	RETLW 	08h
       	RETLW 	34h	;V - jump value = 78h
       	RETLW 	02h
       	RETLW 	01h	
       	RETLW 	02h
       	RETLW 	34h
       	RETLW 	08h	
       	RETLW 	36h	;W - jump value = 7Eh
       	RETLW 	01h
       	RETLW 	01h
       	RETLW 	36h	
       	RETLW 	01h
       	RETLW 	01h
       	RETLW 	36h	
       	RETLW 	08h
       	RETLW 	21h	;X - jump value = 86h
       	RETLW 	11h
       	RETLW 	04h	
       	RETLW 	11h
       	RETLW 	21h
       	RETLW 	08h	;program looks for 08h as end of character
       	RETLW 	20h	;Y - jump value = 8Ch
       	RETLW 	10h
      	RETLW 	07h
       	RETLW 	10h	
       	RETLW 	20h
       	RETLW 	08h	;program looks for 08h as end of character
       	RETLW 	21h	;Z - jump value = 92h
       	RETLW 	23h
       	RETLW 	04h
      	RETLW 	31h
       	RETLW 	21h	       	
		RETLW 	08h	;program looks for 08h as end of character
       	RETLW 	00h	;empty space x 2 columns - jump value = 98h
       	RETLW 	00h
		RETLW 	08h	;program looks for 08h as end of character
		RETLW 	34h	;comma - jump value = 9Bh
       	RETLW 	08h	;program looks for 08h as end of character
      	       	
       	RETLW 	10h  ;1 - jump value = 9Dh
      	RETLW 	37h
       	RETLW 	08h
       	
      	RETLW 	03h  ;2 - jump value = A0h
       	RETLW 	25h
		RETLW 	25h
      	RETLW 	25h
       	RETLW 	11h
       	RETLW 	08h
       	
       	RETLW 	25h  ;3 - jump value = A6h
      	RETLW 	25h		
      	RETLW 	25h
       	RETLW 	12h
       	RETLW 	08h
       	
       	RETLW 	04h  ;4 - jump value = ABh
      	RETLW 	14h
       	RETLW 	24h
      	RETLW 	37h
       	RETLW 	04h
       	RETLW 	08h
       	
       	RETLW 	34h  ;5 - jump value = B1h
      	RETLW 	25h
       	RETLW 	25h
      	RETLW 	25h
       	RETLW 	02h
       	RETLW 	08h
       	
       	RETLW 	16h  ;6 - jump value = B7h
      	RETLW 	25h
       	RETLW 	25h
      	RETLW 	25h
       	RETLW 	02h      	
       	RETLW 	08h
       	
       	RETLW 	21h  ;7 - jump value = BDh
      	RETLW 	22h
       	RETLW 	24h
      	RETLW 	30h
       	RETLW 	08h
       	
       	RETLW 	12h  ;8 - jump value = C2h
      	RETLW 	25h
       	RETLW 	25h
      	RETLW 	25h
       	RETLW 	12h
		RETLW 	08h
		
		RETLW 	10h  ;9 - jump value = C8h
      	RETLW 	25h
       	RETLW 	25h
      	RETLW 	25h
       	RETLW 	16h
		RETLW 	08h
		
					;0 - use jump value = 4Fh
		
		
table2			;words
		ADDWF 	02h,1   ;add W to Program Counter
		RETLW 	29h		;H - Jump1 value for H in table1
      	RETLW 	01h		;A
       	RETLW 	78h		;V	
       	RETLW 	19h		;E
       	RETLW 	40h		;program looks for 40h as end of word
		RETLW 	98h		;empty space
       	RETLW 	01h		;A	
       	RETLW 	40h	;program looks for 40h as end of word
       	RETLW 	23h	;G
      	RETLW 	60h	;R
       	RETLW 	19h	;E	       	
		RETLW 	01h	;A	
		RETLW 	6Ch	;T	
		RETLW 	40h	;program looks for 40h as end of word	
		RETLW 	13h	;D	
		RETLW 	01h	;A	
		RETLW 	8Ch	;Y	
		RETLW 	40h	;program looks for 40h as end of word		
		RETLW 	00h	;0
		RETLW 	80h	;program looks for 80h as end of SENTENCE	


		RETLW 	6Ch	;T - Jump1 value for H in table1
      	RETLW 	60h	;R
       	RETLW 	8Ch	;Y	
       	RETLW 	40h	;program looks for 40h as end of word
		RETLW 	66h	;S
      	RETLW 	4Fh	;O
       	RETLW 	41h	;M	       	
		RETLW 	19h	;E	
		RETLW 	6Ch	;T	
		RETLW 	29h	;H
      	RETLW 	2Eh	;I
       	RETLW 	49h	;N	       	
		RETLW 	23h	;G	
		RETLW 	40h	;program looks for 40h as end of word	
		RETLW 	49h	;N	
		RETLW 	19h	;E	
		RETLW 	7Eh	;W	
		RETLW 	40h	;program looks for 40h as end of word		
		RETLW 	00h	;0
		RETLW 	80h	;program looks for 80h as end of SENTENCE	




		 
	;Delays  

Del_1	movlw 	01h
		movwf 	fileB	
DelX	decfsz 	fileA,1		; ,1 denotes the result of the decrement 
		goto 	DelX	
		decfsz 	fileB,1		;     is placed in the file	
		goto 	DelX
		retlw 	00


	 
	

Del_2	movlw 	0F0h
		movwf 	fileA	
DelY	decfsz 	fileA,1		
		goto 	DelY		
		retlw 	00




Del_3	movlw 	040h
		movwf 	fileB	
DelZ	decfsz 	fileA,1		; ,1 denotes the result of the decrement 
		goto 	DelZ	
		decfsz 	fileB,1		;     is placed in the file	
		goto 	DelZ
		retlw 	00 
		 
	
Del_4	movlw 	040h
		movwf 	fileC	
Del4A	decfsz 	fileA,1		; ,1 denotes the result of the decrement 
		goto 	Del4A	
		decfsz 	fileB,1		;     is placed in the file	
		goto 	Del4A
		decfsz 	fileC,1
		goto 	Del4A
		retlw 	00 	
	


SetUp	bsf		status, rp0 	;Bank 1	
		movlw	b'10000110'		;Turn off T0CKI, prescale for TMR0 = 1:128
		movwf	option_reg
		movlw   07h             ;Set up W to turn off Comparator ports
		movwf   CMCON    
		movlw	b'00001000'		;Set GP0,1,2,4,5, as output
		movwf	TRISIO	        ;enable outputs	
		bcf		status, rp0		;bank 0           
		clrf 	GPIO       		;Clear GPIO of junk		
		goto 	Main	





Main	movlw	03h
		movwf	counter2	;each sentence will appear 3 times
		movlw	04h			;each word will appear for 4 "waves"
		movwf	counter	
MainA	clrf	jump2_savd	;for table2	
MainB	movf	jump2_savd,0
		movwf	jump2
		btfsc	GPIO,3		;looking for close of intertia switch
		goto	MainB	
		call	Del_3
		call	Del_3
		
Main1	movf	jump2,0		;move table2 jump-value into W			
		call 	table2
		movwf	jump1		;put the hex value of the letter into jump1
		xorlw	80h			;see if end of sentence is reached in table2
		btfsc	03,2		;bit 2 of file 3 will be SET (=1)	
		goto	Main5
		movf	jump2,0		;move table2-jump value into W	
		call 	table2
		xorlw	40h			;see if end of word is reached in table2
		btfsc	03,2		;bit 2 of file 3 will be SET (=1)	
		goto	Main3		;end of word - add a delay		
Main2	movf	jump1,0		;put column-value into W
		call	table1

		movwf	GPIO		;display column value
		xorlw	08h			;see if end of character is reached
		btfsc	03,2		;bit 2 of file 3 will be SET (=1)	
		goto	Main4
		call	Del_1		;creates the width of the dot
		clrf	GPIO
		call	Del_2		;creates the space between the dots
		incf	jump1,1	
		goto	Main2

Main3	call	Del_3
		decfsz	counter,1
		goto	MainB	
		incf	jump2,0
		movwf	jump2_savd
		movlw	04h
		movwf	counter		
		goto	MainB


Main4	call	Del_1		;the space between the letters
		call	Del_1	
		call	Del_1
		incf	jump2,1
		goto	Main1


Main5	decfsz	counter2,1
		goto	MainA	
		incf	jump2,0
		movwf	jump2_savd
		movlw	03h
		movwf	counter2	
		goto	MainB			


			;oscillator calibration

		org		3ffh		
		movwf	OSCCAL		
	 

 
		

	end
		

	
	