Guys...I am making a Real Time Clock using DS12c887 and 16X2 LCD...
I following code works great to display seconds extracted from the RTC on the LCD but hours and minutes are not displayed in the way it should. They take any random value...Please find out the solution to it and suggest some debugging techniques...
Try to simulate this using Proteus and you will see the error!
Here is the screenshot of the Proteus simulated circuit
I following code works great to display seconds extracted from the RTC on the LCD but hours and minutes are not displayed in the way it should. They take any random value...Please find out the solution to it and suggest some debugging techniques...
Try to simulate this using Proteus and you will see the error!
Rich (BB code):
#include <REGX51.H>
#include<ABSACC.h>
#define port P3
#define lcd_dataport P2 // lcd_dataport for lcd
#define keypad P1 // Port for keypadpad
#define timeport P0 // Port for RTC
sbit rs = port^0;
sbit rw = port^1;
sbit en = port^2;
sbit key0=keypad^0;
sbit key1=keypad^1;
sbit key2=keypad^2;
sbit key3=keypad^3;
sbit key4=keypad^4;
sbit key5=keypad^5;
sbit key6=keypad^6;
sbit key7=keypad^7;
int hr, min, sec;
void delay(unsigned int msec) //Time delay function
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(unsigned char item) //Function to send command to LCD
{
lcd_dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}
void lcddata(unsigned char item) //Funtion to send data on LCD
{
lcd_dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
}
void lcddata_string(unsigned char *str) // Function to send string on LCD
{
int i=0;
while(str!='\0')
{
lcddata(str);
i++;
delay(1);
}
}
void lcd(unsigned char str[10]) // Funtion to Initialize LCD
{
lcdcmd(0x38);
lcdcmd(0x0C);
lcdcmd(0x01);
lcdcmd(0x80);
lcddata_string(str);
}
void check_key()
{
if(key0==0)
lcd("SET TIME");
if(key1==0)
lcd("Increment");
if(key2==0)
lcd("Decrement");
if(key3==0)
lcd("SET A");
if(key4==0)
lcd("SET B");
if(key5==0)
lcd("SET C");
if(key6==0)
lcd("SET BANGS");
if(key7==0)
lcd("SET GROUPS");
}
void bcdconv(unsigned char mybyte)
{
unsigned char x,y;
x=mybyte&0x0F;
x=x|0x30;
y=mybyte&0xF0;
y=y>>4;
y=y|0x30;
lcddata(y);
lcddata(x);
}
void main()
{
delay(220);
XBYTE[10]=0x20;
XBYTE[11]=0x82;
XBYTE[4]=0x16;
XBYTE[2]=0x56;
XBYTE[0]=0x41;
XBYTE[11]=0x02;
lcd("TIME:");
while(1)
{
lcdcmd(0x88);
hr=XBYTE[4];
bcdconv(hr);
lcddata(':');
min=XBYTE[2];
bcdconv(min);
lcddata(':');
sec=XBYTE[0];
bcdconv(sec);
}
}
Here is the screenshot of the Proteus simulated circuit
Last edited by a moderator: