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.

pic 16f877a qnd lcd jhd162a help

Status
Not open for further replies.

aneeshere

Junior Member level 1
Joined
Jun 21, 2010
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,436
Hi,
I am trying to make a digital clock using timer1 of my pic and display it on my lcd screen. I have written a 100% working code and even simulated successfully using proteus. When I implemented by circuit on hardware the lcd shows nothing but 16 black boxes on the first line only.
is it because of the delay problem?
Am using a 4Mhz crystal with two 33pf capacitors

The source code is

....................................................................................................................

unsigned short hour;
unsigned short minute;
unsigned short sec;
unsigned short date;
unsigned short month;
unsigned short year;
unsigned short temp;
char time[9];
char ddate[11];


unsigned char dec2UpperCh(unsigned char bcd);
unsigned char dec2LowerCh(unsigned char bcd);

void main()
{

TRISB = 0;
PORTB=0;
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);

T1CON=0X15;
TMR1H=0X0B;
TMR1L=0XDC;
INTCON=0XC0;
PIE1.TMR1IE=1;
temp=0;
hour=12;
minute=10;
sec=00;
date=03;
month=07;
year=10;
Lcd_Out(1,1,"Time:");
Lcd_Out(2,1,"Date:");
while(1)
{
time[0]=dec2upperch(hour);
time[1]=dec2lowerch(hour);
time[2]=':';
time[3]=dec2upperch(minute);
time[4]=dec2lowerch(minute);
time[5]=':';
time[6]=dec2upperch(sec);
time[7]=dec2lowerch(sec);
time[8]='\0';

ddate[0]=dec2upperch(date);
ddate[1]=dec2lowerch(date);
ddate[2]='/';
ddate[3]=dec2upperch(month);
ddate[4]=dec2lowerch(month);
ddate[5]='/';
ddate[6]='2';
ddate[7]='0';
ddate[8]=dec2upperch(year);
ddate[9]=dec2lowerch(year);
ddate[10]='\0';

Lcd_Out(1,6,time);
Lcd_Out(2,6,ddate);
Delay_ms(500);
}
}
void interrupt(void)
{
if(PIR1.TMR1IF)
{
PIR1.TMR1IF=0;
TMR1H=0X0B;
TMR1L=0XDC;
temp++;
if(temp==2)
{
sec++;
temp=0;
}
if(sec==60)
{
minute++;
sec=00;
}
if(minute==60)
{
hour++;
minute=00;
}
if(hour==24)
{
date++;
hour=00;
}
if(date==30)
{
month++;
date=01;
}
if(month==12)
{
year++;
month=00;
}
}
}

unsigned char dec2UpperCh(unsigned char dec)
{
return ( (dec/10) + '0');
}

unsigned char dec2LowerCh(unsigned char dec)
{
return ( (dec%10) + '0');
}
 

those white boxes mean that the lcd is incorrectly initiated.

time to read the datasheet.
 

sanjubluerock3 said:
check this link it would be useful for u....


thanks but the link is no use for me because i do have a code,schematic and even the printed pcb.

Can anyone tell me where exactly to place the delay if it is the problem
 

Hi, sorry for bringing up this old post, do you mind sharing your coding for initializing the LCD? I'm using the same LCD but I failed to initialize it using 4 bit interface mode.
Thank you very much
 

Post the LCD.c and LCD.h files.

This type of problem occurs due to incorrect initialization of LCD at the hardware level.

What about your configuration bits? Did you program them correctly?
 

This is my code:
any help pls?

Code:
//LCD Testing
#pragma config OSC = INTIO2
#include "p18f2220.h"
#include "delays.h"

// LCD display ports etc
#define LCDdata LATA		// data port
#define LCDstatus LATBbits    	// control/status port
#define RS LATB0				// read/write bit in LCDstatus
#define E  LATB1 				// enable bit in LCDstatus

void lcd_delay() { Delay1KTCYx(40); }  // if LCD does not work make this longer

// Write a nibble to the LCD
void lcdNibble(int n)
{
  	LCDdata = ((n & 0x0f));			// send out lower Nibble
    LCDstatus.E=1;					// take clock E high 
	lcd_delay();
    LCDstatus.E=0;
	lcd_delay();
 }

// Write a Control Command to the LCD
// This is written as two nibbles
void lcdCmd(int c)
{
 	LCDstatus.RS=0;			        // Take RS pin low for command
	lcdNibble(c >>4);		        // Makeup Upper Nibble
	lcdNibble(c);			        // Makeup Lower Nibble
}

// write a data byte to LCD
int lcdPutchar(int d)
{
	LCDstatus.RS=1; 				// Take RS pin high for data
	lcdNibble(d >>4);     		    // Makeup Upper Nibble
	lcdNibble(d);		            // Makeup Lower Nibble
    return 1;
}

// Initialise the LCD in 4bit Mode
void lcdInit()
{
	LATA = 0;
	LATB = 0;
	ADCON1 = 0x0F;
    TRISBbits.TRISB0=0;  	// set RS and E bits output
    TRISBbits.TRISB1=0;  	// set RS and E bits output
    TRISA &= 0xf0;          // set bits 0-3 output for data
 	LCDstatus.RS=0;			// Take RS pin low for command
	lcdNibble(0x3);		// This put the LCD into Soft Reset 
	lcdNibble(0x3);
	lcdNibble(0x3);
	lcdNibble(0x2);
	lcdCmd(0x28);			// 2 line, 4 bit mode 
    lcdCmd(0x6);			// increment cursor after each write
    lcdCmd(0x1);			// clear display
    lcdCmd(0x2);			// home
    lcdCmd(0xF);			// turn disply on
}

void main(void)
{
	OSCCON = 0x72;			//8MHz Internal Clock
	Delay1KTCYx(50);
	lcdInit();
	lcdPutchar('a');
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top