Arduino MEGA 2560 + NHD240128
I try to make a sketch for ARDUINO MEGA 2560 to use NHD240128
i 'm looking for a sample.
i tried but do not succeed for now.
capture of signals :
https://plus.google.com/107056513026123850606/posts/9sSY4oHiqSJ
https://plus.google.com/107056513026123850606/posts/BF3uar5bAt3
Here is my code :
int i = 0;
int ResetLCD = 31; // PORTC. PC6
int FS1Pin = 32; // PORTC. PC5 Font select signal. H: 6x8, L: 8x8
int MD2Pin = 33; // PORTC. PC4 PORTC. PC Display size signal. H: 32 columns; L: 40 columns
int CEPin = 34; // PORTC. PC3 Active LOW Chip Select signal
int WRPin = 35; // PORTC. PC2 Active LOW Write signal
int RDPin = 36; // PORTC. PC1 Active LOW Read signal
int CDPin = 37; // PORTC. PC0 Register select signal. C/D=1: Command C/D=0: Data
int ValeurPORTA = 0;
int DATA = 0 ;
int LCD_STATUS = 0;
boolean Statusok = false;
int time1 = 0;
int time2 = 0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
//PARAMETRAGE DES BORNES DU PORTC EN SORTIES (RESET/,FS1, MD2,CE/, WR/,RD/
DDRC = 0b11111111;
pinMode(ResetLCD, OUTPUT);
pinMode(FS1Pin, OUTPUT);
pinMode(MD2Pin, OUTPUT);
pinMode(CEPin, OUTPUT);
pinMode(WRPin, OUTPUT);
pinMode(RDPin, OUTPUT);
pinMode(CDPin, OUTPUT);
// initialisation du PORTA en entrées
DDRA = 0b00000000;
// set /CD
digitalWrite(CDPin,HIGH);
//reset FS H: 6x8, L: 8x8
digitalWrite(FS1Pin,LOW);
//reset MD2 H: 32 columns; L: 40 columns
digitalWrite(MD2Pin,LOW);
// set /CS
digitalWrite(CEPin,HIGH);
// set /RD
digitalWrite(RDPin,HIGH);
// set /WR
digitalWrite(WRPin,HIGH);
// set /RESET
digitalWrite(ResetLCD,HIGH);
delay(500);
// reset /RESET
digitalWrite(ResetLCD,LOW);
delay(500);
// set /RESET
digitalWrite(ResetLCD,HIGH);
//delay(1500);
time1 = millis();
while (time2 - time1 < 1500 ) {
time2 = millis();}
//StatusLCDCheck();
//delay(500);
InitLCD();
//InitLCD2();
}
void Writecom(){
DDRA = 0b11111111; //pins 0 to 7 as outputs
PORTA = DATA; //move data to portA
PORTC = PORTC | 0b00000001; // set C/D
delay(1); // pauses
PORTC = PORTC & 0b11111011; // reset /WR
PORTC = PORTC | 0b00000010; // set /RD
delay(1); // pauses
//PORTC = PORTC & 0b11110111; // reset /CS
PORTC = PORTC & 0xF7; // reset /CS
delay(3); // pauses
PORTC = PORTC | 0b00001100; // set /CS et /WR
PORTA = PORTA & 0x00; //on passe les sorties de PORTA à 0
DATA = 0x00;
Serial.print("WriteCom : ");
Serial.println(DATA,HEX);
Serial.println();
}
void Writedata(){
DDRA = 0b11111111; //pins 0 to 7 as outputs
PORTA = DATA; //move data to portA
PORTC = PORTC & 0b11111110; // reset I/D for instruction (C/D)
PORTC = PORTC & 0b11111010; // Reset toggle /CS and /WR
delay(1); // pauses
PORTC = PORTC & 0b11110111; // reset /CS
delay(1); // pauses
PORTC = PORTC | 0b00001100; // set /CS et /WR
PORTA = PORTA & 0x00; //on passe les sorties de PORTA à 0
DATA = 0x00;
Serial.print("Writedata : ");
Serial.println(DATA,HEX);
Serial.println();
}
void StatusLCDCheck() {
// Status Check
// The Status of RA6963 can be read from the data lines.
// RD WR CS C/D SD[7:0]
// L H L H Status Word
LCD_STATUS = 0;
DDRA = 0x00; //pins 0 to 7 as inputs
//DESACTIVATION DES PULL UP
//PORTA = 0x00;
//ACTIVATION DES PULL UP
PORTA = 0xFF;
// set I/D for instruction
PORTC = PORTC | 0b00000001;
delay(3); // pauses
PORTC = PORTC & 0b11110101; //RESET /CS et /RD
PORTC = PORTC | 0b00000100; //SET /WR
//delay(115); // pauses
delay(1500); // pauses
LCD_STATUS = PINA; //LECTURE DES ENTREES DU PORTA
delay(1); // pauses
PORTC = PORTC | 0b00001010; // set /CS et /RD
delay(1); // pauses
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
}
boolean TestStatus() {
if (LCD_STATUS && B00000011) {
//if (0x01 && B00000011) {
return true;
}
else
{return false;}
}
void InitLCD(){
DATA = 0X00;
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata(); //text address = 0000h
DATA = 0X40;
Serial.println("Writecom : 0X40");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //text home address set
DATA = 0X00;
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
DATA = 0X40; //graphic home address = 4000h
Serial.println("Writedata : 0X40");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
DATA = 0X42;
Serial.println("Writecom : 0X42");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //graphic home address set
DATA = 0X1E;
Serial.println("Writedata : 0X1E");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
DATA = 0X00; //text area address = 001Eh
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
DATA = 0X41;
Serial.println("Writecom : 0X41");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //text area control set
DATA = 0X1E;
Serial.println("Writedata : 0X1E");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
DATA = 0X00; //graphic area = 001Eh
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
DATA = 0X43;
Serial.println("Writecom : 0X43");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //graphic area control set
DATA = 0X80;
Serial.println("Writecom : 0X80");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //set display mode
}
void InitLCD2() {
//write text home address =0,0
//writeData(0x00);
//writeData(0x00);
//writeCommand(0x40);
DATA = 0X00;
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata(); //text address = 0000h
DATA = 0X40;
Serial.println("Writecom : 0X40");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //text home address set
//writeData(0x80);
//writeData(0x00);
//writeCommand(0x42);
//write text area address
DATA = 0X80;
Serial.println("Writedata : 0X80");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata(); //text address = 0000h
DATA = 0X42;
Serial.println("Writecom : 0X42");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //text home address set
//writeData(0x10);
//writeData(0x00);
//writeCommand(0x41);
//write graphic area address
DATA = 0X10;
Serial.println("Writedata : 0X10");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
DATA = 0X41;
Serial.println("Writecom : 0X41");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //text home address set
//writeData(0x10);
//writeData(0x00);
//writeCommand(0x43);
//display text and graphics modes
DATA = 0X10;
Serial.println("Writedata : 0X10");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
Serial.println("Writedata : 0X00");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata();
DATA = 0X43;
Serial.println("Writecom : 0X43");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom();
//writeCommand(0x9c);
//enable display
//writeCommand(0x98);
DATA = 0X9C;
Serial.println("Writecom : 0X9C");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom();
DATA = 0X98;
Serial.println("Writecom : 0X98");
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom();
}
void loop()
{
//StatusLCDCheck();
// Screen Reverse 11010000
DATA = 0XD0;
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom();
delay(3000); // pauses for 50 milliseconds
//Display Mode Cursor on, blink on 1001XX11
DATA = 0X93;
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom();
delay(3000); // pauses for 1 milliseconds
DATA = 0X21;
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writedata(); // Lettre A
delay(3000); // pauses for 1 milliseconds
DATA = 0XC0;
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //Data Write and Increment ADP
delay(3000); // pauses for 1 milliseconds
// 0x90 10010000 Display off
DATA = 0X90;
while (Statusok == false) {
StatusLCDCheck(); // met à jour le STATUS
Statusok = TestStatus(); // TEST DE STA0 et STA1
}
Statusok = false;
Serial.print("Status Check : ");
Serial.println(LCD_STATUS,BIN);
Serial.println();
Writecom(); //Data Write and Increment ADP
delay(3000); // pauses for 3 S
}
-
Hello,
You have quite a bit of code there. Did you test it a little bit at a time or just type it all in at once? How much $$$ do you have invested in your project, I wonde if I could raise that much. I have an application kind of like but not a road map. Maybe we could hehp each other at some time in the not too distant future. I have several years of successful software, but it's not current What language are you programming in?
papalyle0 -
i type it in one time, but i worked on several versions, it seems that delay() function is not respected for 1ms and around this value. I'm looking for safe instructions for small delay to respect timing diagram. I do not know if my LCD is not dead , i bought it 2 years ago just now that i try it, it sweeps matrix, contrast is enable. I used sample of New Heaven in datasheet. I hope that we can help each other. I do not find functionnal codes on the web for Arduino Uno or other.
i found this link http://en.radzio.dxp.pl/t6963/ but don't have enough expériences to compile with avr-gcc and transfert code without Arduino IDE (i worked on several langages)
0 -
Are you seeing anything on the display? Do you have any others to test? Also, can you please provide the full part number of the display?0
-
Here is a link to serial of the LCD & Strange Things displayed
https://plus.google.com/photos/107056513026123850606/albums/6008524498068070529
I found a way to use Atmel Studio 6.2 without transfer interface with my Arduino MEGA2560,
then I tested the code of another person lol
https://plus.google.com/107056513026123850606/posts/ZKgBnyQsq9t
Thank you Radosław Kwiecień
(http://en.radzio.dxp.pl/t6963/)
A demo that i've made http://youtu.be/c0WBgH5u-VI0 -
Here is my functional code reviewed and corrected for the Arduino IDE interface
// T.VIEIL - Tuesday 6th May 2014
// Sample code to use NHD240128 with an Arduino MEGA 2560
// PORTA is used for LCD lines DB0 to DB7
// PA0(22) to PA7(29) on Arduino MEGA 2560
// control signals
#define GLCD_WR PC0 // PORTC. PC0 (37) Active LOW Write signal
#define GLCD_RD PC1 // PORTC. PC1 (36) Active LOW Read signal
#define GLCD_CE PC2 // PORTC. PC2 (35) Active LOW Chip Select signal
#define GLCD_CD PC3 // PORTC. PC3 (34) Register select signal. C/D=1: Command C/D=0: Data
#define GLCD_RESET PC4 // PORTC. PC4 (33) Active LOW Reset signal
#define GLCD_FS PC5 // PORTC. PC5 (32) Font select signal. H: 6x8, L: 8x8
// MD2 pin of LCD go to Vss (GND)
void setup() {
DDRA = 0xFF;
DDRC = ((1 << GLCD_WR) | (1 << GLCD_RD) | (1 << GLCD_CE) | (1 << GLCD_CD) | (1 << GLCD_RESET) | (1 << GLCD_FS));
PORTC |= ((1 << GLCD_WR) | (1 << GLCD_RD) | (1 << GLCD_CE) | (1 << GLCD_CD) | (1 << GLCD_RESET) | (1 << GLCD_FS));
// reset /RESET
PORTC &= ~(1 << GLCD_RESET);
delayMicroseconds(1000);
// set /RESET
PORTC |= (1 << GLCD_RESET);
PORTC &= ~(1 << GLCD_FS);
delayMicroseconds(1000);
InitLCD();
}
void Writecom(int Command){
while (!StatusLCDCheck()) {}
PORTA = Command; //move data to portA
PORTC &= ~((1 << GLCD_WR) | (1 << GLCD_CE));
delayMicroseconds(1);
PORTC |= ((1 << GLCD_WR) | (1 << GLCD_CE));
}
void Writedata(int data){
while (!StatusLCDCheck()) {}
DDRA |= 0b11111111; //pins 0 to 7 as outputs
PORTA = data; //move data to portA
PORTC &= ~((1 << GLCD_WR) | (1 << GLCD_CE) | (1 << GLCD_CD));
delayMicroseconds(1);
//delay1();
PORTC |= ((1 << GLCD_WR) | (1 << GLCD_CE) | (1 << GLCD_CD));
}
boolean StatusLCDCheck() {
// Status Check
// The Status of RA6963 can be read from the data lines.
// RD WR CS C/D SD[7:0]
// L H L H Status Word
int LCD_STATUS;
DDRA = 0x00; //pins 0 to 7 as inputs
PORTC &= 0b11111001; //RESET /CS et /RD
delayMicroseconds(1);
//delay1();
LCD_STATUS = PINA; //READ PORTA
PORTC |= 0b00000110; // set /CS et /RD
DDRA = 0xFF; //pins 0 to 7 as outputs
if (LCD_STATUS && B00000011) {
return true;
}
else
{return false;}
}
void InitLCD(){
Writedata(0xE0);
Writedata(0x01); //graphic home address =01E0h
Writecom(0x42); //graphic home address set
Writedata(0x1E);
Writedata(0x00); //graphic area = 001Eh
Writecom(0x43); //graphic area control set
Writedata(0x00);
Writedata(0x00); //text address = 0000h
Writecom(0x40); //text home address set
Writedata(0x1E);
Writedata(0x00); //text area address = 001Eh
Writecom(0x41); //text area control set
Writedata(0x02);
Writedata(0x00);
Writecom(0x22); //set offset register
Writecom(0x9C); //set display mode = text ON + graphic ON
Writecom(0x80); //set display mode = Internal CGROM + OR
//-------------------------------------------------------------------------------------------------
//
// Clears text area of display RAM memory
//
//-------------------------------------------------------------------------------------------------
int i;
Writedata(0x0000 & 0xFF); //TEXT HOME
Writedata(0x0000 >> 8);
Writecom(0x24); //SET ADDRESS POINTER
for(i = 0; i < 900; i++) //TEXT SIZE
{
Writedata(0x00);
Writecom(0xC0); //DATA WRITE_AND_INCREMENT
}
//-------------------------------------------------------------------------------------------------
//
// Clears graphics area of display RAM memory
//
//-------------------------------------------------------------------------------------------------
Writedata(0x01E0 & 0xFF); //GRAPHIC HOME
Writedata(0x01E0 >> 8);
Writecom(0x24); //SET ADDRESS POINTER
for(i = 0; i < 3840; i++) //GRAPHIC SIZE
{
Writedata(0x00);
Writecom(0xC0); //DATA WRITE_AND_INCREMENT
}
}
void loop()
{
int i;
Writedata(0x0000 & 0xFF); //TEXT HOME
Writedata(0x0000 >> 8);
Writecom(0x24); //SET ADDRESS POINTER
boolean Halt = false;
while(Halt == false) {
//***********************************************
//*** it will display the characters of CGROM ***
//***********************************************
//e.g 0x21 Letter A
for (i = 0; i<128;i++) {
Writedata(i); // Write a character
Writecom(0xC0); //Data Write and Increment ADP
}
Halt = true;
}
}0 -
Thank you for sharing!
0
Please sign in to leave a comment.
Comments
6 comments