jaya krishna
Member level 1
- Joined
- May 10, 2012
- Messages
- 41
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- India,coimbatore
- Activity points
- 1,770
display ds1307rtc in lcd ASCII to decimal
hi i want to display DS1307 rtc time in my lcd, in following program it display the time in ASCII value but i need to convert ASCII to decimal value.... any one can help me...
ds1307
hi i want to display DS1307 rtc time in my lcd, in following program it display the time in ASCII value but i need to convert ASCII to decimal value.... any one can help me...
PHP:
#if defined(__PCM__)
#include <16F877A.h>
#use delay(clock=4000000)
#fuses NOWDT,XT, NOPUT, NOPROTECT
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "ds1307.c"
#define rs PIN_C0
#define rw PIN_C1
#define en PIN_C2
void lcdcmd(unsigned char cmd);
void lcddata(unsigned long int volt);
void lcddata1(char *dat);
char dis[]="Time:";
void main(void)
{
int8 sec,min,hour,day,date,month,year,time[4];
set_tris_b(0x00);
set_tris_a(0xFF);
delay_ms(50);
init_ds1307(); // initial DS1307
sec=read_ds1307(0);
write_ds1307(0,sec & 0x7F); // enable oscillator(bit 7 =0)
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
while(1)
{
lcddata1(dis);
sec=read_ds1307(0); // read second
min=read_ds1307(1); // read minute
hour=read_ds1307(2); // read hour
day=read_ds1307(3); // read day
date=read_ds1307(4); // read date
month=read_ds1307(5); // read month
year=read_ds1307(6); // read year
time[1]= (hour);
time[2]= (min);
time[3]= (sec);
lcddata(time[1]+0x30);
lcddata(':');
lcddata(time[2]+0x30);
lcddata(':');
lcddata(time[3]+0x30);
delay_ms(100);
lcdcmd(0x80);
}
}
void lcdcmd(unsigned char cmd)
{
output_b(cmd);
output_low(rs);
output_low(rw);
output_high(en);
delay_ms(1);
output_low(en);
}
void lcddata(unsigned long int volt)
{
output_b(volt);
output_high(rs);
output_low(rw);
output_high(en);
delay_ms(1);
output_low(en);
}
void lcddata1(char *dat)
{
output_high(rs);
for(;*dat!='\0';*dat++)
lcddata(*dat);
}
PHP:
#define DS1307_SDA PIN_C4
#define DS1307_SCL PIN_C3
#use i2c(master, sda=DS1307_SDA, scl=DS1307_SCL)
//==========================
// initial DS1307
//==========================
void init_DS1307()
{
output_float(DS1307_SCL);
output_float(DS1307_SDA);
}
//==========================
// write data one byte to
// DS1307
//==========================
void write_DS1307(byte address, BYTE data)
{
short int status;
i2c_start();
i2c_write(0xd0);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
status=i2c_write(0xd0);
while(status==1)
{
i2c_start();
status=i2c_write(0xd0);
}
}
//==========================
// read data one byte from DS1307
//==========================
BYTE read_DS1307(byte address)
{
BYTE data;
i2c_start();
i2c_write(0xd0);
i2c_write(address);
i2c_start();
i2c_write(0xd1);
data=i2c_read(0);
i2c_stop();
return(data);
}
Attachments
Last edited: