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

📄 main.c

📁 2005年全国大学生电子设计竞赛论文集
💻 C
📖 第 1 页 / 共 2 页
字号:
     	dingdian();  
     
     	xx=xx+2;
     	yy=yy+1.5;
     	dingdian();
     	koupan=*P_IOB_Data;
     	koupan&=0x0f00;
     	if(koupan!=0x0f00)
		{
            break;
		}
     	xx=xx-2;
     	yy=yy-1.5;
     	dingdian();  
         
     	xx=xx+2.5;
     	yy=yy;
     	dingdian();
     	koupan=*P_IOB_Data;
     	koupan&=0x0f00;
     	if(koupan!=0x0f00)
		{
            break;
		}   
     	xx=xx-2.5;
     	yy=yy;
     	dingdian(); 
     
     	xx=xx+2;
     	yy=yy-1.5;
     	dingdian();
     	koupan=*P_IOB_Data;
     	koupan&=0x0f00;
     	if(koupan!=0x0f00)
		{
            break;
		}   
     	xx=xx-2;
     	yy=yy+1.5;
     	dingdian(); 
     	stopxun=1;
     	break;
    }
}
    
//=========================================================================================    
//
//=========================================================================================
void  huifu(void)
{
        //Cls();      //清屏
	Write_instruction(0x80);  //写地址
	WriteLCDData(73);
    WriteLCDData(110);
    WriteLCDData(112);
    WriteLCDData(117);
    WriteLCDData(116); 
    WriteLCDData(126);
    WriteLCDData(32);
	WriteLCDData(88);       //写数据      x
	WriteLCDData(61);  
	WriteLCDData(32);       //写数据
	WriteLCDData(32);  
	WriteLCDData(32);
	Write_instruction(0x8c);  //写地址
	    //WriteLCDData(44); 
	WriteLCDData(89);       //写数据     y
	WriteLCDData(61);  
	WriteLCDData(32);       //写数据
	WriteLCDData(32);
	Write_instruction(0x89);  //写地址   
}
//=========================================================================================
//
//=========================================================================================
void   guiwei(void)
{
	xx=0;
    yy=0;
    dingdian();
}
//=========================================================================================
//
//=========================================================================================
void   ziyou(void)
{
	xx=20;
    yy=85;
    dingdian(); 
    xx=25;
    yy=85;
    dingdian(); 
    xx=30;
    yy=85;
    dingdian(); 
    xx=35;
    yy=85;
    dingdian(); 
    xx=40;
    yy=85;
    dingdian(); 
    xx=45;
    yy=85;
    dingdian(); 
    xx=50;
    yy=85;
    dingdian(); 
    xx=55;
    yy=85;
    dingdian(); 
    xx=60;
    yy=85;
    dingdian(); 
    xx=65;
    yy=85;
    dingdian(); 
    xx=70;
    yy=85;
    dingdian();   
}
//=========================================================================================
//
//=========================================================================================
void  jisuan(void)
{
	x0=aa[0];x1=aa[1];
	y00=aa[2];y11=aa[3];
	                     
	a1=x0*10; b1=y00*10;
	a2=x1;  b2=y11;
	xx=a1+a2;                 //计算出其输入的座标(xx,yy)
	yy=b1+b2;      
}
//=========================================================================================
//
//=========================================================================================
void  dingdian(void)                           //寻找定点
{
	long int  gg,i,j;
	unsigned long int xxx=0,yyy=0;
    unsigned  int  kk1,kk2,kk3=0;
    unsigned  int  sign1=0,sign2=0;
    unsigned long int  nnn,ppp;
    unsigned  int mmm;
    float  v2,u2,v21,v22,u21,u22;
    x=xx;y=yy;
    v1=sqrtf(15*15+113*113);
    v21=(x+15)*(x+15);
    v22=(113-y)*(113-y);
    v2=sqrtf(v21+v22);
    ss1=(v1-v2)*671.53;   //所需走的步数a
                                   
    u1=sqrtf(95*95+113*113);
    u21=(95-x)*(95-x);
    u22=(113-y)*(113-y);
    u2=sqrtf(u21+u22);
    ss2=(u1-u2)*671.53;  //所需走的步数b
    wc1=ss1-l1;
    wc2=ss2-l2;
         
    if(wc1>=0)
    {
    	Set_IOA_Bit(13,1,1,1,1);
        loop1=1;
    }   
    else  {Set_IOA_Bit(13,1,1,0,0); wc1=-wc1;loop1=0;}
    if(wc2>=0) 
    {
    	Set_IOA_Bit(11,1,1,1,1);
     	loop2=1;
    }
    else  {Set_IOA_Bit(11,1,1,0,0); wc2=-wc2;loop2=0;}
    
 //************************************************************* 
  	nnn=50*wc2/wc1;   
    while(1)
   	{
   		if(xxx==wc1) break;
      	for(mmm=0;mmm<50;mmm++)
      	{
      		Set_IOA_Bit(14,1,1,1,1);
        	ddelay();
        	Set_IOA_Bit(14,1,1,0,0);
        	xxx++;
        
       		if(loop1==1)
          	l1++;
      		else  l1--;
      		if(xxx==wc1) break;
        	if((xxx>=500)&&(xxx%500==0))   display();
      	}
   
      	if(xxx==wc1) break;
      	for(mmm=0;mmm<nnn;mmm++)
      	{
      		Set_IOA_Bit(12,1,1,1,1);
        	ddelay();
        	Set_IOA_Bit(12,1,1,0,0);
     		yyy++;
     		if(loop2==1)
          	l2++;
      		else  l2--; 
	  	}  
	}
   	ppp=wc2-yyy;
   	for(mmm=0;mmm<ppp;mmm++)
   	{
   		Set_IOA_Bit(12,1,1,1,1);
     	ddelay();
     	Set_IOA_Bit(12,1,1,0,0);
     	y++;
      	if(loop2==1)
        	l2++;
      	else  l2--;
   	}
   	
  	// l1=ss1;              //当前脉冲数坐标
  	// l2=ss2;
   	display();
}
//=========================================================================================
//
//=========================================================================================
void display(void)
{
    float  mianji,sss,tem,tem1,tem2,tem3,tem4;
    float  bian1,bian2;
    unsigned int zong,heng,heng2,zong2;
    
    bian1=v1-l1/671.53;
    bian2=u1-l2/671.53;
      
    sss=(bian1+bian2+110)/2;
      
    tem1=sss-bian1;
    tem2=sss-bian2;
    tem3=sss-110;
    tem4=tem1*tem2*tem3*sss;
    mianji=sqrtf(tem4);
    zong1=113-mianji/55.0;
    tem=bian1*bian1-(113-zong1)*(113-zong1);
    heng1=sqrtf(tem)-15;
    heng=heng1;
    zong=zong1;
    heng2=(heng1-heng)*10;
    zong2=(zong1-zong)*10;
    if(heng2>=5) heng++;
    if(zong2>=5) zong++;
    Write_instruction(200); 
    WriteLCDData(heng/10+48);
    WriteLCDData(heng%10+48);
    
    Write_instruction(205);
    WriteLCDData(zong/10+48);
    WriteLCDData(zong%10+48);
 
}
//=========================================================================================
/////////////////////////显示模块开始/////////////////////////////////////////////
//=========================================================================================     
void SP_Init1_IOA08(void)  //设置IOA口的低8位为悬浮式输入引脚    
 {
     Set_IOA_Bit(0,0,1,1,1); 
     Set_IOA_Bit(1,0,1,1,1);
     Set_IOA_Bit(2,0,1,1,1);
     Set_IOA_Bit(3,0,1,1,1);
     Set_IOA_Bit(4,0,1,1,1);
     Set_IOA_Bit(5,0,1,1,1);
     Set_IOA_Bit(6,0,1,1,1);
     Set_IOA_Bit(7,0,1,1,1);
  }
//=========================================================================================
//
//=========================================================================================  
 void SP_Init2_IOA08(void)  //设置IOA口的低8位同相高电平输出
  {
     Set_IOA_Bit(0,1,1,1,1); 
     Set_IOA_Bit(1,1,1,1,1);
     Set_IOA_Bit(2,1,1,1,1);
     Set_IOA_Bit(3,1,1,1,1);
     Set_IOA_Bit(4,1,1,1,1);
     Set_IOA_Bit(5,1,1,1,1);
     Set_IOA_Bit(6,1,1,1,1);
     Set_IOA_Bit(7,1,1,1,1);
  }      

//=========================================================================================     
//
//=========================================================================================     
void CheckBusy(void)
{    
	int i;
   	Set_IOA_Bit(8,1,1,0,0);    // CLR ENABLE
    Delay();
    Set_IOA_Bit(9,1,1,1,1);    // SETB R/W
    Delay();
    Set_IOA_Bit(10,1,1,0,0);   // CLR RS
    Delay();
    Set_IOA_Bit(8,1,1,1,1);  //SETB ENABLE
    Delay();
     
    SP_Init1_IOA08(); 
    i=*P_IOA_Data;
    Set_IOA_Bit(8,1,1,0,0);    // CLR ENABLE
    Delay();
    i&=0x0080;
    while(i==0x0080)
    {  
    	Set_IOA_Bit(8,1,1,0,0);    // CLR ENABLE
        Delay();
        Set_IOA_Bit(9,1,1,1,1);    // SETB R/W
        Delay();
        Set_IOA_Bit(10,1,1,0,0);   // CLR RS
        Delay();
        Set_IOA_Bit(8,1,1,1,1);  //SETB ENABLE
        Delay();
      
        SP_Init1_IOA08(); 
        i=*P_IOA_Data;
        Set_IOA_Bit(8,1,1,0,0);    // CLR ENABLE   
        Delay();
	}
    Delay();
}
  
