Initializing a TFT Display for AVR, Using the SSD1289 as an Example.
The other day a TFT display I ordered on AliExpress arrived; let's look at its main specifications.

Main display specifications:
We'll use an Atmega16 as the controlling microcontroller. I didn't look for ready-made initialization examples; I decided to figure out how it works and write my own. First, let's deal with the connection interface. Communication with the SSD1289 controller can take place over 1 of 4 interfaces: i8080, M6800, RGB or SPI, but so that we wouldn't agonize over which to choose, the module manufacturer helped us out. It left a choice of two 16-bit interfaces: Intel's i8080 and Motorola's M6800. i8080 and M6800 are parallel interfaces that can work in 18/16/8-bit mode. I chose i8080, although according to the datasheet it differs from M6800 only in that i8080 has separate write (WR) and read (RD) signals, while M6800 has a single RD/WR direction control signal, plus an additional enable signal E.
Now let's look at the module's pinout.
Power pins.
VCC – the module's supply voltage. Inside the module there is a 3.3V voltage regulator that powers the graphics controller (SSD1289), the resistive touch screen controller (XPT2046) and the SD card. The regulator makes it possible to supply the module with 5V. But data exchange between the microcontroller and the module must use 3.3V. In my circuit the module and the microcontroller are powered from the same voltage, 3.3V, which ensures normal data exchange. At this supply voltage the microcontroller works fine at 8MHz. By the way, I did supply 5 volts to the microcontroller and the module; I was lucky, nothing burned out and everything worked, but you shouldn't do that.
GND – common pin (ground).
LED-A – the TFT display backlight anode; it must be connected through a current-limiting resistor. With a 3.3V supply I connected it through 200 Ohm.
Graphics controller control pins.
[DB15, DB0] (Data Bus) – the 16-bit data/command bus.
RS (Register Select) – the pin used to switch between the data registers (GRAM) and the instruction registers; in the datasheet it's called D/C.
WR (Write) – data/command write strobe.
RD (Read) – data/parameter read strobe.
REST (Reset) – resets the graphics controller.
CS (Chip Select) – activates/deactivates the graphics display.
The overall wiring diagram of the TFT display is shown below.

Now we need to figure out how to send commands/data to the SSD1289; for this, let's look at the picture below.

The picture shows that this can be done in two ways; we'll implement the first.
To send a command, you need to perform the following sequence of actions:
To send data, you need to perform the following sequence of actions:
Below is the implementation of sending commands/data in C.
We've dealt with the connection; now let's move on to initialization. We open the datasheet and find the page that describes the initialization sequence.

To initialize the SSD1289 controller, we need to write the value 0021h to register R07, thus setting GON = 1, DTE = 0, D[1:0] = 01; we won't look at what these bits do, since it doesn't matter for now.

In the next step we turn on the oscillator by writing 0001h to register R00. By the way, if you read data from this register after initialization, it should return 8989h if initialization succeeded.

Next, we go back to R07 again and set the value 0023h.
In the next step we exit sleep mode by writing 0000h to R10.

We wait 30 milliseconds. We write 0033h to register R07. Next, we write 6838h to register R11; let's look at what these digits mean.
POR is the default value, and it equals 6830h. So by default the display can show 65K colors; the first digit 6 in the value 6830h is responsible for this. Remember this, as we'll come back to it later when forming colors.


Next we determine the order in which points are written. The point is that to display an image, it's enough to set the coordinates of only the first point; after that you only need to send the SSD1289 the color of the next point, and it will draw it by itself according to the algorithm we'll now choose. And here I can't say exactly why, but with these settings the mode marked with the green circle turned on, while the one marked with the red circle should have.

We'll leave the value in register R02 at its default, and that completes the initialization.
Now let's put everything we've covered into code.
If you perform all the described steps in sequence, then if initialization succeeds, the screen will be randomly filled with multicolored dots, as in the photo below.
Now we know how to initialize a TFT display with an SSD1289 controller; in the next article we'll look at how to display individual characters and write strings. Also, at the end of the next article you can download an example for Atmel Studio 6.2.
P.S. The place where I bought the display no longer sells it; in the comments Andrey left a link to a display that worked for him, so you don't have to search, I'll leave it here.
Display_ebay
P.P.S. For those who want to quickly check whether their display works, here's the firmware for the Atmega16 ssd1289_i8080.hex

