我有一个 TM4C129ENCZAD 微控制器、用于通过 Telnet 控制 GPIO。 我已经修改了 shell 环境、通过 telnet 通过一些简单的命令来控制 GPIO 输出。
使用以下代码关闭了中的 GPIO、
static void open(char *str) { if (str[1] == '0'){ ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_6, 0); shell_output("<0>",""); } if (str[1] == '1'){ ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0); shell_output("<0>",""); } if (str[1] == '2'){ ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0); shell_output("<0>",""); } if (str[1] == '3'){ ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, 0); shell_output("<0>",""); } if (str[1] == '4'){ ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 0); shell_output("<0>",""); } if (str[1] == '5'){ ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0); shell_output("<0>",""); } if (str[1] == '6'){ ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, 0); shell_output("<0>",""); } if (str[1] == '7'){ ROM_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_1, 0); shell_output("<0>",""); } if (str[1] == '8'){ ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0); shell_output("<0>",""); } if (str[1] == '9'){ ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_2, 0); shell_output("<0>",""); } if (str[1] == 'A'){ ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0); shell_output("<0>",""); } if (str[1] == 'B'){ ROM_GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0, 0); shell_output("<0>",""); } if (str[1] == 'C'){ ROM_GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_2, 0); shell_output("<0>",""); } if (str[1] == 'D'){ ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0); shell_output("<0>",""); } if (str[1] == 'E'){ ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0); shell_output("<0>",""); } if (str[1] == 'F'){ ROM_GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_6, 0); shell_output("<0>",""); } if (str[1] == 'G'){ ROM_GPIOPinWrite(GPIO_PORTR_BASE, GPIO_PIN_5, 0); shell_output("<0>",""); } if (str[1] == 'H'){ ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_2, 0); shell_output("<0>",""); } if (str[1] == 'I'){ ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_3, 0); shell_output("<0>",""); } if (str[1] == 'J'){ ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_6, 0); shell_output("<0>",""); } }
使用 以下代码打开 GPIO 引脚、
static void close(char *str) { if (str[1] == '0'){ ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_6, GPIO_PIN_6); shell_output("<1>",""); } if (str[1] == '1'){ ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5); shell_output("<1>",""); } if (str[1] == '2'){ ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_PIN_4); shell_output("<1>",""); } if (str[1] == '3'){ ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, GPIO_PIN_4); shell_output("<1>",""); } if (str[1] == '4'){ ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_PIN_6); shell_output("<1>",""); } if (str[1] == '5'){ ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_PIN_1); shell_output("<1>",""); } if (str[1] == '6'){ ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_PIN_3); shell_output("<1>",""); } if (str[1] == '7'){ ROM_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_1, GPIO_PIN_1); shell_output("<1>",""); } if (str[1] == '8'){ ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7); shell_output("<1>",""); } if (str[1] == '9'){ ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_2, GPIO_PIN_2); shell_output("<1>",""); } if (str[1] == 'A'){ ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_PIN_1); shell_output("<1>",""); } if (str[1] == 'B'){ ROM_GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0, GPIO_PIN_0); shell_output("<1>",""); } if (str[1] == 'C'){ ROM_GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_2, GPIO_PIN_2); shell_output("<1>",""); } if (str[1] == 'D'){ ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, GPIO_PIN_6); shell_output("<1>",""); } if (str[1] == 'E'){ ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_PIN_5); shell_output("<1>",""); } if (str[1] == 'F'){ ROM_GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_6, GPIO_PIN_6); shell_output("<1>",""); } if (str[1] == 'G'){ ROM_GPIOPinWrite(GPIO_PORTR_BASE, GPIO_PIN_5, GPIO_PIN_5); shell_output("<1>",""); } if (str[1] == 'H'){ ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_2, GPIO_PIN_2); shell_output("<1>",""); } if (str[1] == 'I'){ ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_3, GPIO_PIN_3); shell_output("<1>",""); } if (str[1] == 'J'){ ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_6, GPIO_PIN_6); shell_output("<1>",""); } }
使用以下代码检查 GPIO 引脚、
static void status(char *str) { if (str[1] == '0') { if (ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_6)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '1') { if (ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '2') { if (ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '3') { if (ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_4)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '4') { if (ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_6)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '5') { if (ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_1)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '6') { if (ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_3)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '7') { if (ROM_GPIOPinRead(GPIO_PORTQ_BASE, GPIO_PIN_1)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '8') { if (ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_7)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == '9') { if (ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'A') { if (ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'B') { if (ROM_GPIOPinRead(GPIO_PORTK_BASE, GPIO_PIN_0)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'C') { if (ROM_GPIOPinRead(GPIO_PORTK_BASE, GPIO_PIN_2)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'D') { if (ROM_GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_6)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'E') { if (ROM_GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_5)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'F') { if (ROM_GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_6)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'G') { if (ROM_GPIOPinRead(GPIO_PORTR_BASE, GPIO_PIN_5)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'H') { if (ROM_GPIOPinRead(GPIO_PORTH_BASE, GPIO_PIN_2)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'I') { if (ROM_GPIOPinRead(GPIO_PORTH_BASE, GPIO_PIN_3)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } if (str[1] == 'J') { if (ROM_GPIOPinRead(GPIO_PORTH_BASE, GPIO_PIN_6)) { shell_output("<1>",""); } else { shell_output("<0>",""); } } }
我需要尽快打开/关闭 GPIO 引脚、但切换需要大约750毫秒。
在计算机中、我将通过 C#程序发送 telnet 命令来打开和关闭 GPIO 引脚。
在不验证微控制器是否正确切换的情况下发送打开或关闭命令将阻止某些 GPIO 引脚正确关闭/打开。
do { string close_result1 = cdf_muxes[card].close(channel); string close_result2 = cdf_muxes[card + 1].close(channel); if (close_result1.Contains("1")) cr1 = true; else cr1 = false; if (close_result2.Contains("1")) cr2 = true; else cr2 = false; } while (!(cr1 == true & cr2 == true));
bool or1 = false; bool or2 = false; do { string open_result1 = cdf_muxes[card].open(channel); string open_result2 = cdf_muxes[card + 1].open(channel); if (open_result1.Contains("0")) or1 = true; else or1 = false; if (open_result2.Contains("0")) or2 = true; else or2 = false; } while (!(or1 == true & or2 == true));
是否有人对如何减少打开/关闭 GPIO 引脚所需的时间有任何建议?
谢谢、
Allan