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

📄 comflash程序舉例29010.c

📁 利用串口向单片机节目
💻 C
字号:
//29c010. 29c011a
#include <AT89X52.h>
#include<stdio.h>
#include<math.h>............................................................................
sbit DATA=0x90;//   定义可寻址位SBIT
sbit CLK =0x91;//
sbit LTH =0x92;//
sbit CE1 =0x93;//
sbit USE =0x94;
sbit A16=0xb2;
sbit aa17=0xb3;
sbit aa18=0xb4;
#define en_flash  CE1=0; 
#define dis_flash  CE1=1; 
sfr  WDTRST=0xA6;   定义特殊功能寄存器


unsigned char xdata flash_byte[65535];
unsigned long int ap=0;
unsigned char idata color,flag=0x00,ram_data[130],af,ad;
unsigned int module=0,frame=0,rate=0;


unsigned char com_flag1=0,x=0;
unsigned char total=0,coloreles,read_open=1;
unsigned char swich=0,open_com=0,com_flag=1;
int open_flag=0;
long int sector=0,flash_ap=0,mark_int=0;


delay_1ms(unsigned int xxx)
{unsigned int lll;
  if(xxx!=0)
   {
     while(xxx--)
     {
	  for(lll=0;lll<250;lll++)
        {WDTRST=0x1E;                        //?
         WDTRST=0xE1;
		 }
         }
       }
     } 
 

wait_15ms()
  {
   unsigned char y,w;
    for(y=0;y<40;y++)
     {
	  for(w=0;w<100;w++)
        {WDTRST=0x1E;
         WDTRST=0xE1;
		}       
         }
    }


fasong()//模组发送程序
 {unsigned char  ll;
  for(ll=0;ll<3;ll++)
    {
     DATA=color&0x80;
     color=color<<1;	
     CLK=0; 	 
     CLK=1;
	 WDTRST=0x1E;
     WDTRST=0xE1;

      }
 }


open()
  {  
   LTH=1; 
   delay_1ms(1);
   LTH=0;
   }


sendchar(unsigned char ch)
 {EA=0;
  SBUF=ch;  
  while(TI==0)
  {;
  }
  TI=0;
  EA=1;
  }


void time0(void) interrupt 1 using 1
 {  
    unsigned char yy,ww;
	
    TH0=-(2000/256);
    TL0=-(2000%256);
	mark_int++;
  if(mark_int==5000)
    {sendchar(99);
	 
     for(yy=0;yy<40;yy++)
       {
	    for(ww=0;ww<300;ww++)
          {;}       
           }
	   }
  }



serial()interrupt 4 using 1
 {unsigned char rxd;
  int i,j;
  TR0=1;
  mark_int=0;
  read_open=0;
  rxd=SBUF;
  RI=0;
  if(com_flag1==1)
    {if(rxd==2)com_flag=1,com_flag1=0;
     else open_com=1,com_flag1=0,com_flag=0;
	  }
 
  if(com_flag==1)
    {swich+=rxd;  
     x++;
    if(x==4)
      {
       if(swich==7)
	   {
	     sendchar(77);
		 sector=0;
		 A16=0;
	     x=0;
	     com_flag1=1;
	     com_flag=0;
	     swich=0;
		 }
       else sendchar(55),x=0,swich=0;
        }
     }

 
 if( open_com==1)
  {
  ram_data[open_flag]=rxd;	  	
  if(open_flag==ram_data[0]+1)
   {
    for(j=1;j<=ram_data[0];j++)
      {total+=ram_data[j];  
	    }

	  
    if(total==rxd)
      {
     	total=0;
           en_flash;
       for(j=1;j<=ram_data[0];j++,flash_ap++)   
	      {flash_byte[flash_ap]=ram_data[j];
	        }	

	 wait_15ms();
	 wait_15ms();
	 dis_flash;
	 sector+=1;	
	 flash_ap=128*sector;
	 }
     else sendchar(55),open_flag=-1,total=0;
	}

    
  if(open_flag==ram_data[0]+1)
  { 
    en_flash;		
	 j=128*(sector-1) ;
	for(i=1;i<=ram_data[0];i++,j++)
	 {total+=flash_byte[j];	
	  }
    dis_flash;
	if(total!=rxd)sendchar(33),sector-=1,flash_ap=128*sector;
	else sendchar(77);
	if(sector==512)sector=0,A16=1,flash_ap=128*sector;
	total=0; 
	open_flag=-1; 
   }
     open_flag+=1;
    }



	IE=0x92;
  }





