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.

RTC interfacing with 16F877a

Status
Not open for further replies.
I updated all,
clock is ticking but year has unrecognized chars
I think the problem is with
year = ((year & 0xf0) >> 4)*10 + (year & 0x0F); // Transform year

---------- Post added at 08:09 ---------- Previous post was at 07:31 ----------

It stops after one or two ticking

For year you transformation code is correct, one main thing i observed with RTC DS1307 that if you put abnormal data to register, it will write that one,

Do one thing, write a little program to update correct date and time values in DS1307 IC than check.

It stops after one or two ticking
What do you mean by that?
 

the seconds changes one or two times then it will freeze.
i made it working using software i2c
https://www.edaboard.com/threads/238007/
but the time and date not correct, so i want to get a setup mode....,
what is the easy way to set the date and time ?,

Easy way to set time or date by using code. just write appropriate date and time to corresponding registers at startup. Software I2C or Software UART is not a recommended solution, use microcontroller which have hardware I2C TWI.
 

I am using 16f877a which is having hardware i2c but , i cant make it working, so i am going behind software i2c
 

I am using 16f877a which is having hardware i2c but , i cant make it working, so i am going behind software i2c

Why not use this library

Example code for I2C, routines for PIC16F877 to write to the 24LC01B EEPROM, using the PICDEM 2 demo board from Microchip. By Michael Alon. https://www.microchipc.com/sourcecode/PIC_Hi-Tech_C_I2C_for_EEPROM_24LC01B.zip

Page Link isMicrochip PIC micros and C - source and sample code

Try to learn hardware I2C using TWI EEPROM IC first than implement it with DS1307
 

Can the software i2C can cause problems ?

I have modified the hardware based rtc to getting input from keypad

and attached here

but i cant initialize the time on lcd , just showing zeros on LCD
 

Attachments

  • rtc new.txt
    8 KB · Views: 63

hai varun...

Can you confirm a small doubt in your code?

switch (loc)
{
case 0: val=0x00; break;
case 1: if (val>59) val=0x00; if (val<0) val=60+val; break;
case 2: if (val>23) val=0x00; if (val<0) val=24+val; break;
case 3: val=0x00; break;
case 4: if (val>31) val=0x01; if (val<1) val=31+val; break;
case 5: if (val>12) val=0x01; if (val<1) val=12+val; break;
case 6: if (val>99) val=0x00; if (val<1) val=99+val; break;
}

In all these places, the 2nd if condition is executed upon what condition? i mean if the 1st condition "if (val>59) val=0x00;" fails, the next "if (val<0) val=60+val;" will execute. Is this the manner you have coded or if the 1st if condition true or false, the 2nd if should execute?
 

first condition is checked and writes the hex and if the second condition is reached, value is added and excapes
 

it looks like the function parameters which you are entered in main will not give you any output.
Update_DateTime(0,0);
Update_DateTime(5,1);
Update_DateTime(14,2);
Update_DateTime(22,4);
Update_DateTime(1,5);
Update_DateTime(12,6);

The 2nd if condition always fails as per the values which you have coded. Am i right? sorry if i have not understood properly
 


finally , i solved the issue, it was an issue with the conversion of BCD to hex in the case of year .....
 

Anyone help me with making the clock in 12hr format ?
 

want to set 12hr code and show

It is simple, Register 02h is hour register, you need to first download correct settings for 12h readings than you have to read this register and transfer accordingly,

Bit 6 must be 1 for 12h, bit 5 is for AM/PM, PM = 1, and AM = 0, and rest bits for hour.

For example you have to download 0b01110010 for 12PM settings, than readjust your time transformation register

unsigned char ampm;

//Add this in READ_TIME Function
if ((*hr & 0x20)==1)
{
ampm = 'P';
}
else {
ampm = 'A';
}

// Edit this line in Transform Function
*hr = ((*hr & 0x10) >> 4)*10 + (*hr & 0x0F);


// Add this with Display_Function after sec
Lcd_Chr(2,14, ampm);
Lcd_Chr(2,15, 'M');



Hope this may guide you
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top