Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - tvieil

Pages: [1]
1
Graphic LCDs / Arduino MEGA 2560 + NHD240128
« on: April 26, 2014, 11:32:15 AM »
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 entres
 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


}

Pages: [1]