Main display specifications:
- 3.2 inches, with a resolution of 320x240
- TFT display driver: SSD1289; touch panel driver: XPT2046
- TFT control via the 6800 and 8080 protocols, FSMC support
- SPI touch panel control interface
- 5V or 3.3V supply voltage, thanks to the built-in step-down regulator
- backlight control via PWM
- built-in SD card slot
- free space for soldering FLASH memory
- supports horizontal and vertical orientation, can display multiple windows
- color depth: 18 bits (262,144 combinations)
We'll use an Atmega16 as the controlling microcontroller. I didn't look for ready-made initialization examples; I decided to figure out how it works and write my own. First, let's deal with the connection interface. Communication with the SSD1289 controller can take place over 1 of 4 interfaces: i8080, M6800, RGB or SPI, but so that we wouldn't agonize over which to choose, the module manufacturer helped us out. It left a choice of two 16-bit interfaces: Intel's i8080 and Motorola's M6800. i8080 and M6800 are parallel interfaces that can work in 18/16/8-bit mode. I chose i8080, although according to the datasheet it differs from M6800 only in that i8080 has separate write (WR) and read (RD) signals, while M6800 has a single RD/WR direction control signal, plus an additional enable signal E.
Now let's look at the module's pinout.
Power pins.
VCC – the module's supply voltage. Inside the module there is a 3.3V voltage regulator that powers the graphics controller (SSD1289), the resistive touch screen controller (XPT2046) and the SD card. The regulator makes it possible to supply the module with 5V. But data exchange between the microcontroller and the module must use 3.3V. In my circuit the module and the microcontroller are powered from the same voltage, 3.3V, which ensures normal data exchange. At this supply voltage the microcontroller works fine at 8MHz. By the way, I did supply 5 volts to the microcontroller and the module; I was lucky, nothing burned out and everything worked, but you shouldn't do that.
GND – common pin (ground).
LED-A – the TFT display backlight anode; it must be connected through a current-limiting resistor. With a 3.3V supply I connected it through 200 Ohm.
Graphics controller control pins.
[DB15, DB0] (Data Bus) – the 16-bit data/command bus.
RS (Register Select) – the pin used to switch between the data registers (GRAM) and the instruction registers; in the datasheet it's called D/C.
WR (Write) – data/command write strobe.
RD (Read) – data/parameter read strobe.
REST (Reset) – resets the graphics controller.
CS (Chip Select) – activates/deactivates the graphics display.
The overall wiring diagram of the TFT display is shown below.

Now we need to figure out how to send commands/data to the SSD1289; for this, let's look at the picture below.

