#include<htc.h>
#include"i2csub.c"
#include"lcdsub.c"
void delay(int);
void main()
{
TRISD=0x00;
TRISC0=0;
TRISC1=0;
TRISC2=0;
TRISC3=1;
TRISC4=1;
i2cint();
lcdint();
lcdstr("sai prasanth");
delay(6500);
lcdcmd(0x01);
while(1)
{
gettime();
getdate();
}
}
#define rs RC0
#define rw RC1
#define en RC2
int count=0;
int adc=0;
int p=192;
void lcddisp(char);
void lcdcmd(int cmd);
void delay(int s);
void lcdstr(unsigned char *str);
void lcddisp2(int hr,int min,int sec);
void lcddisp1(char);
void delay(int s)
{
while(s--);
}
void lcdint()
{
lcdcmd(0x38);
lcdcmd(0x01);
lcdcmd(0x0E);
lcdcmd(0x06);
lcdcmd(0x80);
}
void lcdread()
{
char chrrd;
rw=1;
rs=1;
chrrd=PORTD;
en=1;
delay(100);
en=0;
}
void lcddisp(char chr)
{
rw=0;
rs=1;
PORTD=chr;
en=1;
delay(100);
en=0;
}
void lcdcmd(int cmd)
{
rw=0;
rs=0;
PORTD=cmd;
en=1;
delay(100);
en=0;
if(cmd==0x01)
count=0;
}
void lcddisp1(char disp1)
{
rw=0;
rs=1;
PORTD=disp1;
en=1;
delay(100);
en=0;
}
void lcdstr(unsigned char *str)
{
while(*str)
{
delay(2500);
lcddisp1(*str++);
}
}
void lcddisp2(int hr,int min,int sec)
{
count=0;
lcdcmd(0x01);
lcdcmd(0x84);
lcddisp((hr/10)+0x30);
lcddisp((hr%10)+0x30);
lcddisp(':');
lcddisp((min/10)+0x30);
lcddisp((min%10)+0x30);
lcddisp(':');
lcddisp((sec/10)+0x30);
lcddisp((sec%10)+0x30);
}
void i2cint();
int z=0;
void i2cstart();
void i2cstop();
void i2cack();
void lcdstr(unsigned char *str);
void i2cnack();
void lcdcmd(int);
unsigned char i2cread(unsigned char);
void i2cwrite(unsigned char);
void gettime();
void getdate();
unsigned char conv1(int val);
unsigned char conv2(int val);
void wait();
void elay(int);
void check();
void lcddisp(char);
void check()
{
while(RW==1);
RW=0;
}
void elay(int m)
{
while(m--);
}
void wait()
{
while(SSPIF==0);
SSPIF=0;
check();
//while(RW==1);
//RW=0;
}
void i2cint()
{
//PORTC=0X18;
SSPCON=0X28;
SSPSTAT=0X80;
SSPADD=4;
}
void i2cstart()
{
SEN=1;
wait();
}
void i2cstop()
{
PEN=1;
wait();
}
void i2cack()
{
ACKDT=0;
ACKEN=1;
wait();
}
void i2cnack()
{
ACKDT=1;
ACKEN=1;
wait();
}
unsigned char i2cread(unsigned char x)
{
unsigned char data;
SEN=1;
wait();
SSPBUF=0xd0;
wait();
SSPBUF=x;
wait();
RSEN=1;
wait();
SSPBUF=0xd1;
wait();
RCEN=1;
wait();
data=SSPBUF;
//wait();
ACKDT=1;
ACKEN=1;
wait();
i2cstop();
//wait();
return data;
}
void i2cwrite(unsigned char byte)
{
SSPBUF=byte;
wait();
}
void gettime()
{
i2cstart();
lcdcmd(0x80);
lcddisp(conv1(i2cread(0x02)));
lcddisp(conv2(i2cread(0x02)));
lcdstr(":");
lcddisp(conv1(i2cread(0x01)));
lcddisp(conv2(i2cread(0x01)));
lcdstr(":");
lcddisp(conv1(i2cread(0x00)));
lcddisp(conv2(i2cread(0x00)));
}
void getdate()
{
lcdcmd(0xc0);
lcddisp(conv1(i2cread(0x04)));
lcddisp(conv2(i2cread(0x04)));
lcdstr(":");
lcddisp(conv1(i2cread(0x05)));
lcddisp(conv2(i2cread(0x05)));
lcdstr(":");
lcddisp(conv1(i2cread(0x06)));
lcddisp(conv2(i2cread(0x06)));
}
unsigned char conv1(int val)
{
return ( ((val&0xF0)>>4)+0x30);
}
unsigned char conv2(int val2)
{
return ((val2&0x0F)+0x30);
}
#include"i2csub.c"
#include"lcdsub.c"
void delay(int);
void main()
{
TRISD=0x00;
TRISC0=0;
TRISC1=0;
TRISC2=0;
TRISC3=1;
TRISC4=1;
i2cint();
lcdint();
lcdstr("sai prasanth");
delay(6500);
lcdcmd(0x01);
while(1)
{
gettime();
getdate();
}
}
#define rs RC0
#define rw RC1
#define en RC2
int count=0;
int adc=0;
int p=192;
void lcddisp(char);
void lcdcmd(int cmd);
void delay(int s);
void lcdstr(unsigned char *str);
void lcddisp2(int hr,int min,int sec);
void lcddisp1(char);
void delay(int s)
{
while(s--);
}
void lcdint()
{
lcdcmd(0x38);
lcdcmd(0x01);
lcdcmd(0x0E);
lcdcmd(0x06);
lcdcmd(0x80);
}
void lcdread()
{
char chrrd;
rw=1;
rs=1;
chrrd=PORTD;
en=1;
delay(100);
en=0;
}
void lcddisp(char chr)
{
rw=0;
rs=1;
PORTD=chr;
en=1;
delay(100);
en=0;
}
void lcdcmd(int cmd)
{
rw=0;
rs=0;
PORTD=cmd;
en=1;
delay(100);
en=0;
if(cmd==0x01)
count=0;
}
void lcddisp1(char disp1)
{
rw=0;
rs=1;
PORTD=disp1;
en=1;
delay(100);
en=0;
}
void lcdstr(unsigned char *str)
{
while(*str)
{
delay(2500);
lcddisp1(*str++);
}
}
void lcddisp2(int hr,int min,int sec)
{
count=0;
lcdcmd(0x01);
lcdcmd(0x84);
lcddisp((hr/10)+0x30);
lcddisp((hr%10)+0x30);
lcddisp(':');
lcddisp((min/10)+0x30);
lcddisp((min%10)+0x30);
lcddisp(':');
lcddisp((sec/10)+0x30);
lcddisp((sec%10)+0x30);
}
void i2cint();
int z=0;
void i2cstart();
void i2cstop();
void i2cack();
void lcdstr(unsigned char *str);
void i2cnack();
void lcdcmd(int);
unsigned char i2cread(unsigned char);
void i2cwrite(unsigned char);
void gettime();
void getdate();
unsigned char conv1(int val);
unsigned char conv2(int val);
void wait();
void elay(int);
void check();
void lcddisp(char);
void check()
{
while(RW==1);
RW=0;
}
void elay(int m)
{
while(m--);
}
void wait()
{
while(SSPIF==0);
SSPIF=0;
check();
//while(RW==1);
//RW=0;
}
void i2cint()
{
//PORTC=0X18;
SSPCON=0X28;
SSPSTAT=0X80;
SSPADD=4;
}
void i2cstart()
{
SEN=1;
wait();
}
void i2cstop()
{
PEN=1;
wait();
}
void i2cack()
{
ACKDT=0;
ACKEN=1;
wait();
}
void i2cnack()
{
ACKDT=1;
ACKEN=1;
wait();
}
unsigned char i2cread(unsigned char x)
{
unsigned char data;
SEN=1;
wait();
SSPBUF=0xd0;
wait();
SSPBUF=x;
wait();
RSEN=1;
wait();
SSPBUF=0xd1;
wait();
RCEN=1;
wait();
data=SSPBUF;
//wait();
ACKDT=1;
ACKEN=1;
wait();
i2cstop();
//wait();
return data;
}
void i2cwrite(unsigned char byte)
{
SSPBUF=byte;
wait();
}
void gettime()
{
i2cstart();
lcdcmd(0x80);
lcddisp(conv1(i2cread(0x02)));
lcddisp(conv2(i2cread(0x02)));
lcdstr(":");
lcddisp(conv1(i2cread(0x01)));
lcddisp(conv2(i2cread(0x01)));
lcdstr(":");
lcddisp(conv1(i2cread(0x00)));
lcddisp(conv2(i2cread(0x00)));
}
void getdate()
{
lcdcmd(0xc0);
lcddisp(conv1(i2cread(0x04)));
lcddisp(conv2(i2cread(0x04)));
lcdstr(":");
lcddisp(conv1(i2cread(0x05)));
lcddisp(conv2(i2cread(0x05)));
lcdstr(":");
lcddisp(conv1(i2cread(0x06)));
lcddisp(conv2(i2cread(0x06)));
}
unsigned char conv1(int val)
{
return ( ((val&0xF0)>>4)+0x30);
}
unsigned char conv2(int val2)
{
return ((val2&0x0F)+0x30);
}
No comments:
Post a Comment