Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] need help in pic18f4550 programming

Status
Not open for further replies.

rathee

Newbie level 5
Joined
Aug 13, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
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 load=0;
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;
load=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
{
load=0;
//printf("load off\n");
}
while(batt!=0);
load=1;
//printf("low battery\n");
//while(RA4==1)
//printf("battery value\n");
//goto b;
}

}

Rathee...
 

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
Is it a code taken from the datasheet or application note? Is it Compiling?
 

rathee

Newbie level 5
Joined
Aug 13, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
i wrote the code...
its compiling but it gives some warning...

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

rathee

Newbie level 5
Joined
Aug 13, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
oh!!! its so confusing... :-?
im totally lost...
 

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
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
    ss28.jpg
    206.2 KB · Views: 12
  • ss29.jpg
    ss29.jpg
    262.7 KB · Views: 13
Last edited:

numair_noor

Member level 2
Joined
Mar 15, 2012
Messages
50
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,715
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
Joined
Aug 13, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
im not using LDR/LCD, im using inbuilt ADC in pic18f4550, i have uploaded one part of my ckt but are not yet decided...
Untitled.png
i want the switch to be turned ON during there the day time...
 
Last edited:

Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Activity points
0
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
Joined
Aug 13, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
where can i download this proteus??? cant find it... :-(
 

rathee

Newbie level 5
Joined
Aug 13, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
Thanks to internetuser2k12... :smile:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top