;============== LCD_Nokia 3310 Version 1.1 ======================
;
;		display LPH7366-1, LPH7779, LPH7677 / driver PCD8544
;		clock:	4 MHz
;		Author:	Stefano Tomasella
;		date:	13/06/2009
;
;		display an image (bitmap) preloaded into program memory
;
;------------------------------------------------------------
	list	p=16f84A, f=inhx8m
	include	"p16f84A.inc"
	__idlocs  0xfff0		; only last 4 bits can be modified!!
	__CONFIG	_CP_OFF & _PWRTE_OFF & _WDT_OFF & _XT_OSC
;------------------------------------------------------------
;	declare variables
		org		0x10
count1	res 1
count2	res 1
count3	res	1
temp	res 1
count	res 1

							; display pins:
							; pin1: Vdd
#DEFINE	sclk	PORTB,0		; pin2: serial clock
#DEFINE sdin	PORTB,1		; pin3: serial data
#DEFINE dorc	PORTB,2		; pin4: data or command (data active high)
#DEFINE sce		PORTB,3		; pin5: enable (active low)
							; pin6: gnd
							; pin7: Vout (grounded via >1uF capacitor)
#DEFINE res		PORTB,4		; pin8: reset (active low)
;------------------------------------------------------------
		org		0x0000
start
	bsf		STATUS,RP0		; set bank 1
	clrf	TRISA
	clrf	TRISB
	bcf		STATUS,RP0		; set bank 0
	clrf	PORTB

	call	LCDinit
	call	LCDclear

	clrf	count			; show first row
	movlw	0x01
	movwf	PCLATH
row0loop
	movf	count,w
	call	LCDrow0
	call	LCDsendData
	incf	count,f
	movlw	.84
	subwf	count,w
	btfss	STATUS,Z
	goto	row0loop

	clrf	count			; show second row
row1loop
	movf	count,w
	call	LCDrow1
	call	LCDsendData
	incf	count,f
	movlw	.84
	subwf	count,w
	btfss	STATUS,Z
	goto	row1loop

	clrf	count			; show third row
row2loop
	movf	count,w
	call	LCDrow2
	call	LCDsendData
	incf	count,f
	movlw	.84
	subwf	count,w
	btfss	STATUS,Z
	goto	row2loop

	clrf	count			; show fourth row
	movlw	0x02
	movwf	PCLATH
row3loop
	movf	count,w
	call	LCDrow3
	call	LCDsendData
	incf	count,f
	movlw	.84
	subwf	count,w
	btfss	STATUS,Z
	goto	row3loop

	clrf	count			; show fifth row
row4loop
	movf	count,w
	call	LCDrow4
	call	LCDsendData
	incf	count,f
	movlw	.84
	subwf	count,w
	btfss	STATUS,Z
	goto	row4loop

	clrf	count			; show sixth row
row5loop
	movf	count,w
	call	LCDrow5
	call	LCDsendData
	incf	count,f
	movlw	.84
	subwf	count,w
	btfss	STATUS,Z
	goto	row5loop

endLoop
	goto	endLoop

;=============================== routine ========================================
LCDinit
	call	LCDreset		; reset
	movlw	21H				; set extended instruction set
	call	LCDsendCommand
	movlw	0xC0			; (C0 => 64/127) Vop = contrasto
	call	LCDsendCommand
	movlw 	13H				; bias
	call	LCDsendCommand
	movlw	20H				; set normal instruction set - horizontal addressing
	call	LCDsendCommand
	movlw	0CH				; normal mode
	call	LCDsendCommand
	movlw	80H				; set x address to 0
	call	LCDsendCommand
	movlw	40H				; set y address to 0
	goto	LCDsendCommand

LCDreset
	bcf		res				; reset display (active low)
	bsf		res
	return

LCDsendCommand
	bcf		dorc
	goto	LCDsendByte

LCDsendData
	bsf		dorc

LCDsendByte
	movwf	temp
	movlw	0x08
	movwf	count1
	bcf		sce				; enable display
byteLoop
	bcf		sdin
	rlf		temp,f
	btfsc	STATUS,C
	bsf		sdin
	bsf		sclk
	bcf		sclk
	decfsz	count1,f
	goto	byteLoop
	bsf		sce				; disable display
	return

LCDclear					; clear all display and go to location x=0 y=0
	movlw	0x80
	call	LCDsendCommand
	movlw	0x40
	call	LCDsendCommand
	bcf		sdin
	bsf		dorc
	bcf		sce
	movlw	.84
	movwf	count1
c1	movlw	.48
	movwf   count2
c2	bsf		sclk
	bcf		sclk
	decfsz	count2,f
	goto	c2
	decfsz	count1,f
	goto	c1
	bsf		sce
	return

	org		0x0100
LCDrow0						; return every single byte of the figure
	addwf	PCL,f			; bottom ---> top
	retlw	b'00000000'		; first row
	retlw	b'00000000'		;
	retlw	b'00000000'		; left
	retlw	b'00000000'		;   ||
	retlw	b'00000000'		;   ||
	retlw	b'00000000'		;  \||/
	retlw	b'00000000'		;   \/
	retlw	b'10000000'		; right
	retlw	b'11000000'
	retlw	b'01100000'
	retlw	b'00110000'
	retlw	b'00010000'
	retlw	b'00011000'
	retlw	b'00001000'
	retlw	b'00001000'
	retlw	b'00001100'
	retlw	b'00001100'
	retlw	b'00001100'
	retlw	b'00000100'
	retlw	b'00000100'
	retlw	b'00000110'
	retlw	b'00000110'
	retlw	b'00000010'
	retlw	b'00000010'
	retlw	b'00000010'
	retlw	b'00000010'
	retlw	b'00000010'
	retlw	b'00000110'
	retlw	b'00000100'
	retlw	b'00000100'
	retlw	b'00000100'
	retlw	b'00001100'
	retlw	b'00001000'
	retlw	b'00001000'
	retlw	b'00011000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00100000'
	retlw	b'01000000'
	retlw	b'11000000'
	retlw	b'10000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'

	





	
	
	
	
	
	org		0x0155
	
