Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
- // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
- // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. Tiny LCD SHALL NOT, UNDER ANY
- // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
- // DAMAGES, FOR ANY REASON WHATSOEVER.
- //
- END DESCRIPTION *********************************************************/
- /*
- // Rev. NO :: 1.0.0 28/08/13 15:44:50 Nishant singh.
- *************************************************************************/
- #include<REG51F.H>
- #ifdef SPI_8051
- #include "spi_8051.h"
- #else
- #include "bit_bagging_8051.h"
- #endif
- #include "font16x31.h"
- #define TFT_VERTICAL
- #ifdef TFT_VERTICAL
- #warning TFT_320_480_INITIALISED
- #include "butterfly.h"
- #else
- #warning TFT_480_320_INITIALISED
- #endif
- unsigned short gbHeight;
- unsigned short gbWidth;
- /*
- * This function will Set the Address on GRAM of TFT.
- *
- * @param Starting co-ordinate of Address x .(unsigned short x)
- * @param Starting co-ordinate of Address y .(unsigned short y)
- * @param End co-ordinate of Address x .(unsigned short x1)
- * @param End co-ordinate of Address y .(unsigned short y1)
- *
- * @return NONE
- *
- */
- void address_set(unsigned short postion_x,unsigned short postion_y,unsigned short postion_x1,unsigned short postion_y1)
- {
- write_com(0x2A); //Column address set
- write_dat(postion_x>>8);
- write_dat(postion_x); //Starting co-ordinate of x
- write_dat(postion_x1>>8);
- write_dat(postion_x1); //End co-ordinate of x
- write_com(0x2B); //Row address set
- write_dat(postion_y>>8);
- write_dat(postion_y); //Starting co-ordinate of y
- write_dat(postion_y1>>8);
- write_dat(postion_y1); //End co-ordinate of y
- write_com(0x2C);
- }
- #ifdef TFT_VERTICAL
- /*
- * This function will Display the image on TFT
- *
- * @param NONE
- *
- * @return NONE
- *
- */
- void TFT_Putphoto(void)
- {
- unsigned char *img_byte;
- unsigned long img_size;
- address_set(100,310, 219,389);
- TFT_RS = 1;
- TFT_SCK = 1;
- img_byte = gImage_butterfly;
- img_size = 0x4B00; //19200bytes
- while(img_size--)
- {
- write_dat(*img_byte);
- img_byte++;
- }
- }
- #endif
- /*
- * This function will initialize TFT
- *
- * @param NONE
- *
- * @return NONE
- *
- */
- void TFT_init(void)
- {
- TFT_CS = 0;
- TFT_RST=1;
- delay_ms(10);
- TFT_RST=0;
- delay_ms(150);
- TFT_RST=1;
- delay_ms(200);
- /************* Start Initial Sequence **********/
- write_com(0xB0);
- write_dat(0x80); //serial DOUT enable control
- write_com(0xC0);
- write_dat(0x0A); // P-Gamma level
- write_dat(0x0A); // N-Gamma level
- write_com(0xC1); // BT & VC Setting
- write_dat(0x45);
- write_dat(0x07); // VCI1 = 2.5V
- write_com(0xC2); // DC1.DC0 Setting
- write_dat(0x33);
- write_com(0xC5);
- write_dat(0x00);
- write_dat(0x42); // VCM Setting VCOM voltage level for reduce the flicker issue
- write_dat(0x80); // VCM Register Enable
- write_com(0xB1);
- write_dat(0xD0); // Frame Rate Setting
- write_dat(0x11);
- write_com(0xB4);
- write_dat(0x02); // 00: Column inversion; 02: Dot2 inversion
- write_com(0xB6); // RM.DM Setting
- write_dat(0x00);
- #ifdef TFT_VERTICAL
- write_dat(0x22);
- #else
- write_dat(0x02);
- #endif
- write_dat(0x3B);
- write_com(0xB7); // Entry Mode
- write_dat(0x07);
- write_com(0x36); // Color filter setting
- #ifdef TFT_VERTICAL
- write_dat(0x09);
- #else
- write_dat(0x2B); //row/column exchange
- #endif
- write_com(0xF0); // Enter ENG , must be set before gamma setting
- write_dat(0x36);
- write_dat(0xA5);
- write_dat(0xD3);
- write_com(0xE5); // Open gamma function , must be set before gamma setting
- write_dat(0x80);
- write_com(0xE5);
- write_dat(0x01);
- write_com(0xB3);
- write_dat(0x00);
- write_com(0xE5);
- write_dat(0x00);
- write_com(0xF0); // Exit ENG , must be set before gamma setting
- write_dat(0x36);
- write_dat(0xA5);
- write_dat(0x53);
- write_com(0xE0); // Gamma setting
- write_dat(0x00);
- write_dat(0x35);
- write_dat(0x33);
- write_dat(0x00);
- write_dat(0x00);
- write_dat(0x00);
- write_dat(0x00);
- write_dat(0x35);
- write_dat(0x33);
- write_dat(0x00);
- write_dat(0x00);
- write_dat(0x00);
- write_com(0x3A); // interface setting
- write_dat(0x55);
- write_com(0x11); // Exit sleep mode
- delay_ms(250);
- write_com(0x29); // Display on
- }
- /*
- * This function will Drow the circle on TFT .
- *
- * @param center of circle co-ordinate of Rectangle x .(unsigned short x)
- * @param center of circle co-ordinate of Rectangle y .(unsigned short y)
- * @param radius (rad)
- * @param color (color)
- * @param Background color.(unsigned short b_color)
- *
- * @return NONE
- *
- */
- void TFT_circle(unsigned short postion_x,unsigned short postion_y,unsigned char rad ,unsigned short color,unsigned short b_clr)
- {
- unsigned short i,j;
- address_set(postion_x-rad, postion_y-rad, postion_x+rad, postion_y+rad);
- for(i= postion_x-rad;i<=(postion_x+rad);i++)
- {
- for(j =postion_y-rad;j<=(postion_y+rad);j++)
- {
- if((((unsigned short)(i-postion_x)*(i-postion_x))+(unsigned short)((j-postion_y)*(j-postion_y))) < (unsigned short)(rad*rad))
- {
- write_dat(color>>8);
- write_dat(color);
- }
- else
- {
- write_dat(b_clr>>8);
- write_dat(b_clr);
- }
- }
- }
- }
- /*
- * This function will clear the Display .
- *
- * @param Background color.(unsigned short color)
- *
- * @return NONE
- *
- */
- void TFT_Clear_Screen(unsigned short color)
- {
- unsigned short i,j;
- #ifdef TFT_VERTICAL //for Vertical Mode
- address_set(0,0,320,480); //Set area on GRAM
- #else //for Horizontal Mode
- address_set(0,0,480,320); //Set area on GRAM
- #endif
- for (i=0;i<320;i++)
- for (j=0;j<480;j++)
- {
- write_dat(color>>8);
- write_dat(color);
- }
- }
- /*
- * This function will Drow the Rectangle on TFT .
- *
- * @param Starting co-ordinate of Rectangle x .(unsigned short postion_x)
- * @param Starting co-ordinate of Rectangle y .(unsigned short postion_y)
- * @param Background color.(unsigned short color)
- *
- * @return NONE
- *
- */
- void TFT_Rectangle( unsigned short postion_x, unsigned short postion_y, unsigned short color)
- {
- unsigned short i,j;
- #ifdef TFT_VERTICAL
- i = 320/4;
- j = 480/4;
- #else
- j = 320/4;
- i = 480/4;
- #endif
- address_set(postion_x, postion_y, postion_x+i-1, postion_y+j-1);
- for(postion_x=0;postion_x<j; postion_x++)
- {
- for(postion_y=0;postion_y<i;postion_y++)
- {
- write_dat(color>>8);
- write_dat(color);
- }
- }
- }
- /*
- * This function will Write the one char on TFT .
- *
- * @param Starting address of string (char Data_WR)
- * @param Starting co-ordinate of string x .(unsigned short x)
- * @param Starting co-ordinate of string y .(unsigned short y)
- * @param Color of fount. (unsigned short color)
- * @param Background color.(unsigned short b_clr)
- *
- * @return NONE
- *
- */
- void TFT_PutChar(char Data_WR, unsigned short x, unsigned short y, unsigned short color,unsigned short b_clr)
- {
- unsigned short i,j,k,l;
- unsigned short c;
- k = ((gbWidth*gbHeight)/8);//number of bytes per charater
- l = k*Data_WR;//byte location of character
- address_set( x, y, x+gbWidth-1, y+gbHeight-1);
- for(j=0; j<k; j++)
- {
- c=(Font16x31[l+j]);
- for(i=0; i<8; i++)
- {
- if((c & 0x80)==0x80)
- {
- write_dat(color>>8);
- write_dat(color);
- }
- else
- {
- write_dat(b_clr>>8);
- write_dat(b_clr);
- }
- c<<=1;
- }
- }
- }
- /*
- * This function will Display the string on TFT .
- *
- * @param Starting address of string (char *s)
- * @param Starting co-ordinate of string x .(unsigned short x)
- * @param Starting co-ordinate of string y .(unsigned short y)
- * @param Color of fount. (unsigned short color)
- * @param Background color.(unsigned short b_clr)
- *
- * @return NONE
- *
- */
- void TFT_PutString(char *s, unsigned short x, unsigned short y, unsigned short color,unsigned short b_clr)
- {
- while(*s)
- {
- #ifdef TFT_VERTICAL
- if(x >=(319))
- #else
- if(x >=(479))
- #endif
- {
- x=5;
- y += (gbHeight+5);
- #ifdef TFT_VERTICAL
- if(y>=(479))
- #else
- if(y>=(319))
- #endif
- {
- y=5;
- }
- }
- TFT_PutChar((*s), x, y, color, b_clr);
- x += gbWidth;
- s++;
- }
- }
- void main()
- {
- #ifdef SPI_8051
- SPI_initialize();
- #endif
- TFT_init();
- while(1)
- {
- #ifdef TFT_VERTICAL
- gbHeight = 31;
- gbWidth = 16;
- TFT_Clear_Screen(WHITE);
- TFT_PutString(" WELCOME ",5,100, BLACK, BLUE2);
- TFT_PutString(" TO ",5,131, BLACK, BLUE2);
- TFT_PutString(" www.tinylcd.com ",5,162, RED, BLUE2);
- TFT_Putphoto();
- delay(1000);
- gbHeight = 31;
- gbWidth = 16;
- TFT_Clear_Screen(WHITE);
- TFT_PutString(" Size:",5,25, BLACK, WHITE);
- TFT_PutString("3.5'' TFT",85,65, RED, WHITE);
- TFT_PutString(" Pixel:",5,100, BLACK, WHITE);
- TFT_PutString("320x480 ",85,145, RED, WHITE);
- TFT_PutString(" www.tinylcd.com",5,205, BLUE, WHITE);
- TFT_Putphoto();
- delay(1000);
- TFT_Clear_Screen(WHITE);
- TFT_Rectangle(0,0,BLUE);
- TFT_Rectangle(30,30,RED);
- TFT_Rectangle(60,60,YELLOW) ;
- TFT_Rectangle(90,90,MAGENTA);
- TFT_Rectangle(120,120,ORANGE);
- TFT_Rectangle(150,150,GREEN);
- TFT_Rectangle(180,180,CYAN);
- TFT_Rectangle(210,210,BLUE2);
- TFT_PutString(" www.tinylcd.com ",5,430, BLUE, WHITE);
- delay(1000);
- TFT_Clear_Screen(WHITE);
- TFT_circle(160,120,30,BLUE, WHITE);
- TFT_circle(80,240,30,RED, WHITE);
- TFT_circle(240,240,30,GREEN, WHITE);
- TFT_circle(160,360,30,YELLOW, WHITE);
- TFT_PutString("www.tinylcd.com",30,410, BLUE, WHITE);
- delay(1000);
- gbHeight = 31;
- gbWidth = 16;
- TFT_Clear_Screen(WHITE);
- TFT_PutString("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z", 5, 5, BLACK, WHITE);
- TFT_PutString("a b c d e f g h i j k l m n o p q r s t u v w x y z", 5, 150, BLACK, WHITE);
- TFT_PutString("0 1 2 3 4 5 6 7 8 9",5,280, BLACK, WHITE);
- TFT_Putphoto();
- delay(1000);
- #else
- gbHeight = 31;
- gbWidth = 16;
- TFT_Clear_Screen(WHITE);
- TFT_PutString(" WELCOME ",5,90, BLACK, BLUE2);
- TFT_PutString(" TO ",5,121, BLACK, BLUE2);
- TFT_PutString(" www.tinylcd.com ",5,152, RED, BLUE2);
- delay(1000);
- gbHeight = 31;
- gbWidth = 16;
- TFT_Clear_Screen(WHITE);
- TFT_PutString(" Size:",5,25, BLACK, WHITE);
- TFT_PutString(" 3.5'' TFT",115,65, RED, WHITE);
- TFT_PutString(" Pixels:",5,100, BLACK, WHITE);
- TFT_PutString(" 480x320 ",115,145, RED, WHITE);
- TFT_PutString(" www.tinylcd.com",55,205, BLUE, WHITE);
- delay(1000);
- TFT_Clear_Screen(WHITE);
- TFT_Rectangle(0,0,BLUE) ;
- TFT_Rectangle(30,30,RED);
- TFT_Rectangle(60,60,YELLOW) ;
- TFT_Rectangle(90,90,MAGENTA);
- TFT_Rectangle(120,120,ORANGE);
- TFT_Rectangle(150,150,GREEN);
- TFT_Rectangle(180,180,CYAN);
- TFT_Rectangle(210,210,BLUE2);
- delay(1000);
- TFT_Clear_Screen(WHITE);
- TFT_circle(240,80,30,BLUE, WHITE);
- TFT_circle(120,160,30,RED, WHITE);
- TFT_circle(360,160,30,GREEN, WHITE);
- TFT_circle(240,240,30,YELLOW, WHITE);
- TFT_PutString("www.tinylcd.com",120,280, BLUE, WHITE);
- delay(1000);
- gbHeight = 31;
- gbWidth = 16;
- TFT_Clear_Screen(WHITE);
- TFT_PutString("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z", 5, 5, BLACK, WHITE);
- TFT_PutString("a b c d e f g h i j k l m n o p q r s t u v w x y z", 5, 140, BLACK, WHITE);
- TFT_PutString("0 1 2 3 4 5 6 7 8 9",5,250, BLACK, WHITE);
- delay(1000);
- #endif
- TFT_Clear_Screen(WHITE);
- delay(1000);
- TFT_Clear_Screen(BLACK);
- delay(1000);
- TFT_Clear_Screen(BLUE);
- delay(1000);
- TFT_Clear_Screen(RED);
- delay(1000);
- TFT_Clear_Screen(YELLOW);
- delay(1000);
- TFT_Clear_Screen(BLUE2);
- delay(1000);
- TFT_Clear_Screen(CYAN);
- delay(1000);
- TFT_Clear_Screen(GREEN);
- delay(1000);
- TFT_Clear_Screen(ORANGE);
- delay(1000);
- TFT_Clear_Screen(MAGENTA);
- delay(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement