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.

display ds1307rtc in lcd

Status
Not open for further replies.

jaya krishna

Member level 1
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...

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);   
   
 }
ds1307

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

  • realtimeclock.JPG
    realtimeclock.JPG
    247.8 KB · Views: 100
Last edited:

Re: display ds1307rtc in lcd ASCII to decimal

pls any body help for above post..........i need it urgent.............thanks.......
 

Re: display ds1307rtc in lcd ASCII to decimal

Code:
DS1307Read(0x00,&data);
		Time[8]='\0';
		Time[7]=48+(data & 0b00001111);
		Time[6]=48+((data & 0b01110000)>>4);
		Time[5]=':';
	
		DS1307Read(0x01,&data);
	
		Time[4]=48+(data & 0b00001111);
		Time[3]=48+((data & 0b01110000)>>4);
		Time[2]=':';
	
		DS1307Read(0x02,&data);
	
		Time[1]=48+(data & 0b00001111);
		Time[0]=48+((data & 0b00010000)>>4);

		LCDClear();
	
		LCDWriteString("DS1307 RTC Exmple");
	
		LCDWriteStringXY(2,1,Time);
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top