Hello I am having troubles getting my code to inteface with the LCD. My LCD has 16 Pins.
I am using code composer studio.
I am also working with one header tm4c123gh6pm.h
My configuration:
Pin Number | Symbol |
1 | Vss -GND |
2 | Vdd - VBUS |
3 | VO - 10k pot |
4 | RS |
5 | R/W - GND to always write |
6 | E |
7 | DBO - GND |
8 | DB1 - GND |
9 | DB2 - GND |
10 | DB3 - GND |
11 | DB4 |
12 | DB5 |
13 | DB6 |
14 | DB7 |
15 | VCC |
16 | GND |
I am using PB0 to PB3 for D4 to D7
I am using pin PB4 for RS
i am using pin PB5 for EN
This is my code:
#include "G:\Embedded Folder CCS\tm4c123gh6pm.h"
#define RS 16 /* BIT0 mask */
#define EN 32 /* BIT1 mask 00100000*/
#define SCB_CPAC (*((volatile unsigned int*)0xE000ED88))
#define PORTB_DATA (*((volatile uint32_t *)0x400053FC))
#define SYSCTL_RCGCGPIO (*((volatile uint32_t *)0x400FE608))
#define DIR (*((volatile uint32_t *)0x40005400))
#define DEN (*((volatile uint32_t *)0x4000551C))
#include <stdint.h>
void delayMs(int n){
int i, j;
for (i = 0; i < n; i ++){
for( j = 0; j < 3180; j ++) {
} /* do nothing for 1 ms */
} /* delay n microseconds (16 MHz CPU clock) */
}
void LCD_nibble_write(unsigned char data, unsigned char control){
data &=0xF0; /* clear lower nibble for control */
control &= 0x0F; /* clear upper nibble for data */
PORTB_DATA = data|control; /* RS = 0, R/W =0 */
PORTB_DATA = data|control|EN; /* pulse E */
delayMs(1);
PORTB_DATA = data;
delayMs(1);
PORTB_DATA = 0;
}
void LCD_command(unsigned char command){
LCD_nibble_write(command & 0xF0, 0); /* upper nibble first */
LCD_nibble_write(command << 4, 0); /* then lower nibble */
if (command < 4){
delayMs(2); /*commands 1 and 2 need up to 1.64 ms */
}
else{
delayMs(1); /* all others 1 ms */
}
}
void LCD_data(unsigned char data){
LCD_nibble_write(data & 0xF0, RS); /* upper nibble first */
LCD_nibble_write(data << 4, RS); /* then lower nibble */
delayMs(1); /* delay 1 ms */
}
void LCD_init(void){
//SCB_CPAC |= 0x00F00000; /* this is required for the floating point coprocessor */
SYSCTL_RCGCGPIO |= 0x02; /* enable clock to GPIOB */
DIR = 0xFF; /* set all PORTB pins as output */
DEN = 0xFF; /* set all PORTB pins as digital pins */
delayMs(20); /* initialization sequence */
LCD_nibble_write(0x30, 0);
delayMs(5);
LCD_nibble_write(0x30, 0);
delayMs(1);
LCD_nibble_write(0x30, 0);
delayMs(1);
LCD_nibble_write(0x20, 0); /*use 4-bit data mode */
delayMs(1);
LCD_command(0x28); /* set 4-bit data, 2-line, 5x7 font */
LCD_command(0x06); /* move cursor right */
LCD_command(0x01); /* clear screen, move cursor to home */
LCD_command(0x0F); /* turn on display, cursor blinking */
}
int main(void){
LCD_init();
for(;;) {
LCD_command(1); /* clear display */
LCD_command(0x0F); /* LCD cursor location */
delayMs(500);
LCD_data('H');
LCD_data('e');
LCD_data('l');
LCD_data('l');
LCD_data('o');
delayMs(500);
}
}
The goal here is to write "hello" to the LCD.
Thank you for the help.