list	p=16f628A
#include "p16f628A.inc" 
	__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _CP_OFF & _MCLRE_OFF
	
;***** Macros *****
#DEFINE M_P0 bcf STATUS,RP0	;reg. bank 0
#DEFINE M_P1 bsf STATUS,RP0	;reg. bank 1

;***** Pins *****
#DEFINE E PORTA,0 
#DEFINE RS PORTA,1 
#DEFINE CS2 PORTA,2
#DEFINE RW PORTA,3 
#DEFINE CS1 PORTA,7 
#DEFINE BUTTON PORTA,6

;***** Variables *****
CHAR equ 0x20	
TMP0 equ 0x21
TMP1 equ 0x22
TMP2 equ 0x23
SLOUPEC equ 0x24 ;Column
STRANKA equ 0x25

;***** Start *****
	org 0x0  
	goto INIT_PIC 
Table_1: 
	movlw .60    
	xorwf SLOUPEC,0
	
	addwf PCL,F
	retlw	b'11111000';A
	retlw	b'00100100'
	retlw	b'00100010'
	retlw	b'00100100'
	retlw	b'11111000'
	retlw	b'00000000'

	retlw	b'11111110';B
	retlw	b'10010010'
	retlw	b'10010010'
	retlw	b'10101010'
	retlw	b'01000100'
	retlw	b'00000000'

	retlw	b'11111110';C
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'01000100'
	retlw   b'00000000'

	retlw	b'11111110';D
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'01000010'
	retlw	b'00111100'
	retlw   b'00000000'

	retlw	b'11111110';E
	retlw	b'10010010'
	retlw	b'10010010'
	retlw	b'10010010'
	retlw	b'10010010'
	retlw	b'00000000'

	retlw	b'11111110';F
	retlw	b'00010010'
	retlw	b'00010010'
	retlw	b'00010010'
	retlw	b'00010010'
	retlw	b'00000000'

	retlw	b'11111110';G
	retlw	b'10000010'
	retlw	b'10110010'
	retlw	b'10010010'
	retlw	b'01110100'
	retlw	b'00000000'

	retlw	b'11111110';H
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'11111110'
	retlw	b'00000000'

	retlw	b'10000010';I
	retlw	b'10000010'
	retlw	b'11111110'
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'00000000'

	retlw	b'00110000';J
	retlw	b'01000000'
	retlw	b'10000000'
	retlw	b'10000000'
	retlw	b'11111110'
	retlw	b'00000000'
	
    retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
Table_2:
    addwf PCL,F
	retlw	b'11111110';K
	retlw	b'00011000'
	retlw	b'00100100'
	retlw	b'01000010'
	retlw	b'10000001'
	retlw   b'00000000'

	retlw	b'11111110';L
	retlw	b'10000000'
	retlw	b'10000000'
	retlw	b'10000000'
	retlw	b'10000000'
	retlw   b'00000000'

	retlw	b'11111110';M
	retlw	b'00000100'
	retlw	b'00001000'
	retlw	b'00000100'
	retlw	b'11111110'
	retlw	b'00000000'

	retlw	b'11111110';N
	retlw	b'00010000'
	retlw	b'00100000'
	retlw	b'01000000'
	retlw	b'11111110'
	retlw	b'00000000'

	retlw	b'01111100';O
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'01111100'
	retlw	b'00000000'

	retlw	b'11111110';P
	retlw	b'00010010'
	retlw	b'00010010'
	retlw	b'00010010'
	retlw	b'00011100'
	retlw	b'00000000'

	retlw	b'00111100';Q
	retlw	b'01000010'
	retlw	b'01100010'
	retlw	b'01111100'
	retlw	b'10000000'
	retlw	b'00000000'

	retlw	b'11111110';R
	retlw	b'00010010'
	retlw	b'00110010'
	retlw	b'01010010'
	retlw	b'10011100'
	retlw	b'00000000'

	retlw	b'01000100';S
	retlw	b'10001010'
	retlw	b'10010010'
	retlw	b'10100010'
	retlw	b'01000100'
	retlw	b'00000000'

	retlw	b'00000010';T
	retlw	b'00000010'
	retlw	b'11111110'
	retlw	b'00000010'
	retlw	b'00000010'
	retlw	b'00000000'
	
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
   
