int colour; //we'll define the control pins now, change them here if you wire yours differently #define LCD_RST 8 //Define pin 8 as LCD_RST (Shield Reset, NOT to the Reset Button) #define LCD_CS 9 //Define pin 9 as LCD_CS (Chip Select) #define LCD_RS 10 //Define pin 10 as LCD_RS (Register Select, 0=Command/1=Data) #define LCD_WR 11 //Define pin 11 as LCD_WR (Write line - this was like the Enable line on the Hitachi LCD. Active LOW) #define LCD_RD 12 //Define pin 12 as LCD_RD (Read) #define WHITE 0xFFFF #define RED 0xF800 #define GREEN 0x07E0 #define BLUE 0x001F #define CYAN 0x003F #define MAGENTA 0x07C0 #define YELLOW 0xF800 #define BLACK 0x0000 //------------------------------------------------------------------------------------------- void setup() { for (int p = 8; p < 12; p++) { pinMode(p, OUTPUT); //Set Pins 8-12 as Output for use as the control lines. } digitalWrite (LCD_RST, HIGH); //set idle state for RESET digitalWrite (LCD_CS, HIGH); //set Chip Select to high for idle state digitalWrite (LCD_RS, HIGH); //set Register Select line to high (data) for now digitalWrite (LCD_WR, HIGH); //set idle state for WRITE line digitalWrite (LCD_RD, HIGH); //set idle state for READ line /* Important! Make sure nothing is connected to pins 0 or 1 until after you have loaded your sketch onto the board. Disconnect * all wires from pins 0 and 1 if you wish to upload another sketch. Pins 0 and 1 are connected to TX and RX, which is connected * to the TX and RX lines of the USB port connected to your computer. So anything connected to them will interfere with your * computer transmitting data to your UNO board. */ DDRD = 0xFF; //sets up port D as outputs. Port D resides on pins 0-7, so D0-D7 on the TFT get connected to corresponding pins 0-7 //after setting up the Arduino pins, we now initialize the TFT display digitalWrite(LCD_RST, HIGH); // Toggle the RESET line to reset the board, start HIGH delay(15); //need a short delay cause Arduino is faster than the display controller digitalWrite(LCD_RST, LOW); //Strobe the RESET line low delay(200); //need a short delay cause Arduino is faster than the display controller digitalWrite(LCD_RST, HIGH); //Put the RESET line high after reset so board will function normally delay(200); //need a short delay cause Arduino is faster than the display control digitalWrite(LCD_CS, LOW); //Set Chip Select LOW to activate the board //Now we need to wake the board //setting up the wake/sleep register to Wake. Command only, no data blocks. digitalWrite(LCD_RS, LOW); //RS line low means this is a COMMAND PORTD = 0x11; //Clear PORTD and add our six bits of data to the MSB //Now that we've loaded our command onto PORTB and PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); digitalWrite(LCD_WR, HIGH); delay(120); //Wait at least 120 ms for circuitry to respond. //a lot of people attempting to use these screens were running into problems here //by not waiting long enough after hard reset or wake commands //setting up the MADCTL register (screen set up, etc...) digitalWrite(LCD_RS, LOW); //RS line low means this is a COMMAND PORTD = 0x36; //Lock and load Port D with our instruction //Now that we've loaded our command onto PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); digitalWrite(LCD_WR, HIGH); //After sending a command, the TFT controller chip is now expecting data. digitalWrite(LCD_RS, HIGH); //RS line high now indicates this is DATA PORTD = 0x00; //put our setting byte on Port D //Now that we've loaded our data onto PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); digitalWrite(LCD_WR, HIGH); //Lcd_Write_Com(0x3A); //COLMOD (Interface Pixel Format) //Lcd_Write_Data(0x55); //RGB Interface, Color Format 16Bit,Control Interface Color Format 16bit. //setting up COLMOD register digitalWrite(LCD_RS, LOW); //RS line low means this is a COMMAND PORTD = 0x3A; //Lock and load Port D with our instruction //Now that we've loaded our command onto PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); digitalWrite(LCD_WR, HIGH); //After sending a command, the TFT controller chip is now expecting data. digitalWrite(LCD_RS, HIGH); //RS line high now indicates this is DATA PORTD = 0x55; //Clear PORTD and add our six bits of data to the MSB //Now that we've loaded our data onto PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); digitalWrite(LCD_WR, HIGH); //Lcd_Write_Com(0x29); //Display on. //send command to turn on display. Command only, no data block. digitalWrite(LCD_RS, LOW); //RS line low means this is a COMMAND PORTD = 0x29; //load PORTD with our instruction //Now that we've loaded our command onto PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); digitalWrite(LCD_WR, HIGH); //********delete the comment markers from lines 123 and 153 once you've performed your screen test.************ /* //***********Now that we're set up, let's set ALL of the pixels**************************** //Let's now clear the whole screen black //now send the command to write to the current address, 0x2C digitalWrite(LCD_RS, LOW); //RS line low means this is a COMMAND PORTD = 0x2C; //load PORTD with our write to display memory instruction //Now that we've loaded our command onto PORTB and PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); digitalWrite(LCD_WR, HIGH); for (int col=0; col<=239; ++col) {for (int page=0; page<=319; ++page) { //After sending a command, the TFT controller chip is now expecting RGB colour data, in two bytes. //every time we send a colour, the pixel address automatically increments to the next pixel! digitalWrite(LCD_RS, HIGH); //RS line high now indicates this is DATA PORTD = BLACK>>8; //load PORTD with the first byte of our colour //Now that we've loaded our colour on to PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); //strobe the Read/Write line to lock in the first byte of our colour digitalWrite(LCD_WR, HIGH); PORTD = BLACK; //load PORTD with the second byte of our colour //Now that we've loaded our second colour byte onto PORTD, we strobe the Read/Write line). digitalWrite(LCD_WR, LOW); //strobe the Read/Write line to lock in the second byte of our colour digitalWrite(LCD_WR, HIGH); } } */ } //------------------------------------------------------------------------------------------- void loop() { } //------------------------------------------------------------------------------------------- //End of Sketch.