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.

help on menu call function and it can't increment while a butten pressed

Status
Not open for further replies.
I am now getting confused with your concept...
According to me the concept is that you are having the RTC and EEPROM.
And there are 4 switch which are being used to set the RTC time.
Now once the RTC time has been set the other requirement is that user can enter the delay time which will be time from now it will make the relay on, and these delay will also enter by the user using the switch...
Once the user entered the delay, add that delay with current RTC time i.e. delay time+RTC time in EEPROM....
Now after that delay time completed you need to turn on the relay....
Now you are able to do that upto these part...
The problem is that you are asking is that when the relay has been turned on and then if the power failure occurs the relay should retrive it previous status before power failure....
So for that problem the solution is that once the relay has been ON, write 1 to EEPROM some location and at the start up of your code just read the value of that particular location in EEPROM, compare it with 1 if it is 1 then put the relay as ON other wise....


I hope I have understood ur concept correctly....
 
Last edited:
yes really thanks Mr Dj
is this code correct , here this code RMN----User set min, RHR----user set hour, del-----user set delay for relay to turn off, min--rtc minute,hrs---rtc hours

if((min==RMN)&&(Hrs==Rhr))
{
output_high(PIN_D3);
write_eeprom(4, 1);
del=read_eeprom(3);
val=RHR+del;
val1=RMN;
}
else if((val==hrs)&&(val1==min))
{
delay_ms(100);
output_low(PIN_D3);
Write_eeprom(4,0);
}
 
Last edited:
what is val and val1...

And I hope these code you are showing me is of, after the delay has been set for turning on the relay....
 
hi dj

this code always turn on the relay

Val is nothing ..its a variable ,Val1 also

val gives the relay on time hour +relay on delay time
val1 is relay on time minute

to compare for relay turn off

give me possible loop .. thanks
 
If I am understanding the concept correctly is it meaning like there would be the delay time entered by the user for turning ON the relay and once the relay has been turned ON, again the user can enter the delay time which is for turning off the relay...
 
Last edited:
user can enter relay on time and relay off time only. here is the code, relwatch is after relay on status value

RHR=read_eeprom(0);
RMN=read_eeprom(1);
relwatch=read_eeprom(4);
if(relwatch==1)
{
output_high(PIN_D3);
}
if(relwatch==0)
{
output_low(PIN_D3);
}
if((min==RMN)&&(Hrs==Rhr))
{
output_high(PIN_D3);
write_eeprom(4, 1);
del=read_eeprom(3);
val=RHR+del;
val1=RMN;
}
if((val==hrs)&&(val1==min))
{
delay_ms(100);
output_low(PIN_D3);
Write_eeprom(4,0);
}
 
if(relwatch==1)
{
output_high(PIN_D3);
}

if(relwatch==0)
{
output_low(PIN_D3);
}
these piece of the above code needs to be check only once when the system or code starts...

and the below part of the code can be checked in while loop...
 
this code is the main while loop, i need a help if i fuse this code into ic the rtc display runs only after 3-4sec (it means if sec is 34 after that it will not show35, it shows 40)
i think too many if statement i used ,is it fault...?
void display()
{

ds1307_get_date(day,month,year,dow);
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,"Date:%02d:%02d:20%02d",day,month,year);
RHR=read_eeprom(0);
RMN=read_eeprom(1);

if((min==RMN)&&(Hrs==Rhr))
{
output_high(PIN_C5);
write_eeprom(4, 1);
del=read_eeprom(3);
val=RHR+del;
val1=RMN;
}
if((val==hrs)&&(val1==min))
{
delay_ms(100);
output_low(PIN_C5);
Write_eeprom(4,0);

set_adc_channel(0);
complt=read_adc();
if(Complt>30)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"\f Process complete ");
output_low(PIN_C1);
}
if(complt<15)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"\f Process in complete ");
output_high(PIN_C1);

}
}

if(output_high(PIN_C5))
{
delay_ms(1000);
output_high(PIN_C6);
delay_ms(5000);
output_high(PIN_C7);
delay_ms(5000);
output_high(PIN_C2);
}
else if(output_low(PIN_C5))
{
output_low(PIN_C6);
output_low(PIN_C7);
output_low(PIN_C2);
}

}}
 
Last edited:
Make the relay OFF over here by default at the start of the code....
In main loop at the start of the code check the EEPROM location 4 only once...
these would be for the power failure...
if (read_eeprom(4)==1)
relay=1
else
relay=0;

void display()
{

ds1307_get_date(day,month,year,dow);
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,"Date:%02d:%02d:20%02d",day,month, year);
RHR=read_eeprom(0);
RMN=read_eeprom(1);