main()
 {
  
   long int frame,module,rate,cell,read_module=0,read_frame=0,flash_index=0;
   unsigned char k,difference,l; 
   unsigned char time,ag, muit,aj,mm,ac,ab,ah,kk,color1;
   unsigned char colorflash1[9]={0x22,0x44,0x88,0xaa,0xcc};//此处选择要渐变的颜色
   TMOD=0x21;
   TH1=0xf3;
   TL1=0xf3;
   TH0=-(2000/256);
   TL0=-(2000%256);
   ET0=1;
   SCON=0x50;
   PCON=0x80;
   TCON=0x40;
   IE=0x90;
   USE=0;
   A16=0;
   aa17=0;
   aa18=0;
   CE1=0;
   sector=0;
   sendchar(77);
   WDTRST=0x1E;
   WDTRST=0xE1;
   

 module=flash_byte[2]*256+flash_byte[3];
 frame =flash_byte[6]*256+flash_byte[7];
 rate  =flash_byte[10]*256+flash_byte[11];
 cell  =flash_byte[12]*256+flash_byte[13];
 difference=flash_byte[14];
 for(k=0;k<15;k++)
  {sendchar(flash_byte[k]);
   WDTRST=0x1E;
   WDTRST=0xE1;
   }

 
 for(k=0;k<5;k++)
   {for(l=0;l<200;l++)
   {color=0x00;
    fasong();
     }
   LTH=0;
   delay_1ms(10);
   LTH=1;
   delay_1ms(100); 


   for(l=0;l<200;l++)
   {color=0xFF;
    fasong();
     }
   LTH=0;
   delay_1ms(10);
   LTH=1;
   delay_1ms(100);}

  
                    
   
 while(1)
 { 
   WDTRST=0x1E;
   WDTRST=0xE1;
   for(read_frame=0;read_frame<frame;read_frame++)
   {WDTRST=0x1E;
    WDTRST=0xE1;
    flash_index=read_frame*module+128;
	if(flash_index>=65536)flash_index=flash_index-65536,A16=1;
	else A16=0;
    for(read_module=flash_index+module-1;read_module>=flash_index;read_module--)
     { 
	   while(!read_open)
	     {color=0;
		  fasong();
		  LTH=0;
		  LTH=1;
		  WDTRST=0x1E;
          WDTRST=0xE1;		  
		  }	   	   
	    en_flash;
        color=flash_byte[read_module];
        dis_flash;
	    WDTRST=0x1E;
        WDTRST=0xE1;
        fasong(); 		
 	   }
      open();
      delay_1ms(rate);   
      }

   time=1;// 同步渐变
   kk=0;
   ah=0;
   ag=255;
   color1=colorflash1[kk];
for(k=0;k<5;k++)
 {
  ab=colorflash1[kk+1];
  ah=0;
  ag=255;
  muit=255/time;
  muit=muit*time;     
  for(aj=0;aj<muit;aj++)    
  {   
   for(mm=0;mm<200;mm++) //此处为调节变化速度mm=200为30秒(不精确)
    {
     for(af=ag;af>0;af--)      
       {   
         color=color1;
         fasong();  	
         open();
         WDTRST=0x1E;
         WDTRST=0xE1;
        } 
        		    
      for(ac=ah;ac>0;ac--)
       {      
         color=ab;
         fasong();
         open();
         WDTRST=0x1E;
         WDTRST=0xE1;       
        }   
       }        		   	
        ag-=1;
        ah+=1;        
       }  
       kk++;     
     }  
     }
  }

⌨️ 快捷键说明

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