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.
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…