Table_3:
    addwf PCL,F
    retlw	b'11111110';C
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'01000100'
	retlw   b'00000000'

Table_4:
	addwf PCL,F
    retlw	b'11111110';D
	retlw	b'10000010'
	retlw	b'10000010'
	retlw	b'01000010'
	retlw	b'00111100'
	retlw   b'00000000'
Table_5:
	addwf PCL,F
    retlw	b'11111110';E
	retlw	b'10010010'
	retlw	b'10010010'
	retlw	b'10010010'
	retlw	b'10010010'
	retlw	b'00000000'
Table_6:
	addwf PCL,F
    retlw	b'11111110';F
	retlw	b'00010010'
	retlw	b'00010010'
	retlw	b'00010010'
	retlw	b'00010010'
	retlw	b'00000000'
Table_7:
	addwf PCL,F
    retlw	b'11111110';G
	retlw	b'10000010'
	retlw	b'10110010'
	retlw	b'10010010'
	retlw	b'01110100'
	retlw	b'00000000'   
Table_8:
	addwf PCL,F
    retlw	b'11111110';H
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'11111110'
	retlw	b'00000000'

;***** Functions *****
WR_CMD: ;write comand on display
	bcf RS
	movwf PORTB
	bsf E
	call CEKEJ_1ms
	bcf E
	call CEKEJ_1ms
	return

WR_DATA: ;write data on display
	bsf RS
	bcf RW
	movwf PORTB
	bsf E
	call CEKEJ_1ms
	bcf E
	call CEKEJ_1ms
	return
;***** CHOOSE PAGE O-7 *****
PAGE_0:
	movlw b'10111000'
	call WR_CMD
	return
PAGE_1:
	movlw b'10111001'
	call WR_CMD
	return
PAGE_2:
	movlw b'10111010'
	call WR_CMD
	return
PAGE_3:
	movlw b'10111011'
	call WR_CMD
	return
PAGE_4:
	movlw b'10111100'
	call WR_CMD
	return
PAGE_5:
	movlw b'10111101'
	call WR_CMD
	return
PAGE_6:
	movlw b'10111110'
	call WR_CMD
	return
PAGE_7:
	movlw b'10111111'
	call WR_CMD
	return

;***** Initialization *****
INIT_PIC:	
 
	M_P0
	;movlw HIGH Table_1
	;movwf PCLATH
	clrf PORTA ;clear port A
	movlw 0x07 ;
	movwf CMCON ;turn comapator off
	clrf PORTB ;clear port B
	M_P1 ;bank 1
	;1=IN, 0=OUT
	clrf	VRCON
	movlw	b'00100000'	; port A - 5 OUT, 1 IN
	movwf	TRISA
	movlw	b'00000000'	; port B - 8 OUT
	movwf	TRISB
	M_P0 ;bank 0	
	call CEKEJ_1s

INIT_LCD: 
	bsf CS1
	bsf CS2 
	movlw b'00111111' ;display ON
	call WR_CMD
	movlw b'11000000' ;start line
	call WR_CMD
	movlw b'01000000' ;Y address
	call WR_CMD
	movlw b'10111000' ;page 0
	call WR_CMD
;****** END INIT **********
	
	;try something to draw
	bsf CS1
	bsf CS2
	movlw b'10111000' ;page 0
	call WR_CMD
	movlw b'01000000' ;Y address
	call WR_CMD 
	movlw .0
	call Table_1
	call WR_DATA
	clrf SLOUPEC ;SLOUPEC 
;MAIN_1:	
;	btfss BUTTON
;	b MAIN_1
;	b LOOP_1
	
LOOP_1:
	incf SLOUPEC
	movfw SLOUPEC
	call Table_1 ;SLOUPEC=59 je to ok a skace do Table_1
				 ;SLOUPEC=60, reset PCL a skace na Start, potrebuju vedet jak nastavit dalsi stranku pameti	
	call WR_DATA
	movlw .63    
	xorwf SLOUPEC,0
	bz LOOP_2
	b LOOP_1
LOOP_2:
	clrf SLOUPEC
	call PAGE_0
	movlw b'01000000' ;Y address 
	call WR_CMD 
	movlw .0
	call Table_2
	call WR_DATA
LOOP_3:
	incf SLOUPEC
	movfw SLOUPEC
	call Table_2
	call WR_DATA
	movlw .63
	xorwf SLOUPEC,0
	bz LOOP_4
	b LOOP_3
LOOP_4:
	clrf SLOUPEC
	call PAGE_2
	movlw b'01000000' ;Y address
	call WR_CMD 
	movlw .0
	call Table_3
	call WR_DATA
LOOP_5:
	incf SLOUPEC
	movfw SLOUPEC
	call Table_3
	call WR_DATA
	movlw .63
	xorwf SLOUPEC,0
	bz LOOP_6
	b LOOP_5
LOOP_6:
	clrf SLOUPEC
	call PAGE_3
	movlw b'01000000' ;Y address
	call WR_CMD 
	movlw .0
	call Table_4
	call WR_DATA
LOOP_7:
	incf SLOUPEC
	movfw SLOUPEC
	call Table_4
	call WR_DATA
	movlw .63  
	xorwf SLOUPEC,0
	bz LOOP_8
	b LOOP_7
LOOP_8:
	clrf SLOUPEC
	call PAGE_4
	movlw b'01000000' ;Y address
	call WR_CMD 
	movlw .0
	call Table_5
	call WR_DATA
LOOP_9:
	incf SLOUPEC
	movfw SLOUPEC
	call Table_5
	call WR_DATA
	movlw .63
	xorwf SLOUPEC,0
	bz LOOP_10
	b LOOP_9
LOOP_10:
	clrf SLOUPEC
	call PAGE_5
	movlw b'01000000' ;Y address
	call WR_CMD 
	movlw .0
	call Table_6
	call WR_DATA	
LOOP_11:
	incf SLOUPEC
	movfw SLOUPEC
	call Table_6
	call WR_DATA
	movlw .63
	xorwf SLOUPEC,0
	bz LOOP_12
	b LOOP_11
LOOP_12:
	clrf SLOUPEC
	call PAGE_6
	movlw b'01000000' ;Y address
	call WR_CMD 
	movlw .0
	call Table_7
	call WR_DATA
LOOP_13:
	incf SLOUPEC
	movfw SLOUPEC
	call Table_7
	call WR_DATA
	movlw .63
	xorwf SLOUPEC,0
	bz LOOP_14
	b LOOP_13
LOOP_14:
	clrf SLOUPEC
	call PAGE_7
	movlw b'01000000' ;Y address
	call WR_CMD 
	movlw .0
	call Table_8
	call WR_DATA
LOOP_15:
	incf SLOUPEC
	movfw SLOUPEC
	call Table_8
	call WR_DATA
	movlw .63
	xorwf SLOUPEC,0
	bz $
	b LOOP_15


	b	$	


              

;***** Delay *****
CEKEJ_1s:
        MOVLW 0x15  ;21 DEC
        MOVWF TMP2
        MOVLW 0x59  ;89 DEC
        MOVWF TMP1
        MOVLW 0x0B1  ;177 DEC
        MOVWF TMP0
        DECFSZ TMP0,F
        GOTO $-1
        DECFSZ TMP1,F
        GOTO $-5
        DECFSZ TMP2,F
        GOTO $-9
		return

CEKEJ_2ms:
	    MOVLW 0x05  ;5 DEC
        MOVWF TMP1
        MOVLW 0x84  ;132 DEC
        MOVWF TMP0
        DECFSZ TMP0,F
        GOTO $-1
        DECFSZ TMP1,F
        GOTO $-5
		return

CEKEJ_1ms:
		MOVLW 0x02  ;2 DEC
        MOVWF TMP1
        MOVLW 0x4B  ;75 DEC
        MOVWF TMP0
        DECFSZ TMP0,F
        GOTO $-1
        DECFSZ TMP1,F
        GOTO $-3
		return

	END