RTC using DS1307 with pic18f452 and pic18compiler.

Status
Not open for further replies.

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
i want to display the date and time to LCD....

i dont know to how to read and write I2C... the below program is executed...but output is not worked
pls somebody help me...or give some code based on pic18 compiler...

#include<p18f458.h>OR <P18F452.h>
unsigned char SPI(unsigned char mybyte);
void TRANS(unsigned char mychar);
void main()
{
int c;
SSPSTAT=0x00;
SSPCON1=0x22;
TRISC=0x00;
TRISCbits.TRISC4=1;
TRISCbits.TRISC7=1;
TXSTA=0x20;
SPBRG=15;
RCSTAbits.SPEN=1;
TRANS(0x0A);
TRANS(0X0D);
while(1)
{
PORTCbits.RC2=1; //start single byte write
SPI(0x8F);
SPI(0x00);
PORTCbits.RC2=0; // end single byte write
PORTCbits.RC2=1;
SPI(0x80);
c=SSPBUF;
SPI(0x55);
SPI(0x58);
SPI(0x16);
SPI(0x03);
SPI(0x19);
SPI(0x10);
SPI(0x05);
PORTCbits.RC2=0;
PORTC=c;
}
TRANS(0x0D);
}
unsigned char SPI(unsigned char mybyte)
{
SSPBUF=mybyte;
while(!SSPSTATbits.BF);
return SSPBUF;
}

void TRANS(unsigned char mychar)
{
while(!PIR1bits.TXIF);
TXREG=mychar;
}

thanks

jai
 


no routine for LCD in your code

https://adf.ly/4116/pic-lesson-set-time-and-date

look at this site for reference
 

Last edited:

first i try to display in hyper terminal but it not displaying...so i want try to display on LCD...its possible....i m beginner ...pls help me...
 

how to change 24 hour to 12 hour can u help me..... thanks....


#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"

void main(void)
{
int8 sec,min,hour,day,date,month,year,pm;

delay_ms(50);
init_ds1307(); // initial DS1307
//sec=read_ds1307(0);
//write_ds1307(0,sec & 0x7F); // enable oscillator(bit 7 =0)
write_ds1307(2,hour & 0x3F); // extract the hour in BCD


while(true)
{
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
putc(0x0c);

printf("Time : %X:%X:%X\r\n",hour,min,sec);
printf("Day : %02X\r\n",day);
printf("Date : %X/%X/%X\r\n",date,month,year);
delay_ms(500);
}
}
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);
}
PHP:


---------- Post added at 18:23 ---------- Previous post was at 18:21 ----------

PHP:
 hi .................how to change 24 hour to 12 hour by using  DS1307...
 

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…