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

📄 i2c_gpio.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
字号:
#include "triton_ldo_test.h"
#include "UART_irDA.h"

extern UWORD16 AbbDeviceAddress ; 
void GPIO_Eh_high();
void GPIO_Eh_low();
void GPIO_E_high();
void GPIO_E_low();
void GPIO_E_high_Tca6408();
void GPIO_E_low_Tca6408();




void I2C_GPIO()
{

	unsigned short val ;

	UWORD16 Restult_Test = 0;
	int option,gpio_e_num;
  /* I2c interface initialization */
  MSI2C_InitConnectionGPIO();

	while(option)
	{
		UART_Printf(UART2,"==================================================\r\n");
	  	UART_Printf(UART2,"=       I2C to GPIO  TEST                        =\r\n");
	  	UART_Printf(UART2,"==================================================\r\n");      
	  
	    UART_Printf(UART2," 0: Back to upper menu\r\n");
		UART_Printf(UART2," 1: GPIO_E_Tca6408 output high lever\n\r");
		UART_Printf(UART2," 2: GPIO_E_Tca6408 output low lever\n\r");
		UART_Printf(UART2," 3: GPIO_E output high lever\n\r");
		UART_Printf(UART2," 4: GPIO_E output low lever\n\r");

		UART_Printf(UART2," Your choice : \n\r");

	        option=UART_GetNum(UART2);
	        
	        switch(option)
	        {
			case 0:
			  break;

	        case 1:
				UART_Printf(UART2,"Please input GPIO_E number\n\r");
	        	gpio_e_num=UART_GetNum(UART2);
	           	GPIO_E_high_Tca6408(gpio_e_num);
	        break;
	        
	        case 2:
				UART_Printf(UART2,"Please input GPIO_E number\n\r");
	        	gpio_e_num=UART_GetNum(UART2);
	           	GPIO_E_low_Tca6408(gpio_e_num);
	        break;

	        case 3:
				UART_Printf(UART2,"Please input GPIO_E number\n\r");
	        	gpio_e_num=UART_GetNum(UART2);
	         	GPIO_E_high(gpio_e_num);
	        break;

	        case 4:
				UART_Printf(UART2,"Please input GPIO_E number\n\r");
	        	gpio_e_num=UART_GetNum(UART2);
	         	GPIO_E_low(gpio_e_num);
	        break;
	        default:
	        break;
	        }
	}
}


void GPIO_E_high_Tca6408(gpio_e_num)
{
	int previous_content, num;
	int outputadd,reverseadd,directionadd;
	num = gpio_e_num;
	outputadd=0x01;
	reverseadd=0x02;
	directionadd=0x03;
	

	//device ID 0x20,address 0x03

  	previous_content = MSI2C_MasterPollingReceive(AbbDeviceAddressI2C,outputadd);
  	MSI2C_MasterPollingSend(AbbDeviceAddressI2C, outputadd,previous_content|(0x1<<num));
  
 
   previous_content = MSI2C_MasterPollingReceive(AbbDeviceAddressI2C, reverseadd);
   MSI2C_MasterPollingSend(AbbDeviceAddressI2C, reverseadd,previous_content&(~(0x1<<num)));
  
    previous_content = MSI2C_MasterPollingReceive(AbbDeviceAddressI2C, directionadd);
   MSI2C_MasterPollingSend(AbbDeviceAddressI2C, directionadd,previous_content&(~(0x1<<num)));
 
}


void GPIO_E_low_Tca6408(gpio_e_num)
{
	int previous_content, num;
	int outputadd,reverseadd,directionadd;
	num = gpio_e_num;
	outputadd=0x01;
	reverseadd=0x02;
	directionadd=0x03;

	//device ID 0x20,address 0x03

  	previous_content = MSI2C_MasterPollingReceive(AbbDeviceAddressI2C,outputadd);
  	MSI2C_MasterPollingSend(AbbDeviceAddressI2C, outputadd,previous_content&(~(0x1<<num)));
  
 
   previous_content = MSI2C_MasterPollingReceive(AbbDeviceAddressI2C, reverseadd);
   MSI2C_MasterPollingSend(AbbDeviceAddressI2C, reverseadd,previous_content&(~(0x1<<num)));
  
    previous_content = MSI2C_MasterPollingReceive(AbbDeviceAddressI2C, directionadd);
   MSI2C_MasterPollingSend(AbbDeviceAddressI2C, directionadd,previous_content&(~(0x1<<num)));
 
}

void GPIO_E_high(gpio_e_num)
{
	int previous_content, num;
	int outputadd,reverseadd,directionadd;
	num = gpio_e_num;
	if(num>9)
	{
		num = gpio_e_num-10;
		outputadd=0x03;
		reverseadd=0x05;
		directionadd=0x07;
	}
	else
	{
		num = gpio_e_num;
		outputadd=0x02;
		reverseadd=0x04;
		directionadd=0x06;
	}


  	previous_content = MSI2C_MasterPollingReceiveAbb(outputadd);
  	MSI2C_MasterPollingSendAbb(outputadd,previous_content|(0x1<<num));
  
 
   previous_content = MSI2C_MasterPollingReceiveAbb(reverseadd);
  MSI2C_MasterPollingSendAbb(reverseadd,previous_content&(~(0x1<<num)));
  
    previous_content = MSI2C_MasterPollingReceiveAbb(directionadd);
  MSI2C_MasterPollingSendAbb(directionadd,previous_content&(~(0x1<<num)));
 
}

void GPIO_E_low(gpio_e_num)
{
	int previous_content, num;
	int outputadd,reverseadd,directionadd;
	num = gpio_e_num;
	if(num>9)
	{
		num = gpio_e_num-10;
		outputadd=0x03;
		reverseadd=0x05;
		directionadd=0x07;
	}
	else
	{
		num = gpio_e_num;
		outputadd=0x02;
		reverseadd=0x04;
		directionadd=0x06;
	}
  	previous_content = MSI2C_MasterPollingReceiveAbb(outputadd);
  	MSI2C_MasterPollingSendAbb(outputadd,previous_content&(~(0x1<<num)));
  
 
    previous_content = MSI2C_MasterPollingReceiveAbb(reverseadd);
    MSI2C_MasterPollingSendAbb(reverseadd,previous_content&(~(0x1<<num)));
  
    previous_content = MSI2C_MasterPollingReceiveAbb(directionadd);
    MSI2C_MasterPollingSendAbb(directionadd,previous_content&(~(0x1<<num)));
 
}


void GPIO_Eh_high()
{
	int previous_content;
  previous_content = MSI2C_MasterPollingReceiveAbb(0x3);
  MSI2C_MasterPollingSendAbb(0x03,0xff);
  
 
   previous_content = MSI2C_MasterPollingReceiveAbb(0x5);
  MSI2C_MasterPollingSendAbb(0x05,0);
  
    previous_content = MSI2C_MasterPollingReceiveAbb(0x7);
  MSI2C_MasterPollingSendAbb(0x07,0);
 
}

void GPIO_Eh_low()
{
	int previous_content;
  previous_content = MSI2C_MasterPollingReceiveAbb(0x3);
  MSI2C_MasterPollingSendAbb(0x03,0x00);
  
 
   previous_content = MSI2C_MasterPollingReceiveAbb(0x5);
  MSI2C_MasterPollingSendAbb(0x05,0);
  
    previous_content = MSI2C_MasterPollingReceiveAbb(0x7);
  MSI2C_MasterPollingSendAbb(0x07,0);
 
}





void Tca6408_menu(void)
{
int temp;
MSI2C_InitConnectionAbb();
//MSI2C_MasterPollingSend(0x20,0x00,0x80);
temp=MSI2C_MasterPollingReceive(0x20,0x03);//device ID 0x20,address 0x03
MSI2C_MasterPollingSend(0x20,0x03,0x7f);   //set GPIO7 direction
MSI2C_MasterPollingSend(0x20,0x01,0xff); //set GPIO7 high
MSI2C_MasterPollingSend(0x20,0x01,0x0f);//set GPIO7 low
MSI2C_MasterPollingSend(0x20,0x01,0xff);
//MSI2C_MasterPollingSend(0x20,0x00,0x8e);
temp=MSI2C_MasterPollingReceive(0x20,0x00);


}

⌨️ 快捷键说明

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