GURMEET singh
Junior Member level 2
- Joined
- Oct 10, 2012
- Messages
- 21
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,402
Please correct me,if i am doing wrong..its not working:sad:
// Config word
#define _LEGACY_HEADERS
// Define pins
#define _XTAL_FREQ 40000000
#include <htc.h>
// Main function
#define lcd_port PORTB
#define LCD_EN RA1
#define LCD_RS RA0
////////////////////////////////////////////////////////////////////
//void delay();
//void lcd_cmd ();
//void lcd_data (unsigned char dat);
//void lcd_init ();
/////////////////////delay routine///////////////////////////////////
/////////////////////main program///////////////////////////////////////
void delay(unsigned int temp)
{
while(temp!=0)
{
temp--;
}
}
/////////////////////main program///////////////////////////////////////
void lcd_cmd (unsigned char cmd)
{
unsigned char a;
a=cmd;
lcd_port = (cmd & 0xf0);
LCD_RS=0;
LCD_EN=1;
delay(300);
LCD_EN=0;
a=cmd;
lcd_port = ((cmd<<4) & 0xf0);
LCD_RS=0;
LCD_EN=1;
delay(300);
LCD_EN=0;
delay(500);
}
void lcd_data (unsigned char dat)
{
unsigned char a;
a=dat;
lcd_port = (dat & 0xf0);
LCD_RS=1;
LCD_EN=1;
delay(300);
LCD_EN=0;
a=dat;
lcd_port = ((dat<<4) & 0xf0);
LCD_RS=1;
LCD_EN=1;
delay(300);
LCD_EN=0;
delay(500);
delay(500);
}
void lcd_string(unsigned char *str)
{
while(*str)
lcd_data(*str++);
delay(300);
}
void lcd_init ()
{
lcd_cmd (0x28); // 4-bit mode - 2 line - 5x7 font.
lcd_cmd (0x0C); // Display no cursor - no blink.
lcd_cmd (0x06); // Automatic Increment - No Display shift.
lcd_cmd (0x80); // Address DDRAM with 0 offset 80h.
}
void main(void)
{
TRISA=0x00;
TRISB=0x00;
delay(200);
lcd_init ();
lcd_cmd (0x81);
lcd_string("HELLO");
lcd_cmd (0xc1);
lcd_string("NITISH");
// while(1);
}