The picture shows that this can be done in two ways; we'll implement the first.
To send a command, you need to perform the following sequence of actions:
- set the D/C pin to zero to say we're going to send a command
- set the RD pin to one to make sure we're writing
- activate the chip by setting the CS pin to zero
- put the data on the bus, in our case these are two ports
- set the WR pin to one
- wait a few microseconds
- set the WR pin to zero
- set the CS pin to one to deactivate the chip
To send data, you need to perform the following sequence of actions:
- set the D/C pin to one to say we're going to send data
- set the RD pin to one to make sure we're writing
- activate the chip by setting the CS pin to zero
- put the data on the bus, in our case these are two ports
- set the WR pin to one
- wait a few microseconds
- set the WR pin to zero
- set the CS pin to one to deactivate the chip
Below is the implementation of sending commands/data in C.
#define D0 PORTA //since data is transmitted over a 16-bit bus,
#define D7 PORTD //we use two ports for it
#define COMMAND_PORT PORTB //control port
#define lcd_dc 0 //may also be called RS (comm - 0; data - 1)
#define lcd_res 1 //(active - 0)
#define lcd_rd 2 //(read_active - 0)
#define lcd_cs 3 //(chip_select_active - 0)
#define lcd_wr 5 //(write_active - 0)
void Lcd_Write_Index(uint16_t index)
{
COMMAND_PORT &= ~(1<<lcd_dc); //we're going to send a command
COMMAND_PORT |= (1<<lcd_rd); //set the read pin to 1
COMMAND_PORT &= ~(1<<lcd_cs); //activate the chip
D0 = (index & 0X00FF); //send the low byte via D0
D7 = (index & 0XFF00)>>8; //then the high byte via D7
COMMAND_PORT &= ~(1<<lcd_wr); //now strobe with the write bit
_delay_us(5);
COMMAND_PORT |= (1<<lcd_wr);
COMMAND_PORT |= (1<<lcd_cs); //deactivate the chip
}
////////////////////////
void Lcd_Write_Data(uint16_t data) //all the same, only DC is set to one
{
COMMAND_PORT |= (1<<lcd_dc) ;
COMMAND_PORT |= (1<<lcd_rd);
COMMAND_PORT &= ~(1<<lcd_cs);
D0 = (data & 0X00FF);
D7 = (data & 0XFF00)>>8;
COMMAND_PORT &= ~(1<<lcd_wr);
_delay_us(5);
COMMAND_PORT |= (1<<lcd_wr);
COMMAND_PORT |= (1<<lcd_cs);
}
/////////////let's write a simple function for writing data to registers
void Lcd_Write_Reg(uint16_t lcd_reg, uint16_t lcd_data)
{
COMMAND_PORT &= ~(1<<lcd_cs);
Lcd_Write_Index(lcd_reg);
Lcd_Write_Data(lcd_data);
COMMAND_PORT |= (1<<lcd_cs);
}
We've dealt with the connection; now let's move on to initialization. We open the datasheet and find the page that describes the initialization sequence.

To initialize the SSD1289 controller, we need to write the value 0021h to register R07, thus setting GON = 1, DTE = 0, D[1:0] = 01; we won't look at what these bits do, since it doesn't matter for now.

In the next step we turn on the oscillator by writing 0001h to register R00. By the way, if you read data from this register after initialization, it should return 8989h if initialization succeeded.

Next, we go back to R07 again and set the value 0023h.
In the next step we exit sleep mode by writing 0000h to R10.

We wait 30 milliseconds. We write 0033h to register R07. Next, we write 6838h to register R11; let's look at what these digits mean.
POR is the default value, and it equals 6830h. So by default the display can show 65K colors; the first digit 6 in the value 6830h is responsible for this. Remember this, as we'll come back to it later when forming colors.


Next we determine the order in which points are written. The point is that to display an image, it's enough to set the coordinates of only the first point; after that you only need to send the SSD1289 the color of the next point, and it will draw it by itself according to the algorithm we'll now choose. And here I can't say exactly why, but with these settings the mode marked with the green circle turned on, while the one marked with the red circle should have.

We'll leave the value in register R02 at its default, and that completes the initialization.
Now let's put everything we've covered into code.
#define lcd_res 1 //(active - 0)
void Init()
{
_delay_ms(100); //a short delay after power-on
COMMAND_PORT |= (1<<lcd_res); //set reset to 1 so the SSD1289 turns on
Lcd_Write_Reg(0X0007, 0X0021); //then write the values to the registers
Lcd_Write_Reg(0X0000, 0X0001);
Lcd_Write_Reg(0X0007, 0X0023);
Lcd_Write_Reg(0X0010, 0X0000);
_delay_ms(30);
Lcd_Write_Reg(0X0007, 0X0033);
Lcd_Write_Reg(0X0011, 0X6838);
Lcd_Write_Reg(0X0002, 0X0600);
}
If you perform all the described steps in sequence, then if initialization succeeds, the screen will be randomly filled with multicolored dots, as in the photo below.
Now we know how to initialize a TFT display with an SSD1289 controller; in the next article we'll look at how to display individual characters and write strings. Also, at the end of the next article you can download an example for Atmel Studio 6.2.
P.S. The place where I bought the display no longer sells it; in the comments Andrey left a link to a display that worked for him, so you don't have to search, I'll leave it here.
Display_ebay
P.P.S. For those who want to quickly check whether their display works, here's the firmware for the Atmega16 ssd1289_i8080.hex

