Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Lcd_interfacing_unable to assign portd

Status
Not open for further replies.

sx1

Newbie level 2
Joined
Dec 23, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
Hello,

I am trying to interface the LCD with the PIC 16f877a microcontroller . I am using the MPLAB ICD2 debugger. But somehow I am never able to assign PORTD to 0x20 or 0x28 or any hexadecimal number starting with 0. I am using the 4 bit mode to interface the LCD. So to set the bit mode and number of lines I have to send 0x28 but i am unable to send it as the debugger interprets it is as 0x08. It works well for MPLAB SIM. I had burned the same code yesterday and was successful in printing the string but today somehow it isnt working and i am sure it isn't a hardware problem.
 

#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 4000000
#endif

#include<htc.h>
#include<pic.h>
#include "delay.h"
#define D4 (1<<4) // the bit of portD connected to the particular pin of LCD is set to 1
#define D5 (1<<5)
#define D6 (1<<6)
#define D7 (1<<7)
#define LCD_RS RC4
#define LCD_RW RC3
#define LCD_EN RC5
#define UP (1<<4)
#define DOWN (1<<5)
#define LEFT (1<<6)
#define RIGHT (1<<7)
#define lcd_port PORTD
#define control PORTC
#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))

void lcdcmd (unsigned char cmd);
void lcd_reset();
void lcddata (unsigned char dat);
void lcd_clear(void);
void lcd_character(char c);
void lcd_line1(unsigned char pos);
void lcd_string(const char * s);

void lcdcmd (unsigned char cmd)
{
int i=0,sum=0,sum1=0;

__delay_us(40);

sum1=cmd+sum1;
for (i=0;i<=15;i++)
sum=sum+cmd;

lcd_port = ( sum1 & 0xF0 );
LCD_STROBE();
lcd_port=sum;
lcd_port = (lcd_port & 0xF0);
LCD_STROBE();
}

void lcd_reset()
{

TRISC=0;
TRISD=0;
PORTC=0x00;
__delay_ms(15); // wait 15mSec after power applied,
lcd_port = 0x03;
LCD_STROBE();
__delay_ms(5);
LCD_STROBE();
__delay_us(200);
LCD_STROBE();
__delay_us(200);
lcd_port = 2; // Four bit mode
LCD_STROBE();

}

void lcddata (unsigned char dat)
{
int i=0,sum=0;
__delay_us(40);

lcd_port=dat;
LCD_STROBE();

lcd_port = ( dat & 0xF0 );
LCD_STROBE();
lcd_port=dat;
for (i=0;i<=15;i++)
sum=sum+lcd_port;
lcd_port=sum;
lcd_port = (lcd_port & 0xF0);
LCD_STROBE();

}

void lcd_line2(unsigned char pos)
{
LCD_RS = 0;
lcdcmd(0xC0+pos);
}

void lcd_line1(unsigned char pos)
{
LCD_RS = 0;
lcdcmd(0x80+pos);
}

void lcd_string(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcdcmd(*s++);
}

void lcd_clear(void)
{
LCD_RS = 0;
lcdcmd(0x01);
__delay_ms(2);
}

void lcd_character(char c)
{
LCD_RS = 1; // write characters
lcdcmd( c );
}


void lcd_init(void)
{
lcd_reset();
lcdcmd(0x28);
lcdcmd(0x0F); // Display on cursor on
lcd_clear();
lcdcmd(0x06); // Entry mode
// lcdcmd(0x08); //display off

lcd_line1(0);
lcd_string("Hi !!");
lcd_line2(0);
lcd_string("LCD Interfacing");
lcd_port=0x20;
// lcdcmd(0x01); // Clear display


}



void main(void)
{


TRISD=0x00;
TRISC=0x00;
lcd_init();

while(1);


}

---------- Post added at 06:59 ---------- Previous post was at 06:55 ----------

the smiley is the digit eight
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top