TFT sample code for Newhaven display NHD-1.8-128160TF.
#include <htc.h> #include <stdio.h> #include "pic18f4550.h" #define bRS RB0 #define bWR RB1 #define bRD RB2 #define bRST RB3 //CS Tied Low - Always active /***************************************************************/ void delay(unsigned int d) { int i, j; for(i=0; i<d; i++) {_delay(50);} } /***************************************************************/ void fast_data_out(unsigned char i) //sets port and toggles RW bit for quick output { PORTD = i; bWR = 1; bWR = 0; } /***************************************************************/ /***************************************************************/ void data_out(unsigned char i) //Data Output 8-bit, 8080 Interface { delay(1); bRS = 1; //RS = 1: Data select delay(1); PORTD = i; delay(1); bWR = 1; delay(1); bWR = 0; delay(1); } /***************************************************************/ /***************************************************************/ void comm_out(unsigned char i) //Command Output 8-bit,8080 Interface { delay(1); bRS = 0; //Command select delay(1); PORTD = i; delay(1); bWR = 1; delay(1); bWR = 0; delay(1); } /***************************************************************/ /***************************************************************/ void HX8353D_init() { char a = 0x00; bRD = 1; bRST = 1; delay(10); bRST = 0; delay(10); bRST = 1; delay(10); comm_out(0x29); //Display ON comm_out(0x36); //Memory access control data_out(0x08); //Set pixel write order: Red, Green, Blue comm_out(0xB9); //Enter Extension Command data_out(0xFF); //Followed by 3 extension parameters data_out(0x83); data_out(0x53); comm_out(0x11); //Sleep out comm_out(0xC6); //Set UADJ to trimming fequency data_out(0x31); comm_out(0xB5); //Set Power Control data_out(0x0B); data_out(0x0B); data_out(0x07); comm_out(0xB1); //Set Power Control data_out(0x00); data_out(0x00); comm_out(0xB2); //Set Display Control data_out(0x00); comm_out(0xB6); //Set power control data_out(0x84); data_out(0x6C); data_out(0x74); comm_out(0xE0); //Set Gamma data_out(0x70); data_out(0x77); data_out(0x20); data_out(0x0F); data_out(0x8F); data_out(0x00); data_out(0x04); data_out(0x0D); data_out(0x02); data_out(0x01); data_out(0x75); data_out(0x00); data_out(0x70); data_out(0x04); data_out(0x80); data_out(0x0F); data_out(0x0F); data_out(0x02); data_out(0x0D); comm_out(0x3A); //Interface pixel format data_out(0x06); //8-bit 8080 mode, 3bytes per pixel comm_out(0x29); //Display ON } /***************************************************************/ /***************************************************************/ void Display_Picture() { int i; comm_out(0x2C); for(i=0;i<(128*40);i++) //Write 40 Lines { bRS=1; fast_data_out(0xFF); //Red fast_data_out(0x00); //Green fast_data_out(0x00); //Blue } for(i=0;i<(128*40);i++) //Write 40 Lines { bRS=1; fast_data_out(0x00); //Red fast_data_out(0xFF); //Green fast_data_out(0x00); //Blue } for(i=0;i<(128*40);i++) //Write 40 Lines { bRS=1; fast_data_out(0x00); //Red fast_data_out(0x00); //Green fast_data_out(0xFF); //Blue } for(i=0;i<(128*40);i++) //Write 40 Lines { bRS=1; fast_data_out(0xFF); //Red fast_data_out(0xFF); //Green fast_data_out(0xFF); //Blue } } /***************************************************************/ /***************************************************************/ void main() { char i; TRISB = 0x00; //data bits TRISD = 0x00; //control bits PORTB = 0x00; delay(10); PORTB = 0xFF; delay(10); PORTD = 0x00; delay(10); PORTD = 0xFF; delay(10); while(1) { HX8353D_init(); //Initialize controller Display_Picture(); //Begin writing delay(1000); } }