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.

How to set a alarm for my real tiime clock?

Status
Not open for further replies.
No underscore between "unsigned" and "char". When you crate the new alarm variables, you can set them to the time you want the alarm to activate. So, for example, if you want the alarm to activate the alarm at 4:30, you could do:
Code:
unsigned char alarmHrs = 4;
unsigned char alarmMins = 30;
 
Last edited:
Ya.There is no underscore between 'unsigned' and 'char'.A bit weird why I have type it with underscore.:)So create the new alarm variables in global variable,then proceed to Read RTC function there right?The previous post I wrote for
Code:
alarmMin=uc_i2c_rtc_get_minutes();
alarmHrs=uc_i2c_rtc_get_hours();
is it wrong?After that then write the if else statement for comparing the time?
Code:
if((clkmin==alarmMin) && (clkhrs==alarmHrs))
{
 buzzeron/activatealarm
}
Thanks for your reply.:)
 
Last edited:
now trying to write the code.
Code:
clkmin=uc_i2c_rtc_get_minutes();   //read 1 byte min
clkhrs=uc_i2c_rtc_get_hours();   //read 1 byte hrs
so is it the alarmMin and alarmHrs need to be read as well,for instance:
Code:
alarmMin=uc_i2c_rtc_get_minutes
alarmHrs=uc_i2c_rtc_get_hours
?
 
Last edited:
The functions uc_i2c_get_minutes() and uc_i2c_get_hours() return the current time from the real-time clock. They have nothing to do with setting the alarm time. The alarm time is directly set by assigning a specific numerical value, like I demonstrated in post #21 above.
 
Just now I have try to write the coding.But it can't work.Would you mind to check for me?
Code:
#define buzzer RA4
then the 2 new variables have created.
Code:
unsigned char alarmMin=4;
unsigned char alarmHrs=0;
after that i write the coding in the Read RTC function there.
Code:
if ((clkmin==alarmMin) && clkhrs==alarmHrs))
{
    buzzer=1;
}

is it need put an end behind?I have check it through internet and there is no 'end' stated after the if else statement.Is it anything I do wrong?Hope to see your reply soon.Thanks.
 
Last edited:
Also, with alarmMin=4 and alarmHrs=0, the alarm will activate at 0:04. Is that a valid time? Did you mean 4:00? If so, it should be alarmHrs=4 and alarmMin=0.
 
Rusttree,because the clock is run in 24 hours mode.So I thought when I write alarmMin=4 and alarmHrs=0 the alarm will activate at 00.04 just like 12.04am in 12 hours mode.I will try it again and see.Thanks for the help Rusttree.
 
Rusttree,I have tried just now.I use a green LED to represent the buzzer,when the current time is equal to the alarm time, then the buzzer=1 that's mean the green LED will light up.I set the alarmMin=12 and alarmHrs=12,but the LED does not light up.I have attached the coding here.I have checked the coding and I'm sure that it is right.Can you correct me if I'm doing anything wrong?Thanks.I write it at 'Read RTC function' there.
 

Attachments

  • alarm.c
    14.9 KB · Views: 182
  • 003.JPG
    003.JPG
    1.7 MB · Views: 147
Last edited:
Based on the photograph, it looks like you have your LEDs wired incorrectly:
1) You have the current-limiting resistors wired in parallel with the LEDs instead of in series. That basically renders the resistor completely ineffective and all of the current from the PIC pin is dumping into the LED. This may have damaged the PIC, the LED, or both.
2) Are those 22ohm resistors? That's not enough resistance to properly limit the current through those LEDs. You need to pick a value at least 10 times that.
3) Are you certain you have the green LED in the correct way? Make sure the flat side (cathode) of the LED is on the grounded side.

EDIT: Just realized you're using the resistors as pull-up resistors. So ignore #1 above. #2 is definitely still valid, though. You need more than 22ohms. I don't know if your circuitry for the LEDs is correct, though. Is there a reason you have it that way? Why not just PIC pin->LED->resistor->ground?
 
Last edited:
Rusttree,ya.Those are 220ohm resistors.So I used to change the resistors to 10kohm resistors?Besides,I'm sure I connected the LED in a correct way.The cathode (shorter leg) is on the grounded side.Is it there is the different I connected the resistor on anode and cathode?I thought they are the same if I placed it either anode or cathode.I have tested the green LED before,when I give it 5V,it can light up as well.
 
Last edited:
They look like 22 ohm resistors, not 220. It could be bad coloring from the camera, but the third stripe on those two resistors looks black, not brown. But if you're sure those are 220 ohm resistors, then you're good.

Anyway, I still think you're wiring is a little hokey on those LEDs. The PIC pin, LED, and resistor should all be in series with each other. And no, it doesn't matter which side the resistor is on, as long as everything is in series. You're correct that the shorter leg is typically the cathode, but don't trust that. You don't know if that leg got cut at an earlier time. Use the flattened side of the plastic to determine which side is the cathode.
 
Rusttree,I'm sure that the green LED I'd connected in a series way...the red wire is connected to pic RA4 and the brown wire is ground..the resistor is direct connect to VCC...so it is VCC goes to resistor then PIC then anode then out from cathode and goes to ground..and the green LED got light up..so I think the LED is works.Am I right?Is it the coding problem?
 
The LED, resistor, and ground are in series. The PIC pin is not. The wiring you have now is not correct. When RA4 is high, current will flow directly from RA4, into the LED, and into ground. That will probably cause the PIC pin to over-current and break. When RA4 is low, current will flow through the resistor into RA4 AND the LED. In both cases, you've got problems.

For both LEDs, please re-wire them as follows:
PIC pin --- LED --- resistor --- ground
 
Ya Rusttree.I finally got what you mean.:).But I have tried already,it is still the same.The green LED does not light up when the time is 12:12.Is it the coding problem?Thanks for the help Rusttree.The coding I got post it at post #31.
 

Attachments

  • 010.JPG
    010.JPG
    1.5 MB · Views: 131
Last edited:
Let's assume the green LED is broken. Take it out and just probe the wire coming off RA4 with a multimeter. You should see it jump from 0V to VDD when the alarm activates.

If it doesn't, there's a chance the RA4 pin is bad because of the wiring you had before. Try using a different I/O pin.
 
The green LED is not broken because I have test it by giving it current.It does light up.Besides,I have change the pin to RD0,but it still the same...the LED does not light up.
 
Last edited:
When you tried RD0, did you clear the appropriate TRISD bit? And possibly the ANSEL bit too (if it's an analog pin)?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top