has anybody interfaced 16*2 lcd using msp430f5529?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
has anybody interfaced 16*2 lcd using msp430f5529?
Hi Ryan,
i tried interfacing lcd on msp430f5529, but when i execute my code it skips my delay routine...it never goes into the delay routine.
here is my code,
#include <msp430.h>
#include <in430.h>
//#include <math.h>
/*
* main.c
*/
void init_lcd();
void cmd_wr(unsigned char ch);
void data_wr(unsigned char dat);
void delay(unsigned int i);
void enable();
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR = 0x1c;
P2DIR = 0xF0;
init_lcd();
cmd_wr(0x85);
data_wr('A');
while(1);
}
void init_lcd()
{
delay(5);
delay(5);
delay(5);
cmd_wr(0x22);
delay(5);
cmd_wr(0x22);
delay(5);
cmd_wr(0x22);
delay(5);
cmd_wr(0x33);
delay(5);
cmd_wr(0x20);
delay(5);
cmd_wr(0x28);
delay(5);
cmd_wr(0x0e);
delay(5);
/* cmd_wr(0x06);
delay(5);*/
cmd_wr(0x01);
delay(5);
}
void cmd_wr(unsigned char ch)
{
P1OUT=0x00;
P2OUT=(ch & 0xf0 | P2OUT & 0x0f);
enable();
P2OUT=(ch<<4 & 0xf0 | P2OUT & 0x0f);
enable();
}
void delay(unsigned int i)
{
unsigned int cnt,j;
for(cnt=0;cnt<=i;cnt++)
{
for(j=0;j<=10;j++);
}
}
void data_wr(unsigned char dat)
{
P1OUT=0x40;
P2OUT=(dat & 0xf0 | P2OUT & 0x0f);
enable();
P2OUT=(dat<<4 & 0xf0 | P2OUT & 0x0f);
enable();
}
void enable()
{
P1OUT=0x10;
_nop();
_nop();
_nop();
_nop();
// _nop();
P1OUT=0x00;
}
Plz guide me if im making any mistake.
Regards,
Neha
NEHA SONAWDEKAR said:it never goes into the delay routine
It may have been optimized away. You can a) turn optimization off in your IDE or b) declare your counting variable as volatile.
Hi Dennis Eichmann,
I tried alot but there is no luck. only cursor blinks could not see data on lcd.
I'm using JHD162A lcd.
here is my code
#include <msp430.h>
#include <in430.h>
//#include <math.h>
/*
* main.c
*/
void init_lcd();
void cmd_wr(unsigned char ch);
void data_wr(unsigned char dat);
void delay();
void enable();
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
//P1DIR = 0x1c;
//P2DIR = 0xF0;
P1DIR |= BIT2+ BIT3+ BIT4;
P2DIR |= BIT4+ BIT5+ BIT6+ BIT7;
init_lcd();
cmd_wr(0x85);
delay();
while(1)
{
// delay();
//delay();
//delay();
data_wr('A');
// delay();
//delay();
//delay();
//delay();
}
//while(1);
}
void init_lcd()
{
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
cmd_wr(0x22);
delay();
delay();
delay();
delay();
delay();
cmd_wr(0x22);
delay();
delay();
delay();
delay();
cmd_wr(0x22);
delay();
delay();
delay();
delay();
cmd_wr(0x33);
delay();
delay();
delay();
delay();
cmd_wr(0x20);
delay();
delay();
delay();
delay();
cmd_wr(0x28);
delay();
delay();
delay();
delay();
cmd_wr(0x0e);
delay();
delay();
delay();
delay();
/*cmd_wr(0x06);
delay();
delay();
delay();
delay();*/
cmd_wr(0x01);
delay();
delay();
delay();
delay();
}
void cmd_wr(unsigned char ch)
{
P1OUT=0x00;
P2OUT=(ch & 0xf0 | P2OUT & 0x0f);
enable();
P2OUT=(ch<<4 & 0xf0 | P2OUT & 0x0f);
enable();
}
/*void delay(unsigned int i)
{
unsigned int cnt,j;
for(cnt=0;cnt<=i;cnt++)
{
for(j=0;j<=10;j++);
}
}*/
void delay()
{
for(;;)
{
volatile unsigned int Ms;
Ms = 1000;
do Ms--;
while(Ms != 0);
}
}
void data_wr(unsigned char dat)
{
P1OUT=0x04;
P2OUT=(dat & 0xf0 | P2OUT & 0x0f);
enable();
P2OUT=(dat<<4 & 0xf0 | P2OUT & 0x0f);
enable();
}
void enable()
{
P1OUT=0x10;
_nop();
_nop();
_nop();
_nop();
// _nop();
P1OUT=0x00;
}
plz guide me.
Regards,
Neha
Hi Ryan,
got the output....there was a connection problem.
R/W pin and enable was not connected properly.
i also used bit set(|=) as suggested by you,to avoid overwriting.
Thanks.
Regards,
Neha
**Attention** This is a public forum