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

📄 test2407.c

📁 DSP部分功能测试 串口
💻 C
字号:
//------------------------------------//
//---test2407.c-----------------------//
//------------------------------------//

#include    "f2407_c.h"
#include 	"string.h"
//#include 	"math.h"
#include 	"stdlib.h"
#include 	"ioports.h"
#include 	"ctype.h"
//#include 	"time1.h"
//#include "register.h"
 

#define TERM_H {\
	*PBDATDIR = *PBDATDIR | 0x1010;\
	}

#define TERM_L {\
	*PBDATDIR= *PBDATDIR & 0xffef;\
	}

#define DIE_H {\
	*PBDATDIR = *PBDATDIR | 0x0404;\
	}

#define DIE_L {\
	*PBDATDIR= *PBDATDIR & 0xfffb;\
	}

#define OUTPUT port2000  
#define INPUT port4000      

#define INBUF_LEN 30
                   
volatile ioport unsigned int port2000;/*LED*/
volatile ioport unsigned int port4000;
extern unsigned char ucinput[14];
unsigned char ucSq; //限位信号00无,01,10,11
unsigned char  SciRecBuf[INBUF_LEN];
unsigned int read_flag;
unsigned int uipreangle;
unsigned char test=0;
unsigned int uiAutoUpPara1,uiAutoUpPara2,uiAutoUpPara3,uiAutoUpPara4;
unsigned long Encode_counter;
unsigned long Maxest_counter,Maxer_counter = 0;
unsigned long ulAutoUpPara;
//clock_t runtime0,runtime1,runtime;
char pc_qubai,pc_tuixiao,pc_impact,pc_fangbai;
int key_code;
unsigned int outputbuf;
extern char cParaNo;
extern char auto_qubai;
extern char autoUp_flag;
extern int uiRecNum;
extern unsigned int ReadArr[10];
extern unsigned int Len_RecChar;
void UartSent();

//禁止中断 
void inline disable_int()
{
	asm("	setc INTM");
	asm("	setc SXM");
}                                   
//使能总中断
void inline enable_int()
{
	asm("	clrc INTM");//hehe,the spaces is request!!
}

//--------------------- MAIN ROUTINE -------------------------------//
//IOPB0 : TERM--out;	IO_PB1 : DBIT_485--in;		IOPB2 : DI_E_485--in;//
//IOPB3 : ; 			IOPB4 : SDA_B24CXX--I/O; 	IOPB5 : SCL_B24CXX--out;//
//IOPB6:;	IOPB7:;//
void main(void)
{
	unsigned char wr_flag;
   	unsigned int d_ram,p_ram,t_sci,t_x25650,t_can,i;

  	unsigned int comarr[10];
//	asm("	setc CNF");
   	*WDCR  = 0x00E8;//看门狗
//    *SCSR1 = 0x00fd;
	*SCSR1 = 0x004d;//4Xclk SCICLKen EVA en EVB en 
   	*SCSR2 = (*SCSR2 | 0x000B) & 0x000F;
   	WSGR = 0x01c0;
  	*MCRA = 0x0003;     //enable SCI TXD & RXD    // group A pins 
   	*MCRA = *MCRA | 0x0018; //enable QEP1 & QEP2
//   *MCRA = 0x0000;//
   	*MCRB = 0xFEDC;                     // group B pins //
   	*MCRC = 0x0000;                     // group C pins //
	disable_int();
  // *IMR = 0x0000; 
	*IMR = 0x01;                     // clear the IMR register //
   	*IFR = 0xffff;                      // clear any pending core interrupts // 
   
 //  enable_int();
   	*WDKEY =0x5555;
   	*WDKEY =0xaaaa; 
   	*PCDATDIR=*PCDATDIR|0x2000;		//PC5 is output//


	OUTPUT = 0xffff;

	read_flag = 0;
	Encode_counter = 0 ;
	Maxest_counter = 0;
	pc_qubai=0x0;
	pc_tuixiao=0x0;
	pc_impact=0x0;
	pc_fangbai=0x0;
	outputbuf=0xffff;
	cParaNo = 0xff;
	Len_RecChar=0;
	uiRecNum=0;
	auto_qubai=0;
	autoUp_flag=1;
	wr_flag=0;
	for(i=0;i<14;i++)
	{
	ucinput[i]=0;
	}
//------------------//
//	*PADATDIR=*PADATDIR|0xff00;  //PA: is output//

	*PBDATDIR=*PBDATDIR|0xfdff; //IOPB1 is in, others out IOPB4:term
	
    delay(0);
	uipreangle = (unsigned int)(ReadPara(0x100,8));
	delay(0xff);
	ulAutoUpPara = ReadPara(0x200,8);
	uiAutoUpPara4 = (unsigned int)(ulAutoUpPara%100/2);
	ulAutoUpPara = ulAutoUpPara/100;
	uiAutoUpPara3 = (unsigned int)(ulAutoUpPara%100/2);
	ulAutoUpPara = ulAutoUpPara/100;
	uiAutoUpPara2 = (unsigned int)(ulAutoUpPara%100/2);
	ulAutoUpPara = ulAutoUpPara/100;
	uiAutoUpPara1 = (unsigned int)(ulAutoUpPara%100/2);	

	sci_init();   	
    QEPINIT();   
//	test24C16();
    while(1)
    {
//    	LEDTest(5);     				//LED TEST 原有//
//		OUTPUT = 0xffff;
//--------------------------------后加
		
		if (test ==0)
		{
			test = 1;
		}
		else test = 0;

		if((Encode_counter & 0xffff) < 0x7fff)
		{
			Maxest_counter = MaxerQep();
		}
		else
		{
			Maxer_counter = 0;
		}
		Encode_counter =(unsigned long) *T2CNT;	  

		TERM_L;
	//	OUTPUT = 0xffff;
		

    	delay(050);

	//	OUTPUT = 0xFDFF;    
		TERM_H;
		DIE_L;
		key_code = ~keyscan();

		if(ucinput[5]==1 && ucinput[6] == 1)
		{
			SetQep(uipreangle);
			Maxer_counter = 0;
		}
		//----置限位信号----------------------//
		ucSq = 0x0;
		if(ucinput[5] == 1)
		{
			ucSq = ucSq | 0x01;
		}
		else 
		{
			ucSq = ucSq & 0xfe;
		}
		if(ucinput[6] == 1)
		{
			ucSq = ucSq | 0x02;
		}
		else
		{
			ucSq = ucSq & 0xfd;
		}
		if(1==autoUp_flag)
			AutoUp();
		operation();
          /*SCI TEST*/
		DspAckSci();
		if(cParaNo == 0x40)
		{
			//重置预 angle
			EEPROM_LC256(comarr,0x100,0x00A1,8);
			for(i = 0;i<8;i++)
			{
				if(comarr[i] != ReadArr[i])
					wr_flag = 0x1;
			}
			if(wr_flag == 0x1)
			{
				EEPROM_LC256(ReadArr,0x100,0x00A0,8);
				wr_flag = 0;
			}
			//
			uipreangle = (unsigned int)(ReadPara(0x100,8));
			SetQep(uipreangle);
			cParaNo = 0xff;
		}
		if(cParaNo == 0x41)
		{
			//reset the autoup para
			EEPROM_LC256(ReadArr,0x200,0x00A0,8);
			ulAutoUpPara = ReadPara(0x200,8);
			uiAutoUpPara4 = (unsigned int)(ulAutoUpPara%100/2);
			ulAutoUpPara = ulAutoUpPara/100;
			uiAutoUpPara3 = (unsigned int)(ulAutoUpPara%100/2);
			ulAutoUpPara = ulAutoUpPara/100;
			uiAutoUpPara2 = (unsigned int)(ulAutoUpPara%100/2);
			ulAutoUpPara = ulAutoUpPara/100;
			uiAutoUpPara1 = (unsigned int)(ulAutoUpPara%100/2);
		
			cParaNo = 0xff;
		}
		if((Encode_counter & 0xffff) < 0x7fff)
		{
			Maxest_counter = MaxerQep();
		}
		else
		{
			Maxer_counter = 0;
		}
//    t_sci=test_sci();
		delay(140);
		if((Encode_counter & 0xffff) < 0x7fff)
		{
			Maxest_counter = MaxerQep();
		}
		else
		{
			Maxer_counter = 0;
		}
		delay(300);
    //if(t_sci==0)LEDflash(0x00fb); 
	
	
//----------------------------
	
	}

}                                       // end of main() //  

