#include <Headers\AT91SAM7X256.H>
#include <Headers\delay.h>
/**********************************************
Define zone
**********************************************/
#define S6DLCD_DATAPORT_B
#define S6DLCD_DATAPORT_OFFSET 2
#define S6DLCD_CONTROLPORT_B
#define S6DLCD_RST 18
#define S6DLCD_RS 19
#define S6DLCD_CS 20
#define S6DLCD_WR 21
#define S6DLCD_RD 22
#define _S6DLCD_DATAPORT_ID_ AT91C_ID_PIOB
#define _S6DLCD_DATAPORT_PER_ *AT91C_PIOB_PER
#define _S6DLCD_DATAPORT_PDR_ *AT91C_PIOB_PDR
#define _S6DLCD_DATAPORT_OER_ *AT91C_PIOB_OER
#define _S6DLCD_DATAPORT_ODR_ *AT91C_PIOB_ODR
#define _S6DLCD_DATAPORT_PUER_ *AT91C_PIOB_PPUER
#define _S6DLCD_DATAPORT_PUDR_ *AT91C_PIOB_PPUDR
#define _S6DLCD_DATAPORT_PDSR_ *AT91C_PIOB_PDSR
#define _S6DLCD_DATAPORT_SODR_ *AT91C_PIOB_SODR
#define _S6DLCD_DATAPORT_CODR_ *AT91C_PIOB_CODR
#define _S6DLCD_DATAPORT_PCER_ *AT91C_PMC_PCER
#define _S6DLCD_DATAPORT_PCDR_ *AT91C_PMC_PCDR
#define _S6DLCD_CONTROLPORT_ID_ AT91C_ID_PIOB
#define _S6DLCD_CONTROLPORT_PER_ *AT91C_PIOB_PER
#define _S6DLCD_CONTROLPORT_PDR_ *AT91C_PIOB_PDR
#define _S6DLCD_CONTROLPORT_OER_ *AT91C_PIOB_OER
#define _S6DLCD_CONTROLPORT_ODR_ *AT91C_PIOB_ODR
#define _S6DLCD_CONTROLPORT_PUER_ *AT91C_PIOB_PPUER
#define _S6DLCD_CONTROLPORT_PUDR_ *AT91C_PIOB_PPUDR
#define _S6DLCD_CONTROLPORT_SODR_ *AT91C_PIOB_SODR
#define _S6DLCD_CONTROLPORT_CODR_ *AT91C_PIOB_CODR
#define S6DLCD_RST_LOW _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_RST)
#define S6DLCD_RST_HIGH _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_RST)
#define S6DLCD_RS_LOW _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_RS)
#define S6DLCD_RS_HIGH _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_RS)
#define S6DLCD_CS_LOW _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_CS)
#define S6DLCD_CS_HIGH _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_CS)
#define S6DLCD_RD_LOW _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_RD)
#define S6DLCD_RD_HIGH _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_RD)
#define S6DLCD_WR_LOW _S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_WR)
#define S6DLCD_WR_HIGH _S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_WR)
#define S6DLCD_DATAPORT_INPUT _S6DLCD_DATAPORT_ODR_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET),_S6DLCD_DATAPORT_PER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET)
#define S6DLCD_DATAPORT_INPUT_CLK_E _S6DLCD_DATAPORT_PCER_ = (1 << _S6DLCD_DATAPORT_ID_)
#define S6DLCD_DATAPORT_INPUT_CLK_D _S6DLCD_DATAPORT_PCDR_ = (1 << _S6DLCD_DATAPORT_ID_)
#define S6DLCD_DATAPORT_OUTPUT _S6DLCD_DATAPORT_OER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET)
#define S6DLCD_DATAPORT_CLEAR _S6DLCD_DATAPORT_CODR_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET)
#define HIGH 1
#define LOW 0
#define X_CONST 240
#define Y_CONST 320
#define PREC_TOUCH_CONST 10
#define PixSizeX 13.78
#define PixOffsX 411
#define PixSizeY 11.01
#define PixOffsY 378
#define WINDOW_XADDR_START 0x0050 // Horizontal Start Address Set
#define WINDOW_XADDR_END 0x0051 // Horizontal End Address Set
#define WINDOW_YADDR_START 0x0052 // Vertical Start Address Set
#define WINDOW_YADDR_END 0x0053 // Vertical End Address Set
#define GRAM_XADDR 0x0020 // GRAM Horizontal Address Set
#define GRAM_YADDR 0x0021 // GRAM Vertical Address Set
#define GRAMWR 0x0022 // memory write
/* LCD color */
#define S6DLCD_White 0xFFFF
#define S6DLCD_Black 0x0000
#define S6DLCD_Blue 0x001F
#define S6DLCD_Blue2 0x051F
#define S6DLCD_Red 0xF800
#define S6DLCD_Magenta 0xF81F
#define S6DLCD_Green 0x07E0
#define S6DLCD_Cyan 0x7FFF
#define S6DLCD_Yellow 0xFFE0
/**********************************************
Val Zone
**********************************************/
int TP_X,TP_Y;
/**********************************************
Standard C functions zone
**********************************************/
void Write_Command(unsigned int c)
{
S6DLCD_RS_LOW; //LCD_RS=0;
S6DLCD_CS_LOW; //LCD_CS =0;!
S6DLCD_DATAPORT_OUTPUT;
S6DLCD_DATAPORT_CLEAR;
_S6DLCD_DATAPORT_SODR_ = ((c>>8) << S6DLCD_DATAPORT_OFFSET); //LCD_DataPortH=DH>>8;
S6DLCD_WR_LOW; //LCD_WR=0;
S6DLCD_WR_HIGH; //LCD_WR=1;!
S6DLCD_DATAPORT_CLEAR;
_S6DLCD_DATAPORT_SODR_ = ((c) << S6DLCD_DATAPORT_OFFSET); //LCD_DataPortH=DH;
S6DLCD_WR_LOW; //LCD_WR=0;
S6DLCD_WR_HIGH; //LCD_WR=1;
S6DLCD_CS_HIGH ; //LCD_CS =0;
}
void Write_Data(unsigned int c)
{
S6DLCD_RS_HIGH; //LCD_RS=0;
S6DLCD_CS_LOW; //LCD_CS =0;!
S6DLCD_DATAPORT_OUTPUT;
S6DLCD_DATAPORT_CLEAR;
_S6DLCD_DATAPORT_SODR_ = ((c>>8) << S6DLCD_DATAPORT_OFFSET); //LCD_DataPortH=DH>>8;
S6DLCD_WR_LOW; //LCD_WR=0;
S6DLCD_WR_HIGH; //LCD_WR=1;!
S6DLCD_DATAPORT_CLEAR;
_S6DLCD_DATAPORT_SODR_ = ((c) << S6DLCD_DATAPORT_OFFSET); //LCD_DataPortH=DH;
S6DLCD_WR_LOW; //LCD_WR=0;
S6DLCD_WR_HIGH; //LCD_WR=1;
S6DLCD_CS_HIGH; //LCD_CS =0;
}
void Write_Command_Data(unsigned int cmd,unsigned int dat)
{
Write_Command(cmd);
Write_Data(dat);
}
void Lcd_Init()
{
S6DLCD_DATAPORT_INPUT_CLK_E;
_S6DLCD_DATAPORT_PER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET);
_S6DLCD_DATAPORT_OER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET);
_S6DLCD_DATAPORT_PUER_ = (0xFFFF << S6DLCD_DATAPORT_OFFSET);
_S6DLCD_CONTROLPORT_PER_ = (1 << S6DLCD_RST) | (1 << S6DLCD_RS) | (1 << S6DLCD_CS) | (1 << S6DLCD_WR) | (1 << S6DLCD_RD);
_S6DLCD_CONTROLPORT_OER_ = (1 << S6DLCD_RST) | (1 << S6DLCD_RS) | (1 << S6DLCD_CS) | (1 << S6DLCD_WR) | (1 << S6DLCD_RD);
_S6DLCD_CONTROLPORT_PUDR_ = (1 << S6DLCD_RST) | (1 << S6DLCD_RS) | (1 << S6DLCD_CS) | (1 << S6DLCD_WR) | (1 << S6DLCD_RD);
_S6DLCD_CONTROLPORT_SODR_ = (1 << S6DLCD_RST) | (1 << S6DLCD_CS) | (1 << S6DLCD_RD);
_S6DLCD_CONTROLPORT_CODR_ = (1 << S6DLCD_WR);
S6DLCD_RST_HIGH;
delay_ms(500);
S6DLCD_RST_LOW;
delay_ms(500);
S6DLCD_RST_HIGH;
S6DLCD_CS_HIGH;
S6DLCD_WR_HIGH;
delay_ms(1000);
Write_Command_Data(0x0011,0x2004);
Write_Command_Data(0x0013,0xCC00);
Write_Command_Data(0x0015,0x2600);
Write_Command_Data(0x0014,0x252A);
// Write_Command_Data(0x14,0x002A);
Write_Command_Data(0x0012,0x0033);
Write_Command_Data(0x0013,0xCC04);
//delayms(1);
Write_Command_Data(0x0013,0xCC06);
//delayms(1);
Write_Command_Data(0x0013,0xCC4F);
//delayms(1);
Write_Command_Data(0x0013,0x674F);
Write_Command_Data(0x0011,0x2003);
//delayms(1);
Write_Command_Data(0x0030,0x2609);
Write_Command_Data(0x0031,0x242C);
Write_Command_Data(0x0032,0x1F23);
Write_Command_Data(0x0033,0x2425);
Write_Command_Data(0x0034,0x2226);
Write_Command_Data(0x0035,0x2523);
Write_Command_Data(0x0036,0x1C1A);
Write_Command_Data(0x0037,0x131D);
Write_Command_Data(0x0038,0x0B11);
Write_Command_Data(0x0039,0x1210);
Write_Command_Data(0x003A,0x1315);
Write_Command_Data(0x003B,0x3619);
Write_Command_Data(0x003C,0x0D00);
Write_Command_Data(0x003D,0x000D);
Write_Command_Data(0x0016,0x0007);
Write_Command_Data(0x0002,0x0013);
Write_Command_Data(0x0003,0x0003);
Write_Command_Data(0x0001,0x0127);
//delayms(1);
Write_Command_Data(0x0008,0x0303);
Write_Command_Data(0x000A,0x000B);
Write_Command_Data(0x000B,0x0003);
Write_Command_Data(0x000C,0x0000);
Write_Command_Data(0x0041,0x0000);
Write_Command_Data(0x0050,0x0000);
Write_Command_Data(0x0060,0x0005);
Write_Command_Data(0x0070,0x000B);
Write_Command_Data(0x0071,0x0000);
Write_Command_Data(0x0078,0x0000);
Write_Command_Data(0x007A,0x0000);
Write_Command_Data(0x0079,0x0007);
Write_Command_Data(0x0007,0x0051);
//delayms(1);
Write_Command_Data(0x0007,0x0053);
Write_Command_Data(0x0079,0x0000);
Write_Command_Data(0x0007,0x0051);
Write_Command(0x0022);
delay_ms(500);
}
void SetXY(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1)
{
Write_Command_Data(0x0046,(x1 << 8)| x0);
//Write_Command_Data(0x0047,x1);
Write_Command_Data(0x0047,y1);
Write_Command_Data(0x0048,y0);
Write_Command_Data(0x0020,x0);
Write_Command_Data(0x0021,y0);
Write_Command (0x0022);
//LCD_WriteCMD(GRAMWR);
}
void Pant(unsigned int color)
{
int i,j;
SetXY(0,239,0,319);
for(i=0;i<320;i++)
{
for (j=0;j<240;j++)
{
Write_Data(color);
}
}
}
void LCD_clear()
{
unsigned int i,j;
SetXY(0,239,0,319);
for(i=0;i<X_CONST;i++)
{
for(j=0;j<Y_CONST;j++)
{
Write_Data(0x0000);
}
}
}