Skip to content

TP3465V 16 Bit Mode to the 2.2″ TFT LCD

October 21, 2016

The Elecfreaks LCD is very nice but each of the 320X240 pixels requires you to send 16 bits over SPI.  Even an arduino takes a noticeable length of time to clear the screen and for the olduino it can be quite long.  I got 16 bit mode working a while ago and finally worked it into a screen clearing routine today.  With an 8 bit transfer routine coded in assembler it took right around .9 seconds to clear the screen.  With a carefully crafted 16 bit clear routine it takes about .6 sec.  The fundamental reason for it is that I have to leave a nop gap between pairs of writes to the SPI chip so I chew up an extra instruction there.  Then, even though I’ve unrolled the loop there’s some overhead, and the timer interrupt steals some cycles each ms.  The result is that the best i can do is a bit over 2 mb/sec rather than the theoretical 4 mb.

The first routine below is an assembly language fill routine that uses 8 bit mode. It gets passed the count as well as the value to send. Knowing it’s always 2 bytes/pixel it does double up the loop payload. The second routine uses 16 bit mode and sends 8 bytes per loop pass.

 

void zfilla(unsigned int n, unsigned char c){ //send n copies of c
	__asm
	;prolog will have prepped ix
	ld	e,(ix+4)
	ld	d,(ix+5)
	srl d			;divide de
	rr	e		;by 2
; here count/2 is in de, value is at (ix+6)
; now we want lsb of count, msb+1(*) in d (* unless already 0)
	ld b,e          ; Number of loops is in DE
	dec de          ; Calculate DB value (destroys B, D and E)
	inc d
	ld a,(ix+6)
l_zfilla_00101:
		out (0x81),a
		nop
		out (0x81),a
	djnz l_zfilla_00101
	dec d
	jp nz,l_zfilla_00101
	;epilog will restore ix and return
	__endasm;
n;c; //refs to keep compiler happy
}
void zclear(char c){ //fill the lcd by sending 153600 c's
	__asm
	ld	de,#19200 ;153600/8

; here count is in de, value is at (ix+4)
; now we want lsb of count, msb+1(*) in d (* unless already 0)
	ld b,e          ; Number of loops is in DE
	dec de          ; Calculate DB value (destroys B, D and E)
	inc d

	ld	a,0xFF	;set channel 0 to 16 bits
	out (0x8c),a ;by writing to the MWM bit
	nop

	ld a,(ix+4)
l_zclear_00101:
		out (0x80),a ;second byte
		out (0x81),a ;first byte
		nop
		out (0x80),a ;second byte
		out (0x81),a ;first byte
		nop
		out (0x80),a ;second byte
		out (0x81),a ;first byte
		nop
		out (0x80),a ;second byte
		out (0x81),a ;first byte
	djnz l_zclear_00101
	dec d
	jp nz,l_zclear_00101

	ld	a,0x00	;set channel 0 to 8 bits
	out (0x8c),a

	;epilog will restore ix and return
	__endasm;
c; //refs to keep compiler happy
}

I always want the last word so that wordpress doesn’t eat my code!

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: