⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2.0tft demomain 1.c

📁 LCD模块驱动 SHARP2.0“TFT模块驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
 /********************************************************/
/*         MAIN PROGRAM FOR DEMOTOOL FOR SHARP          */
/*               2.0TFT          REVION 2            */
/********************************************************/

#include <reg52.H>
sfr FST    = 0xb6;
sfr T2MOD  = 0xc9;
sfr IP0    = 0xb8;
sfr IP0H   = 0xb7;
sfr IP1    = 0xf8;
sfr IP1H   = 0xf7;
sfr IEN0    = 0xa8;
sfr IEN1   = 0xe8;
sfr CCAP1H    = 0xfb;
sfr CCAP1L    = 0xeb;
sfr CCAPM1    = 0xdb;
sfr CCON    = 0xd8;
sfr CH      = 0xf9;
sfr CL    = 0xe9;
sfr CMOD    = 0xd9;
sfr AUXR    =0x8e;

#define true 1
#define false 0
#define key_mask 0x0f
#define block_mask 0x07
#define key_up 0x0e
#define key_down 0x0d
#define key_shift 0x0b
#define key_playpause 0x07
#define key_poweroff 0x0c
#define setup_sector 0x07
#define BLOCK_ADDR_MASK 0xf8
#define FLASH_START 0x00

char xdata LCDDATA _at_ 0xDD00;
char xdata LCDREG _at_ 0xDC00;

char xdata LCDHBYTE _at_ 0xEF00;
char xdata AUXOUT _at_ 0xF700;
char xdata FLASH_5555 _at_ 0x5555;
char xdata FLASH_2AAA _at_ 0x2aaa;


sbit LCDcs=P1^6;
sbit Flashcs=P1^7;
sbit Led=P3^5;
sbit Dtr=P3^3;
sbit Dsr=P3^4;
sbit Bl1=P1^4;
sbit SCL = P3^0;
sbit SDA = P3^1;

sbit CS = P2^1;
sbit RS = P2^0;

unsigned char xdata *Image_data_addr;
unsigned char idata Auxdata;
unsigned char idata Bl_brightness;

unsigned char idata Block_addr;
unsigned char idata Contrast;
unsigned long int idata  Download_total;
unsigned long int idata  Download_counter;
unsigned char idata Download_process;
unsigned int idata Download_x;
unsigned char idata Picno;
bit Shift;
bit Pause;
bit Download_over;
bit Empty;
bit Chip_copy;
bit Chip_copy_over;


void Cpu_init();
void Init_LCD();
void Key_int();
void System_init();
void Pcam1_init();
void Serial_init();

void Program_flash(unsigned char xdata *image_data,unsigned char io_data);
void Chip_erase_flash();
void Display(unsigned char block_addr);
void Display_scrollup(unsigned char block_addr);
void Display_scrolldown(unsigned char block_addr);
void Display_x_shut(unsigned char block_addr);


void Display_Checkar();
void Display_RGBG();
void Display_Black();
void Display_White();
void Display_logo();
void Display_downloading();
void Display_downloaded();
void Display_eraseing();	
void Display_erased();
void Display_chipcopy_transfering();
void Display_chipcopy_receiving();
void Display_x_shut(unsigned char block_addr);
void Display_R();
void Display_G();
void Display_B();


void Hardreset();
void Poweroff();
void Chip_select_flash();
void Chip_select_LCD();
void Led_light(bit led);
void Led_flash(unsigned char cycle);
void Key_up_server();
void Key_down_server();
void Key_shift_server();
void Key_playpause_server();
void Auxdata_write(unsigned char data_mask,unsigned char auxa_data);
void Delayus(int value);
void Delayms(int value);

void SPI_Disp();
void SPI_Command();
void SPI_Send_Data(unsigned char DATA);

unsigned char code Logo9616[192];
unsigned char code Downloading[480];
unsigned char code Transfering[480];
unsigned char code Receiving[384];
unsigned char code Downloaded[192];
unsigned char code Erasing[192];
unsigned char code Erased[192];