//----------------------------------------//
//----dong zuo control--------------------//
int operation()
{
	if((ucinput[0] == 0x1) || (pc_qubai ==0x1) || (auto_qubai == 0x1))
	{
		outputbuf = outputbuf & 0xfffe;
		OUTPUT = outputbuf;
		delay(0x1ff);
		pc_qubai = 0x0;
		autoUp_flag = 0x0;
		auto_qubai = 0x0;
	}
	if((ucinput[0] == 0x0) && (pc_qubai ==0x0))
	{
		outputbuf = outputbuf | 0x0001;
		OUTPUT = outputbuf;

	}
	if((ucinput[1] == 0x1) || (pc_tuixiao ==0x1))
	{
		outputbuf = outputbuf & 0xfffd;
		OUTPUT = outputbuf;
		delay(0x1ff);
		pc_tuixiao = 0x0;
	}
	if((ucinput[1] == 0x0) && (pc_tuixiao ==0x0))
	{
		outputbuf = outputbuf | 0x0002;
		OUTPUT = outputbuf;
	}
	if((ucinput[2] == 0x1) || (pc_impact ==0x1) && (ucinput[6] == 0x0))
	{
		outputbuf = outputbuf & 0xffef;//
		OUTPUT = outputbuf;
		delay(0x2ff);
		pc_impact = 0x0;
	}
	if((ucinput[2] == 0x0) && (pc_impact ==0x0))
	{
		outputbuf = outputbuf | 0x0010;
		OUTPUT = outputbuf;
	}
	if((ucinput[3] == 0x1) || (pc_fangbai ==0x1))
	{
		outputbuf = outputbuf & 0xffdf;
		OUTPUT = outputbuf;
		delay(0x1ff);
	//	pc_fangbai = 0x0;
	}
	if((ucinput[3] == 0x0) && (pc_fangbai ==0x0))
	{
		outputbuf = outputbuf | 0x002f;
		OUTPUT = outputbuf;
	}

	if(test = 0)
	{
		outputbuf = outputbuf & 0xffdf;
		OUTPUT = outputbuf;
	//	delay(0x1ff);
	//	pc_fangbai = 0x0;
	}
	if(test = 1)
	{
		outputbuf = outputbuf | 0x002f;
		OUTPUT = outputbuf;
	}



}

//-------------------------------------------------//
//---------中断------------------------------------//
//-------------------------------------------------//
void interrupt int111()
{
	switch( *PIVR)
	{
		case 6: UartRec();
		break;
		case 7: UartSent();
		break;
		default : enable_int() ;
	}
//	return;
}

void UartSent()
{
	*IFR = 0xffff;
	enable_int();
//	return;
}


void interrupt nothing()
{	
	*IFR = 0xffff;
	enable_int();
//	return;
}

/*
void interrupt nmiint()
{
	*IFR = 0xffff;
	*SCSR1 = *SCSR1 | 0x0001;
	enable_int();
	return;
}




*/

⌨️ 快捷键说明

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