[General] lcd 4-bit mode on MSP430G2553

Status
Not open for further replies.

madhav_b

Newbie level 1
Joined
May 11, 2019
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
27
I had used middle four port pins of controller i.e P1.2 to P1.5 as my data output pins to LCD(D4 to D7). I'm facing difficulty to solve this.
Earlier i had performed LCD interfacing with 4-bit mode successfully with P1.4 to P1.7 as data output dins, but by changing pins it is not working .

Program used for P1.4 - P1.7
#include <msp430.h>
#include <inttypes.h>

#define CMD 0
#define DATA 1

#define LCD_OUT P1OUT
#define LCD_DIR P1DIR
#define D4 BIT4
#define D5 BIT5
#define D6 BIT6
#define D7 BIT7
#define RS BIT2
#define EN BIT3

// Delay function for producing delay in 0.1 ms increments
void delay(uint8_t t)
{
uint8_t i;
for(i=t; i > 0; i--)
__delay_cycles(100);
}

// Function to pulse EN pin after data is written
void pulseEN(void)
{
LCD_OUT |= EN;
delay(1);
LCD_OUT &= ~EN;
delay(1);
}

//Function to write data/command to LCD
void lcd_write(uint8_t value, uint8_t mode)
{
if(mode == CMD)
LCD_OUT &= ~RS; // Set RS -> LOW for Command mode
else
LCD_OUT |= RS; // Set RS -> HIGH for Data mode

LCD_OUT = ((LCD_OUT & 0x0F) | (value & 0xF0)); // Write high nibble first
pulseEN();
delay(1);

LCD_OUT = ((LCD_OUT & 0x0F) | ((value << 4) & 0xF0)); // Write low nibble next
pulseEN();
delay(1);
}

// Function to print a string on LCD
void lcd_print(char *s)
{
while(*s)
{
lcd_write(*s, DATA);
s++;
}
}

// Function to move cursor to desired position on LCD
void lcd_setCursor(uint8_t row, uint8_t col)
{
const uint8_t row_offsets[] = { 0x00, 0x40};
lcd_write(0x80 | (col + row_offsets[row]), CMD);
delay(1);
}

// Initialize LCD
void lcd_init()
{
//P2SEL &= ~(BIT6+BIT7);
LCD_DIR |= (D4+D5+D6+D7+RS+EN);
LCD_OUT &= ~(D4+D5+D6+D7+RS+EN);

delay(150); // Wait for power up ( 15ms )
lcd_write(0x33, CMD); // Initialization Sequence 1
delay(50); // Wait ( 4.1 ms )
lcd_write(0x32, CMD); // Initialization Sequence 2
delay(1); // Wait ( 100 us )

// All subsequent commands take 40 us to execute, except clear & cursor return (1.64 ms)

lcd_write(0x28, CMD); // 4 bit mode, 2 line
delay(1);

lcd_write(0x0F, CMD); // Display ON, Cursor ON, Blink ON
delay(1);

lcd_write(0x01, CMD); // Clear screen
delay(20);

lcd_write(0x06, CMD); // Auto Increment Cursor
delay(1);

lcd_setCursor(0,0); // Goto Row 1 Column 1
}

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog

lcd_init();
lcd_setCursor(0,5);
lcd_print("hello");
// lcd_setCursor(1,5);
//lcd_print("lcd");
lcd_setCursor(0,0);
while(1);

}


but i need different configuration like
#define D4 BIT2
#define D5 BIT3
#define D6 BIT4
#define D7 BIT5
#define RS BIT0
#define EN BIT1
 

but i need different configuration like
#define D4 BIT2
#define D5 BIT3
#define D6 BIT4
#define D7 BIT5
#define RS BIT0
#define EN BIT1
Try:
#define D4 0x04
#define D5 0x08
#define D6 0x10
#define D7 0x20
#define RS 0x01
#define EN 0x02

Brian.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…