void main()
{
	FST=0X08;				//clock double disable
	AUXR=0x02;
	Bl_brightness=0;		        //init bightlight
	Shift=0;
	Pause=0;
	Chip_copy=0;
	Image_data_addr=FLASH_START;
	Download_counter=0;
	Download_process=0;
	Download_total=0xff;
	Download_over=false;
	Auxdata=0x08;
	IEN0=0;
	Led_light(false);
   
	Init_LCD();
	System_init();
	Bl_brightness=255;		//init bightlight
	CCAP1H=255-Bl_brightness;     //set duty
	Display_logo();
	Picno=1;
mloop1:	while(Pause==1) goto mloop1;    //if pause ,notgo
	    Display(Picno&0x03);
	    if(Empty==false) Delayms(100);
	    Picno++;
mloop2:	while(Pause==1) goto mloop2;    //if pause ,notgo
	    Display(Picno&0x03);
	    if(Empty==false) Delayms(100);
	    Picno++;
mloop3:	while(Pause==1) goto mloop3;    //if pause ,notgo
	    Display(Picno&0x03);
	    if(Empty==false) Delayms(100);
	    Picno++;
mloop4:	while(Pause==1) goto mloop4;    //if pause ,notgo
	    Display(Picno&0x03);
	    if(Empty==false) Delayms(100);
        Picno++;
//mloop5:	while(Pause==1) goto mloop5;
//		Display_R();
//		Delayms(100);
//mloop6:	while(Pause==1) goto mloop5;
//		Display_G();
//		Delayms(100);
//mloop7:	while(Pause==1) goto mloop5;
//		Display_B();
//		Delayms(100);
        goto mloop1;
loop:
	    Led_light(true);
     	Delayms(100);
    	Led_light(false);
    	Delayms(100);
    	goto loop;
 }


void System_init() 
{	
	unsigned char key;
	unsigned char flash00;
    system_init_begin:	
	P1=P1|key_mask;
	key=P1&key_mask;
	switch (key)
    {    
		case key_mask:				//demonstation
		{						 
			Pcam1_init();
			IP0=0x01;              //proitity setup :external i0
			EX0=1;                 //open the io interrupt
			EA=1;
		IT0=1;	
		}
			break;
		case 0x00:					//chip_erase
		{
			Bl1=true;
			Led_light(true);                     
		  	Delayms(1000);
			P1=P1|key_mask;
			key=P1&key_mask;
			if ((key&key_mask)!=0) goto system_init_begin;		
			Display_eraseing();
			Chip_erase_flash();
			Display_erased();
			Delayms(100);
			Led_flash(3); 
		}
			break;
		case 0x02:                 //Chip_copy trans
		{
			Chip_copy=1;
			Display_chipcopy_transfering();
		 	Serial_init();					//serial port
			ES=true;                        //UART interrupt enable
			Block_addr=0;
			Image_data_addr=0;
			Auxdata_write(BLOCK_ADDR_MASK,0);
			Chip_select_flash();
			SBUF=*(Image_data_addr);
			Image_data_addr++;
transloop:	while(Chip_copy_over==0) goto transloop;           //loop 
			EA=0;
		}
			break;
		case 0x03:					//Chip_copy receive
		{	
			Chip_copy=1;
			Display_chipcopy_receiving();
		 	Serial_init();					//serial port
			ES=true;                        //UART interrupt enable
			Block_addr=0;
			Image_data_addr=0;
			Auxdata_write(BLOCK_ADDR_MASK,0);
			Chip_select_flash();
receiveloop:while(Chip_copy_over==0) goto receiveloop;           //loop 
			EA=0;
		}
			break;
		case 0x01:				
		{
 		}
			break;
		case 0x04:				
		{
 		}
			break;
		case 0x05:				
		{
 		}
			break;
		case 0x06:				
		{
 		}
			break;
		default:                             //Block data receiver
		{									
			Block_addr=key^key_mask;
          	Auxdata_write(BLOCK_ADDR_MASK,(Block_addr<<1)&block_mask);
			Chip_select_flash();
			Image_data_addr=FLASH_START;
			flash00=*(Image_data_addr);
			if (flash00!=0xff) goto dover;
		 	Serial_init();					//serial port
			ES=true;                        //UART interrupt enable
			Display_downloading();
doverloop:	while(Download_over==0) goto doverloop;           //loop 
			EA=0;
			Delayms(10);
dover:		        EA=0;
			Display(Block_addr);
			if (flash00!=0xff) Display_downloaded(); 
			Led_flash(3);
		}
	}
}





//========================================================
void Display(unsigned char block_addr)
{  	unsigned char xdata *image_data_addr;
	unsigned char xdata *data_addr;
	unsigned int data_offset;
	unsigned int width;
	unsigned int highth;
	unsigned int total_addr;
	unsigned char r;
	unsigned char g;
	unsigned char b;
	unsigned char block_addr_1;
    unsigned int i;
	unsigned int j;
	unsigned int m;
	unsigned int n;
	unsigned int k;

    block_addr=block_addr<<1; 
	block_addr_1=block_addr+1;
	image_data_addr=FLASH_START;
	Auxdata_write(BLOCK_ADDR_MASK,block_addr&block_mask);
	Chip_select_flash();
	r=*image_data_addr;
	if(r==0x0FF) 	
        { Empty=true;
	      goto end;
	    }
	else Empty=false;
	data_offset=*(image_data_addr+10);               //data offset
	width=*(image_data_addr+18);                    //image width
	highth=*(image_data_addr+22);                    //image highth
	image_data_addr=image_data_addr+data_offset;
	image_data_addr=image_data_addr+((highth)*(3*width));
	data_addr=image_data_addr;
	total_addr=data_offset+((highth)*(3*width));
	Auxdata_write(BLOCK_ADDR_MASK,block_addr_1&block_mask);
	Chip_select_flash();
	Chip_select_LCD();
	SPI_Command();
	SPI_Send_Data(0x15);   SPI_Send_Data(0x83);  //x end
	SPI_Command();
	SPI_Send_Data(0x12);   SPI_Send_Data(0x00);   //x start 
	SPI_Command();
	SPI_Send_Data(0x16);   SPI_Send_Data(0xb1);   //y end
	SPI_Command();
	SPI_Send_Data(0x13);   SPI_Send_Data(0x00);   //y start
	SPI_Command();
	SPI_Send_Data(0x18);   SPI_Send_Data(0x00);   //address auto increment

   for(i=0;((i+1)*3*width)<=(total_addr);i++)
 	       {  image_data_addr=image_data_addr-(width*3);
		      for(j=0;j<width;j++)
 	         	{ image_data_addr=image_data_addr+3;
			      Chip_select_flash();
			      r = (*(image_data_addr-1));
			      g = (*(image_data_addr-2));
			      b = (*(image_data_addr-3));
			     	Chip_select_LCD();
		    SPI_Disp();
			SPI_Send_Data(((r)&(0xf8))+((g>>5)&(0x07)));   		
 	        SPI_Send_Data(((g<<3)&(0xe0))+((b>>3)&(0x1f)));
		        }
              image_data_addr=image_data_addr-(width*3);
			 
           }                                                       


 
   
//    image_data_addr=image_data_addr-3*width; 
	 image_data_addr=total_addr-((i+1)*3*width);
     Auxdata_write(BLOCK_ADDR_MASK,block_addr&block_mask);
	 Chip_select_flash();
     for (i++;i<highth;i++)
       {  image_data_addr=image_data_addr-(width*3);	
	      for(j=0;j<width;j++)
          {  image_data_addr=image_data_addr+3;
	         Chip_select_flash();
	         r = (*(image_data_addr-1));
	         g = (*(image_data_addr-2));
	         b = (*(image_data_addr-3));
	       	Chip_select_LCD();
		    SPI_Disp(); 
			SPI_Send_Data(((r)&(0xf8))+((g>>5)&(0x07)));   		
 	        SPI_Send_Data(((g<<3)&(0xe0))+((b>>3)&(0x1f))) ;
          }
          image_data_addr=image_data_addr-(width*3);
    	}
     
end:    ;
}
//========================================================

void Display_scrollup(unsigned char block_addr)
{  	unsigned char xdata *image_data_addr;
	unsigned char xdata *data_addr;
	unsigned int data_offset;
	unsigned int width;
	unsigned int highth;
	unsigned int total_addr;
	unsigned char r;
	unsigned char g;
	unsigned char b;
	unsigned char block_addr_1;
    unsigned int i;
	unsigned int j;
	unsigned int m;
	unsigned int n;
//	unsigned int k;
	
    block_addr=block_addr<<1; 
	block_addr_1=block_addr+1;
	image_data_addr=FLASH_START;
	Auxdata_write(BLOCK_ADDR_MASK,block_addr&block_mask);
	Chip_select_flash();
	r=*image_data_addr;
	if(r==0x0FF) 	
      { Empty=true;
	    goto end;
	  }
	else Empty=false;
	data_offset=*(image_data_addr+10);               //data offset
	width=*(image_data_addr+18);                    //image width
	highth=*(image_data_addr+22);                    //image highth
	image_data_addr=image_data_addr+data_offset;
	image_data_addr=image_data_addr+((highth)*(3*width));
	total_addr=image_data_addr;
	Auxdata_write(BLOCK_ADDR_MASK,block_addr_1&block_mask);
	Chip_select_flash();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -