SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By Robban
#54191
Edit: Dangit, being the noob I am I put this in the wrong part of the forum. (my only excuse is I ended up in this part while doing searches before posting :D This would fit better in the PIC area as that is what I'm using)
After a couple of weeks of on and off trying to get this to work I'm turning to you guys to put me out of my misery.

I'm trying to use the display in 4096 colour mode sending the colour in this format to the display "0000RRRR GGGGBBBB" as shown here. However, it seems that my display is receiving data in a RBG order rather than the more sane RGB order.

In the pic below I'm drawing a box of Red, Green and Blue however, it is showing Red, Blue, Green. By reversing the last byte of the colour it seems to display normally (see code at the end of the post). I guess I could live with that for simple stuff. However, when trying to display a picture this doesn't seem to work out.

At the top of the image you'll see 8 strips of random junk which should actually be displaying the colours of the rainbow (you can see the blurry original on my computer above the LCD). I'm using the program found here to convert the 24bit BMP that I created as a test. I'm telling the program to spit the data out in its "12bit B" format which looks like this "XXXXRRRR GGGGBBBB".

The 8 stips of garbled coloured dots represent me sending the data from the program in different ways. Top to bottom and non reversed, one byte reversed, last reversed and finally all reversed. Nothing seems to do the trick.

The colours are also very washed out (tweaking the contrast doesn't do much more than either blowing them completely or making the screen darker than is useful while still having washed out colours).

Image

Right, time for the guts. I'm using this to initialize the display (Phillips btw):
Code: Select all
// From http://www.idcomm.com/personal/lorenblaney/lcdcode.txt
void initLcd(void) {        

	LCD_RES = 0;  // reset the controller
	DelayMs(10);
	LCD_RES = 1;
	DelayMs(10);
	LCD_CS = 0;     // enable the chip
	
	LCD_command(DISCTL); // Display control
	LCD_data(0);  //0    // 2 divisions, switching period=8 (default)
	LCD_data(32); //32    // nlines/4 - 1 = 132/4 - 1 = 32)
	LCD_data(0);  //0     // no inversely highlighted lines

	LCD_command(COMSCN); // Common scan directions
	LCD_data(1);     // Scan 1->80, 160<-81
	
	LCD_command(OSCON);  // turn on internal oscillator
	
	LCD_command(SLEEPOUT); // Sleep out
	
	LCD_command(SETCON);	//Set Contrast(PHILLIPS)
	//LCD_data(0x30);	//ebay
	LCD_data(0x33);	//sparkfun
	
	LCD_command(BSTRON);
	
	LCD_command(PWRCTR); // Power control
	LCD_data(0x0F);  // everything on: reference voltage, regulator,
	                //  circuit voltage follower, and boosters
	//LCD_command(DISINV); // Inverse display (for proper colors)
	
	LCD_command(INVON);
	
	LCD_command(MADCTL);	//Memory Access Control(PHILLIPS)
	LCD_data(0xC8);
	//LCD_data(0xC0);
	
	LCD_command(DATCTL); // Data control
	LCD_data(0x03);  // page address inverted, column address normal,
	                //  address scan in page direction
	LCD_data(0x00);  // RGB sequence (default) Yes, I've tried both 0x01 and 0xFF
	LCD_data(0x04);  // special mode selects 12-bit color for single pixels <==
	
	LCD_command(VOLCTR); // Voltage control
	LCD_data(5);    // contrast setting: 0..63
	LCD_data(3);     // resistance ratio (only value that works)
	
	LCD_command(DISPON);  // turn on the display
	
	fillWin(setWin(0, 0, 130, 130), 0x0000); // clear display memory
	
	DelayMs(100);   // wait for power supply voltage to stabilize
	

} // initLcd
Functions for defining "window" size and filling said "window"
Code: Select all
int setWin(int x0, int y0, int x1, int y1) {
// Set rectangular area for a window on the LCD
// Returns its area (in pixels)
    int t;

    if (x0>x1) {t=x0; x0=x1; x1=t;}     // put coordinates into ascending order
    if (y0>y1) {t=y0; y0=y1; y1=t;}

    LCD_command(CASETP);      // set column address
    LCD_data(x0);      // start (visible area starts in column 2)
    LCD_data(x1);      // end

    LCD_command(PASETP);      // set page (row) address
    LCD_data(y0);        // start
    LCD_data(y1);        // end

return (x1-x0+1) * (y1-y0+1);   // area
} // setWin
void fillWin(int area, int color) {     // Fill window with specified color
    int i;
    LCD_command(RAMWRP);
    for (i=0; i<area; i++) {
        LCD_data(color>>8);
    	LCD_data(color);      // Reversing the order of this fixes the small boxes
    }
} // fillWin
This is the data I'm using for displaying the image (can't seem to fit much more than this into the 16f886 so I guess I need to learn how to handle external EEPROMs now too...):
Code: Select all
const unsigned char bitmap[]= 
{
		0x0F, 0x00, 0x0F, 0x00, 0x0F, 0x00, 0x0F, 0x01, 0x0F, 0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F, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 
		0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFD, 0x00, 0xFC, 0x00, 0xFC, 0x00, 0xFB, 0x00, 0xFA, 0x00, 0xF9, 0x00, 0xF9, 0x00, 0xF8, 0x00, 0xF7, 0x00, 0xF6, 
		0x00, 0xF5, 0x00, 0xF5, 0x00, 0xF4, 0x00, 0xF3, 0x00, 0xF2, 0x00, 0xF2, 0x00, 0xF1, 0x00, 0xF1, 0x00, 0xF0, 0x00, 0xF0, 0x01, 0xF0, 0x01, 0xF0, 
		0x02, 0xF0, 0x02, 0xF0, 0x03, 0xF0, 0x04, 0xF0, 0x04, 0xF0, 0x05, 0xF0, 0x06, 0xF0, 0x07, 0xF0, 0x08, 0xF0, 0x09, 0xF0, 0x09, 0xF0, 0x0A, 0xF0, 
		0x0B, 0xF0, 0x0C, 0xF0, 0x0D, 0xF0, 0x0D, 0xF0, 0x0E, 0xF0, 0x0E, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0xE0, 0x0F, 0xE0, 0x0F, 0xD0, 0x0F, 0xC0, 
		0x0F, 0xC0, 0x0F, 0xB0, 0x0F, 0xA0, 0x0F, 0x90, 0x0F, 0x80, 0x0F, 0x70, 0x0F, 0x60, 0x0F, 0x60, 0x0F, 0x50, 0x0F, 0x40, 0x0F, 0x30, 0x0F, 0x20, 
		0x0F, 0x20, 0x0F, 0x10, 0x0F, 0x00, 0x0F, 0x00
	};

And finally a slice from the main program:
Code: Select all
	color = 0b0000111100000000; // Displays Red
	setWin(20,60,40,80);
	fillWin(400, color);
	
	color = 0b0000000011110000; // Displays Blue
	setWin(40,60,60,80);
	fillWin(400, color);

	color = 0b0000000000001111; // Displays Green
	setWin(60,60,80,80);
	fillWin(400, color);

	
	
	setWin(0,0,129,129);
	LCD_command(RAMWRP);

	for(x = 1040; x > 0; x--){
		if(x%2 == 0){
			LCD_data(bitmap[x]);
		}else{
			LCD_data(bitmap[x]);
		}
	}

	for(x = 1040; x > 0; x--){
		if(x%2 == 0){
			LCD_data(reverse(bitmap[x]));
		}else{
			LCD_data(bitmap[x]);
		}
	}
	for(x = 1040; x > 0; x--){
		if(x%2 == 0){
			LCD_data(bitmap[x]);
		}else{
			LCD_data(reverse(bitmap[x]));
		}
	}
	for(x = 1040; x > 0; x--){
		if(x%2 == 0){
			LCD_data(reverse(bitmap[x]));
		}else{
			LCD_data(reverse(bitmap[x]));
		}
	}
	
	
	
	for(x = 0; x < 1040; x++){
		if(x%2 == 0){
			LCD_data(bitmap[x]);
		}else{
			LCD_data(bitmap[x]);
		}
	}
	for(x = 0; x < 1040; x++){
		if(x%2 == 0){
			LCD_data(reverse(bitmap[x]));
		}else{
			LCD_data(bitmap[x]);
		}
	}
	for(x = 0; x < 1040; x++){
		if(x%2 == 0){
			LCD_data(bitmap[x]);
		}else{
			LCD_data(reverse(bitmap[x]));
		}
	}
	for(x = 0; x < 1040; x++){
		if(x%2 == 0){
			LCD_data(reverse(bitmap[x]));
		}else{
			LCD_data(reverse(bitmap[x]));
		}
	}

Also as a side note, the really annoying high pitched whine from the SparkFun carrier board is normal, right?