LCDrow1
	addwf	PCL,f
	retlw	b'00000000'		; second row
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'11000000'
	retlw	b'01110000'
	retlw	b'00001100'
	retlw	b'00000110'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'11111000'
	retlw	b'11101110'
	retlw	b'11111100'
	retlw	b'11111000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'11110000'
	retlw	b'11111100'
	retlw	b'11101110'
	retlw	b'11111100'
	retlw	b'11111000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000001'
	retlw	b'00000011'
	retlw	b'00000100'
	retlw	b'00011000'
	retlw	b'11100000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'11000000'
	retlw	b'00100000'
	retlw	b'00010000'
	retlw	b'00001000'
	retlw	b'00001000'
	retlw	b'00010000'
	retlw	b'11100000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'11111000'
	retlw	b'00000110'
	retlw	b'00000010'
	retlw	b'00000010'
	retlw	b'00000010'
	retlw	b'00000110'
	retlw	b'00011000'
	retlw	b'11100000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'10000000'
	retlw	b'10000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'



	
	
	
	
	
	
	



	org		0x01AA
LCDrow2
	addwf	PCL,f
	retlw	b'00000000'		; third row
	retlw	b'11111000'
	retlw	b'00001111'
	retlw	b'00000011'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'10000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000011'
	retlw	b'00000111'
	retlw	b'00000111'
	retlw	b'00000011'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000001'
	retlw	b'00000111'
	retlw	b'00001111'
	retlw	b'00000111'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'10000000'
	retlw	b'10000000'
	retlw	b'10000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000001'
	retlw	b'00011110'
	retlw	b'11110000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00111110'
	retlw	b'11000011'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000011'
	retlw	b'11111110'
	retlw	b'00000000'
	retlw	b'00111111'
	retlw	b'11000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'11111000'
	retlw	b'00000111'
	retlw	b'00000000'
	retlw	b'11110000'
	retlw	b'00001110'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000001'
	retlw	b'00001110'
	retlw	b'11110000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	
	
	
	
	
	
	





	
	org		0x0200
LCDrow3
	addwf	PCL,f
	retlw	b'00000000'		; fourth row
	retlw	b'00011111'
	retlw	b'11110000'
	retlw	b'10000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00001000'
	retlw	b'00000100'
	retlw	b'00000110'
	retlw	b'00000101'
	retlw	b'00001101'
	retlw	b'00001000'
	retlw	b'00010000'
	retlw	b'00110000'
	retlw	b'01110000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11100000'
	retlw	b'11110000'
	retlw	b'11110000'
	retlw	b'01110000'
	retlw	b'00011000'
	retlw	b'10001000'
	retlw	b'10000110'
	retlw	b'11000001'
	retlw	b'01000011'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'10000000'
	retlw	b'10000000'
	retlw	b'10000000'
	retlw	b'01111000'
	retlw	b'00000111'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000011'
	retlw	b'11111100'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00001111'
	retlw	b'00001000'
	retlw	b'00001110'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000111'
	retlw	b'00001000'
	retlw	b'00001110'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'11100000'
	retlw	b'00011110'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	
	
	
	
	
	





	
	
	org		0x0255
LCDrow4
	addwf	PCL,f
	retlw	b'00000000'		; fifth row
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000011'
	retlw	b'00001110'
	retlw	b'00011000'
	retlw	b'01100000'
	retlw	b'11000000'
	retlw	b'10000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000001'
	retlw	b'00000011'
	retlw	b'00000101'
	retlw	b'00001001'
	retlw	b'00110001'
	retlw	b'00100001'
	retlw	b'00100001'
	retlw	b'00100001'
	retlw	b'00100001'
	retlw	b'00100011'
	retlw	b'00010011'
	retlw	b'00001111'
	retlw	b'00000111'
	retlw	b'00000011'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00011100'
	retlw	b'00100011'
	retlw	b'00100000'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'10100000'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'01000001'
	retlw	b'01000001'
	retlw	b'10000010'
	retlw	b'00000110'
	retlw	b'00000100'
	retlw	b'00000100'
	retlw	b'00000100'
	retlw	b'00000100'
	retlw	b'00000011'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'11111111'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	
	
	
	
	
	
	
	
	
	
	
	
	
	org		0x02AA
LCDrow5
	addwf	PCL,f
	retlw	b'00000000'		; sixth row
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000001'
	retlw	b'00000010'
	retlw	b'00000110'
	retlw	b'00000100'
	retlw	b'00001000'
	retlw	b'00001000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00110000'
	retlw	b'00110000'
	retlw	b'00100000'
	retlw	b'01100000'
	retlw	b'01100000'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'01000000'
	retlw	b'01100000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00110000'
	retlw	b'00110000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00001000'
	retlw	b'00001100'
	retlw	b'00000100'
	retlw	b'00000110'
	retlw	b'00000010'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000001'
	retlw	b'00000010'
	retlw	b'00001100'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00110000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00110000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00010000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00100000'
	retlw	b'00110000'
	retlw	b'00010000'
	retlw	b'00001110'
	retlw	b'00000001'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
	retlw	b'00000000'
;------------------------------------------------------------
	end
;============================================================
