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

📄 dio.c

📁 MS320F2812 Sci驱动程序
💻 C
字号:
#include "DSP28_Device.h"


unsigned int * AZ_INH0 = (unsigned int *) 0x00100000;
unsigned int * AZ_RDC  = (unsigned int *) 0x00100002;
unsigned int * AZ_INH1 = (unsigned int *) 0x0010000C;

unsigned int * EL_INH0 = (unsigned int *) 0x00100006;
unsigned int * EL_RDC  = (unsigned int *) 0x00100008;
unsigned int * EL_INH1 = (unsigned int *) 0x0010000A;

unsigned int * DIG_IN  = (unsigned int *) 0x00100010;
unsigned int * DIG_OUT = (unsigned int *) 0x00100012;

unsigned int * KEY_ROW = (unsigned int *) 0x00100014;
unsigned int * KEY_COL = (unsigned int *) 0x00100016;

unsigned int * LED_DISP = (unsigned int *) 0x00100018;

/*void InhibitRDC(int port)
{
	int data;
	if(port == 1)
	{
		data = *AZ_INH0;
	}
	if(port == 2)
	{
		data = *EL_INH0;
	}
}

void FreeRDC(int port)
{
	int data;
	if(port == 1)
	{
		data = *AZ_INH1;
	}
	if(port == 2)
	{
		data = *EL_INH1;
	}
}*/

unsigned int ReadRDC(int axis)
{
	unsigned int RdcValue, xdata;
	if(axis == 1)
	{
		xdata = *AZ_INH0;
		RdcValue = *AZ_RDC;
		xdata = *AZ_INH1;
	}
	if(axis == 2)
	{
		xdata = *EL_INH0;
		RdcValue = *EL_RDC;
		xdata = *EL_INH1;
	}
	return RdcValue;
}		


int KeyTable[4][4] ={ 0x01, 0x02, 0x03, 0x0A,
					  0x04, 0x05, 0x06, 0x0B,
					  0x07, 0x08, 0x09, 0x0C,
					  0x0F, 0x00, 0x0E, 0x0D};
					  
int PollingKey(void)
{
	int key_row;
	int key_col;
	int key_val;
	int key_cnt;
	
	for(key_cnt=0; key_cnt<4; key_cnt++)
	{
		key_row = ~(0x01 << key_cnt);
		*KEY_ROW = key_row;
		key_col = *KEY_COL;
		key_col = key_col & 0x0F;
		if(key_col != 0x0F)
		{
			switch(key_col)
			{
				case 0x0E:
					key_val = KeyTable[key_cnt][0];
					break;
				case 0x0D:
					key_val = KeyTable[key_cnt][1];
					break;	
				case 0x0B:
					key_val = KeyTable[key_cnt][2];
					break;
				case 0x07:
					key_val = KeyTable[key_cnt][3];
					break;	
				default:
					key_val = -1;
					break;
			}
			return key_val;
		}
	}
	return -1;
}

int PreKeyVal = 0xFFFF;

int ProcessKey(void)
{
	int key_val;
	
	key_val = PollingKey();
	if(key_val != PreKeyVal)
	{
		PreKeyVal = key_val;
		return key_val;
	}
	else
	{
		return 0xFFFF;
	}
}

int KeyBuff[10];	
//Header Axis Sign Data5 Data4 Data3 Data2 Data1 End
//0x0C   1/2  0/1  0-3   0-9   0-9   0-9   0-9   0x0D
int KeyCnt = 0;
int AzZeroPos = 0;
int ElZeroPos = 0;
int AzDefaultZeroPos = 0;
int ElDefaultZeroPos = 0;
int PressedKeyValue = 0;
int BreakFlag = 0;

