problem with rtc clock in lcd display with pic16f877a

Status
Not open for further replies.

rangerskm

Full Member level 4
Joined
Jan 23, 2013
Messages
199
Helped
0
Reputation
2
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,663
i am having problem with my real time which is not displaying in lcd but working with simulation and showing time in it.i am posting the code in it please explain the code and say the problem in it.
first header file is lcd.h
Code:
// lcd header file
Lcd_Init();
Lcd_data(unsigned char,unsigned char );
Lcd_Display(unsigned char ,char const *);
set_delay(unsigned char ,unsigned int );
Lcd_Decimal(unsigned char ,unsigned int ,unsigned char );
Lcd_write(unsigned char ,unsigned char );

#define rs RD0
#define en RD1

#define dat_port PORTD

Lcd_Init()
{	
	
	Lcd_data(0x02,0);
	Lcd_data(0x28,0);
	Lcd_data(0x0c,0);
	Lcd_data(0x06,0);
	Lcd_data(0x01,0);

}

Lcd_data(unsigned char x,unsigned char y)
{
	unsigned char a,b,t;
	a=  x & 0xf0;
	b= (x<<4) & 0xf0;
	
	t=dat_port & 0x0f;
	dat_port=a|t;
	rs=y;
	en=1;set_delay(1,250);
	en=0;

	t=dat_port & 0x0f;
	dat_port=b|t;
	rs=y;
	en=1;set_delay(1,250);
	en=0;	
}
Lcd_write(unsigned char x,unsigned char y)
{
	Lcd_data(x,0);//command_mode
	Lcd_data(y,1);//data_mode
}

Lcd_Display(unsigned char x,char const *y)
{
	Lcd_data(x,0); //command mode
	while(*y!='\0')Lcd_data(*y++,1); //data mode
}
Lcd_Decimal(unsigned char x,unsigned int y,unsigned char n)
{
	Lcd_data(x,0);
	unsigned int m=1;
	while(n--)m=m*10;
	while(m>1)
	{
		Lcd_data((y%m)/(m/10)+0x30 , 1);
		m=m/10;
	}

}

set_delay(unsigned char x,unsigned int y)
{
	while(x--)while(y--);
}

second header file is rtc.h

Code:
//rtc header file
#define sda_dir TRISC4
#define scl_dir TRISC3

#define i2c_sp 100 //kbps  
#define xtal_freq 4000000

i2c_init();
i2c_start();
i2c_stop();
i2c_write_byte(unsigned char );
unsigned char i2c_read_byte();
i2c_restart();
set_time(unsigned char ,unsigned char ,unsigned char ,unsigned char );
get_time(unsigned char );
#define sda_dir TRISC4
#define scl_dir TRISC3

#define i2c_sp 100   
#define xtal_freq 4000000

i2c_init();
i2c_start();
i2c_stop();
i2c_write_byte(unsigned char );
unsigned char i2c_read_byte();
i2c_restart();
set_time(unsigned char ,unsigned char ,unsigned char ,unsigned char );
get_time(unsigned char );

i2c_init()
{
	sda_dir=1;
	scl_dir=1;

	SSPADD=((xtal_freq/4000)/i2c_sp)-1;
	SSPSTAT=0x80; 
	SSPCON=0x28;
}

i2c_start()
{
	SEN=1;
	while(!SSPIF);
	SSPIF=0;
}
i2c_stop()
{
	PEN=1;
	while(!SSPIF);
	SSPIF=0;
}
i2c_restart()
{
	RSEN=1;
	while(!SSPIF);
	SSPIF=0;
}
i2c_write_byte(unsigned char x)
{

	SSPBUF=x;
	while(!SSPIF);
	SSPIF=0;
	while(ACKSTAT);
}

unsigned char i2c_read_byte()
{
	RCEN=1;
	while(!SSPIF);
	SSPIF=0;
	return SSPBUF;
}

set_time(unsigned char loc,unsigned char a,unsigned char b,unsigned char c)
{
	i2c_start();
	i2c_write_byte(0xd0);
	i2c_write_byte(loc);
	
	i2c_write_byte(a);i2c_write_byte(b);i2c_write_byte(c);

	i2c_stop();
}

get_time(unsigned char loc)
{
	unsigned char v,i,j,k;
	i2c_start();
	i2c_write_byte(0xd0);
	i2c_write_byte(loc);

	i2c_restart();
	i2c_write_byte(0xd1);
	v=i2c_read_byte();
	i2c_stop();
		
	i=(v>>4)&0x0f;
	j= v & 0x0f;
	k=i*10+j;
	return(k);
}

third one is main file

Code:
#include<pic.h>
#include"pic_lcd.h"
#include"rtc.h"


unsigned char i,x[]={0x80,0x87,0x8d,0,0xc0,0xc7,0xcd},b;


main()
{
	TRISD=0x00;
	Lcd_Init();
	Lcd_Display(0x80,"----------------");
	Lcd_Display(0xc0,"----------------");
	i2c_init();
	set_time(0,0x15,0x30,0x00);set_delay(1,10);
	set_time(4,0x22,0x06,0x11);set_delay(1,10);
	while(1)
	{
		for(i=0;i<7;i++)
		{
			if(i==3)continue;
			b=get_time(i);
			Lcd_Decimal(x[i],b,2);
			set_delay(1,25);
		}
	}			
}

i have posted full code here it will be help full for many people who wants rtc code for pic 16f877a
compiled used hi tech c compiler, mplab


please explain the code and problem for not display in the lcd .
my lcd shows blank .i adjusted the contrast many time but no effect
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…