这可能是一个长射,但我想我会给它一个射门。
基本上、我尝试手动获取1个字符、即使在通用20x4 LCD 屏幕上打印也是如此(专门购买 :https://www.adafruit.com/product/198)
我的代码是超级基本的、因为我基本上尝试用4位模式复制第42页上的"示例": https://cdn-shop.adafruit.com/datasheets/HD44780.pdf
下面是我的代码 :#include "tm4c123ghp6.h" #define PORTB (*(volatile unsigned long *) 0x400050FC) #define GPIO_PORTB_OUT (*(volatile unsigned long *) 0x400050FC)//位5-0 #define GPIO_PORTB_DIR_R (*(volatile unsigned long *) 0x40005400) #define GPIO_PORTB_AFSEL_R (*(volatile unsigned long *) 0x40005420) #define GPIO_PORTB_DEN_R (*(volatile unsigned long *) 0x4000551C) #define GPIO_PORTB_AMSEL_R (*(volatile unsigned long *) 0x40005528) #define GPIO_PORTB_PCTL_R (*(volatile unsigned long *) 0x4000552C) #define GPIO_Porte _IN (*(volatile unsigned long *) 0x4002400C)//位1-0 #define SENSOR (*((volatile unsigned long *) 0x4002400C) #define GPIO_PORT_DIR_R (*(volatile unsigned long *) 0x40024400) #define GPIO_Porte _AFSEL_R (*(volatile unsigned long *) 0x40024420) #define GPIO_Porte _DEN_R (*(volatile unsigned long *) 0x4002451C) #define GPIO_Porte _AMSEL_R (*(volatile unsigned long *) 0x40024528) #define GPIO_Porte _PCTL_R (*(volatile unsigned long *) 0x4002452C) #define SYSCTL_RCGC2_R (*(volatile unsigned long *) 0x400FE108) #define SYSCTL_RCGC2_GPIOE 0x00000010 //端口 E 时钟门控控制 #define SYSCTL_RCGC2_GPIOB 0x00000002 //端口 B 时钟门控控制 //假设连接 PB3-PB0 = D7-D4 // RS = PB4 // EN = PB5 //输入:delayMS 的 msec 数 //输出:none void delayMS (unsigned long msec){ unsigned long count; while (msec > 0){//在仍有 delayMS 时重复 计数= 16000;//大约1ms while (count > 0){ count--; } //此 while 循环大约需要3个周期 msec--; } }int main (void){ volatile unsigned long delay; SYSCTL_RCGC2_R |= 0x12; // 1) B E delay = SYSCTL_RCGC2_R; // 2)无需解锁 GPIO_PORTB_AMSEL_R &=~0x3F;// 3)禁用 PB5-0 GPIO_PORTB_PCTL_R 上的模拟功能&&~ ~0x00FFFFFF;// 4)启用常规 GPIO GPIO_PORTB_DIR_R |= 0x3F;// 5) PB5_ORTB_R 上的输出 ;// 0 GPIO_0 = 0xTB_R 0或 PBORSEL 上的0 while (1){ PORTB = 0x02; delayMS (5); PORTB = 0x12;//启用 delayMS (5); PORTB = 0x02;//使能关闭 PORTB = 0x02; delayMS (5); PORTB = 0x12;//启用 delayMS (5); PORTB = 0x02;//使能关闭 PORTB = 0x10;//启用 delayMS (5); PORTB = 0x00;//使能关闭 PORTB = 0x10;//启用 delayMS (5); PORTB = 0x00;//使能关闭 PORTB = 0x10;//启用 delayMS (5); PORTB = 0x2E; delayMS (5); PORTB = 0x00;//使能关闭 PORTB = 0x10;//启用 delayMS (5); PORTB = 0x26; delayMS (5); PORTB = 0x00;//使能关闭 PORTB = 0x10;//启用 delayMS (5); PORTB = 0x34; delayMS (5); PORTB = 0x00;//使能关闭 PORTB = 0x10;//启用 delayMS (5); PORTB = 0x38; delayMS (5); PORTB = 0x00;//使能关闭 PORTB = 0x00; delayMS (5); PORTB |= 0x00; delayMS (5); PORTB |= 0x00; } }
它非常基本、因为我对使用 Tiva 板非常陌生。 我可以执行基本的 GPIO 操作、但没有什么花哨的东西。 我还意识到 HAL 库存在..但我只是尝试在调试器中按照这个"示例"代码发送准确的命令。 我没有 R/W连接,它接地。 Enable 是 PB5、 RS 是 PB4、是 DB7-DB4 PB3-0
我确信它已连接到试验电路板上。 但我确信我只是遗漏了一些明显的东西。 我阅读了数据表,根据我的理解,我需要将 enable high-->do command---> Turn enable off? 因此、我尝试使用较小的延迟。
有什么想法吗? 这可能不是合适的论坛、但我想我会给它一个机会。