int KeyInput(void)
{
	int PressedKey;
	int SetValue;
	PressedKey = ProcessKey();
	if(PressedKey != 0xFFFF)
	{
		if(PressedKey == 0x0A)
		{
			DisplayType = 1;
			return 0;
		}
		if(PressedKey == 0x0E)
		{
			DisplayType = 2;
			return 0;
		}
		
		if(PressedKey == 0x0B)
		{
			DisplayType = 5;
			if(BreakFlag == 0)
				BreakFlag = 1;
			else
				BreakFlag = 0;
			return 0;
		}

		if(PressedKey == 0x0C)
		{
			KeyCnt = 1;
			KeyBuff[0]= 0x0C;
			DisplayType = 0;
			return 0;
		}
		else if(PressedKey == 0x0D)
		{
			if(KeyCnt != 8)
			{
				KeyCnt = 0;
				return 0;
			}
			else
			{
				SetValue = KeyBuff[7]+KeyBuff[6]*10+KeyBuff[5]*100
						   +KeyBuff[4]*1000+KeyBuff[3]*10000;
				if(KeyBuff[2] != 0)
					SetValue = -SetValue;
				if(KeyBuff[1] == 1)
				{
					AzZeroPos = SetValue;
					DisplayType = 3;
				}
				if(KeyBuff[1] == 2)
				{
					ElZeroPos = SetValue;
					DisplayType = 4;
				}
				KeyCnt = 0;
				return 1;
			}
				
		}
		else 
		{
			if(KeyCnt != 0)
			{	
				PressedKeyValue = PressedKey;
				if((PressedKey >= 0) && (PressedKey <= 0x09))
				{
					KeyBuff[KeyCnt] = PressedKey;
					KeyCnt++;
					if(KeyCnt > 8)
					{
						KeyCnt = 0;
						return 0;
					}
				}
			}
		}
		
	}
	
	return 0;
}

void Display(int type, unsigned int value)
{
	unsigned int led_val;
	unsigned int led_sel;
	unsigned int disp_val;
	unsigned int tmp;
	int led_cnt;
	
	disp_val = value;
	
	led_val = 0xDF00 | type;
	*LED_DISP = led_val;
	led_val = 0xFF00 | type;
	*LED_DISP = led_val;	
	
	for(led_cnt=0; led_cnt<5; led_cnt++)
	{
		tmp = disp_val%10;
		led_sel = (~(0x01<<(led_cnt+8)))&0xFF00;
		led_val = led_sel | tmp;
		*LED_DISP = led_val;
		led_val = 0xFF00 | tmp;
		*LED_DISP = led_val;
		disp_val = (disp_val/10);
	}
/*	led_val = 0xFE00;
	*LED_DISP = led_val;
	led_val = 0xFF00;
	*LED_DISP = led_val;	*/
}

unsigned int ReadDigitalInput(void)
{
	return *DIG_IN;
}

void ProcessDigInput(unsigned int di_value)
{
	if((di_value & ENABLED) != 0)
	{
		if((di_value & LEFT_TURN) != 0)
		{
			Azimuth -= 50;	//0.27Deg
			if(Azimuth <-30000)		//-165Deg
				Azimuth = -3000;
		}
		else if((di_value & RIGHT_TURN) != 0)
		{
			Azimuth += 50;		
			if(Azimuth > 30000)		//165Deg
				Azimuth = 30000;
		}
		else
		{
			//NOP
		}
		
		if((di_value & UP_TURN) != 0)
		{
			Elevation += 50;
			if(Elevation > 20000)	//120Deg
				Elevation = 20000;
		}
		else if((di_value & DOWN_TURN) != 0)
		{
			Elevation -= 50;
			if(Elevation < -4000)	//-20Deg
				Elevation = -4000;		
		}
		else
		{
			//NOP
		}	
	}	
		
}

int DoVal = 0;

void WriteDigitalOutput(unsigned int do_val)
{
	*DIG_OUT = do_val;
	DoVal = do_val;
}

void SetDoBit(int bit)
{
	int DoBit = 1;
	
	DoBit <<= bit;
	DoVal |= DoBit;
	
	*DIG_OUT = DoVal;
}

void ClrDoBit(int bit)
{
	int DoBit = 1;
	
	DoBit <<= bit;
	DoBit = ~DoBit;
	DoVal &= DoBit;
	
	*DIG_OUT = DoVal;
}

/*=========================================
	no more
=========================================*/

⌨️ 快捷键说明

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