Пример #1
0
void SendLcd(unsigned char type, unsigned char dat) 
{
	byte i;

    LCD_DATA(type);                     // set up first bit as command or data 
    LCD_CS(0);							// Enable device CS

    LCD_CLK(0);							// Pull Clock LOW
    LCD_CLK(1);							// Pul Clock HIGH
    
    if(dat == 0x0){        // spi cannot transfer zero??
      LCD_DATA(0);
      for(i=0; i<8; i++){
      
        LCD_CLK(0);							// Pull Clock LOW
        LCD_CLK(1);	
      }
    }
    else{
    SPCR |=0x50;						// Enable Hardware SPI
    SPSR |= 0x1;
    SPDR = dat; 						// send data
    
    while(!(SPSR & 0x80));				// wait until send complete

    }

    SPCR &=~0x50;						// Disable Hardware SPI, this releases the SPI pins
										// for general IO use. which is used to send the 1'st 
      LCD_CS(1);							// disable device CS									// bit out
}
/*******************************************************************************
* Transfer 1 byte over the serial communication                                *
*   Parameter:    byte:   byte to be sent                                      *
*                 mode:   OUT = transmit byte, IN = receive byte               *
*   Return:               byte read while sending                              *
*******************************************************************************/
static unsigned char spi_tran_man (unsigned char byte, unsigned int mode) {
  unsigned char val = 0;
  int i;

  if (mode == OUT) { DAT_MODE (OUT); }
  else             { DAT_MODE (IN);  }

  for (i = 7; i >= 0; i--) {
    LCD_CLK(0);
    delay(1);
    if (mode == OUT) {
      LCD_DAT((byte & (1 << i)) != 0);
    }
    else {
      val |= (BUS_VAL() << i);
    }
    LCD_CLK(1);
    delay(1);
  }
  return (val);
}
Пример #3
0
void LCD_Init(void)
{
	

    LCD_CS(1);
    LCD_CLK(0);
    LCD_DATA(0);

    LCD_RESET(1);
    delay(50);
    LCD_RESET(0);
    delay(50);
    LCD_RESET(1);
    delay(50);

    LCD_CS(1);
    LCD_CLK(1);
    LCD_DATA(1);
    delay(10);

    SendLcd(LCDCommand,SWRESET);
    delay(10);

    SendLcd(LCDCommand,SLEEPOUT);  // Sleepout
//       SendLcd(LCDCommand,INVON);  // Invert display mode
//    SendLcd(LCDCommand,BSTRON);  // BoostON
	SendLcd(LCDCommand,MADCTL);  // memory access control
    SendLcd(LCDData,0xe0);
	SendLcd(LCDCommand,SETCON);  // Set Contrast
    SendLcd(LCDData,0x40);
	delay(10);
    SendLcd(LCDCommand,DISPON);  // Display On
	
	SendLcd(LCDCommand,COLMOD);  // Set Color Mode
  
  	SendLcd(LCDData,0x03);			// 12bit per pixel
	SendLcd(LCDCommand,NOP);  // Set Color Mode

}
Пример #4
0
void SendLcd_color(unsigned char color){
  
    LCD_DATA(LCDData);                     // set up first bit as command or data 

    LCD_CLK(0);							// Pull Clock LOW
    LCD_CLK(1);							// Pul Clock HIGH
    
    
   
     LCD_CLK(0);  
    SPCR |=0x50;						// Enable Hardware SPI
    SPSR |=0x1;

    SPDR = color; 						// send data
    
    while(!(SPSR & 0x80));				// wait until send complete

						// disable device CS

    SPCR &=~0x50;						// Disable Hardware SPI, this releases the SPI pins
   
	LCD_CLK(0);										// for general IO use. which is used to send the 1'st 
									// bit out
}