Hi, I did not like any library for handling the LCD so I write her but I do not know what to do next .... where's my mistake? Thank you very much.
#include <msp430g2452.h>
#define LCD_DIR P1DIR
#define LCD_OUT P1OUT
#define LCD_PIN_RS BIT0
#define LCD_PIN_EN BIT1
#define LCD_PIN_D4 BIT2
#define LCD_PIN_D5 BIT3
#define LCD_PIN_D6 BIT4
#define LCD_PIN_D7 BIT5
void PulseLCD(void)
{
LCD_OUT |= LCD_PIN_EN;
__delay_cycles(2000);
LCD_OUT &= (~LCD_PIN_EN);
__delay_cycles(2000);
}
void SendBite(char data)
{
if(data & 0x01)
LCD_OUT |= LCD_PIN_D4;
else
LCD_OUT &= ~LCD_PIN_D4;
__delay_cycles(2000);
if(data & 0x02)
LCD_OUT |= LCD_PIN_D5;
else
LCD_OUT &= ~LCD_PIN_D5;
__delay_cycles(2000);
if(data & 0x04)
LCD_OUT |= LCD_PIN_D6;
else
LCD_OUT &= ~LCD_PIN_D6;
__delay_cycles(2000);
if(data & 0x08)
LCD_OUT |= LCD_PIN_D7;
else
LCD_OUT &= ~LCD_PIN_D7;
__delay_cycles(2000);
PulseLCD();
}
void SendInstruction(char data)
{
LCD_OUT &= ~LCD_PIN_RS;
SendBite((data>>4) & 0x0F);
SendBite((data) & 0x0F);
}
void SendByte(char data)
{
LCD_OUT |= LCD_PIN_RS;
SendBite((data>>4) & 0x0F);
SendBite((data) & 0x0F);
}
void InitLCD(void)
{
LCD_OUT &= (~LCD_PIN_EN);
LCD_OUT |= LCD_PIN_RS;
__delay_cycles(100000);
SendInstruction(0x02);
SendInstruction(0x0C);
SendInstruction(0x01);
SendInstruction(0x06);
}
void LCDSetPosition(char Row, char Col)
{
char address;
if (Row == 0)
{
address = 0;
}
else
{
address = 0x40;
}
address |= Col;
SendInstruction(0x80 | address);
}
void LCDClear(void)
{
SendInstruction(0x01);
}
void LCDGoToHome(void)
{
SendInstruction(0x02);
}
void LCDShiftLeft(void)
{
SendInstruction(0x18);
}
void LCDShiftRight(void)
{
SendInstruction(0x1C);
}
void LCDBlinkCursor(void)
{
SendInstruction(0x0F);
}
void LCDPrintString(const char * Text)
{
while (*Text)
SendByte(*Text++);
}
