So this is probably a long shot, but I figured i'd give it a shot.
Basically im trying to manually get 1 character even printing on a generic 20x4 LCD screen (purchased this specifically: https://www.adafruit.com/product/198)
So my code is SUPER basic, because im basically trying to replicate their "example" on page 42 with 4 bit mode: https://cdn-shop.adafruit.com/datasheets/HD44780.pdf
here is my code: #include "tm4c123gh6pm.h" #define PORTB (*((volatile unsigned long *)0x400050FC)) #define GPIO_PORTB_OUT (*((volatile unsigned long *)0x400050FC)) // bits 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)) // bits 1-0 #define SENSOR (*((volatile unsigned long *)0x4002400C)) #define GPIO_PORTE_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 // port E Clock Gating Control #define SYSCTL_RCGC2_GPIOB 0x00000002 // port B Clock Gating Control // This assumes that the hookups PB3-PB0 = D7-D4 // RS = PB4 // EN = PB5 // Inputs: Number of msec to delayMS // Outputs: None void delayMS(unsigned long msec){ unsigned long count; while(msec > 0 ) { // repeat while there are still delayMS count = 16000; // about 1ms while (count > 0) { count--; } // This while loop takes approximately 3 cycles msec--; } } int main(void){ volatile unsigned long delay; SYSCTL_RCGC2_R |= 0x12; // 1) B E delay = SYSCTL_RCGC2_R; // 2) no need to unlock GPIO_PORTB_AMSEL_R &= ~0x3F; // 3) disable analog function on PB5-0 GPIO_PORTB_PCTL_R &= ~0x00FFFFFF; // 4) enable regular GPIO GPIO_PORTB_DIR_R |= 0x3F; // 5) outputs on PB5-0 GPIO_PORTB_AFSEL_R &= ~0x3F; // 6) regular function on PB5-0 GPIO_PORTB_DEN_R |= 0x3F; // 7) enable digital on PB5-0 while(1){ PORTB = 0x02; delayMS(5); PORTB = 0x12; //enable on delayMS(5); PORTB = 0x02; //enable off PORTB = 0x02; delayMS(5); PORTB = 0x12; //enable on delayMS(5); PORTB = 0x02; //enable off PORTB = 0x10; //enable on delayMS(5); PORTB = 0x00; //enable off PORTB = 0x10; //enable on delayMS(5); PORTB = 0x00; //enable off PORTB = 0x10; //enable on delayMS(5); PORTB = 0x2E; delayMS(5); PORTB = 0x00; //enable off PORTB = 0x10; //enable on delayMS(5); PORTB = 0x26; delayMS(5); PORTB = 0x00; //enable off PORTB = 0x10; //enable on delayMS(5); PORTB = 0x34; delayMS(5); PORTB = 0x00; //enable off PORTB = 0x10; //enable on delayMS(5); PORTB = 0x38; delayMS(5); PORTB = 0x00; //enable off PORTB = 0x00; delayMS(5); PORTB |= 0x00; delayMS(5); PORTB |= 0x00; } }
It's pretty basic, because im pretty new to using the TIVA board. I can do basic GPIO stuff but nothing fancy. I also realize HAL libraries exist..but I was just trying to follow this "example" code in the debugger sending the exact commands. I don't have R/W
hooked up , it's tied to ground. Enable
is PB5, and RS
is PB4 with DB7-DB4
being PB3-0
I am certain it is hooked up on the breadboard fine. But im sure im just missing something obvious. I read over the datasheet, and from my understanding, I need to bring enable high--->do command---->turn enable off? So im trying to use small delays.
Any ideas? This may not be the proper forum but I figured i'd give it a shot.