1sr part:
#include "Font.h"
#include "digitalWriteFast.h"
#define DB10 2
#define DB11 3
#define DB12 4
#define DB13 5
#define DB14 6
#define DB15 7
#define DB16 8
#define DB17 9
#define CS 11
#define RS 13
#define WR 12
#define RD A0 //use as analog pin in digital mode. allows easy upgrade to mega. as pin14 is different
#define RESET 10
#define lcd_Data
#define red 0xf800
#define green 0x07e0
#define blue 0x001f
#define black 0x0000
#define white 0xffff
#define gray 0x8c51
#define yellow 0xFFE0
#define cyan 0x07FF
#define purple 0xF81F
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A1; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A3; // z-axis (only on 3-axis models)
//int xpin = 0; // variable to read the value from the analog pin 0
//int ypin = 0; // variable to read the value from the analog pin 0
//int zpin = 0; // variable to read the value from the analog pin 0
char value2[4] ;
unsigned int colorc[]={red,green,blue,black,white,gray,yellow,cyan,purple};
void setup()
{
char c;
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(DB10,OUTPUT);
pinMode(DB11,OUTPUT);
pinMode(DB12,OUTPUT);
pinMode(DB13,OUTPUT);
pinMode(DB14,OUTPUT);
pinMode(DB15,OUTPUT);
pinMode(DB16,OUTPUT);
pinMode(DB17,OUTPUT);
pinMode(RESET,OUTPUT);
pinMode(CS,OUTPUT);
pinMode(WR,OUTPUT);
pinMode(RS,OUTPUT);
pinMode(RD,OUTPUT);
lcd_Init();
Serial.begin(1152000);
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
lcd_Clear(yellow);
delay(1);
lcd_Clear(green);
delay(1);
for(byte y=0; y<100;y++)
lcd_Circle(120, 120, y,purple);
lcd_Line(0,0, 190,310,white);
lcd_Line(190,310, 0,0,white);
lcd_Str(0,150," Arduino TFT (profounddevices) ",white,blue);
lcd_Str(0,0," Atmega328 Example ",yellow,black);
delay(1000000);// pause her efor reset
}
void charcodetable()
{
char c;
lcd_Str(0,0," 0123456789ABCDEF",white,red);
c=0x30;
for(int y=0;y<10;y++)
lcd_Char(0,y+1,c++,white,red);
c=0x41;
for(int y=10;y<16;y++)
lcd_Char(0,y+1,c++,white,red);
// disp_ANKFont();
for(int y=0;y<204;y+=12)
for(int x=0;x<102;x++)
lcd_Pixel(x,y,black);
for(int x=5;x<102;x+=6)
for(int y=0;y<204;y++)
lcd_Pixel(x,y,black);
}
void loop()
{
itoa (xpin, value2, 10);
lcd_Str(10,180,'Text Value :'+value2,white,blue);
}
void SET_LOW(int pin)
{
digitalWriteFast2(pin,LOW);
}
void SET_HIGH(int pin)
{
digitalWriteFast2(pin,HIGH);
}
extern void Trans_Dat(unsigned int index, unsigned int data)
{
unsigned char low8 = lowByte(index);
unsigned char high8 = highByte(index);
digitalWriteFast2(CS,LOW);//SET_LOW(CS);
digitalWriteFast2(RS,LOW);//SET_LOW(RS);
digitalWriteFast2(WR,HIGH);//SET_HIGH(WR);
Write_Data(high8);
digitalWriteFast2(WR,LOW);//SET_LOW(WR);
digitalWriteFast2(WR,HIGH); //SET_HIGH(WR);
Write_Data(low8);
digitalWriteFast2(WR,LOW);//SET_LOW(WR);
digitalWriteFast2(WR,HIGH); //SET_HIGH(WR);
digitalWriteFast2(RS,HIGH); //SET_HIGH(RS);
low8 = lowByte(data);
high8 = highByte(data);
Write_Data(high8);
//delayMicroseconds(5);
//PORTD = high8;
digitalWriteFast2(WR,LOW); // SET_LOW(WR);
// delayMicroseconds(5);
digitalWriteFast2(WR,HIGH) //SET_HIGH(WR);
Write_Data(low8);
//delayMicroseconds(5);
digitalWriteFast2(WR,LOW);// SET_LOW(WR);
// delayMicroseconds(5);
digitalWriteFast2(WR,HIGH) ;//SET_HIGH(WR);
//delayMicroseconds(5);
digitalWriteFast2 (CS,HIGH); //SET_HIGH(CS);
}
void Write_Data(unsigned char data)
{// made pin specific as port is not the same on arduino and mega
// PORTD=data<<2; //FASTERWAY/ WHY BECAUSE PIN IS NOW KNOWN ALWAYS. IT IS HARDCODED IN COMPILE
if (bitRead(data,0)){digitalWriteFast2(DB10,HIGH);} else{digitalWriteFast2(DB10,LOW);}// digitalWriteFast2(DB16,bitRead(data,6));
if (bitRead(data,2)){digitalWriteFast2(DB12,HIGH);} else{digitalWriteFast2(DB12,LOW);}// digitalWriteFast2(DB17,bitRead(data,6));
if (bitRead(data,4)){digitalWriteFast2(DB14,HIGH);} else{digitalWriteFast2(DB14,LOW);}// digitalWriteFast2(DB16,bitRead(data,6));
if (bitRead(data,6)){digitalWriteFast2(DB16,HIGH);} else{digitalWriteFast2(DB16,LOW);}// digitalWriteFast2(DB17,bitRead(data,6));
if (bitRead(data,1)){digitalWriteFast2(DB11,HIGH);} else{digitalWriteFast2(DB11,LOW);}// digital
if (bitRead(data,3)){digitalWriteFast2(DB13,HIGH);} else{digitalWriteFast2(DB13,LOW);}// digitalWriteFast2(DB17,bitRead(data,6));
if (bitRead(data,5)){digitalWriteFast2(DB15,HIGH);} else{digitalWriteFast2(DB15,LOW);}// digitalWriteFast2(DB16,bitRead(data,6));
if (bitRead(data,7)){digitalWriteFast2(DB17,HIGH);} else{digitalWriteFast2(DB17,LOW);}// digitalWriteFast2(DB17,bitRead(data,6));
}
void lcd_Init(void)
{
digitalWriteFast2(RD,HIGH); //SET_HIGH(RD);
digitalWriteFast2 (RD,HIGH); //SET_HIGH(RESET);
delay(3);
digitalWriteFast2(RESET,LOW); //SET_LOW(RESET);
delay(15);
digitalWriteFast2(RESET,HIGH);//SET_HIGH(RESET);
delay(20);
Trans_Dat(0x00E3, 0x3008);
Trans_Dat(0x00E7, 0x0012);
Trans_Dat(0x00EF, 0x1231);
Trans_Dat(0x0001, 0x0100);
Trans_Dat(0x0002, 0x0700); // set line inversion
// Trans_Dat(0x0003, 0b0001000000011000); // ???
Trans_Dat(0x0003, 0b0001000000110000); // ???
Trans_Dat(0x0004, 0x0000);
Trans_Dat(0x0008, 0x0207);
Trans_Dat(0x0009, 0x0000);
Trans_Dat(0x000A, 0x0000);
Trans_Dat(0x000C, 0x0000);
Trans_Dat(0x000D, 0x0000);
Trans_Dat(0x000F, 0x0000);
Trans_Dat(0x0010, 0x0000);
Trans_Dat(0x0011, 0x0007);
Trans_Dat(0x0012, 0x0000); // VREG1OUT voltage
Trans_Dat(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
delay(200);
Trans_Dat(0x0010, 0x1490); // SAP, BT[3:0], AP[2:0], DSTB, SLP, STB
Trans_Dat(0x0011, 0x0227);
delay(50); // Delayms 50ms
Trans_Dat(0x0012, 0x001c); // External reference voltage= Vci;
delay(50); // Delayms 50ms
Trans_Dat(0x0013, 0x0A00); // R13=0F00 when R12=009E;VDV[4:0] for VCOM amplitude
Trans_Dat(0x0029, 0x000F); // R29=0019 when R12=009E;VCM[5:0] for VCOMH//0012//
Trans_Dat(0x002B, 0x000D); // Frame Rate = 91Hz
delay(50);
Trans_Dat(0x0030, 0x0000);
Trans_Dat(0x0031, 0x0203);
Trans_Dat(0x0032, 0x0001);
Trans_Dat(0x0035, 0x0205);
Trans_Dat(0x0036, 0x030C);
Trans_Dat(0x0037, 0x0607);
Trans_Dat(0x0038, 0x0405);
Trans_Dat(0x0039, 0x0707);
Trans_Dat(0x003C, 0x0502);
Trans_Dat(0x003D, 0x1008);
lcd_ClearWindow();
Trans_Dat(0x0060, 0xA700); // Gate Scan Line
Trans_Dat(0x0061, 0x0001);
Trans_Dat(0x006A, 0x0000);
Trans_Dat(0x0080, 0x0000);
Trans_Dat(0x0081, 0x0000);
Trans_Dat(0x0082, 0x0000);
Trans_Dat(0x0083, 0x0000);
Trans_Dat(0x0084, 0x0000);
Trans_Dat(0x0085, 0x0000);
Trans_Dat(0x0090, 0x0010);
Trans_Dat(0x0092, 0x0600); //0x0000
Trans_Dat(0x0093, 0x0003);
Trans_Dat(0x0095, 0x0110);
Trans_Dat(0x0097, 0x0000);
Trans_Dat(0x0098, 0x0000);
Trans_Dat(0x0007, 0x0133);
}
#define ENDCOL 240 // X
#define ENDROW 320 // Y
#define XChar (int)((ENDCOL) / 6)
#define YLine (int)((ENDROW) / 12)
void lcd_Clear(unsigned int Color)
{
unsigned long i;
lcd_SetX(0);
lcd_SetY(0);
lcd_ClearWindow();
for(i=0;i<320UL*240UL;i++)
Trans_Dat(0x0022,Color);
}
void lcd_ClearWindow(void)
{
lcd_SetWindow(0,239,0,319);
}
void lcd_SetWindow(unsigned int HSA,unsigned int HEA,unsigned int VSA,unsigned int VEA)
{
Trans_Dat(0x0050, HSA); // ??(Horizontal) G
Trans_Dat(0x0051, HEA); // ??(Horizontal)
Trans_Dat(0x0052, VSA); // ??(Vertical)
Trans_Dat(0x0053, VEA); // ??(Vertical)
}