MikroElektronika - View Topic - DS1307 MikroC Library1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary

Login

Register

FAQ

Search

Itiscurrently20Oct201519:34

Viewunansweredposts|Viewactivetopics
BoardindexCompilersmikroCCompilersOlderversionsofmikroCCompilersmikroCforPICmikroCGeneral

AlltimesareUTC+1hour

DS1307MikroCLibrary

Page3of3 [44posts]

GotopagePrevious1,2,3

Printview

Previoustopic|Nexttopic

Author
dronology

Joined:29Dec200723:48
Posts:106
Location:istanbul

Message
Postsubject:

Posted:03Nov200809:09

Dear majerv,
Add these functions to your program. You can display the time value on your screen. But this display function is for T6963C drived screen.
If you use KS108 or LM series LCD's (40x2 , 20x2 alphanumeric LCD) or anything else, you need yo modify this code.

Code:Selectall

voidDisplay_Time(charsec,charmin,charhr,charday,charmn,charyear);
voidZero_Fill(char*value);

//OutputvaluestoLCD
voidDisplay_Time(charsec,charmin,charhr,charday,charmn,charyear){
T6963C_waitReady();
ByteToStr(day,tnum);
txt0=rtrim(tnum);
Zero_Fill(txt0);
T6963C_waitReady();
ByteToStr(day,tnum);
txt1=rtrim(tnum);
Zero_Fill(txt1);
T6963C_write_text(txt1,9,5,1);
//LCD_Out(1,6,txt);
T6963C_waitReady();
ByteToStr(mn,tnum);
txt2=rtrim(tnum);
Zero_Fill(txt2);
T6963C_write_text(txt2,12,5,1);
//LCD_Out(1,9,txt);
T6963C_waitReady();
ByteToStr(year,tnum);
txt3=rtrim(tnum);
Zero_Fill(txt3);
T6963C_write_text(txt3,15,5,1);
//LCD_Out(1,9,txt);
T6963C_waitReady();
ByteToStr(hr,tnum);
txt4=rtrim(tnum);
Zero_Fill(txt4);
T6963C_write_text(txt4,9,6,1);
//LCD_Out(1,9,txt);
T6963C_waitReady();
ByteToStr(min,tnum);
txt5=rtrim(tnum);
Zero_Fill(txt5);
T6963C_write_text(txt5,12,6,1);
//LCD_Out(1,9,txt);
T6963C_waitReady();

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

1/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
ByteToStr(sec,tnum);
txt6=rtrim(tnum);
Zero_Fill(txt6);
T6963C_write_text(txt6,15,6,1);
//LCD_Out(1,9,txt);
T6963C_waitReady();
}//~

