# [SOLVED]need help in pic18f4550 programming

Status
Not open for further replies.

#### rathee

##### Newbie level 5
hi, i have the following code, the dusk or dawn sensor will sense and give the output to microcontroller and the MC should compare dusk or dawn and switch the relay accordingly... but the program which i wrote is not working and im very bad in programming could anyone pls help me in this case...
Code:
#include "p18f4550.h"
#include "string.h"
#include "stdio.h"
#include "delays.h"
#include "p18cxxx.h"

#define macro
//#define PORTAbits.RB4

void main()
{
int batt=0;
int relay=0;
int i;
char time[10];

/* Compare two strings without regard to case */
if (strcmp("night","day")==0)
printf("day\n");
else
printf("night\n");

b:
if(strcmp(time,"night")==0)
{
a:
do
{
relay=1;
//printf("charging\n");
}
while(batt!=1);
//printf("battery full\n");
relay=0;

i=300;
while(i>0)
{
//delay_ms(1000);
Delay100TCYx(1000);
//printf("battery value\n");
i--;
}
goto a;
}
else if(strcmp(time,"day")==0)
{
do
{
}
while(batt!=0);
//printf("low battery\n");
//while(RA4==1)
//printf("battery value\n");
//goto b;
}

}

Rathee...

#### internetuser2k12

##### Banned
Is it a code taken from the datasheet or application note? Is it Compiling?

#### rathee

##### Newbie level 5
i wrote the code...
its compiling but it gives some warning...

Warning [2066] type qualifier mismatch in assignment...

#### rathee

##### Newbie level 5
oh!!! its so confusing... :-?
im totally lost...

#### internetuser2k12

##### Banned
Can you post the schematic? Are you using ADC? Are you giving the output of LDR to ADC and depending upon the value of ADC, are you trying to switch on/off the relay?

relay, batt, and load are int variables. I don't see any port working. Is your schematic like that shown in the image?

Do you ant something like this. The relay operates if it is dark i.e., adc value less than or equal to 500. If adc value is greater than 500 i.e., if more light is present, relay turns off.

#### Attachments

• ss28.jpg
206.2 KB · Views: 9
• ss29.jpg
262.7 KB · Views: 10
Last edited:

#### numair_noor

##### Member level 2
FOR THE VERY SIMPLE PROGRAMME, YOU CAN USE level triggered mode in microcontroller. take an input from the pin, and when its level goes from low to high you can set timer for 5 seconds and then just make the relay working. by giving the logic one on the output side.
as internetuser2k12 said, you can also use the adc which is the best option for your work as far as i know.

#### rathee

##### Newbie level 5
im not using LDR/LCD, im using inbuilt ADC in pic18f4550, i have uploaded one part of my ckt but are not yet decided...

i want the switch to be turned ON during there the day time...

Last edited:

#### internetuser2k12

##### Banned
In your image it is showing, P3.1, P3.2, etc. It is a 8051/52 uC. Can you draw your circuit in proteus and zip and upload? The LCD i used just to see the adc values. It can be removed. What are you using as sensor for ADC? Ofcourse you are using inbuilt ADC but you have to give analog input from some sensor.

#### rathee

##### Newbie level 5
Thanks to internetuser2k12... :smile:

Status
Not open for further replies.