Hi, I am trying to interface an LCD w/ Hitachi hd44780 controller in 4-bit mode. I am having lots of trouble, and it is not working. I am suspecting that something is wrong with my delay function, but I am not sure. Could anyone please help me out???
P1.0 = RS, P1.1 = R/W’, P1.2 = Enable, P1.3 = D7, P1.4 = D6, P1.5 = D5, P1.3 = D4
#include “msp430x20x2.h”
#include “LCD.h”
#define EN 0x04
#define RW 0x02
#define RS 0x01
int main( void )
{
LCD_init();
LCD_data(0x48); // Write ‘H’
LCD_data(0x49); // Write ‘I’
return 0;
}
void LCD_data(unsigned char data)
{
P1OUT = (((data >> 4) & 0x78) | EN | RS);
P1OUT = (((data >> 4) & 0x78) | RS);
P1OUT = ((data & 0x78) | EN | RS);
P1OUT = ((data & 0x78) | RS);
delay(7); // 218.75 us delay (32 kHz internal clock for Timer A)
delay(7); // 218.75 us delay
}
void LCD_init()
{
delay(640); // 20 ms delay
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
_NOP();
P1DIR |= 0x7F; /* P1.0 - P1.6 set to output direction
(D4-D7, E, R/W’, RS) */
LCD_command(0x20); // Set to 4-bit operation
delay(7);
delay(7);
LCD_command(0x20); // Select 1-line display, 5x8 dot character font, & 4-bit display
LCD_command(0x00);
delay(7);
LCD_command(0x00); // Turn on display and cursor
LCD_command(0x38);
delay(7);
delay(7);
LCD_command(0x00); // Increment address by one and shift cursor to the right
LCD_command(0x30);
delay(7);
delay(7);
}
void LCD_command (char command)
{
P1OUT = (command | EN);
P1OUT = command;
}
//void delayus (int us)
void delay (int count)
{
CCR0 = (count + 50000); // CCR0 is the value that TAR (Timer counter) counts to
TACTL = TASSEL_1 + MC_2; // Start ACLK, continuous mode
while (TAR < count); // Waits until specified count is reached
CCR0 = 0; // Stops timer
TACTL &= TACLR; // Resets counter (TAR) and timer
}