|
|
View previous topic :: View next topic |
Author |
Message |
kamillas
Joined: 24 Oct 2011 Posts: 50
|
aide me |
Posted: Fri Nov 04, 2011 1:45 pm |
|
|
I want to add an interruption in my program in Part B for my program returns to Part A , you can aide me please?
#include <16F877A.h>
#device adc=10
#FUSES NOWDT,HS, NOPROTECT,NOLVP, NOWRT
#use delay(clock=20mhz)
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3)
#include "lcd_flex.c"
#include "ds1307.c"
void main()
{
int i ;
byte k ;
byte j ;
byte d;
byte sec;
byte min;
byte hrs;
byte day;
byte month;
byte year;
byte dow;
j=1;
lcd_init(); //initialize lcd
//initialize 1307
ds1307_init();
ds1307_set_date_time(18,12,9,3,12,59,55); //day, month,year,dow,hr,min.sec
while(1)
{
AA:
ds1307_get_date(day,month,year,dow); part A
ds1307_get_time(hrs,min,sec);
lcd_gotoxy(1,1);
printf(lcd_putc,"Time : %02d:%02d:%02d",hrs,min,sec);
lcd_gotoxy(1,2);
printf(lcd_putc,"Data : %02d:%02d:%02d",day,month,year);
delay_ms(1000);
d=hrs;
if ((D==j)&&(min==0)&&(sec==0))
{
BB: for (k=1;k<=j;++k)
{
for (i=1;i<=60;++i)
{
output_high(PIN_b0);
delay_ms(1);
output_low(PIN_b0);
delay_ms(1);
}
delay_ms(1000);
}
j++;
}
if (hrs==12){
j=1;
}
if ((hrs>12)&&(min==0)&&(sec==0))
{
partB
goto BB;
}
}
}
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Nov 04, 2011 2:02 pm |
|
|
It's very hard to figure out what you really are trying to do,perhaps explain in words will help.
One thing is that since C allows long variable names, it will help everyone to use descriptive names not just 'j','k','aa',etc.
Variable names like 'alarm_hours','previous_minutes', 'get_display_RTC_info' instead of 'AA'. will help you see the 'flow' of the program and it's easier to remember what a variable is used for.
Also use the 'Code' option when cut and pasting your program,that will really help ! |
|
|
vortexe9000
Joined: 07 Jun 2010 Posts: 50 Location: Banned - spammer
|
thddf |
Posted: Sat Nov 05, 2011 3:54 am |
|
|
_________________ Banned for spamming his own posts
Last edited by vortexe9000 on Sun Feb 19, 2012 7:49 am; edited 2 times in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sat Nov 05, 2011 4:59 am |
|
|
quick comments...
Ok, I'm Canadian so I know some French..it looks like you want to display a 12 hr clock while the RTC is in 24hr mode.
Are you aware you can set the RTC (DS1307) to 12 hour mode ? It's in the datasheet,simple bitset(bit 6 of register 2) see table 2 on page 8.
It's easy enough to copy the DS1307.c driver to my_ds1307.c driver, make the change, then use this as your driver. Do NOT edit the original driver or you won't have a good 'original' in case you make a typo !
Two comments about the IF(hr.....section)
1) instead of the 12 if statements, reduce to one.
IF( hr=>13 ) {hr=hr-12) }
2) rename the RTC data variables to say rtc_hr,rtc_min,rtc_sec,etc.
the 'modified' hours variable could be new_rtc_hr.
It appears you read the RTC, change the 'hr' to 12 hour format then loop again.Every read of the RTC changes 'hr' to 24 hour data and then you change it to 12 hour.......again, and again and again.....
By naming variables as to what they are or do, it's a lot easier to follow
Also always add 'errors' to the use rs232(....) options.It'll keep the UART hardware 'happy' and your program running. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|