Help me in relay programming

Hi,
I’m a student doing project with pic18f4550, i wanna sense the day and night and switch the relay accordingly.
and im very bad in programming i wrote a basic c programming which is as follows,

#include<string.h>
#include<stdio.h>
int main(void)
{
int load=0;
int batt=0;
int relay=0;
char time[10];
{
   /* Compare two strings without regard to case */
   if (0 == strcmp("night", "day"))
      printf("day\n");
   else
      printf("night\n");
}
b:
if(strcmp(time,"night")==0)
{
a:
do
{
relay=1;
load=1;
printf("charging\n");
}
while(batt!=1);
printf("battery full\n");
relay=0;
//int i=300;
//while(i>0)
//{
//delay 1000;
//printf("battery value\n");
//i--;
//}
goto a;
}
else if(strcmp(time,"day")==0)
{
do
{
load=0;
printf("load off\n");
}
while(batt!=0);
load=1;
printf("low battery\n");
//while(RA4==1)
//printf("battery value\n");
//goto b;
}
}

i have editted could u pls edit my code now…
Could anyone help me in developing this programming accordingly…

Hello. Please use the [ code][/ code] tags (without spaces) to format your code. The first incorrect thing I noticed in your program are these lines:

/* Compare two strings without regard to case */
if (0 == strcmp("night", "day"))

Actually strcmp is case sensitive as far as I know (but I suppose it could be different in your programming environment). Also, on that line you comparing two constant strings so the answer will always be the same: the strings are not equal and strcmp returns a non-zero value.

–David

thanks for ur reply…
according to my project i have a dusk to dawn sensor which senses the dusk or dawn and reports to the microcontroller then the microcontroller controls the system by switching ON/OFF the relay…
what changes should i make in the program to work accordingly…
plsss help me out…

rathee

is there anyone to help me… :frowning: :frowning: :frowning: :frowning: :frowning:

Hello.

Did David’s reply not help? What errors are you getting now?

- Ryan

there is no error but it gives a warning 2066…

Is the warning resulting in a problem for you? Can you please post the full text of your warning?

- Ryan

Is their a reason you’re not doing something like:

if (0 == "night")
{
  printf("Day\n");
}
else
{
  printf("Night\n");
}

Also, I am assuming you’re using Visual Studio?

Hi rathee,

Since you said this is a school project, I can not do your work for you but can give some some suggestions to help you learn.

First list the functional requirements, for example:

When it is day turn on the charger.
When it is night turn the charger off.

Then I might write some puedo code that represents the requirements:

Read lightSensor
If lightSensor is DAY then
set chargerRelay ON
else
set chargerRelay OFF

After this you can translate the puedo code to the implementation language syntax.

Hope this helps,
Mike