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

📄 gpio.c.svn-base

📁 Spearhead2000 的 USB驱动程序
💻 SVN-BASE
字号:
#include <gpio.h>#include <uart.h>voidgpioWrite(unsigned char gpio_num, unsigned char gpio_val){//	*GPP_DIR &= ~(1 << gpio_num);	switch(gpio_num)	{	case 0x0:	   *GPP_DOUT0 = gpio_val;	   break;	case 0x1:	   *GPP_DOUT1 = gpio_val;	   break;	case 0x2:	   *GPP_DOUT2 = gpio_val;	   break;	case 0x3:	   *GPP_DOUT3 = gpio_val;	   break;	case 0x4:	   *GPP_DOUT4 = gpio_val;	   break;	case 0x5:	   *GPP_DOUT5 = gpio_val;	   break;	}}unsigned chargpioRead(unsigned char gpio_num){        unsigned char gpio_val = 0;	//	*GPP_DIR |= (1 << gpio_num);	gpio_val = (*GPP_DATA >> gpio_num);		return(gpio_val);}static char in_buf = 0;void gpio_test(void){	static char value;    	static char schedule;	 	schedule = 'r';		while(schedule != 's')	{		*GPP_DIR = 0x0000000f;		//		UART_tx_vec("select i for Input(0 <-> 3) or o for Output(4 <-> 5) IOs",strlen("select i for Input(0 <-> 3) or o for Output(4 <-> 5) IOs"));		UART_tx_vec("Test SPEARHEAD Leds",strlen("Test SPEARHEAD Leds"));//	    	while (!(UART_getc(&value)));		/*		switch(value)		{		case 'o':			*/			UART_tx_vec("select the value to send 0/1",strlen("select the value to send 0/1"));	    		while (!(UART_getc(&value)));			if (value == '0')UART_tx_vec("value is 0",strlen("value is 0")); 			else UART_tx_vec("value is 1",strlen("value is 1"));					UART_tx_vec("select the GPIO sender 4 <-> 5",strlen("select the GPIO sender 4 <-> 5"));	    		while (!(UART_getc(&in_buf)));					switch(in_buf)			{			case '4':				UART_tx_vec("GPIO 4",strlen("GPIO 4"));				if (value == '0') gpioWrite(4, 0); else gpioWrite(4, 1);			break;			case '5':				UART_tx_vec("GPIO 5",strlen("GPIO 5"));				if (value == '0') gpioWrite(5, 0); else gpioWrite(5, 1);			break;			default:				UART_tx_vec("Wrong selection!",strlen("Wrong selection!"));			break;			}/*		break;					case 'i':			UART_tx_vec("select the GPIO receiver 0 <-> 3",strlen("select the GPIO receiver 0 <-> 3"));	    		while (!(UART_getc(&in_buf)));					switch(in_buf)			{			case '0':				UART_tx_vec("GPIO 0",strlen("GPIO 0"));				UART_tx_vec("the received value is",strlen("the received value is"));				if (gpioRead(0) == 0) UART_tx_vec("0",strlen("0")); else UART_tx_vec("1",strlen("1"));			break;			case '1':				UART_tx_vec("GPIO 1",strlen("GPIO 1"));				UART_tx_vec("the received value is",strlen("the received value is"));				if (gpioRead(1) == 0) UART_tx_vec("0",strlen("0")); else UART_tx_vec("1",strlen("1"));			break;			case '2':				UART_tx_vec("GPIO 2",strlen("GPIO 2"));				UART_tx_vec("the received value is",strlen("the received value is"));				if (gpioRead(2) == 0) UART_tx_vec("0",strlen("0")); else UART_tx_vec("1",strlen("1"));			break;			case '3':				UART_tx_vec("GPIO 3",strlen("GPIO 3"));				UART_tx_vec("the received value is",strlen("the received value is"));				if (gpioRead(3) == 0) UART_tx_vec("0",strlen("0")); else UART_tx_vec("1",strlen("1"));			break;			default:				UART_tx_vec("Wrong selection!",strlen("Wrong selection!"));			break;			}		break;		}		*/			UART_tx_vec("press s to stop r to run",strlen("press s to stop r to run"));	while (!(UART_getc(&schedule)));	while (!(UART_putc(13)));	while (!(UART_putc(10)));	}}

⌨️ 快捷键说明

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