EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Reg-RTC

Reg-RTC

|

Microcontroller › PIC › Reg-RTC

  • This topic has 11 replies, 2 voices, and was last updated 9 years, 10 months ago by Prabakaran P M.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • August 20, 2015 at 5:23 am #3913
    karthick.v
    Participant

    Hai buddy,

                  I can able to program in i2c but i can able to read and write in RTC,what are all procedures to program rtc and how to program.

    August 20, 2015 at 12:06 pm #13188
    Prabakaran P M
    Participant

    Hi Karthick

    what microcontroller have you choosed to read the RTC register.

    August 21, 2015 at 6:22 am #13190
    karthick.v
    Participant

    Hai Prabha,

                   Iam working in pic16f877a

     

    August 21, 2015 at 7:36 am #13191
    Prabakaran P M
    Participant

    Hi karthick

    I'm not sure about what compiler you are using, my suggestion for you is to use MikroC for pic google it you can find sample code to read RTC register. It is a free software with 2KB of Code limitation.

    August 21, 2015 at 9:38 am #13192
    karthick.v
    Participant
    hai duddy,
                  The following is the rtc program i have an doubt in this program that why we are giving for hours    sendi2c(0x02);//////for minutes  sendi2c(0x01);////for seconds  sendi2c(0x00);//////date  sendi2c(0x04);/////month sendi2c(0x05);//////year sendi2c(0x07);///////
    // RTC Interface with PIC 16F877A:
    #include<pic.h>
    void portconfig();
    void sendi2c(char x);
    char receivei2c();
    void start();
    void stop();
    void rpstart();
    void delay();
    void lcd_cmd();
    void cmd(char , char );
    //void lcd_data(char);
    char arr[ ]="TIME :  :  :  .";
    char arr1[ ]="DATE :  –  –  . ";
    void lcd_con(int );
    void time();
    void date();
    int conv(int i);
    void rtc_write();
    void rtc_read();
    int h,y;
    void main()
    {
    int h,y,D2;
    portconfig();
    ADCON1=0X07;
    lcd_cmd();
    SSPCON=0X38;
    SSPCON2=0X00;
    SSPSTAT=0X80;
    SSPADD=9;
     
    cmd(0X80,0);
    for(h=0;arr[h]!='';h++)
    {
    cmd(arr[h],1);
    }
    cmd(0XC0,0);
    for(h=0;arr1[h]!='';h++)
    {
    cmd(arr1[h],1);
    }
     
    while(1)
    {
    time();
    date();
    //cmd(0X01,0);
    //cmd(0X80,0);
    //rtc_write();
    //rtc_read();
     
    }
    }
    //void rtc_write()
    //{
    //start();
    //sendi2c(0XD0);
    //sendi2c(0X0F);
    //sendi2c('a');
    //stop();
    //}
    //void rtc_read()
    //{
    //start();
    //sendi2c(0xD0);
    //sendi2c(0X0F);
    //rpstart();
    //sendi2c(0xD1);
    //y=receivei2c();
    //stop();
    ////lcd_con(y);
    ////cmd(0x89,0);
    //}
    void portconfig()
    {
    TRISB=0X00;
    TRISE=0X00;
    PORTB=0X00;
    PORTE=0X00;
    TRISD=0;
    PORTD=0;
    TRISC3=1;
    TRISC4=1;
    }
    void lcd_cmd()
    {
    cmd(0x38,0);
    cmd(0x0C,0);
    cmd(0x06,0);
    cmd(0x01,0);
    cmd(0x80,0);
    delay();
    }
     
    void cmd(char d, char e)
    {
    RE0=e;
    RE1=0;
    RE2=1;
    PORTB=d;
    delay();
    RE2=0;
    }
     
    void time()
    {
              //Hours
    start();
    sendi2c(0xD0);
    sendi2c(0x02);
    rpstart();
    sendi2c(0xD1);
    y=receivei2c();
    stop();  
    lcd_con(y);
    cmd(0x86,0); 
     
                 //Minutes
    start();
    sendi2c(0xD0);
    sendi2c(0x01);
    rpstart();
    sendi2c(0xD1);
    y=receivei2c();
    stop();
    lcd_con(y);
    cmd(0x89,0);
     
                 //Seconds
    start();
    sendi2c(0xD0);
     
    rpstart();
    sendi2c(0xD1);
    y=receivei2c();
    stop();
    lcd_con(y);
    cmd(0x8C,0);    
    }
     
    void date()
    {
                  //DATE
    start();
    sendi2c(0xD0);
    sendi2c(0x04);
    //stop();
    rpstart();
    //start();
    sendi2c(0xD1);
    y=receivei2c();
    stop();
    lcd_con(y);
    cmd(0xC6,0);
     
                 //MONTH
    start();
    sendi2c(0xD0);
    sendi2c(0x05);
    rpstart();
    sendi2c(0xD1);
    y=receivei2c();
    stop();
    lcd_con(y);
    cmd(0xC9,0);
     
                  //Year
    start();
    sendi2c(0xD0);
    sendi2c(0x07);
    rpstart();
    sendi2c(0xD1);
    y=receivei2c();
    stop();
    lcd_con(y);
    cmd(0xCC,0);
    }
     
    void lcd_con(int i)
    {
     
    int D1,D2;
    int temp;
    temp=i;
    i=(((temp&0X7F)>>4)*10+(temp&0X0F));
     
    D1=i/10;
    D2=i%10;
     
    cmd(D1+48,1);
    cmd(D2+48,1);
    }
     
    void delay()
    {
    int j;
    for(j=0;j<500;j++);
    }
     
    char receivei2c()
    {
    SSPIF=0;
    RCEN=1;
    char rc;
    while(SSPIF==0);
    SSPIF=0;
    rc=SSPBUF;
    return rc;
    }
     
    void rpstart()
    {
    delay();
    RSEN=1;
    while(!SSPIF);
    SSPIF=0;
    }
     
    void start()
    {
    delay();
    SEN=1;
    while(!SSPIF);
    SSPIF=0;
    }
     
    void sendi2c(char x)
    {
    delay();
    SSPBUF=x;
    while(!SSPIF);
    SSPIF=0;
    }
     
    void stop()
    {
    delay();
    PEN=1;
    while(!SSPIF);
    SSPIF=0;
    }
    August 21, 2015 at 9:44 am #13193
    Prabakaran P M
    Participant

    DS1307 has total 64 bytes of memory area which is divided into two segments:

    1. RTC Register Area
    2. General Purpose RAM
    0x00 Seconds
    0x01 Minutes
    0x02 Hours
    0x03 Day
    0x04 Date
    0x05 Month
    0x06 Year
    0x07 Control
    0x08 
    0x3F
    RAM 
    56 x 8
     

    Each parameters of time is stored in different address thats why we are denoting the address

     

    August 21, 2015 at 10:07 am #13194
    karthick.v
    Participant

    thanks buddy for clearing my doubt and now i have a clear idea in RTC

    August 21, 2015 at 10:31 am #13195
    Prabakaran P M
    Participant

    Feel free to post your doubts

    August 21, 2015 at 10:54 am #13196
    karthick.v
    Participant

    Thanks buddy,I have the following questions

    * In RTC why we are first writing and then reading any reason is there and what is the purpose of giving sendi2c(0x0f) in the above program

    *In I2C master (receiver) & slave (transmitter) mode: what are the register value for both master & slave

    SSPSTAT

    SSPCON1

    SSPCON2

    *which tutorial is best  for reading gps and gsm

    August 21, 2015 at 12:18 pm #13197
    Prabakaran P M
    Participant

    Hi karthick,

     *First we are writting data to fetch the address or commands to the slave i.e first we have to send the address which we have to read and then we will read the data.Two address you have to fetch in I2C one is Slave address and another one is Register address for reading the register data.

    *As far as i go through the datasheet i can't find any way to configure both master and slave mode. you can achieve it by the program logic which will change the register values accordingly.

    *http://www.engineersgarage.com/embedded/pic-microcontroller-projects/interface-gsm-module-call-message-circuit

    http://www.engineersgarage.com/articles/gsm-gprs-modules

    http://www.engineersgarage.com/tutorials/gps-receivers-nmea-standards

    http://www.engineersgarage.com/embedded/avr-microcontroller-projects/gps-interface-circuit

    August 21, 2015 at 1:36 pm #13200
    karthick.v
    Participant

    Sir,

    my previous question was wrong what i ment was  so for  we used to write the data  by master and read the data by slave .Is it possible to read data by master and write data by slave if it is possible means what is register value for SSPSTAT,SSPCON1 and SSPCON2 for both master and slave

      

    August 22, 2015 at 5:50 am #13201
    Prabakaran P M
    Participant

    Hi karthick

    RTC acts as a slave here it is designed to act as a slave to provide data. if you are using two microcontrollers (any) with i2c you can make them two to act as a slave or master according to your requirements. you have to go throught he data sheet of your microcontroller to know the values to be loaded to the special function register.

  • Author
    Posts
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • PIC KIT 3 not able to program dsPIC June 20, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 20, 2025
  • using a RTC in SF basic June 20, 2025
  • Relay buzzing after transformer change? June 20, 2025
  • Back to the old BASIC days June 19, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise