Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1072
  • Last Modified:

LCD Display

Hi Everyone,

Following is my code to display some msgs on LCD.I cant get the "range" displayed on the second line. Please help.

//pic16f877a running at 4 Mhz
// 2x16 LCD, 4 bit mode
#include<pic.h>

int RTC = 0;
int Dlay;

static volatile bit RS @ (unsigned) & PORTD*8 + 0;
static volatile bit EN @ (unsigned) & PORTD*8 + 2;
static volatile bit RW @ (unsigned) & PORTD*8 + 1;

char Message[17] = "*PARKING SENSOR*";
char Msg[7]="Range=";

void interrupt tmr0_int(void)
{
if(T0IF)
{
T0IF = 0;
RTC++;
}
}

void LCDNibble(char Nibble)
{
PORTD= Nibble;
EN=1;
EN=0;
}

void LCDByte(char Byte)
{
PORTD= (PORTD & 0x0F )|( Byte & 0xF0);
EN=1;
EN=0;
Dlay= RTC+6;
while(Dlay!=RTC);

PORTD= (PORTD & 0x0F)| (( Byte<<4) & 0xF0);
EN=1;
EN=0;
Dlay= RTC+6;
while(Dlay!=RTC);
}

void main()
{
int i,j;
OPTION = 0x01;  //   /4 prescale
TMR0=0;
T0IE=1;
GIE=1;
RBPU=0;
RW=0;

TRISD=0x00;
PORTD=0x00;

Dlay= RTC+ 20;
while(Dlay!=RTC);

LCDNibble(0x30);

Dlay= RTC+6;
while(Dlay!=RTC);

LCDNibble(0x30);

Dlay= RTC+1;
while(Dlay!=RTC);

LCDNibble(0x30);

Dlay= RTC+1;
while(Dlay!=RTC);

LCDNibble(0x20);

Dlay= RTC+1;
while(Dlay!=RTC);

LCDByte(0x28);
LCDByte(0x08);
LCDByte(0x01);
LCDByte(0x06);
LCDByte(0x0E);

RS=1;

for(i=0;i<16;i++)
LCDByte(Message);


for(j=0;j<6;j++)
LCDByte(Msg[j]);




while(1)
{

}
}
0
vpool
Asked:
vpool
  • 2
2 Solutions
 
markps_1Commented:
While the first column begings on the position 0x00 the second column on a 16x2 begins on the position 0x40.
That is done in a way so that this controller is fully compatible with different sizes of LCDs.

 The best way to drive LCDs based on the HD44870 chipset is to make a function to position the cursor and then keep track of the cursor's position when printing on the screen, so you know when to add 0x40 to the position to jump to the next line.


 http://home.iae.nl/users/pouweha/lcd/lcd0.shtml
0
 
markps_1Commented:
Try adding this function.

// Moves the cursor to the desired position.
LCD_Locate(unsigned char Position)
{


      RS = 0;
      LCDByte(0x80 + Position);
        RS = 1;
}

Then add this code before the second For

LCD_Locate(0x40);

 You can create a function called LCD_Print for example that will receive arguments like (String1, String2) for the two lines... or (String, Position) so you don't need to worry about the location of the cursor.

This website is one of the best with all the comands you'll need.. but a very neet page is the LCD sim.
http://www.geocities.com/dinceraydin/lcd/index.html
http://www.geocities.com/dinceraydin/djlcdsim/djlcdsim.html
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now