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.

Weekday alarm in PCF8583

Status
Not open for further replies.

otuzsubat

Member level 4
Joined
Jun 7, 2004
Messages
72
Helped
7
Reputation
14
Reaction score
5
Trophy points
1,288
Location
istanbul, Turkey
Activity points
668
pcf8583 pic

I want to use weekday alarm in PCF8583. For example, i want that it produces an interrupt at every Monday, 13:30. My code is below. Could you say me where is the mistake?

int int2bcd(int dec){
return ((dec/10)<<4)+(dec%10);
}

void rtc_set(){
i2c_start();
i2c_write(0xA2); //send device address
i2c_write(0x00);//send address byte

i2c_write(0x80);//Stop RTC counting
/*************Write actual time ****************/
i2c_write(0x00);//Hundredth of second
i2c_write(0x00);//Seconds
i2c_write(rtc[3]);//Minutes(in BCD format)
i2c_write(rtc[2]);//Hours(in BCD format, 24hour format)
i2c_write(rtc[0]);//Year/Date(in BCD format)
i2c_write(rtc[1]);//Weekday/Month(in BCD format)
i2c_write(0x00);//Disable Timer
/*************Write alarm time ****************/
i2c_write(0xA0);// Alarm Flag, Interrupt, No timer alarm, Weekday alarm
i2c_write(0x00);//Alarm Hundredth of second
i2c_write(0x00);//Alarm Seconds
i2c_write(int2bcd(alarm.minute));//Alarm Minutes
i2c_write(int2bcd(alarm.hour));//Alarm Hours
i2c_write(0x00);//Alarm Date
i2c_write((0x01<<(alarm.day-1)));//Alarm Weekday
i2c_stop();
delay_ms(5);

i2c_start();//start transmission
i2c_write(0x00); //send device address
i2c_write(0x00);//Send address byte
i2c_write(0x04);//Start RTC counting
i2c_stop();
delay_ms(5);
}
 

pcf8583 example

First of all I must say that I am not using PCF8583.

But when I look at your code:
i2c_start();//start transmission
i2c_write(0x00); //send device address
i2c_write(0x00);//Send address byte
i2c_write(0x04);//Start RTC counting
i2c_stop();
delay_ms(5);

I think you should use 0xA2 as the device adress as you used in your previous command.

hope this helps
 

pcf8583

Have a look at : **broken link removed**

Will give you full examples Time, alarm, events using PCF8583. SAR
 

pcf8583 + pic

Cman; I made a typing mistake and corrected it.

SAR; It's nice site. But there is not any example of using weekday alarm.

I have written my problem to Philips. I hope they will help me. Because there isn't enough information in datasheet.
Also, i'm trying different codes to use weekday alarm. When i succeeded, i will write the code here.
 

int2bcd

Before, i was entering alarm and time values by keypad.To be sure that RTC is working, i wrote a simple program.
In this program first, i wrote 23:59:55:00 Monday (i suppose the 000 is Monday, 001 Tuesday..110 Sunday) to RTC.
Then, i wrote 00:00:05:00 Tuesday as alarm time. After, i powered up the PIC it produced an interrupt.
Instead of using external interrupt, you can also use reading alarm flag which is the 1. bit of control register.
Do not forget clearing alarm flag after interrupt produced and connecting a pull-up resistor to the interrupt output of RTC.
Because, it is an open collector output.
#include <18F452.h>
#include <string.h>
#include <stdlib.h>
#fuses HS, PROTECT, NOWDT, NOBROWNOUT, PUT, NOLVP
#use delay (clock=20000000)
#use I2C(MASTER, sda=PIN_C4, scl=PIN_C3,SLOW)
#include<lcd.c>
short int ex_interrupt=0;
#INT_EXT
void EXT_ISR(){
ex_interrupt=1;
}
void main(){
byte temp=0;
enable_interrupts(GLOBAL);
ext_int_edge(H_TO_L);
set_tris_b(0x03);
set_tris_c(0xC0);
set_tris_d(0x08);

i2c_start();
i2c_write(0xA2); //send device address
i2c_write(0x00);//send address byte
//Write to RTC 23:59:55:00 Monday
//alarm time is 00:00:05:00 Tuesday
i2c_write(0x80);//Control Register,Stop counting
i2c_write(0x00);//hund. of seconds
i2c_write(0x55);//Seconds
i2c_write(0x59);//Minutes
i2c_write(0x23);//Hours
i2c_write(0x01);//Year_Date
i2c_write(0x01);//Weekday_Month
i2c_write(0x00);//Timer
i2c_write(0xA0);//Alarm Control Register
i2c_write(0x00);//Alarm hund. of seconds
i2c_write(0x05);//Alarm Seconds
i2c_write(0x00);//Alarm Minutes
i2c_write(0x00);//Alarm Hours
i2c_write(0x00);//Alarm Date has no effect in weekday alarm
i2c_write(0x02);//Alarm Weekday
i2c_stop();
delay_ms(5);

i2c_start();//start counting again
i2c_write(0xA2); //send device address
i2c_write(0x00);//send address byte
i2c_write(0x04);
i2c_stop();
delay_ms(5);

//You can load new alarm values to alarm registers without stop counting
i2c_start();
i2c_write(0xA2); //send device address
i2c_write(0x08);//send address byte
i2c_write(0xA0);//Alarm Control Register
i2c_write(0x00);//Alarm hund. of seconds
i2c_write(0x05);//Alarm Seconds
i2c_write(0x00);//Alarm Minutes
i2c_write(0x00);//Alarm Hours
i2c_write(0x00);//Alarm Date has no effect in weekday alarm
i2c_write(0x02);//Alarm Weekday
i2c_stop();

lcd_init();
lcd_gotoxy(1,1);
delay_ms(10);
enable_interrupts(INT_EXT);//External interrupt must be enable after RTC is set.
while(1){
i2c_start();//Reading alarm flag
i2c_write (0xA2); //send device address
i2c_write(0x00); //send RTC address byte
i2c_start();//again start transmission for reading data
i2c_write(0xA3);//reading address
temp=i2c_read(0);
i2c_stop();
if(bit_test(temp,1)){
lcd_putc("Flag\n");
}
if(ex_interrupt){
lcd_putc("Interrupt\n");
}
if(bit_test(temp,1)||ex_interrupt){
harici_interrupt=0;
lcd_putc("Alarm Ringing");
i2c_start();//After interrupt you must clear alarm flag
i2c_write(0xA2);//device address
i2c_write(0x00);//adress byte
i2c_write(0x04);//control register
i2c_stop();
delay_ms(60000);
}
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top