voidZero_Fill(char*value){//filltextrepesentation
if(value[1]==0){//withleadingzero
value[1]=value[0];
value[0]=48;
value[2]=0;
}

_________________
R. Giskard Reventlov & R. Daneel Olivaw
http://www.circuitechs.com
http://www.dronology.com

Top
masterblastersachin

Postsubject:

Posted:03Nov200810:54

Mohan wrote:
Joined:07May200810:01
Posts:34
Location:BANGALORE

Hi,
Try this out. I used the code at http://www.mikroe.com/forum/viewtopic.php?t=15813
and adapted for EP5, PIC16F877A, 8Mhz crystal & DS1307
LCD at PORTB with EP5 default config, PORTD pull down, Switch Jumper J17 set to VCC

Code:Selectall

//DefinitionsforI2CdevicesBIOS
#defineDS1307_HWAddress0xD0//HardwareaddressoftheRTC
//KeypadPortandlines
#defineKEYPAD_PORTPORTD//Selectkeypadport
#defineKEYPAD_MENUF0//Menu/Exit
#defineKEYPAD_SELECTF1//Select
#defineKEYPAD_INCF2//Incnumber
#defineKEYPAD_DECF3//Decnumber
#defineKEYPAD_RESETF7//Reset
#ifndefHIGH
#defineHIGH1
#defineLOW0
#endif//HIGH+LOW
unsignedcharbSec,bMin,bStd,bDay,bMon,bYear,oldstate;
unsignedintuSec,uMin,uStd,uDay,uMon,uYear;
unsignedcharoutput[21];
externvoidmenu(void);
externvoidStoreToRTC(void);
externvoidInitDisplay(void);
externvoidSet_Position(unsignedcharSign);
externvoidIncDecSign(unsignedSign,unsigneddirect);
externunsignedcharDS1307_Read(unsignedcharAddr);
externvoidDS1307_Write(unsignedcharAddr,unsignedcharData);
//ReadsabytefromtheDS1307(softwarecontrolled)
//Input:addresstowriteto
//Output:thebytevalueinthememoryposition
//Desc:thefunctionreadsasinglebyte(Data)atatimetothedataaddressindicatedinAddr.

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

2/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
unsignedcharDS1307_Read(unsignedcharAddr)
{
unsignedcharAddrBuff;
AddrBuff=DS1307_HWAddress;
I2C_Start();//IssueI2Cstartsignal
I2C_Wr(AddrBuff);//Sendhardwareaddressforwritting
I2C_Wr(Addr);//Sendthedataaddress
I2C_Repeated_Start();
AddrBuff.F0=HIGH;//Configurethedatadirectionbitforreading
I2C_Wr(AddrBuff);//Senddeviceaddress
AddrBuff=I2C_Rd(0);//ReadthebytefromtheslaveandNACKtoendcomms
I2C_Stop();//Freeupthebus
return(AddrBuff);
}
//WritesabytetotheDS1307(softwarecontrolled)
//Input:addresstowriteto,valuetobewritten
//Output:none
//Desc:thefunctionwritesasinglebyte(Data)atatimetothedataaddressindicatedinDataAddr.
voidDS1307_Write(unsignedcharAddr,unsignedcharData)
{
I2C_Start();//IssueI2Cstartsignal
I2C_Wr(DS1307_HWAddress);//Sendhardwareaddressforwritting
I2C_Wr(Addr);//Sendlowbyteofthedataaddress
I2C_Wr(Data);//Sendthedata
I2C_Stop();//Freethebus
return;
}
voidInitDisplay(void)
{
Lcd_Config(&PORTB,4,5,6,3,2,1,0);//Lcd_Init_EP5,seeAutocomplete
Lcd_Cmd(LCD_CLEAR);
Lcd_Cmd(LCD_CURSOR_OFF);//Turnoffcursor
Lcd_Out(1,1,"Time:00:00:00");
Lcd_Out(2,1,"Date:00.00.0000");
Delay_ms(2000);
}
voidReset_Clock(void)
{
bStd=0;
bMin=0;
bSec=0;
bDay=18;
bMon=7;
bYear=8;
StoreToRTC();
InitDisplay();
}
voidSet_Position(unsignedcharSign)
{
switch(Sign)
{
case0:uStd=(unsignedint)bStd;
sprinti(&output,"%02u",uStd);
Lcd_Out(1,7,output);
Lcd_Out(1,8,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case1:uMin=(unsignedint)bMin;
sprinti(&output,"%02u",uMin);
Lcd_Out(1,10,output);
Lcd_Out(1,11,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case2:uSec=(unsignedint)bSec;
sprinti(&output,"%02u",uSec);
Lcd_Out(1,13,output);
Lcd_Out(1,14,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case3:uDay=(unsignedint)bDay;
sprinti(&output,"%02u",uDay);
Lcd_Out(2,7,output);

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

3/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
Lcd_Out(2,8,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case4:uMon=(unsignedint)bMon;
sprinti(&output,"%02u",uMon);
Lcd_Out(2,10,output);
Lcd_Out(2,11,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case5:uYear=(unsignedint)bYear+2000;
sprinti(&output,"%04u",uYear);
Lcd_Out(2,13,output);
Lcd_Out(2,16,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
};
}
voidIncDecSign(unsignedSign,unsigneddirect)
{
switch(Sign)
{
case0:if(!direct)
{
bStd++;
if(bStd>23)
bStd=23;
}else{
if(bStd>0)
bStd;
};
uStd=(unsignedint)bStd;
break;
case1:if(!direct)
{
bMin++;
if(bMin>59)
bMin=59;
}else{
if(bMin>0)
bMin;
};
uMin=(unsignedint)bMin;
break;
case2:if(!direct)
{
bSec++;
if(bSec>59)
bSec=59;
}else{
if(bSec>0)
bSec;
};
uSec=(unsignedint)bSec;
break;
case3:if(!direct)
{
bDay++;
if(bDay>31)
bDay=31;
}else{
if(bDay>0)
bDay;
};
uDay=(unsignedint)bDay;
break;
case4:if(!direct)
{
bMon++;
if(bMon>12)
bMon=12;
}else{
if(bMon>0)
bMon;
};
uMon=(unsignedint)bMon;

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

4/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
break;
case5:if(!direct)
{
bYear++;
if(bYear>99)
bYear=99;
}else{
if(bYear>0)
bYear;
};
uYear=(unsignedint)bYear+2000;
break;
};
}
//StoreallSettingsintoDS1307
/////////////////////////////////
voidStoreToRTC(void)
{
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
Lcd_Out(1,1,"StoretoRTC");
bSec=(((bSec/10)<<4)&0xF0)+((bSec(bSec/10)*10)&0b00001111);
DS1307_Write(0x00,bSec);
bMin=(((bMin/10)<<4)&0xF0)+((bMin(bMin/10)*10)&0b00001111);
DS1307_Write(0x01,bMin);
bStd=(((bStd/10)<<4)&0xF0)+((bStd(bStd/10)*10)&0b00001111);
DS1307_Write(0x02,bStd);
//bDay=((bDay&0x30)>>4)*10+(bDay&0b00001111);
bDay=(((bDay/10)<<4)&0x30)+((bDay(bDay/10)*10)&0b00001111);
DS1307_Write(0x04,bDay);
bMon=(((bMon/10)<<4)&0x10)+((bMon(bMon/10)*10)&0b00001111);
DS1307_Write(0x05,bMon);
bYear=(((bYear/10)<<4)&0xC0)+((bYear(bYear/10)*10)&0b00001111);
DS1307_Write(0x06,bYear);
delay_ms(2000);
}
//KeyPort,inputviabutton
//////////////////////////////
//F0=Menu/Exit
//F1=Select
//F2=INCNumber
//F3=DECNumber
//F7=ResetClockChip
voidmenu(void)
{
unsignedcharSig;
Sig=0;
Lcd_Out(1,1,"Set");
Lcd_Out(2,1,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
Set_Position(Sig);
Delay_ms(2000);
do
{
//Menukeypressed?
////////////////////
if(KEYPAD_PORT.KEYPAD_MENU==1){
delay_ms(250);
break;
};
if(KEYPAD_PORT.KEYPAD_SELECT==1){
delay_ms(250);
Sig++;
if(Sig>5)
Sig=0;
Set_Position(Sig);
};
//Increment

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

5/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
if(KEYPAD_PORT.KEYPAD_INC==1){
delay_ms(100);
IncDecSign(Sig,0);
Set_Position(Sig);
};
//Decrement
if(KEYPAD_PORT.KEYPAD_DEC==1){
delay_ms(100);
IncDecSign(Sig,1);
Set_Position(Sig);
};
Delay_ms(100);
}while(1);
//StoreallSettingsinDS1307
///////////////////////////////
StoreToRTC();
//ExittoClock
Lcd_Cmd(Lcd_CURSOR_OFF);

//RefreshDisplay
InitDisplay();
}
voidmain(void)
{
TRISD=0b10001111;
PORTB=0x00;
TRISC=0x00;
PORTC=0b00;
TRISD=0x00;
PORTD=0x00;
TRISE=0x00;
PORTE=0x00;
ADCON1=7;//disableanaloginputs
I2C_Init(100000);//initializeI2C
I2C_Start();//issuestartsignal
I2C_Wr(0xD0);//addressDS1307
I2C_Wr(0);//startfromwordataddress0
I2C_Wr(0);//write0toREG0(enablecounting+0sec)
I2C_Stop();//issuestopsignal
InitDisplay();
oldstate=0;
//ClockRoutine
////////////////
do
{
delay_ms(100);
bSec=DS1307_Read(0x00);
bSec=((bSec&0xF0)>>4)*10+(bSec&0b00001111);
uSec=(unsignedint)bSec;
bMin=DS1307_Read(0x01);
bMin=((bMin&0xF0)>>4)*10+(bMin&0b00001111);
uMin=(unsignedint)bMin;
bStd=DS1307_Read(0x02);
bStd=((bStd&0xF0)>>4)*10+(bStd&0b00001111);
uStd=(unsignedint)bStd;
bDay=DS1307_Read(0x04);
bDay=((bDay&0x30)>>4)*10+(bDay&0b00001111);
uDay=(unsignedint)bDay;
bMon=DS1307_Read(0x05);
bMon=((bMon&0x10)>>4)*10+(bMon&0b00001111);
uMon=(unsignedint)bMon;
bYear=DS1307_Read(0x06);
bYear=((bYear&0xC0)>>4)*10+(bYear&0b00001111);
uYear=(unsignedint)bYear+2000;

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

6/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
sprinti(&output,"%02u:%02u:%02u",uStd,uMin,uSec);
Lcd_out(1,7,output);
sprinti(&output,"%02u.%02u.%04u",uDay,uMon,uYear);
Lcd_out(2,7,output);
//Menukeypressed?
////////////////////
if(KEYPAD_PORT.KEYPAD_MENU==1){
delay_ms(250);
menu();
}elseif(KEYPAD_PORT.KEYPAD_RESET==1){
delay_ms(250);
Reset_Clock();
};
}while(1);
}

hey dude ,is this code works without any error....


but in my system its showing the error as demo limit
help me yar.....
thank u.....
_________________
SACHIN
http://belgaum.myminicity.com/

Top

petrd

Postsubject:

masterblastersachin

Posted:03Nov200811:12

Hi!
This may be in case if you use MikroC without activation key and you program use more then 2K program memory (demo limit from mE).
Regards!

Joined:14Feb200811:04
Posts:71
Location:Russia,Voronezh
Top

Postsubject:

Posted:04Nov200804:52

Mohan wrote:
Joined:07May200810:01
Posts:34
Location:BANGALORE

Hi,
Try this out. I used the code at http://www.mikroe.com/forum/viewtopic.php?t=15813
and adapted for EP5, PIC16F877A, 8Mhz crystal & DS1307
LCD at PORTB with EP5 default config, PORTD pull down, Switch Jumper J17 set to VCC

Code:Selectall

//DefinitionsforI2CdevicesBIOS
#defineDS1307_HWAddress0xD0//HardwareaddressoftheRTC
//KeypadPortandlines
#defineKEYPAD_PORTPORTD//Selectkeypadport
#defineKEYPAD_MENUF0//Menu/Exit
#defineKEYPAD_SELECTF1//Select
#defineKEYPAD_INCF2//Incnumber
#defineKEYPAD_DECF3//Decnumber
#defineKEYPAD_RESETF7//Reset
#ifndefHIGH
#defineHIGH1
#defineLOW0
#endif//HIGH+LOW
unsignedcharbSec,bMin,bStd,bDay,bMon,bYear,oldstate;
unsignedintuSec,uMin,uStd,uDay,uMon,uYear;
unsignedcharoutput[21];

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

7/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
externvoidmenu(void);
externvoidStoreToRTC(void);
externvoidInitDisplay(void);
externvoidSet_Position(unsignedcharSign);
externvoidIncDecSign(unsignedSign,unsigneddirect);
externunsignedcharDS1307_Read(unsignedcharAddr);
externvoidDS1307_Write(unsignedcharAddr,unsignedcharData);
//ReadsabytefromtheDS1307(softwarecontrolled)
//Input:addresstowriteto
//Output:thebytevalueinthememoryposition
//Desc:thefunctionreadsasinglebyte(Data)atatimetothedataaddressindicatedinAddr.
unsignedcharDS1307_Read(unsignedcharAddr)
{
unsignedcharAddrBuff;
AddrBuff=DS1307_HWAddress;
I2C_Start();//IssueI2Cstartsignal
I2C_Wr(AddrBuff);//Sendhardwareaddressforwritting
I2C_Wr(Addr);//Sendthedataaddress
I2C_Repeated_Start();
AddrBuff.F0=HIGH;//Configurethedatadirectionbitforreading
I2C_Wr(AddrBuff);//Senddeviceaddress
AddrBuff=I2C_Rd(0);//ReadthebytefromtheslaveandNACKtoendcomms
I2C_Stop();//Freeupthebus
return(AddrBuff);
}
//WritesabytetotheDS1307(softwarecontrolled)
//Input:addresstowriteto,valuetobewritten
//Output:none
//Desc:thefunctionwritesasinglebyte(Data)atatimetothedataaddressindicatedinDataAddr.
voidDS1307_Write(unsignedcharAddr,unsignedcharData)
{
I2C_Start();//IssueI2Cstartsignal
I2C_Wr(DS1307_HWAddress);//Sendhardwareaddressforwritting
I2C_Wr(Addr);//Sendlowbyteofthedataaddress
I2C_Wr(Data);//Sendthedata
I2C_Stop();//Freethebus
return;
}
voidInitDisplay(void)
{
Lcd_Config(&PORTB,4,5,6,3,2,1,0);//Lcd_Init_EP5,seeAutocomplete
Lcd_Cmd(LCD_CLEAR);
Lcd_Cmd(LCD_CURSOR_OFF);//Turnoffcursor
Lcd_Out(1,1,"Time:00:00:00");
Lcd_Out(2,1,"Date:00.00.0000");
Delay_ms(2000);
}
voidReset_Clock(void)
{
bStd=0;
bMin=0;
bSec=0;
bDay=18;
bMon=7;
bYear=8;
StoreToRTC();
InitDisplay();
}
voidSet_Position(unsignedcharSign)
{
switch(Sign)
{
case0:uStd=(unsignedint)bStd;
sprinti(&output,"%02u",uStd);
Lcd_Out(1,7,output);
Lcd_Out(1,8,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case1:uMin=(unsignedint)bMin;
sprinti(&output,"%02u",uMin);
Lcd_Out(1,10,output);

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

8/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
Lcd_Out(1,11,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case2:uSec=(unsignedint)bSec;
sprinti(&output,"%02u",uSec);
Lcd_Out(1,13,output);
Lcd_Out(1,14,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case3:uDay=(unsignedint)bDay;
sprinti(&output,"%02u",uDay);
Lcd_Out(2,7,output);
Lcd_Out(2,8,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case4:uMon=(unsignedint)bMon;
sprinti(&output,"%02u",uMon);
Lcd_Out(2,10,output);
Lcd_Out(2,11,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
case5:uYear=(unsignedint)bYear+2000;
sprinti(&output,"%04u",uYear);
Lcd_Out(2,13,output);
Lcd_Out(2,16,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
break;
};
}
voidIncDecSign(unsignedSign,unsigneddirect)
{
switch(Sign)
{
case0:if(!direct)
{
bStd++;
if(bStd>23)
bStd=23;
}else{
if(bStd>0)
bStd;
};
uStd=(unsignedint)bStd;
break;
case1:if(!direct)
{
bMin++;
if(bMin>59)
bMin=59;
}else{
if(bMin>0)
bMin;
};
uMin=(unsignedint)bMin;
break;
case2:if(!direct)
{
bSec++;
if(bSec>59)
bSec=59;
}else{
if(bSec>0)
bSec;
};
uSec=(unsignedint)bSec;
break;
case3:if(!direct)
{
bDay++;
if(bDay>31)
bDay=31;
}else{
if(bDay>0)
bDay;
};

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

9/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
uDay=(unsignedint)bDay;
break;
case4:if(!direct)
{
bMon++;
if(bMon>12)
bMon=12;
}else{
if(bMon>0)
bMon;
};
uMon=(unsignedint)bMon;
break;
case5:if(!direct)
{
bYear++;
if(bYear>99)
bYear=99;
}else{
if(bYear>0)
bYear;
};
uYear=(unsignedint)bYear+2000;
break;
};
}
//StoreallSettingsintoDS1307
/////////////////////////////////
voidStoreToRTC(void)
{
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
Lcd_Out(1,1,"StoretoRTC");
bSec=(((bSec/10)<<4)&0xF0)+((bSec(bSec/10)*10)&0b00001111);
DS1307_Write(0x00,bSec);
bMin=(((bMin/10)<<4)&0xF0)+((bMin(bMin/10)*10)&0b00001111);
DS1307_Write(0x01,bMin);
bStd=(((bStd/10)<<4)&0xF0)+((bStd(bStd/10)*10)&0b00001111);
DS1307_Write(0x02,bStd);
//bDay=((bDay&0x30)>>4)*10+(bDay&0b00001111);
bDay=(((bDay/10)<<4)&0x30)+((bDay(bDay/10)*10)&0b00001111);
DS1307_Write(0x04,bDay);
bMon=(((bMon/10)<<4)&0x10)+((bMon(bMon/10)*10)&0b00001111);
DS1307_Write(0x05,bMon);
bYear=(((bYear/10)<<4)&0xC0)+((bYear(bYear/10)*10)&0b00001111);
DS1307_Write(0x06,bYear);
delay_ms(2000);
}
//KeyPort,inputviabutton
//////////////////////////////
//F0=Menu/Exit
//F1=Select
//F2=INCNumber
//F3=DECNumber
//F7=ResetClockChip
voidmenu(void)
{
unsignedcharSig;
Sig=0;
Lcd_Out(1,1,"Set");
Lcd_Out(2,1,"");
Lcd_Cmd(LCD_BLINK_CURSOR_ON);
Set_Position(Sig);
Delay_ms(2000);
do
{
//Menukeypressed?
////////////////////
if(KEYPAD_PORT.KEYPAD_MENU==1){
delay_ms(250);

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

10/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
break;
};
if(KEYPAD_PORT.KEYPAD_SELECT==1){
delay_ms(250);
Sig++;
if(Sig>5)
Sig=0;
Set_Position(Sig);
};
//Increment
if(KEYPAD_PORT.KEYPAD_INC==1){
delay_ms(100);
IncDecSign(Sig,0);
Set_Position(Sig);
};
//Decrement
if(KEYPAD_PORT.KEYPAD_DEC==1){
delay_ms(100);
IncDecSign(Sig,1);
Set_Position(Sig);
};
Delay_ms(100);
}while(1);
//StoreallSettingsinDS1307
///////////////////////////////
StoreToRTC();
//ExittoClock
Lcd_Cmd(Lcd_CURSOR_OFF);

//RefreshDisplay
InitDisplay();
}
voidmain(void)
{
TRISD=0b10001111;
PORTB=0x00;
TRISC=0x00;
PORTC=0b00;
TRISD=0x00;
PORTD=0x00;
TRISE=0x00;
PORTE=0x00;
ADCON1=7;//disableanaloginputs
I2C_Init(100000);//initializeI2C
I2C_Start();//issuestartsignal
I2C_Wr(0xD0);//addressDS1307
I2C_Wr(0);//startfromwordataddress0
I2C_Wr(0);//write0toREG0(enablecounting+0sec)
I2C_Stop();//issuestopsignal
InitDisplay();
oldstate=0;
//ClockRoutine
////////////////
do
{
delay_ms(100);
bSec=DS1307_Read(0x00);
bSec=((bSec&0xF0)>>4)*10+(bSec&0b00001111);
uSec=(unsignedint)bSec;
bMin=DS1307_Read(0x01);
bMin=((bMin&0xF0)>>4)*10+(bMin&0b00001111);
uMin=(unsignedint)bMin;
bStd=DS1307_Read(0x02);
bStd=((bStd&0xF0)>>4)*10+(bStd&0b00001111);

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

11/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
uStd=(unsignedint)bStd;
bDay=DS1307_Read(0x04);
bDay=((bDay&0x30)>>4)*10+(bDay&0b00001111);
uDay=(unsignedint)bDay;
bMon=DS1307_Read(0x05);
bMon=((bMon&0x10)>>4)*10+(bMon&0b00001111);
uMon=(unsignedint)bMon;
bYear=DS1307_Read(0x06);
bYear=((bYear&0xC0)>>4)*10+(bYear&0b00001111);
uYear=(unsignedint)bYear+2000;
sprinti(&output,"%02u:%02u:%02u",uStd,uMin,uSec);
Lcd_out(1,7,output);
sprinti(&output,"%02u.%02u.%04u",uDay,uMon,uYear);
Lcd_out(2,7,output);
//Menukeypressed?
////////////////////
if(KEYPAD_PORT.KEYPAD_MENU==1){
delay_ms(250);
menu();
}elseif(KEYPAD_PORT.KEYPAD_RESET==1){
delay_ms(250);
Reset_Clock();
};
}while(1);
}

hey dude ,is this code works without any error....


but in my system its showing the error as demo limit
help me yar.....
thank u.....
_________________
SACHIN
http://belgaum.myminicity.com/

Top

masterblastersachin

Postsubject:

Posted:04Nov200810:01

can any body eaxplain me what is this Demo limit?


its not exceeding the 2k program memory.....
Joined:07May200810:01
Posts:34
Location:BANGALORE

Top

_________________
SACHIN
http://belgaum.myminicity.com/

SPONTEX

Postsubject:

Posted:06Nov200817:52

Hello,
your code is ok, i compilated it with PIC16F877A and results:

Joined:13Jun200707:31
Posts:22

Used ROM: 4734 octets


Used RAM: 148 octets
So you are beyond 2Ko... (2734 octets in overflow)

Top
malikmuhammadali

Postsubject:Re:CodeforDS1307

Posted:25Apr201015:58

WHEN I BUILD THIS CODE I GET THE ERROR.BCZ TWO MAIN FUNCTIONS ARE DEFINED IN A SINGLE SINGLE CODE FILE.REPLY WT I

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

12/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
DO........?

Joined:21Apr201015:30
Posts:1
Top

balazs

Postsubject:Re:DS1307MikroCLibrary

Posted:28Apr201012:32

In the main program you have to declare PORTB as output.


That means you have to write TRISB =0,and it will work.
Joined:20Mar201014:53
Posts:37

Top

Regards.

doup

Postsubject:18f4550withDS1307

Posted:10Nov201121:40

Hi! I have a problem. I want to build a digital clock with 18f4550 and RTC. My source
Joined:10Nov201121:33
Posts:2

Code:Selectall

//LCDsetup
sbitLCD_RSatLATD0_bit;
sbitLCD_ENatLATD1_bit;
sbitLCD_D4atLATA2_bit;
sbitLCD_D5atLATA3_bit;
sbitLCD_D6atLATA4_bit;
sbitLCD_D7atLATA5_bit;
sbitLCD_RS_DirectionatTRISD0_bit;
sbitLCD_EN_DirectionatTRISD1_bit;
sbitLCD_D4_DirectionatTRISA2_bit;
sbitLCD_D5_DirectionatTRISA3_bit;
sbitLCD_D6_DirectionatTRISA4_bit;
sbitLCD_D7_DirectionatTRISA5_bit;
charseconds,minutes,hours,day,month,year;//Globaldate/timevariables
//SoftwareI2Cconnections
sbitSoft_I2C_SclatRB1_bit;
sbitSoft_I2C_SdaatRB0_bit;
sbitSoft_I2C_Scl_DirectionatTRISB1_bit;
sbitSoft_I2C_Sda_DirectionatTRISB0_bit;
//EndSoftwareI2Cconnections
//ReadstimeanddateinformationfromRTC(PCF8583)
voidRead_Time(){
Soft_I2C_Start();//Issuestartsignal
Soft_I2C_Write(0xD0);//AddressPCF8583,seePCF8583datasheet
Soft_I2C_Write(2);//Startfromaddress2
Soft_I2C_Start();//Issuerepeatedstartsignal
Soft_I2C_Write(0xD1);//AddressPCF8583forreadingR/W=1
seconds=Soft_I2C_Read(1);//Readsecondsbyte
minutes=Soft_I2C_Read(1);//Readminutesbyte
hours=Soft_I2C_Read(1);//Readhoursbyte
day=Soft_I2C_Read(1);//Readyear/daybyte
month=Soft_I2C_Read(0);//Readweekday/monthbyte
Soft_I2C_Stop();//Issuestopsignal
}
//Formatsdateandtime
voidTransform_Time(){
seconds=((seconds&0xF0)>>4)*10+(seconds&0x0F);//Transformseconds
minutes=((minutes&0xF0)>>4)*10+(minutes&0x0F);//Transformmonths
hours=((hours&0xF0)>>4)*10+(hours&0x0F);//Transformhours
year=(day&0xC0)>>6;//Transformyear
day=((day&0x30)>>4)*10+(day&0x0F);//Transformday
month=((month&0x10)>>4)*10+(month&0x0F);//Transformmonth
}
//OutputvaluestoLCD
voidDisplay_Time(){

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

13/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
Lcd_Chr(1,6,(day/10)+48);//Printtensdigitofdayvariable
Lcd_Chr(1,7,(day%10)+48);//Printonessdigitofdayvariable
Lcd_Chr(1,9,(month/10)+48);
Lcd_Chr(1,10,(month%10)+48);
Lcd_Chr(1,15,year+48);//Printyearvariable(startfromyear2010)

Lcd_Chr(2,6,(hours/10)+48);
Lcd_Chr(2,7,(hours%10)+48);
Lcd_Chr(2,9,(minutes/10)+48);
Lcd_Chr(2,10,(minutes%10)+48);
Lcd_Chr(2,12,(seconds/10)+48);
Lcd_Chr(2,13,(seconds%10)+48);
}

//Performsprojectwideinit
voidInit_Main(){
OSCCON=0x71;//rajelbelltsa8Mhzre
while((OSCCON&0x4)!=0x4);//vrakozsazrajelstabilitsig
delay_ms(500);
ADCON1=0x0F;//Configureallportswithanalogfunctionasdigital
CMCON=7;
TRISD=0;
PORTD=0xFF;
TRISD=0xff;
TRISA=0;
PORTA=0xFF;
TRISA=0xff;
Soft_I2C_Init();//InitializeSoftI2Ccommunication
Lcd_Init();//InitializeLCD
Lcd_Cmd(_LCD_CLEAR);//ClearLCDdisplay
Lcd_Cmd(_LCD_CURSOR_OFF);//Turncursoroff
Lcd_Out(1,1,"Date:");//PrepareandoutputstatictextonLCD
Lcd_Chr(1,8,'.');
Lcd_Chr(1,11,'.');
Lcd_Chr(1,16,'.');
Lcd_Out(2,1,"Time:");
Lcd_Chr(2,8,':');
Lcd_Chr(2,11,':');
Lcd_Out(1,12,"201");//startfromyear2010
}
//Mainprocedure
voidmain(){
Delay_ms(500);
Init_Main();//Performinitialization
while(1){//Endlessloop
Read_Time();//ReadtimefromRTC(PCF8583)
Transform_Time();//Formatdateandtime
Display_Time();//PrepareanddisplayonLCD
}
}

The Lcd display always shows


Date:01.00.2010
Time:01:01:00
and the RTC is not running.
Somebody help me?

Top

internetuser2k11

Postsubject:Re:ds1307

Posted:04Nov201215:41

Hello! dronology
Joined:12Apr201202:39
Posts:258

A part of my code is like this

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

14/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary

Code:Selectall

voidWrite_Time(){
I2C2_Start();//issuestartsignal
I2C2_Wr(DS1307);//addressDS1307
I2C2_Wr(0);//startfromwordataddress(REG0)
I2C2_Wr(0x80);//write$80toREG0.(pausecounter+0sec)
I2C2_Wr(0);//write0tominuteswordto(REG1)
I2C2_Wr(0x17);//write17tohoursword(24hoursmode)(REG2)
I2C2_Wr(0x02);//write2Monday(REG3)
I2C2_Wr(0x04);//write4todateword(REG4)
I2C2_Wr(0x05);//write5(May)tomonthword(REG5)
I2C2_Wr(0x01);//write01toyearword(REG6)
I2C2_Stop();//issuestopsignal
I2C2_Start();//issuestartsignal
I2C2_Wr(0xD0);//addressDS1307
I2C2_Wr(0);//startfromwordataddress0
I2C2_Wr(0);//write0toREG0(enablecounting+0sec)
I2C2_Stop();//issuestopsignal
}

In that I want to know what value I have to write in this code

Code:Selectall

I2C2_Wr(0x17);//write17tohoursword(24hoursmode)(REG2)

to make the clock work in 12 hr mode? I also want to display AM and PM.

Thanks
Jayanth D

Top

thronborg

Postsubject:Re:DS1307MikroCLibrary

Posted:08Aug201305:52

Hi from totally newbee


Joined:06Aug201311:10
Posts:14

I use MikroC 6.0.0 and tried to run this code but i only got a lot of ERRORS.
What is the problem, have they changed so the old I2C_Start must be changed to I2C1????
And the same with the Lcd Config?
If the problem is MikroC 6.0.0 i must downgrade to version 4 to get it to work??
Thanks in advance
Attachments:

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

15/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary

Skrmavbild20130808kl.06.48.23.png[19.21KiB|Viewed1394times]

Top

jaybhut

Postsubject:Re:DS1307MikroCLibrary

marina.petrovic

Posted:24Jan201410:58

hi i know this is too old post and its not good to replay in this.
but i am in hurry and again new be and wanting for code of DS1307 with PIC 16F887 controller.
so, please will you give me that code or link?

Joined:24Jan201410:55
Posts:4

Top

Postsubject:Re:DS1307MikroCLibrary

Posted:27Jan201415:12

Hi,
Our RTC2 click features the DS1307 serial realtime clock (RTC),
so please, take a look at RTC2 click examples:
http://www.libstock.com/projects/view/2 ... ckexample
Joined:18Apr201308:11
Posts:2986

The example is written for EasyPIC v7 PIC18F45K22, but with the help of PIC16F887 datasheet
you can try to adjust the example to work with your microcontroller/hardware.
Best regards,
Marina

Top
aviraje8@gmail.com

Postsubject:Re:DS1307MikroCLibrary

Posted:28Nov201410:27

Hi am using mikroC compiler for 8051.In this compiler rtc interfacing with 8051 library is given.it works but it do not displays todays
date & time value plz help me
Joined:26Jun201407:03
Posts:15

this is the code

char seconds, minutes, hours, date, month; // Global date/time variables


unsigned int year;
unsigned int RTCModuleAddress, YearOffset; // RTC chip description variables
#define DS1307 // Uncomment this line if you use DS1307 RTC chip (mE RTC2 extra board)
// Software I2C connections
sbit Soft_I2C_Scl at P2_3_bit;
sbit Soft_I2C_Sda at P2_4_bit;
// End Software I2C connections
// LCD module connections
sbit LCD_RS at P2_0_bit;
sbit LCD_EN at P2_1_bit;

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

16/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
sbit LCD_D4 at P0_4_bit;
sbit LCD_D5 at P0_5_bit;
sbit LCD_D6 at P0_6_bit;
sbit LCD_D7 at P0_7_bit;
// End LCD module connections
// Performs projectwide init
void Init_Main() {
#ifdef DS1307
RTCModuleAddress = 0xD0;
YearOffset = 2000;
#endif

Soft_I2C_Init(); // Initialize Soft I2C communication


Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
LCD_Out(1,1,"Date:"); // Prepare and output static text on LCD
Lcd_Chr(1,8,':');
Lcd_Chr(1,11,':');
LCD_Out(2,1,"Time:");
Lcd_Chr(2,8,':');
Lcd_Chr(2,11,':');
}

// Reads time and date information from DS1307 RTC


void Read_Time_DS1307()
{
char byte_read;
Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(RTCModuleAddress); // RTC module address + write (R#/W = 0)
Soft_I2C_Write(0); // Start from seconds byte
Soft_I2C_Start(); // Issue repeated start signal
Soft_I2C_Write(RTCModuleAddress+1); // RTC module address + read (R#/W = 1)
byte_read = Soft_I2C_Read(1); // Read seconds byte
seconds = ((byte_read & 0x70) >> 4)*10 + (byte_read & 0x0F); // Transform seconds
byte_read = Soft_I2C_Read(1); // Read minutes byte
minutes = ((byte_read & 0x70) >> 4)*10 + (byte_read & 0x0F); // Transform minutes
byte_read = Soft_I2C_Read(1); // Read hours byte
/*if (byte_read.B6) { // 12h format
hours = ((byte_read & 0x10) >> 4)*10 + (byte_read & 0x0F); // Transform hours
if (byte_read.B5) // PM flag
hours = hours + 12;
}
else
hours = ((byte_read & 0x30) >> 4)*10 + (byte_read & 0x0F); // Transform hours
byte_read = Soft_I2C_Read(1); // Read weekday byte
byte_read = Soft_I2C_Read(1); // Read date byte
date = ((byte_read & 0x30) >> 4)*10 + (byte_read & 0x0F); // Transform date
byte_read = Soft_I2C_Read(1); // Read month byte
month = ((byte_read & 0x10) >> 4)*10 + (byte_read & 0x0F); // Transform month
byte_read = Soft_I2C_Read(1); // Read year byte
year = YearOffset + ((byte_read & 0xF0) >> 4)*10 + (byte_read & 0x0F); // Transform year */
Soft_I2C_Stop(); // Issue stop signal
}
// Reads time and date information from RTC
void Read_Time() {
#ifdef DS1307
Read_Time_DS1307();
#endif

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

17/18

10/21/2015

mikroElektronikaViewtopicDS1307MikroCLibrary
}
// Output values to LCD
void Display_Time() {
Lcd_Chr(1, 6, (date / 10) + 48); // Print tens digit of date variable
Lcd_Chr(1, 7, (date % 10) + 48); // Print oness digit of date variable
Lcd_Chr(1, 9, (month / 10) + 48);
Lcd_Chr(1,10, (month % 10) + 48);
Lcd_Chr(1,12, ((year / 1000) % 10) + 48); // Print year
Lcd_Chr(1,13, ((year / 100) % 10) + 48);
Lcd_Chr(1,14, ((year / 10) % 10) + 48);
Lcd_Chr(1,15, (year % 10) + 48);
Lcd_Chr(2, 6, (hours / 10) + 48);
Lcd_Chr(2, 7, (hours % 10) + 48);
Lcd_Chr(2, 9, (minutes / 10) + 48);
Lcd_Chr(2,10, (minutes % 10) + 48);
Lcd_Chr(2,12, (seconds / 10) + 48);
Lcd_Chr(2,13, (seconds % 10) + 48);
}
// Main procedure
void main() {
Delay_ms(2000);
Init_Main(); // Perform initialization
while (1) { // Endless loop
Read_Time(); // Read time from RTC
Display_Time(); // Prepare and display on LCD
Delay_ms(1000); // Wait 1 second
}
}

Top

Displaypostsfromprevious: Allposts

Sortby Posttime

Ascending

Page3of3 [44posts]

Go
GotopagePrevious1,2,3

BoardindexCompilersmikroCCompilersOlderversionsofmikroCCompilersmikroCforPICmikroCGeneral

AlltimesareUTC+1hour

Whoisonline
Usersbrowsingthisforum:Noregisteredusersand1guest
Youcannotpostnewtopicsinthisforum
Youcannotreplytotopicsinthisforum
Youcannotedityourpostsinthisforum
Youcannotdeleteyourpostsinthisforum
Youcannotpostattachmentsinthisforum
Searchfor:

Go

Jumpto: mikroCGeneral

Go

PoweredbyphpBBForumSoftwarephpBBGroup

http://www.mikroe.com/forum/viewtopic.php?f=13&t=16343&start=30

18/18

You might also like