happy09
Newbie level 1
I am using ATMega8L but facing problem in its initialization. I am trying with following code. Please help me
#include <Global.h>
#define CLR_DATA_BITS 0xC3 //11000011
//#define LCD_PORT P2
#define LCD_PORT PORTD
#define Lcd_e PORTB.6
#define Lcd_rs PORTD.6
extern void Delay_ticks(unsigned char);
extern void Small_delay(void);
void Initlcd(void);
void Pulse_E(void);
void Write_lcd_data(unsigned char);
void Write_lcd_comm(unsigned char);
//unsigned char extern Port0_var, Port1_var;
unsigned char Lcd_cntr, Lcd_pointer;
void Write_lcd_number (unsigned char,unsigned char, unsigned char);
void Write_line(unsigned char,unsigned char, unsigned char *);
const unsigned char lcd_table[5] = {0x28, 0x0C, 0x01, 0x06, 0x14};
const unsigned char lcd_initable[4] = {0x03, 0x03, 0x03, 0x02};
void Initlcd(void)
{
Lcd_rs = 0;
for (Lcd_cntr = 0; Lcd_cntr < 4; Lcd_cntr++)
{
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= ((lcd_initable[Lcd_cntr] & 0xC3)<<4);
Pulse_E();
Small_delay();//Delay_ticks(0x01);
}
for (Lcd_cntr = 0; Lcd_cntr < 5; Lcd_cntr++)
{
Write_lcd_comm (lcd_table[Lcd_cntr]);
Small_delay();
}
}
void Write_lcd_comm(unsigned char val)
{
Lcd_rs = 0;
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= val & 0x3C;
Pulse_E();
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= ((val & 0xC3)<<4);
Pulse_E();
}
void Write_lcd_data (unsigned char val)
{
Lcd_rs = 1;
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= val & 0x3C;
Pulse_E();
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= ((val & 0xC3)<<4);
Pulse_E();
}
void Pulse_E(void)
{
unsigned char I;
Lcd_e = 1;
for(I = 0; I<20; I++);
Lcd_e = 0;
}
void Write_line(unsigned char line_no,unsigned char Column_no, unsigned char * msg_add)
{
if(line_no == 0)
Write_lcd_comm(0x80+Column_no); //0x80
else if(line_no == 1)
Write_lcd_comm(0xC0+Column_no); //0xC0
#ifdef LCD_FOUR_LINE
else if(line_no == 2)
Write_lcd_comm(0x90+Column_no);
else if(line_no == 3)
Write_lcd_comm(0xD0+Column_no);
#endif
for(Lcd_pointer=0; Lcd_pointer < 16; Lcd_pointer++)
{
#ifdef LCD_SINGLE_LINE
if(Lcd_pointer == 8)
Write_lcd_comm(0xC0);
#endif
if (*msg_add == '\0')
return;
Write_lcd_data(*msg_add);
msg_add++;
}
}
void Write_lcd_number (unsigned char line_no,unsigned char Column_no, unsigned char val)
{
if(line_no == 0)
Write_lcd_comm(0x80+Column_no); //0x80
else if(line_no == 1)
Write_lcd_comm(0xC0+Column_no); //0xC0
#ifdef LCD_FOUR_LINE
else if(line_no == 2)
Write_lcd_comm(0x90+Column_no);
else if(line_no == 3)
Write_lcd_comm(0xD0+Column_no);
#endif
/* Change only for modem */
Small_delay();
Write_lcd_data(0x30+val/10);
Small_delay();
Write_lcd_data(0x30+val%10);
Small_delay();
}
#include <Global.h>
#define CLR_DATA_BITS 0xC3 //11000011
//#define LCD_PORT P2
#define LCD_PORT PORTD
#define Lcd_e PORTB.6
#define Lcd_rs PORTD.6
extern void Delay_ticks(unsigned char);
extern void Small_delay(void);
void Initlcd(void);
void Pulse_E(void);
void Write_lcd_data(unsigned char);
void Write_lcd_comm(unsigned char);
//unsigned char extern Port0_var, Port1_var;
unsigned char Lcd_cntr, Lcd_pointer;
void Write_lcd_number (unsigned char,unsigned char, unsigned char);
void Write_line(unsigned char,unsigned char, unsigned char *);
const unsigned char lcd_table[5] = {0x28, 0x0C, 0x01, 0x06, 0x14};
const unsigned char lcd_initable[4] = {0x03, 0x03, 0x03, 0x02};
void Initlcd(void)
{
Lcd_rs = 0;
for (Lcd_cntr = 0; Lcd_cntr < 4; Lcd_cntr++)
{
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= ((lcd_initable[Lcd_cntr] & 0xC3)<<4);
Pulse_E();
Small_delay();//Delay_ticks(0x01);
}
for (Lcd_cntr = 0; Lcd_cntr < 5; Lcd_cntr++)
{
Write_lcd_comm (lcd_table[Lcd_cntr]);
Small_delay();
}
}
void Write_lcd_comm(unsigned char val)
{
Lcd_rs = 0;
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= val & 0x3C;
Pulse_E();
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= ((val & 0xC3)<<4);
Pulse_E();
}
void Write_lcd_data (unsigned char val)
{
Lcd_rs = 1;
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= val & 0x3C;
Pulse_E();
LCD_PORT &= CLR_DATA_BITS;
LCD_PORT |= ((val & 0xC3)<<4);
Pulse_E();
}
void Pulse_E(void)
{
unsigned char I;
Lcd_e = 1;
for(I = 0; I<20; I++);
Lcd_e = 0;
}
void Write_line(unsigned char line_no,unsigned char Column_no, unsigned char * msg_add)
{
if(line_no == 0)
Write_lcd_comm(0x80+Column_no); //0x80
else if(line_no == 1)
Write_lcd_comm(0xC0+Column_no); //0xC0
#ifdef LCD_FOUR_LINE
else if(line_no == 2)
Write_lcd_comm(0x90+Column_no);
else if(line_no == 3)
Write_lcd_comm(0xD0+Column_no);
#endif
for(Lcd_pointer=0; Lcd_pointer < 16; Lcd_pointer++)
{
#ifdef LCD_SINGLE_LINE
if(Lcd_pointer == 8)
Write_lcd_comm(0xC0);
#endif
if (*msg_add == '\0')
return;
Write_lcd_data(*msg_add);
msg_add++;
}
}
void Write_lcd_number (unsigned char line_no,unsigned char Column_no, unsigned char val)
{
if(line_no == 0)
Write_lcd_comm(0x80+Column_no); //0x80
else if(line_no == 1)
Write_lcd_comm(0xC0+Column_no); //0xC0
#ifdef LCD_FOUR_LINE
else if(line_no == 2)
Write_lcd_comm(0x90+Column_no);
else if(line_no == 3)
Write_lcd_comm(0xD0+Column_no);
#endif
/* Change only for modem */
Small_delay();
Write_lcd_data(0x30+val/10);
Small_delay();
Write_lcd_data(0x30+val%10);
Small_delay();
}