if(switch pressed or some event)
{
Here you need to put the code for entering the delay by the user...
These delay time entered by use would be once only when some has been pressed
or some other takes place fo if loop...

Now from above piece of code you will have the delay time...

relay_on_time_hrs = RHR+delay time hrs.
relay_on_time_mins = RMN+delay time min.
}

if((relay_on_time_mins>=RMN)&&(relay_on_time_hrs>=Rhr))
{
output_high(PIN_C5);
write_eeprom(4, 1);
At these point in time make the value of the relay_on_time_mins and relay_on_time_hrs higher
then 24 if it in 24hrs format or higher then 12 if 12 hrs. format so that it never again will get compared with
RTC time unless and untill new delay time has been entered...
These part would be critical because if you dont set the >24 or >12 then what will happen is that
relay is on again when after 24 hrs the same time reappears..
}

Same above funda will be applicable for the relay_off time as the two blocks of statement...



set_adc_channel(0);
complt=read_adc();
if(Complt>30)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"\f Process complete ");
output_low(PIN_C1);
}
if(complt<15)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"\f Process in complete ");
output_high(PIN_C1);

}
}

if(output_high(PIN_C5))
{
delay_ms(1000);
output_high(PIN_C6);
delay_ms(5000);
output_high(PIN_C7);
delay_ms(5000);
output_high(PIN_C2);
}
else if(output_low(PIN_C5))
{
output_low(PIN_C6);
output_low(PIN_C7);
output_low(PIN_C2);
}

}}
 
how to get loop out from while loop if( min=del) lines to main .....display()....
void display()
{
label:
ds1307_get_date(day,month,year,dow);
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,"Date:%02d:%02d:20%02d",day,month,year);
RHR=read_eeprom(0);
RMN=read_eeprom(1);

if((min==RMN)&&(Hrs==Rhr))
{

while(1)
{

//delay_ms(100);
output_high(PIN_C5);

lcd_gotoxy(1,1);
printf(lcd_putc,"\f system");
lcd_gotoxy(1,2);
printf(lcd_putc,"\ processing.....");

output_high(PIN_C6);
delay_ms(2000);
output_high(PIN_C7);
delay_ms(2000);
output_high(PIN_C2);
delay_ms(1000);
write_eeprom(4, 1);
del=read_eeprom(2);
RHR=read_eeprom(0);
RMN=read_eeprom(1);
// val=RHR+del;
//if(val==24)
//val=0;
//if(val==25)
//val=1;
//if(val==26)
//val=2;
//if(val==27)
//val=3;
//val1=RMN;
ds1307_get_time(hrs,min,sec);

if(min==del)
{
delay_ms(100);
output_low(PIN_C5);
output_low(PIN_C6);
output_low(PIN_C2);
output_low(PIN_C7);
delay_ms(100);
Write_eeprom(4, 0);
printf(lcd_putc,"\f");
break;
}
}
}
if(min==del)
{
while(1)
{

set_adc_channel(0);
complt=read_adc();
delay_ms(100);
if(Complt>30)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"\f Process");
lcd_gotoxy(1,2);
printf(lcd_putc," complete ");
output_low(PIN_C1);
goto label;
}
if(complt<15)
{
lcd_gotoxy(1,1);
printf(lcd_putc,"\f Process ");
lcd_gotoxy(1,2);
printf(lcd_putc," incomplete ");
output_high(PIN_C1);
delay_ms(100);
if(!input(PIN_A2))
{
delay_ms(100);
output_low(PIN_C1);
Write_eeprom(4, 0);
break;

}
}


}

}
 
now i getting loop out

but i can't acess C6 and C7 pin ....why c6 pin always high C7 always zero why ...?
how to disable tx and rx (rs 232 )
 
Make sure that SPEN bit7 in receive status and control register (RCSTA) is 0 to disable the serial port...
 
hi dj good morning

one more doubt how to display 10bit adc value to lcd

lcd_putc(" .........",adc value);.........?

8bit===%03u....
10bit====???
 
PIC 16F877A:
The ADRESH:ADRESL register pair is the location where the 10-bit A/D result is loaded at the completion of the A/D conversion. This register pair is 16 bits wide.The A/D module gives the flexibility to left or right justify the 10-bit result in the 16-bit result register.
So you will have the result which would be by default 10 bits only....
 
thanks dj how to display to lcd

show me the printf function from digital

8bit adc so 255
here 0-0 255*20=5100
how to display 0-5100 value to lcd
a=read_adc(0)
a=a*20;
lcd_putc(" %4_",a);....?here is my question
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top