//=========================================================================================
//
//=========================================================================================  
void Write_instruction(int j)
{
	int a;  
    CheckBusy();
    Set_IOA_Bit(8,1,1,0,0);    // CLR ENABLE
    Delay();
    Set_IOA_Bit(9,1,1,0,0);    // CLR R/W 
    Delay();
    Set_IOA_Bit(10,1,1,0,0);   // CLR RS 
    Delay();
    Set_IOA_Bit(8,1,1,1,1);  //SETB ENABLE 
    Delay();
    SP_Init2_IOA08();  //输出
    a=*P_IOA_Data&0xff00;
    j=j|a;
    *P_IOA_Data=j;
    Set_IOA_Bit(8,1,1,0,0);    // CLR ENABLE
    Delay();
}
    
//=========================================================================================    
//
//=========================================================================================
void WriteLCDData(int k) 
{  
	int b;
   	CheckBusy();
    Set_IOA_Bit(8,1,1,0,0);    // CLR ENABLE
    Delay();
    Set_IOA_Bit(9,1,1,0,0);    // CLR R/W 
    Delay();
    Set_IOA_Bit(10,1,1,1,1);   // SETB RS 
    Delay();     
    Set_IOA_Bit(8,1,1,1,1);  //SETB ENABLE
    Delay();      
    SP_Init2_IOA08();  //输出口
    b=*P_IOA_Data&0xff00;
    k=b|k;
    *P_IOA_Data=k;
    Set_IOA_Bit(8,1,1,0,0);    // CLR ENABLE
    Delay();
}      
//=========================================================================================
//
//=========================================================================================          
void Initial(void)
{    
	Write_instruction(0x38);
    Write_instruction(0x0e);      //当将该处改为0x0f时,光标闪烁
    Write_instruction(0x06);    //当将该处的数据改变为0x0c时,不显示光标,为0x06时显示光标
} 
//=========================================================================================
//
//========================================================================================= 
void Delay(void)
{  
	unsigned int m=0x0064;
    while(m--)
    *P_Watchdog_Clear=0x0001;
}

//=========================================================================================
//
//=========================================================================================
void Cls(void)
{   
    Write_instruction(1);
} 
      
/////////////////////////显示模块结束/////////////////////////////////////////////  

//=========================================================================================
//
//=========================================================================================
void  ddelay(void)
{
	unsigned ii=0x0070;
   	while(ii--)
    *P_Watchdog_Clear=0x0001;
}  

void PlayS480(int Result)
{ 
	int j,k,i;
	SACM_S480_Initial(1);                     //播放初始化,来自于SacmV26e.lib
	SACM_S480_Play(Result, 3, 3);
	while((SACM_S480_Status()&0x0001) != 0)   //填充队列播放,来自于SacmV26e.lib
	{
		SACM_S480_ServiceLoop();
		*P_Watchdog_Clear=0x0001;
	}
	SACM_S480_Stop();                          //停止播放,来自于SacmV26e.lib
	asm("FIQ OFF");    

}       

⌨️ 快捷键说明

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