Skip to content

LCD Speed Improvements

March 13, 2014

I’ve gone about as far as makes sense in speeding up the LCD write routines.

The Clear takes more than 3 seconds because of the sheer amount of data being moved.

_lcdclearer: 	//fills full lcd with 0's
	ldaD R8,240*320/4 //#cells  /4
	ldi 0\n	dec 2\n	str 2 //set up the work area
	"	cpy2 R9,2\n	sex 9	//point a temp reg at it and make that X
$$clrloop:		//come back here for more
	out 6\n	dec 9\n	out 6\n	dec 9\n	out 6\n	dec 9\n	out 6\n	dec 9
	out 6\n	dec 9\n	out 6\n	dec 9\n	out 6\n	dec 9\n	out 6\n	dec 9	//send 8 0's
	dec R8	//decrease counter
	glo R8\n	bnz $$clrloop //back for more
	ghi R8\n	bnz $$clrloop //til done
	inc R2	//release work area
	cretn\n	//and we're done

There are 240*320 pixels and each one requires 2 8 bit writes. To cut down on loop overhead I do 4 pixels on each pass of the loop, trading a little bit of space for speed. To get much better I would have to get the SPI clock speed up to 2 MHZ so I could do repeated OUT 6’s without a delay between them. Then I could do 8 pixels per pass and probably cut the time in half.

The guts of the charcater rendering is the routine called fontcel. It gets called with R12 pointing to an entry in the font table. Each table entry is 8 bits wide by 12 bytes high. To render a character you have to pick up each byte and examine the bits in sequence: for a 1 bit send two pixels of FF to light it up; for a 0 bit send two pixels of 0 to darken it. I don’t know if the routine below is optimum but it’s not bad. If I HAD to do it faster I might think about storing the fonts as 12X8 bytes instead of bits although that would make the table enormous.

_fontcel:			//fontcel(* byte) sends twelve rows of an 8 bit bitmapped font
	sex 3		//for inline output
	ldi 12\n	plo 9 //row count
$$nextbyte:\n"
	lda 12\n	plo 10		//next byte to be serialized
	ldi 8\n		plo 8 //bit count
$$nextbit:\n"
	glo 10		//byte to be seriallized
	shl\n	plo 10\n	bdf $$sendbit
	out 6\n	db 000\n	sex 3\n	out 6\n	db 000	//darken it
	br $$testcount	//see if we're done
$$sendbit:
	out 6\n	db 255\n	sex 3\n	out 6\n	db 255	//light it up
$$testcount:	//see if we're done
	dec 8\n	glo 8\n	bnz $$nextbit	//done the bits?
	dec 9\n	glo 9\n	bnz $$nextbyte	//done the bytes?
	sex 2		//restore normal x reg before exit
	cretn

The other time consuming part of character printing is setting up the window to write into. Doing this lets the fontcel routine just spit out the bits but it does take time. To set up the window you send a 0x2a command then the 4 byte begin and end x coordinates the a 0x2b command and the y coordinates. Finally you send a 0x2c before the data. All this involves turning the data/command bit on and off and many other shuffles. I’ve optimized that bit setting with inline assembly “fastdwon” and “fastdwoff” but it still adds up. It occurs to me now looking at it that I could probably avoid changing the Y address except when I change lines but I’m not going to bother for now. I thought about making a routine in assembly that would take a command string with operands – only set the command bit for the first byte and send the rest as data but I don’t see an easy way to inline it which might be the only real savings. Anyway, the text speed is less annoying than the clearing speed so i’ll leave it.

void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
   unsigned int params[2]; //address parameters to be sent
   fastdwoff(LCD_CS); //select LCD
   fastdwoff(LCD_DC); //turn data bit off for command
   spisend(0x2a); //
   params[0]=x1; params[1]=x2;
   fastdwon(LCD_DC); //turn data bit on
   spisendN((unsigned char *) params,4);
   fastdwoff(LCD_DC); //turn data bit off for command
   spisend(0x2b);	//
   params[0]=y1; params[1]=y2;
   fastdwon(LCD_DC); //turn data bit on
   spisendN((unsigned char *) params,4);
   fastdwoff(LCD_DC); //turn data bit off for command
   spisend(0x2c); //send the "Write Memory Start" command
   fastdwon(LCD_CS); //de-select LCD
}
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: