How to set Pin11 and Pin13 with HIGH and LOW output?

hello, experts:
I am trying to write driver for one SPI LCD(for UNO), but i don't know how to set Pin11 and Pin13 with HIGH and LOW output.

just like this:
#define PIN5_LOW {DDRD |= 0x20;PORTD &=~ 0x20;}
#define PIN5_HIGH {DDRD |= 0x20;PORTD |= 0x20;}

THANKS!!! ]:smiley:

Why don't you use the SPI library?

pylon:
Why don't you use the SPI library?

because the SPI LCD have not D/C pin :sweat_smile:

D/C pin? What is that?

CrossRoads:
D/C pin? What is that?

one pin of normal SPI LCD :smiley:

If its SPI then by definition it would have Clock, Data In, and Chip Select (slave select).
What are you saying yours does not have?
Do you have a link to yours?

CrossRoads:
If its SPI then by definition it would have Clock, Data In, and Chip Select (slave select).
What are you saying yours does not have?
Do you have a link to yours?

there is not link for this 'special' SPI LCD.
but i can list all the pins of this LCD: VDD, CS, MOSI(SDI), SDO, SCK, RST, BL, GND

Its not "special" in any way. Just normal SPI. CS, MOSI(SDI), SDO, SCK, those are the standard SPI pins.

Mark

holmes4:
Its not "special" in any way. Just normal SPI. CS, MOSI(SDI), SDO, SCK, those are the standard SPI pins.

Mark

ok, actually, comparing with this SPI LCD(LCD display with ILI9341 driver on Arduino - Displays - Arduino Forum), there is not D/C pin at my SPI LCD .
if i want write cmd, i can do it like this:
void TFT::sendCMD(INT8U cmd)
{
digitalWrite(pin_cs, LOW);
digitalWrite(pin_sck, LOW);
digitalWrite(pin_sdi, LOW);
digitalWrite(pin_sck, HIGH);
SPI.transfer(cmd);
digitalWrite(pin_cs, HIGH);
}

I don't know whether i can write this function in TFT.cpp, because digitalWrite() is used in *.ino file.
so, i need one way(like this: ) to set CS, SCK, SDI Pin's HIGH and LOW ouput :sweat_smile:

{
    digitalWrite(pin_cs, LOW);
    digitalWrite(pin_sck, LOW); << not needed - is controlled by SPI mode
    digitalWrite(pin_sdi, LOW);  << not needed - pin is ignore when CS is High
    digitalWrite(pin_sck, HIGH); << not needed
    SPI.transfer(cmd);                << SCK & SDI are toggled here
    digitalWrite(pin_cs, HIGH);    
}

Why do you think the extra control changes are needed?

CrossRoads:

{

digitalWrite(pin_cs, LOW);
   digitalWrite(pin_sck, LOW); << not needed - is controlled by SPI mode
   digitalWrite(pin_sdi, LOW);  << not needed - pin is ignore when CS is High
   digitalWrite(pin_sck, HIGH); << not needed
   SPI.transfer(cmd);                << SCK & SDI are toggled here
   digitalWrite(pin_cs, HIGH);    
}



Why do you think the extra control changes are needed?

thanks for your comments.
because i have tested this LCD with normal I/O pin by output HIGH/LOW and it works, but the display speed is toooo slowly, so, i try the SPI way and i want to port this code ]:smiley:

int pin_bl = 3;
int pin_cs = 4;
int pin_sdi = 5;
int pin_sck = 6;
int pin_rst = 7;


//write one byte by SPI
void TFT_SPI_Write_Byte(byte num)    
{  
    int count=0;  
    
    for( count=0; count<8; count++ )  
    { 
        digitalWrite(pin_sck, LOW);
        if(num&0x80)
        {
            digitalWrite(pin_sdi, HIGH); 
        }
        else
        {
            digitalWrite(pin_sdi, LOW);   
        }
        num<<=1;    
        digitalWrite(pin_sck, HIGH);        
    }               
}

// write command one byte
void LCD_WR_REG(byte cmd)     
{ 
    digitalWrite(pin_cs, LOW);
    digitalWrite(pin_sck, LOW);
    digitalWrite(pin_sdi, LOW);
    digitalWrite(pin_sck, HIGH);
    TFT_SPI_Write_Byte(cmd);
    digitalWrite(pin_cs, HIGH);       
}

.....
.....

void setup()
{
    // arduino pin setting, IO for SPI
    pinMode(pin_bl, OUTPUT);
    pinMode(pin_cs, OUTPUT);
    pinMode(pin_sdi, OUTPUT);
    pinMode(pin_sck, OUTPUT);
    pinMode(pin_rst, OUTPUT);

    // clear and reset LCD buffer
    digitalWrite(pin_bl, LOW);  
    digitalWrite(pin_rst, LOW);  
    delay(10);
    digitalWrite(pin_rst, HIGH);  

    // init lcd
    lcd_init();
    LCD_Clear(0x0000);

    //line
    LCD_DrawLine(0, 0, 240, 320);
}

D/C means that the pin is not connected!. Look in the datasheet you will be given the meanings and use of each PIN.

Mark