NHD-2.8-240320AF-CSXP-FT Black Screen
I am new to using a graphic display and am unable to produce anything other then a black screen. I based the following off the example code. I am simply trying make the screen a solid color. The display is setup to use 8 bit parallels and 262k color. Any help would be appreciated.
void main(void) {
OSCCON1 = 0b1100000;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
TFT_Display();
while(1){
}
}
void TFT_7789_Init(void){ //end of PORTD changes is 0b00011000 or 0x18
//need to set up port D pins
PORTDbits.RD0 = 0;//Set cs to 0 pin 10 chip select true
PORTDbits.RD3 = 1; //Set rd to 1 pin 13 no read
PORTDbits.RD2 = 0; //Set WR to 0 pin 12 write enabled
PORTDbits.RD4 = 0; //Set RES to 0 pin 11 resets LCD
__delay_us(100); // allows for LCD to Reset
PORTDbits.RD4 = 1; //Set RES to 1 pin 11 sets reset back to high
__delay_us(100); // allows for LCD to exit Reset
TFT_Write_Command(0x0011); //exit sleep mode
__delay_us(100);
TFT_Write_Command(0x0036);
TFT_Write_Data(0x0080); //MADCTL: memory data access control
TFT_Write_Command(0x003A);
TFT_Write_Data(0x0066); //COLMOD: Interface Pixel format 262K-colors 18bit/pixel 3 bytes per pixel
TFT_Write_Command(0x0021); //INVON: Display inversion ON
TFT_Write_Command(0x00B2);
TFT_Write_Data(0x000C);
TFT_Write_Data(0x0C);
TFT_Write_Data(0x00);
TFT_Write_Data(0x33);
TFT_Write_Data(0x33); //PORCTRK: Porch setting
TFT_Write_Command(0x00B7);
TFT_Write_Data(0x0035); //GCTRL: Gate Control
TFT_Write_Command(0x00BB);
TFT_Write_Data(0x002B); //VCOMS: VCOM setting
TFT_Write_Command(0x00C0);
TFT_Write_Data(0x002C); //LCMCTRL: LCM Control
TFT_Write_Command(0x00C2);
TFT_Write_Data(0x0001);
TFT_Write_Data(0xFF); //VDVVRHEN: VDV and VRH Command Enable
TFT_Write_Command(0x00C3);
TFT_Write_Data(0x0011); //VRHS: VRH Set
TFT_Write_Command(0x00C4);
TFT_Write_Data(0x0020); //VDVS: VDV Set
TFT_Write_Command(0x00C6);
TFT_Write_Data(0x000F); //FRCTRL2: Frame Rate control in normal mode
TFT_Write_Command(0x00D0);
TFT_Write_Data(0x00A4);
TFT_Write_Data(0xA1); //PWCTRL1: Power Control 1
TFT_Write_Command(0x00E0);
TFT_Write_Data(0x00D0);
TFT_Write_Data(0x0000);
TFT_Write_Data(0x0005);
TFT_Write_Data(0x000E);
TFT_Write_Data(0x0015);
TFT_Write_Data(0x000D);
TFT_Write_Data(0x0037);
TFT_Write_Data(0x0043);
TFT_Write_Data(0x0047);
TFT_Write_Data(0x0009);
TFT_Write_Data(0x0015);
TFT_Write_Data(0x0012);
TFT_Write_Data(0x0016);
TFT_Write_Data(0x0019); //PVGAMCTRL: Positive Voltage Gamma control
TFT_Write_Command(0x00E1);
TFT_Write_Data(0x00D0);
TFT_Write_Data(0x0000);
TFT_Write_Data(0x0005);
TFT_Write_Data(0x000D);
TFT_Write_Data(0x000C);
TFT_Write_Data(0x0006);
TFT_Write_Data(0x002D);
TFT_Write_Data(0x0044);
TFT_Write_Data(0x0040);
TFT_Write_Data(0x000E);
TFT_Write_Data(0x001C);
TFT_Write_Data(0x0018);
TFT_Write_Data(0x0016);
TFT_Write_Data(0x0019); //NVGAMCTRL: Negative Voltage Gamma control
TFT_Write_Command(0x002A);
TFT_Write_Data(0x0000);
TFT_Write_Data(0x0000);
TFT_Write_Data(0x0000);
TFT_Write_Data(0x00EF); //X address set
TFT_Write_Command(0x002B);
TFT_Write_Data(0x0000);
TFT_Write_Data(0x0000);
TFT_Write_Data(0x0001);
TFT_Write_Data(0x003F); //Y address set
__delay_us(10);
}
void TFT_Write_Command(unsigned int command){ //want port D to be 0b00011000 or 0x18
PORTDbits.RD0 = 0; //Set CS to 0 pin 10 chip select true
PORTDbits.RD1 = 0; //Set D/C to 0 pin 11 '0' = command
PORTDbits.RD3 = 1; //Set rd to 1 pin 13 no read
PORTDbits.RD2 = 0; //Set WR to 0 pin 12 write enabled
LATA = command; // writes command input to PORTA
__delay_us(10);
PORTDbits.RD2 = 1; //Set WR to 1 pin 12 write disabled
__delay_us(1); //PORTD ends at 0x1C
}
void TFT_Write_Data(unsigned int TFTdata){
LATA = TFTdata; // writes data to PORTA
PORTDbits.RD1 = 1; // Set D/C to 1 pin 11 '1' = data
PORTDbits.RD2 = 0; //Set WR to 0 pin 12 write enabled
// during write PORTD = 0x1A
__delay_us(1);
PORTDbits.RD2 = 1; //Set WR to 1 pin 12 write disabled
//PORTD ends in 0x1E
}
void TFT_Display(void){
TFT_7789_Init();
TFT_Write_Command(0x002C); //memory write
unsigned long n;
unsigned int red = 248;
unsigned int green = 248;
unsigned int blue = 248;
for (n=0; n<76800; n++){
PORTDbits.RD1 = 1; //sets to send data
LATA = red;
PORTDbits.RD2 = 0; //Set WR to 0 pin 12 write enabled
PORTDbits.RD2 = 1; //Set WR to 0 pin 12 write disabled
LATA = green;
PORTDbits.RD2 = 0; //Set WR to 0 pin 12 write enabled
PORTDbits.RD2 = 1; //Set WR to 0 pin 12 write disabled
LATA = blue;
PORTDbits.RD2 = 0; //Set WR to 0 pin 12 write enabled
PORTDbits.RD2 = 1; //Set WR to 0 pin 12 write disabled
}
TFT_Write_Command(0x0029); //display on
//__delay_us(1000);
endcheck = 1;
}
-
Hi crharris,
Please review and reference our Arduino example code written for our NHD-2.8-240320AF-CSXP-F display written in 8-bit parallel mode that may be helpful to examine:
https://www.newhavendisplay.com/resources_dataFiles/excode/txt/Arduino/NHD-2.8-240320AF-CSXP-F.txt
Please also ensure there is no accidental cross-wiring between microcontroller pins and the display. Our wiring diagram can be referenced on pg. 5 of our display datasheet below:
https://www.newhavendisplay.com/specs/NHD-2.8-240320AF-CSXP-FT.pdf
Best,0
Please sign in to leave a comment.
Comments
1 comment