Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

18F2620 with Isl1208 RTC help

Status
Not open for further replies.

haseeb123

New Member
Hello

I'm using PIC18F2620 internal OSC @ 4MHz and i'm using the
ISL1208 RTC with the PIC.

Simple objective, is to set RTC alarm INT to 1minute reptitive cycle
so that the PIC wakes up via its INT0 after every minute and prints out on
hyper terminal. Sadly nothing seems to be happening. I know my PIC
board is fine cause my flashing LED program works fine on this board and
I also previously tried the DS1307 RTC as well on same baord and it
worked. The reason im using ISL1208 is because of its alarm feature.
The ISL1208 operates at 400kHz where as the DS1307 operates
at 100kHz. Could this be the problem? Im using CCS compiler and
can not seem to change that setting...or do i even need to?

Please can someone help me to achieve this simple program objective.

Below is my test code.

Thanks
Haseeb



Code:
#include <18F2620.h> 
#include <stdio.h>  

#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOPUT, NOPBADEN  
// Set Speed to 4Mhz 
#use delay(clock=4000000) 
// RS232 to Modem 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_B5, STREAM=Modem) 
// RTS232 to User Port 
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_C7, STREAM=User) 
// Configure I2C as Master 
#use i2c(master, sda=PIN_C4 , scl=PIN_C3)  





char clock_sleeping = 1, //flag to tell us that we have woken up from sleeping when the clock is INT (0 = wakeup / 1 = sleep) 

    SC; //dumping the contents of the SC register from ISL1208 



    

//Defining ISRs.... 

#int_ext 
void EXT_ISR (void) 
{    

   //we have woken up from sleep 
   clock_sleeping = 0;       
    
} 






void main(void) 
{ 

   delay_ms(100); //startup delay 

    
   EXT_INT_EDGE(0,H_TO_L);         // Int0 Edge Trigger - high to low transition 
   EXT_INT_EDGE(1,H_TO_L);         // Int1 Edge Trigger - high to low transition 
   enable_interrupts(INT_EXT);      // Enable int0 
   enable_interrupts(INT_EXT1);   // Enable int1     
   enable_interrupts(GLOBAL);      // Enable all interupts 






   //Reseting all RTC registers to 'ZERO'..... 

    i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x00);          // Reset Second (SC) 
    i2c_write(0x00);         // data byte ZERO 
    i2c_stop(); 

   delay_ms(100); //startup delay 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x01);          // Reset Minute (MN) 
    i2c_write(0x00);         // data byte ZERO 
    i2c_stop(); 

   delay_ms(100); //startup delay 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x02);          // Reset Hour (HR) 
    i2c_write(0x00);         // data byte ZERO 
    i2c_stop(); 

   delay_ms(100); //startup delay 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x03);          // Reset date (DT) 
    i2c_write(0x00);         // data byte ZERO 
    i2c_stop(); 
    
   delay_ms(100); //startup delay 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x04);          // Reset Month (MO) 
    i2c_write(0x00);         // data byte ZERO 
    i2c_stop(); 

   delay_ms(100); //startup delay 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x05);          // Reset Year (YR) 
    i2c_write(0x00);         // data byte ZERO 
    i2c_stop(); 
    
   delay_ms(100); //startup delay 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x06);          // Day of the Week (DW) 
    i2c_write(0x00);         // data byte ZERO 
    i2c_stop(); 







   delay_ms(100); //startup delay 







   //Configuring the Interrupt Control Register (IR) 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x08);          // Address of (IR) register 
    i2c_write(0xC0);         // data byte (IM = 1, ALME = 1, LPMODE = 0, FOBATB = 0, FO3 = 0, FO2 = 0, FO1 = 0, FO0 = 0) 
    i2c_stop();                                        





   delay_ms(100); //startup delay 







   //Configuring the Alarm Registers... 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x0C);          // Second register (SCA) 
    i2c_write(0xB0);         // Seconds set to 30, enabled 
    i2c_stop();                                     

    
   delay_ms(100); //startup delay 


   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x0D);          // Minute register (MNA) 
    i2c_write(0x00);         // Minutes disabled 
    i2c_stop();    

    
   delay_ms(100); //startup delay       


   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x0E);          // Hour register (HRA) 
    i2c_write(0x00);         // Hours disabled 
    i2c_stop();    


   delay_ms(100); //startup delay       


   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x0F);          // Date register (DTA) 
    i2c_write(0x00);         // Date disabled 
    i2c_stop();    


   delay_ms(100); //startup delay       


   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x10);          // Month register (MOA) 
    i2c_write(0x00);         // Month disabled 
    i2c_stop();    


   delay_ms(100); //startup delay       


   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x11);          // Day of the Week register (DWA) 
    i2c_write(0x00);         // Day of the Week disabled 
    i2c_stop();    




  



   delay_ms(100); //startup delay 








   //Configuring the Status Register (SR) 

   i2c_start(); 
   i2c_write(0xDE);          // address of the ISL1208 (Write Mode)    
    i2c_write(0x07);          // Address of (SR) register 
    i2c_write(0x90);         // data byte (ARST = 1, XTOSCB = 0, Reserved = 0, WRTC = 1, Reserved = 0, ALM = 0, BAT = 0, RTCF = 0) 
    i2c_stop();                   






   delay_ms(100); //startup delay 






    while(TRUE) 
   { 
             
      sleep(); //goto sleep now... 



      delay_ms(100); //When waking up, delay needed to bring the PIC up to working state 



      if(clock_sleeping == 0) //did we wake up from clock INT?       
      {          

         //Reading the Status Register (SR) to Reset the Alarm bit - (ALM) 

         i2c_start(); 
         i2c_write(0xDF);       // address of the ISL1208 (Read Mode)    
          SC = i2c_read(0x07);   //dumping the contents of the SC register into a dummy variable 
          i2c_stop();       




         fprintf(User,"PIC Woke UP!");   // print to screen 
                


          
         clock_sleeping = 1; //set sleep flag to indicate that we are about to goto sleep again...       
          


      }             



   } 




}
 
Status
Not open for further replies.
Back
Top