could you correct my program about lcd

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my problem is that my lcd cannot display on second line.
i think on my program lcd_new command doesn't work~
actually i refered a program from gccforum.

here are simple specS & programs!!
4bit mode lcd
i used portc bit 7 as RS
portc bit 6 as R/W
portc bit 5 as E

data bits 4bit porta 7 6 5 4

DDRAM adress
1 2 3 4 ..................... 16
first line 00 01 02 03 0f
second line 40 41 42 43 4f

if someone know a solution plz correct my program.
i want to just dispaly second line~

#include
#define u08 unsigned char
#define u16 unsigned int
void delay(void);
void command(u08 com_data);
void printc(u08 data);
void clear_display(void);
void function_set(void);
void display_on(void);
void entry_mode(void);
void pirnts(u08 *s);
void lcd_home(void);
void lcd_newline(void);
void lcd_nextline(void);
void lcd_gotoxy(u08 x, u08 y);
void lcd_goto(void);
void lcd_init(void);
void display_shift(void);
void entry_mode(void);
void lcd_clr(void);
u08 lcd_x=0;
u08 lcd_y=0;

void delay(void)
{
u16 i,j;
for(i=0;i<255;i++)
{
for(j=0;j<255;j++)
{
}
}
}

void command(u08 com_data)
{
u08 c_temp1;
u08 c_temp2;
cbi(PORTC,7);
cbi(PORTC,6);
sbi(PORTC,3);

c_temp1 = (com_data&0xf0);
outp(c_temp1,PORTA);
cbi(PORTC,3);

cbi(PORTC,7);
cbi(PORTC,6);
sbi(PORTC,3);
c_temp2 = (com_data&0x0f)<<4;
outp(c_temp2,PORTA);//one line에 put!!
cbi(PORTC,3);

}

void printc(u08 data)
{
delay();
u08 temp1;
u08 temp2;

delay();

if(data=='x')
{
// delay();
lcd_newline();
delay();
}

else
{
sbi(PORTC,7);//data
cbi(PORTC,6);//write
sbi(PORTC,3);//high

temp1 = (data&0xf0);
outp(temp1,PORTA);
cbi(PORTC,3);//low

sbi(PORTC,7);
cbi(PORTC,6);
sbi(PORTC,3);

temp2 = (data&0x0f)<<4;
outp(temp2,PORTA);
cbi(PORTC,3);

}

}
void prints(u08 *s)
{
u08 c;
while((c=*s++))
{
printc(c);
}
}
void clear_display(void)
{
command(0x01);
}

void function_set(void)
{
command(0x28);
}

void display_on(void)
{
command(0x08);

}
void entry_mode(void)
{
command(0x06);
}

void lcd_init(void)
{
outp(0x00,PORTA);
outp(0xff,DDRA);

clear_display();
delay();

function_set();
delay();

display_on();
delay();

entry_mode();
delay();

}

void lcd_home(void)
{
command(0x02);
}

/*
void lcd_gotoxy(u08 x, u08 y)
{
lcd_x=x; lcd_y=y;
lcd_goto();
}
*/
void lcd_clr(void)
{
command(0x01);
delay();
}

void lcd_newline(void)
{
command(0xc0);
delay();
}

int main(void)
{
lcd_init();
lcd_home();
for (;;)
{
//lcd_home();
delay();
lcd_clr();
//command(0xc0);
//delay();
prints("lcd is the mostx");
prints("second linex");
delay();

}
}

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think You should call function lcd_newline() beetwen both prints(..)

Regards
AK